mirror of
git://git.suckless.org/dwm
synced 2025-04-20 03:24:46 +01:00
Compare commits
No commits in common. "master" and "0.1" have entirely different histories.
19
LICENSE
19
LICENSE
@ -1,23 +1,6 @@
|
|||||||
MIT/X Consortium License
|
MIT/X Consortium License
|
||||||
|
|
||||||
© 2006-2019 Anselm R Garbe <anselm@garbe.ca>
|
(C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
© 2006-2009 Jukka Salmi <jukka at salmi dot ch>
|
|
||||||
© 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
|
|
||||||
© 2007-2011 Peter Hartlich <sgkkr at hartlich dot com>
|
|
||||||
© 2007-2009 Szabolcs Nagy <nszabolcs at gmail dot com>
|
|
||||||
© 2007-2009 Christof Musik <christof at sendfax dot de>
|
|
||||||
© 2007-2009 Premysl Hruby <dfenze at gmail dot com>
|
|
||||||
© 2007-2008 Enno Gottox Boland <gottox at s01 dot de>
|
|
||||||
© 2008 Martin Hurton <martin dot hurton at gmail dot com>
|
|
||||||
© 2008 Neale Pickett <neale dot woozle dot org>
|
|
||||||
© 2009 Mate Nagy <mnagy at port70 dot net>
|
|
||||||
© 2010-2016 Hiltjo Posthuma <hiltjo@codemadness.org>
|
|
||||||
© 2010-2012 Connor Lane Smith <cls@lubutu.com>
|
|
||||||
© 2011 Christoph Lohmann <20h@r-36.net>
|
|
||||||
© 2015-2016 Quentin Rameau <quinq@fifth.space>
|
|
||||||
© 2015-2016 Eric Pruitt <eric.pruitt@gmail.com>
|
|
||||||
© 2016-2017 Markus Teich <markus.teich@stusta.mhn.de>
|
|
||||||
© 2020-2022 Chris Down <chris@chrisdown.name>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
copy of this software and associated documentation files (the "Software"),
|
copy of this software and associated documentation files (the "Software"),
|
||||||
|
54
Makefile
54
Makefile
@ -1,45 +1,55 @@
|
|||||||
# dwm - dynamic window manager
|
# dwm - dynamic window manager
|
||||||
# See LICENSE file for copyright and license details.
|
# (C)opyright MMVI Anselm R. Garbe
|
||||||
|
|
||||||
include config.mk
|
include config.mk
|
||||||
|
|
||||||
SRC = drw.c dwm.c util.c
|
SRC = bar.c client.c dev.c draw.c event.c main.c util.c
|
||||||
OBJ = ${SRC:.c=.o}
|
OBJ = ${SRC:.c=.o}
|
||||||
|
MAN1 = dwm.1
|
||||||
|
BIN = dwm
|
||||||
|
|
||||||
all: dwm
|
all: config dwm
|
||||||
|
@echo finished
|
||||||
|
|
||||||
|
config:
|
||||||
|
@echo dwm build options:
|
||||||
|
@echo "LIBS = ${LIBS}"
|
||||||
|
@echo "CFLAGS = ${CFLAGS}"
|
||||||
|
@echo "LDFLAGS = ${LDFLAGS}"
|
||||||
|
@echo "CC = ${CC}"
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
${CC} -c ${CFLAGS} $<
|
@echo CC $<
|
||||||
|
@${CC} -c ${CFLAGS} $<
|
||||||
|
|
||||||
${OBJ}: config.h config.mk
|
${OBJ}: dwm.h
|
||||||
|
|
||||||
config.h:
|
|
||||||
cp config.def.h $@
|
|
||||||
|
|
||||||
dwm: ${OBJ}
|
dwm: ${OBJ}
|
||||||
${CC} -o $@ ${OBJ} ${LDFLAGS}
|
@echo LD $@
|
||||||
|
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz
|
rm -f dwm *.o core
|
||||||
|
|
||||||
dist: clean
|
dist: clean
|
||||||
mkdir -p dwm-${VERSION}
|
mkdir -p dwm-${VERSION}
|
||||||
cp -R LICENSE Makefile README config.def.h config.mk\
|
cp -R Makefile README LICENSE config.mk *.h *.c ${MAN1} dwm-${VERSION}
|
||||||
dwm.1 drw.h util.h ${SRC} dwm.png transient.c dwm-${VERSION}
|
|
||||||
tar -cf dwm-${VERSION}.tar dwm-${VERSION}
|
tar -cf dwm-${VERSION}.tar dwm-${VERSION}
|
||||||
gzip dwm-${VERSION}.tar
|
gzip dwm-${VERSION}.tar
|
||||||
rm -rf dwm-${VERSION}
|
rm -rf dwm-${VERSION}
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
mkdir -p ${DESTDIR}${PREFIX}/bin
|
@mkdir -p ${DESTDIR}${PREFIX}/bin
|
||||||
cp -f dwm ${DESTDIR}${PREFIX}/bin
|
@cp -f ${BIN} ${DESTDIR}${PREFIX}/bin
|
||||||
chmod 755 ${DESTDIR}${PREFIX}/bin/dwm
|
@echo installed executable files to ${DESTDIR}${PREFIX}/bin
|
||||||
mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
||||||
sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1
|
@cp -f ${MAN1} ${DESTDIR}${MANPREFIX}/man1
|
||||||
chmod 644 ${DESTDIR}${MANPREFIX}/man1/dwm.1
|
@echo installed manual pages to ${DESTDIR}${MANPREFIX}/man1
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f ${DESTDIR}${PREFIX}/bin/dwm\
|
for i in ${BIN}; do \
|
||||||
${DESTDIR}${MANPREFIX}/man1/dwm.1
|
rm -f ${DESTDIR}${PREFIX}/bin/`basename $$i`; \
|
||||||
|
done
|
||||||
.PHONY: all clean dist install uninstall
|
for i in ${MAN1}; do \
|
||||||
|
rm -f ${DESTDIR}${MANPREFIX}/man1/`basename $$i`; \
|
||||||
|
done
|
||||||
|
24
README
24
README
@ -1,6 +1,7 @@
|
|||||||
dwm - dynamic window manager
|
dwm - dynamic window manager
|
||||||
============================
|
----------------------------
|
||||||
dwm is an extremely fast, small, and dynamic window manager for X.
|
|
||||||
|
dwm is an extremly fast, small, and dynamic X11 window manager.
|
||||||
|
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
@ -10,8 +11,8 @@ In order to build dwm you need the Xlib header files.
|
|||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
Edit config.mk to match your local setup (dwm is installed into
|
Edit config.mk to match your local setup. dwm is installed into
|
||||||
the /usr/local namespace by default).
|
the /usr/local namespace by default.
|
||||||
|
|
||||||
Afterwards enter the following command to build and install dwm (if
|
Afterwards enter the following command to build and install dwm (if
|
||||||
necessary as root):
|
necessary as root):
|
||||||
@ -30,19 +31,10 @@ the DISPLAY environment variable is set correctly, e.g.:
|
|||||||
|
|
||||||
DISPLAY=foo.bar:1 exec dwm
|
DISPLAY=foo.bar:1 exec dwm
|
||||||
|
|
||||||
(This will start dwm on display :1 of the host foo.bar.)
|
This will start dwm on display :1 of the host foo.bar.
|
||||||
|
|
||||||
In order to display status info in the bar, you can do something
|
|
||||||
like this in your .xinitrc:
|
|
||||||
|
|
||||||
while xsetroot -name "`date` `uptime | sed 's/.*,//'`"
|
|
||||||
do
|
|
||||||
sleep 1
|
|
||||||
done &
|
|
||||||
exec dwm
|
|
||||||
|
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
-------------
|
-------------
|
||||||
The configuration of dwm is done by creating a custom config.h
|
The configuration of dwm is done by customizing the wm.h source file. To
|
||||||
and (re)compiling the source code.
|
customize the key bindings edit dev.c.
|
||||||
|
1
TODO
Normal file
1
TODO
Normal file
@ -0,0 +1 @@
|
|||||||
|
- improve mouse based resizals with quadrant approach (then I think we have feature completeness already)
|
46
bar.c
Normal file
46
bar.c
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
|
* See LICENSE file for license details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dwm.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
barclick(XButtonPressedEvent *e)
|
||||||
|
{
|
||||||
|
int x = 0;
|
||||||
|
Arg a;
|
||||||
|
for(a.i = 0; a.i < TLast; a.i++) {
|
||||||
|
x += textw(tags[a.i]) + dc.font.height;
|
||||||
|
if(e->x < x) {
|
||||||
|
view(&a);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
draw_bar()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
dc.x = dc.y = 0;
|
||||||
|
dc.w = bw;
|
||||||
|
drawtext(NULL, False, False);
|
||||||
|
|
||||||
|
dc.w = 0;
|
||||||
|
for(i = 0; i < TLast; i++) {
|
||||||
|
dc.x += dc.w;
|
||||||
|
dc.w = textw(tags[i]) + dc.font.height;
|
||||||
|
drawtext(tags[i], i == tsel, True);
|
||||||
|
}
|
||||||
|
if(sel) {
|
||||||
|
dc.x += dc.w;
|
||||||
|
dc.w = textw(sel->name) + dc.font.height;
|
||||||
|
drawtext(sel->name, True, True);
|
||||||
|
}
|
||||||
|
dc.w = textw(stext) + dc.font.height;
|
||||||
|
dc.x = bx + bw - dc.w;
|
||||||
|
drawtext(stext, False, False);
|
||||||
|
XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
|
||||||
|
XFlush(dpy);
|
||||||
|
}
|
616
client.c
Normal file
616
client.c
Normal file
@ -0,0 +1,616 @@
|
|||||||
|
/*
|
||||||
|
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
|
* See LICENSE file for license details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <X11/Xatom.h>
|
||||||
|
#include <X11/Xutil.h>
|
||||||
|
|
||||||
|
#include "dwm.h"
|
||||||
|
|
||||||
|
void (*arrange)(Arg *) = tiling;
|
||||||
|
|
||||||
|
static Rule rule[] = {
|
||||||
|
/* class instance tags floating */
|
||||||
|
{ "Firefox-bin", "Gecko", { [Twww] = "www" }, False },
|
||||||
|
};
|
||||||
|
|
||||||
|
static Client *
|
||||||
|
next(Client *c)
|
||||||
|
{
|
||||||
|
for(; c && !c->tags[tsel]; c = c->next);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
zoom(Arg *arg)
|
||||||
|
{
|
||||||
|
Client **l, *c;
|
||||||
|
|
||||||
|
if(!sel)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(sel == next(clients) && sel->next) {
|
||||||
|
if((c = next(sel->next)))
|
||||||
|
sel = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(l = &clients; *l && *l != sel; l = &(*l)->next);
|
||||||
|
*l = sel->next;
|
||||||
|
|
||||||
|
sel->next = clients; /* pop */
|
||||||
|
clients = sel;
|
||||||
|
arrange(NULL);
|
||||||
|
focus(sel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
max(Arg *arg)
|
||||||
|
{
|
||||||
|
if(!sel)
|
||||||
|
return;
|
||||||
|
sel->x = sx;
|
||||||
|
sel->y = sy + bh;
|
||||||
|
sel->w = sw - 2 * sel->border;
|
||||||
|
sel->h = sh - 2 * sel->border - bh;
|
||||||
|
craise(sel);
|
||||||
|
resize(sel, False);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
view(Arg *arg)
|
||||||
|
{
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
tsel = arg->i;
|
||||||
|
arrange(NULL);
|
||||||
|
|
||||||
|
for(c = clients; c; c = next(c->next))
|
||||||
|
draw_client(c);
|
||||||
|
draw_bar();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tappend(Arg *arg)
|
||||||
|
{
|
||||||
|
if(!sel)
|
||||||
|
return;
|
||||||
|
|
||||||
|
sel->tags[arg->i] = tags[arg->i];
|
||||||
|
arrange(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ttrunc(Arg *arg)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
if(!sel)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(i = 0; i < TLast; i++)
|
||||||
|
sel->tags[i] = NULL;
|
||||||
|
tappend(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ban_client(Client *c)
|
||||||
|
{
|
||||||
|
XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
|
||||||
|
XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
floating(Arg *arg)
|
||||||
|
{
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
arrange = floating;
|
||||||
|
for(c = clients; c; c = c->next) {
|
||||||
|
if(c->tags[tsel])
|
||||||
|
resize(c, True);
|
||||||
|
else
|
||||||
|
ban_client(c);
|
||||||
|
}
|
||||||
|
if(sel && !sel->tags[tsel]) {
|
||||||
|
if((sel = next(clients))) {
|
||||||
|
craise(sel);
|
||||||
|
focus(sel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tiling(Arg *arg)
|
||||||
|
{
|
||||||
|
Client *c;
|
||||||
|
int n, i, w, h;
|
||||||
|
|
||||||
|
w = sw - mw;
|
||||||
|
arrange = tiling;
|
||||||
|
for(n = 0, c = clients; c; c = c->next)
|
||||||
|
if(c->tags[tsel] && !c->floating)
|
||||||
|
n++;
|
||||||
|
|
||||||
|
if(n > 1)
|
||||||
|
h = (sh - bh) / (n - 1);
|
||||||
|
else
|
||||||
|
h = sh - bh;
|
||||||
|
|
||||||
|
for(i = 0, c = clients; c; c = c->next) {
|
||||||
|
if(c->tags[tsel]) {
|
||||||
|
if(c->floating) {
|
||||||
|
craise(c);
|
||||||
|
resize(c, True);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(n == 1) {
|
||||||
|
c->x = sx;
|
||||||
|
c->y = sy + bh;
|
||||||
|
c->w = sw - 2 * c->border;
|
||||||
|
c->h = sh - 2 * c->border - bh;
|
||||||
|
}
|
||||||
|
else if(i == 0) {
|
||||||
|
c->x = sx;
|
||||||
|
c->y = sy + bh;
|
||||||
|
c->w = mw - 2 * c->border;
|
||||||
|
c->h = sh - 2 * c->border - bh;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
c->x = sx + mw;
|
||||||
|
c->y = sy + (i - 1) * h + bh;
|
||||||
|
c->w = w - 2 * c->border;
|
||||||
|
c->h = h - 2 * c->border;
|
||||||
|
}
|
||||||
|
resize(c, False);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ban_client(c);
|
||||||
|
}
|
||||||
|
if(!sel || (sel && !sel->tags[tsel])) {
|
||||||
|
if((sel = next(clients))) {
|
||||||
|
craise(sel);
|
||||||
|
focus(sel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
prevc(Arg *arg)
|
||||||
|
{
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
if(!sel)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
|
||||||
|
craise(c);
|
||||||
|
focus(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nextc(Arg *arg)
|
||||||
|
{
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
if(!sel)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!(c = next(sel->next)))
|
||||||
|
c = next(clients);
|
||||||
|
if(c) {
|
||||||
|
craise(c);
|
||||||
|
c->revert = sel;
|
||||||
|
focus(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ckill(Arg *arg)
|
||||||
|
{
|
||||||
|
if(!sel)
|
||||||
|
return;
|
||||||
|
if(sel->proto & WM_PROTOCOL_DELWIN)
|
||||||
|
send_message(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
|
||||||
|
else
|
||||||
|
XKillClient(dpy, sel->win);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
resize_title(Client *c)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
c->tw = 0;
|
||||||
|
for(i = 0; i < TLast; i++)
|
||||||
|
if(c->tags[i])
|
||||||
|
c->tw += textw(c->tags[i]) + dc.font.height;
|
||||||
|
c->tw += textw(c->name) + dc.font.height;
|
||||||
|
if(c->tw > c->w)
|
||||||
|
c->tw = c->w + 2;
|
||||||
|
c->tx = c->x + c->w - c->tw + 2;
|
||||||
|
c->ty = c->y;
|
||||||
|
XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
update_name(Client *c)
|
||||||
|
{
|
||||||
|
XTextProperty name;
|
||||||
|
int n;
|
||||||
|
char **list = NULL;
|
||||||
|
|
||||||
|
name.nitems = 0;
|
||||||
|
c->name[0] = 0;
|
||||||
|
XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
|
||||||
|
if(!name.nitems)
|
||||||
|
XGetWMName(dpy, c->win, &name);
|
||||||
|
if(!name.nitems)
|
||||||
|
return;
|
||||||
|
if(name.encoding == XA_STRING)
|
||||||
|
strncpy(c->name, (char *)name.value, sizeof(c->name));
|
||||||
|
else {
|
||||||
|
if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
|
||||||
|
&& n > 0 && *list)
|
||||||
|
{
|
||||||
|
strncpy(c->name, *list, sizeof(c->name));
|
||||||
|
XFreeStringList(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
XFree(name.value);
|
||||||
|
resize_title(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
update_size(Client *c)
|
||||||
|
{
|
||||||
|
XSizeHints size;
|
||||||
|
long msize;
|
||||||
|
if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
|
||||||
|
size.flags = PSize;
|
||||||
|
c->flags = size.flags;
|
||||||
|
if(c->flags & PBaseSize) {
|
||||||
|
c->basew = size.base_width;
|
||||||
|
c->baseh = size.base_height;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
c->basew = c->baseh = 0;
|
||||||
|
if(c->flags & PResizeInc) {
|
||||||
|
c->incw = size.width_inc;
|
||||||
|
c->inch = size.height_inc;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
c->incw = c->inch = 0;
|
||||||
|
if(c->flags & PMaxSize) {
|
||||||
|
c->maxw = size.max_width;
|
||||||
|
c->maxh = size.max_height;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
c->maxw = c->maxh = 0;
|
||||||
|
if(c->flags & PMinSize) {
|
||||||
|
c->minw = size.min_width;
|
||||||
|
c->minh = size.min_height;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
c->minw = c->minh = 0;
|
||||||
|
if(c->flags & PWinGravity)
|
||||||
|
c->grav = size.win_gravity;
|
||||||
|
else
|
||||||
|
c->grav = NorthWestGravity;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
craise(Client *c)
|
||||||
|
{
|
||||||
|
XRaiseWindow(dpy, c->win);
|
||||||
|
XRaiseWindow(dpy, c->title);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
lower(Client *c)
|
||||||
|
{
|
||||||
|
XLowerWindow(dpy, c->title);
|
||||||
|
XLowerWindow(dpy, c->win);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
focus(Client *c)
|
||||||
|
{
|
||||||
|
Client *old = sel;
|
||||||
|
XEvent ev;
|
||||||
|
|
||||||
|
XFlush(dpy);
|
||||||
|
sel = c;
|
||||||
|
if(old && old != c)
|
||||||
|
draw_client(old);
|
||||||
|
draw_client(c);
|
||||||
|
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
|
||||||
|
XFlush(dpy);
|
||||||
|
while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
init_tags(Client *c)
|
||||||
|
{
|
||||||
|
XClassHint ch;
|
||||||
|
static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
|
||||||
|
unsigned int i, j;
|
||||||
|
Bool matched = False;
|
||||||
|
|
||||||
|
if(!len) {
|
||||||
|
c->tags[tsel] = tags[tsel];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(XGetClassHint(dpy, c->win, &ch)) {
|
||||||
|
if(ch.res_class && ch.res_name) {
|
||||||
|
for(i = 0; i < len; i++)
|
||||||
|
if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
|
||||||
|
&& !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
|
||||||
|
{
|
||||||
|
for(j = 0; j < TLast; j++)
|
||||||
|
c->tags[j] = rule[i].tags[j];
|
||||||
|
c->floating = rule[i].floating;
|
||||||
|
matched = True;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(ch.res_class)
|
||||||
|
XFree(ch.res_class);
|
||||||
|
if(ch.res_name)
|
||||||
|
XFree(ch.res_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!matched)
|
||||||
|
c->tags[tsel] = tags[tsel];
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
manage(Window w, XWindowAttributes *wa)
|
||||||
|
{
|
||||||
|
Client *c, **l;
|
||||||
|
XSetWindowAttributes twa;
|
||||||
|
Window trans;
|
||||||
|
|
||||||
|
c = emallocz(sizeof(Client));
|
||||||
|
c->win = w;
|
||||||
|
c->tx = c->x = wa->x;
|
||||||
|
c->ty = c->y = wa->y;
|
||||||
|
if(c->y < bh)
|
||||||
|
c->ty = c->y += bh;
|
||||||
|
c->tw = c->w = wa->width;
|
||||||
|
c->h = wa->height;
|
||||||
|
c->th = bh;
|
||||||
|
c->border = 1;
|
||||||
|
c->proto = win_proto(c->win);
|
||||||
|
update_size(c);
|
||||||
|
XSelectInput(dpy, c->win,
|
||||||
|
StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
|
||||||
|
XGetTransientForHint(dpy, c->win, &trans);
|
||||||
|
twa.override_redirect = 1;
|
||||||
|
twa.background_pixmap = ParentRelative;
|
||||||
|
twa.event_mask = ExposureMask;
|
||||||
|
|
||||||
|
c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
|
||||||
|
0, DefaultDepth(dpy, screen), CopyFromParent,
|
||||||
|
DefaultVisual(dpy, screen),
|
||||||
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
|
||||||
|
|
||||||
|
update_name(c);
|
||||||
|
init_tags(c);
|
||||||
|
|
||||||
|
for(l = &clients; *l; l = &(*l)->next);
|
||||||
|
c->next = *l; /* *l == nil */
|
||||||
|
*l = c;
|
||||||
|
|
||||||
|
XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
|
||||||
|
GrabModeAsync, GrabModeSync, None, None);
|
||||||
|
XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
|
||||||
|
GrabModeAsync, GrabModeSync, None, None);
|
||||||
|
XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
|
||||||
|
GrabModeAsync, GrabModeSync, None, None);
|
||||||
|
|
||||||
|
if(!c->floating)
|
||||||
|
c->floating = trans
|
||||||
|
|| ((c->maxw == c->minw) && (c->maxh == c->minh));
|
||||||
|
|
||||||
|
arrange(NULL);
|
||||||
|
/* mapping the window now prevents flicker */
|
||||||
|
if(c->tags[tsel]) {
|
||||||
|
XMapRaised(dpy, c->win);
|
||||||
|
XMapRaised(dpy, c->title);
|
||||||
|
focus(c);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ban_client(c);
|
||||||
|
XMapRaised(dpy, c->win);
|
||||||
|
XMapRaised(dpy, c->title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gravitate(Client *c, Bool invert)
|
||||||
|
{
|
||||||
|
int dx = 0, dy = 0;
|
||||||
|
|
||||||
|
switch(c->grav) {
|
||||||
|
case StaticGravity:
|
||||||
|
case NorthWestGravity:
|
||||||
|
case NorthGravity:
|
||||||
|
case NorthEastGravity:
|
||||||
|
dy = c->border;
|
||||||
|
break;
|
||||||
|
case EastGravity:
|
||||||
|
case CenterGravity:
|
||||||
|
case WestGravity:
|
||||||
|
dy = -(c->h / 2) + c->border;
|
||||||
|
break;
|
||||||
|
case SouthEastGravity:
|
||||||
|
case SouthGravity:
|
||||||
|
case SouthWestGravity:
|
||||||
|
dy = -c->h;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (c->grav) {
|
||||||
|
case StaticGravity:
|
||||||
|
case NorthWestGravity:
|
||||||
|
case WestGravity:
|
||||||
|
case SouthWestGravity:
|
||||||
|
dx = c->border;
|
||||||
|
break;
|
||||||
|
case NorthGravity:
|
||||||
|
case CenterGravity:
|
||||||
|
case SouthGravity:
|
||||||
|
dx = -(c->w / 2) + c->border;
|
||||||
|
break;
|
||||||
|
case NorthEastGravity:
|
||||||
|
case EastGravity:
|
||||||
|
case SouthEastGravity:
|
||||||
|
dx = -(c->w + c->border);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(invert) {
|
||||||
|
dx = -dx;
|
||||||
|
dy = -dy;
|
||||||
|
}
|
||||||
|
c->x += dx;
|
||||||
|
c->y += dy;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
resize(Client *c, Bool inc)
|
||||||
|
{
|
||||||
|
XConfigureEvent e;
|
||||||
|
|
||||||
|
if(inc) {
|
||||||
|
if(c->incw)
|
||||||
|
c->w -= (c->w - c->basew) % c->incw;
|
||||||
|
if(c->inch)
|
||||||
|
c->h -= (c->h - c->baseh) % c->inch;
|
||||||
|
}
|
||||||
|
if(c->x > sw) /* might happen on restart */
|
||||||
|
c->x = sw - c->w;
|
||||||
|
if(c->y > sh)
|
||||||
|
c->ty = c->y = sh - c->h;
|
||||||
|
if(c->minw && c->w < c->minw)
|
||||||
|
c->w = c->minw;
|
||||||
|
if(c->minh && c->h < c->minh)
|
||||||
|
c->h = c->minh;
|
||||||
|
if(c->maxw && c->w > c->maxw)
|
||||||
|
c->w = c->maxw;
|
||||||
|
if(c->maxh && c->h > c->maxh)
|
||||||
|
c->h = c->maxh;
|
||||||
|
resize_title(c);
|
||||||
|
XSetWindowBorderWidth(dpy, c->win, 1);
|
||||||
|
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
|
||||||
|
e.type = ConfigureNotify;
|
||||||
|
e.event = c->win;
|
||||||
|
e.window = c->win;
|
||||||
|
e.x = c->x;
|
||||||
|
e.y = c->y;
|
||||||
|
e.width = c->w;
|
||||||
|
e.height = c->h;
|
||||||
|
e.border_width = c->border;
|
||||||
|
e.above = None;
|
||||||
|
e.override_redirect = False;
|
||||||
|
XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
|
||||||
|
XFlush(dpy);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
dummy_error_handler(Display *dsply, XErrorEvent *err)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
unmanage(Client *c)
|
||||||
|
{
|
||||||
|
Client **l;
|
||||||
|
|
||||||
|
XGrabServer(dpy);
|
||||||
|
XSetErrorHandler(dummy_error_handler);
|
||||||
|
|
||||||
|
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
|
||||||
|
XDestroyWindow(dpy, c->title);
|
||||||
|
|
||||||
|
for(l = &clients; *l && *l != c; l = &(*l)->next);
|
||||||
|
*l = c->next;
|
||||||
|
for(l = &clients; *l; l = &(*l)->next)
|
||||||
|
if((*l)->revert == c)
|
||||||
|
(*l)->revert = NULL;
|
||||||
|
if(sel == c)
|
||||||
|
sel = sel->revert ? sel->revert : clients;
|
||||||
|
|
||||||
|
free(c);
|
||||||
|
|
||||||
|
XFlush(dpy);
|
||||||
|
XSetErrorHandler(error_handler);
|
||||||
|
XUngrabServer(dpy);
|
||||||
|
arrange(NULL);
|
||||||
|
if(sel)
|
||||||
|
focus(sel);
|
||||||
|
}
|
||||||
|
|
||||||
|
Client *
|
||||||
|
gettitle(Window w)
|
||||||
|
{
|
||||||
|
Client *c;
|
||||||
|
for(c = clients; c; c = c->next)
|
||||||
|
if(c->title == w)
|
||||||
|
return c;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Client *
|
||||||
|
getclient(Window w)
|
||||||
|
{
|
||||||
|
Client *c;
|
||||||
|
for(c = clients; c; c = c->next)
|
||||||
|
if(c->win == w)
|
||||||
|
return c;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
draw_client(Client *c)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
if(c == sel) {
|
||||||
|
draw_bar();
|
||||||
|
XUnmapWindow(dpy, c->title);
|
||||||
|
XSetWindowBorder(dpy, c->win, dc.fg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
XSetWindowBorder(dpy, c->win, dc.bg);
|
||||||
|
XMapWindow(dpy, c->title);
|
||||||
|
|
||||||
|
dc.x = dc.y = 0;
|
||||||
|
|
||||||
|
dc.w = 0;
|
||||||
|
for(i = 0; i < TLast; i++) {
|
||||||
|
if(c->tags[i]) {
|
||||||
|
dc.x += dc.w;
|
||||||
|
dc.w = textw(c->tags[i]) + dc.font.height;
|
||||||
|
drawtext(c->tags[i], False, True);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dc.x += dc.w;
|
||||||
|
dc.w = textw(c->name) + dc.font.height;
|
||||||
|
drawtext(c->name, False, True);
|
||||||
|
XCopyArea(dpy, dc.drawable, c->title, dc.gc,
|
||||||
|
0, 0, c->tw, c->th, 0, 0);
|
||||||
|
XFlush(dpy);
|
||||||
|
}
|
116
config.def.h
116
config.def.h
@ -1,116 +0,0 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
|
||||||
|
|
||||||
/* appearance */
|
|
||||||
static const unsigned int borderpx = 1; /* border pixel of windows */
|
|
||||||
static const unsigned int snap = 32; /* snap pixel */
|
|
||||||
static const int showbar = 1; /* 0 means no bar */
|
|
||||||
static const int topbar = 1; /* 0 means bottom bar */
|
|
||||||
static const char *fonts[] = { "monospace:size=10" };
|
|
||||||
static const char dmenufont[] = "monospace:size=10";
|
|
||||||
static const char col_gray1[] = "#222222";
|
|
||||||
static const char col_gray2[] = "#444444";
|
|
||||||
static const char col_gray3[] = "#bbbbbb";
|
|
||||||
static const char col_gray4[] = "#eeeeee";
|
|
||||||
static const char col_cyan[] = "#005577";
|
|
||||||
static const char *colors[][3] = {
|
|
||||||
/* fg bg border */
|
|
||||||
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
|
|
||||||
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
|
|
||||||
};
|
|
||||||
|
|
||||||
/* tagging */
|
|
||||||
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
|
||||||
|
|
||||||
static const Rule rules[] = {
|
|
||||||
/* xprop(1):
|
|
||||||
* WM_CLASS(STRING) = instance, class
|
|
||||||
* WM_NAME(STRING) = title
|
|
||||||
*/
|
|
||||||
/* class instance title tags mask isfloating monitor */
|
|
||||||
{ "Gimp", NULL, NULL, 0, 1, -1 },
|
|
||||||
{ "Firefox", NULL, NULL, 1 << 8, 0, -1 },
|
|
||||||
};
|
|
||||||
|
|
||||||
/* layout(s) */
|
|
||||||
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
|
|
||||||
static const int nmaster = 1; /* number of clients in master area */
|
|
||||||
static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
|
|
||||||
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
|
|
||||||
|
|
||||||
static const Layout layouts[] = {
|
|
||||||
/* symbol arrange function */
|
|
||||||
{ "[]=", tile }, /* first entry is default */
|
|
||||||
{ "><>", NULL }, /* no layout function means floating behavior */
|
|
||||||
{ "[M]", monocle },
|
|
||||||
};
|
|
||||||
|
|
||||||
/* key definitions */
|
|
||||||
#define MODKEY Mod1Mask
|
|
||||||
#define TAGKEYS(KEY,TAG) \
|
|
||||||
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
|
|
||||||
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
|
|
||||||
{ MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
|
|
||||||
{ MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
|
|
||||||
|
|
||||||
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
|
|
||||||
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
|
|
||||||
|
|
||||||
/* commands */
|
|
||||||
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
|
|
||||||
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
|
|
||||||
static const char *termcmd[] = { "st", NULL };
|
|
||||||
|
|
||||||
static const Key keys[] = {
|
|
||||||
/* modifier key function argument */
|
|
||||||
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
|
|
||||||
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
|
|
||||||
{ MODKEY, XK_b, togglebar, {0} },
|
|
||||||
{ MODKEY, XK_j, focusstack, {.i = +1 } },
|
|
||||||
{ MODKEY, XK_k, focusstack, {.i = -1 } },
|
|
||||||
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
|
|
||||||
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
|
|
||||||
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
|
|
||||||
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
|
|
||||||
{ MODKEY, XK_Return, zoom, {0} },
|
|
||||||
{ MODKEY, XK_Tab, view, {0} },
|
|
||||||
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
|
|
||||||
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
|
|
||||||
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
|
|
||||||
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
|
|
||||||
{ MODKEY, XK_space, setlayout, {0} },
|
|
||||||
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
|
|
||||||
{ MODKEY, XK_0, view, {.ui = ~0 } },
|
|
||||||
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
|
|
||||||
{ MODKEY, XK_comma, focusmon, {.i = -1 } },
|
|
||||||
{ MODKEY, XK_period, focusmon, {.i = +1 } },
|
|
||||||
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
|
|
||||||
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
|
|
||||||
TAGKEYS( XK_1, 0)
|
|
||||||
TAGKEYS( XK_2, 1)
|
|
||||||
TAGKEYS( XK_3, 2)
|
|
||||||
TAGKEYS( XK_4, 3)
|
|
||||||
TAGKEYS( XK_5, 4)
|
|
||||||
TAGKEYS( XK_6, 5)
|
|
||||||
TAGKEYS( XK_7, 6)
|
|
||||||
TAGKEYS( XK_8, 7)
|
|
||||||
TAGKEYS( XK_9, 8)
|
|
||||||
{ MODKEY|ShiftMask, XK_q, quit, {0} },
|
|
||||||
};
|
|
||||||
|
|
||||||
/* button definitions */
|
|
||||||
/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
|
|
||||||
static const Button buttons[] = {
|
|
||||||
/* click event mask button function argument */
|
|
||||||
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
|
||||||
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
|
|
||||||
{ ClkWinTitle, 0, Button2, zoom, {0} },
|
|
||||||
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
|
|
||||||
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
|
|
||||||
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
|
|
||||||
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
|
|
||||||
{ ClkTagBar, 0, Button1, view, {0} },
|
|
||||||
{ ClkTagBar, 0, Button3, toggleview, {0} },
|
|
||||||
{ ClkTagBar, MODKEY, Button1, tag, {0} },
|
|
||||||
{ ClkTagBar, MODKEY, Button3, toggletag, {0} },
|
|
||||||
};
|
|
||||||
|
|
38
config.mk
38
config.mk
@ -1,39 +1,31 @@
|
|||||||
# dwm version
|
# Customize to fit your system
|
||||||
VERSION = 6.5
|
|
||||||
|
|
||||||
# Customize below to fit your system
|
|
||||||
|
|
||||||
# paths
|
# paths
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
|
CONFPREFIX = ${PREFIX}/etc
|
||||||
MANPREFIX = ${PREFIX}/share/man
|
MANPREFIX = ${PREFIX}/share/man
|
||||||
|
|
||||||
X11INC = /usr/X11R6/include
|
X11INC = /usr/X11R6/include
|
||||||
X11LIB = /usr/X11R6/lib
|
X11LIB = /usr/X11R6/lib
|
||||||
|
|
||||||
# Xinerama, comment if you don't want it
|
VERSION = 0.1
|
||||||
XINERAMALIBS = -lXinerama
|
|
||||||
XINERAMAFLAGS = -DXINERAMA
|
|
||||||
|
|
||||||
# freetype
|
|
||||||
FREETYPELIBS = -lfontconfig -lXft
|
|
||||||
FREETYPEINC = /usr/include/freetype2
|
|
||||||
# OpenBSD (uncomment)
|
|
||||||
#FREETYPEINC = ${X11INC}/freetype2
|
|
||||||
#MANPREFIX = ${PREFIX}/man
|
|
||||||
|
|
||||||
# includes and libs
|
# includes and libs
|
||||||
INCS = -I${X11INC} -I${FREETYPEINC}
|
LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11
|
||||||
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS}
|
|
||||||
|
|
||||||
# flags
|
# Linux/BSD
|
||||||
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
|
CFLAGS = -Os -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \
|
||||||
#CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
|
-DVERSION=\"${VERSION}\"
|
||||||
CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os ${INCS} ${CPPFLAGS}
|
|
||||||
LDFLAGS = ${LIBS}
|
LDFLAGS = ${LIBS}
|
||||||
|
#CFLAGS = -g -Wall -O2 -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \
|
||||||
|
# -DVERSION=\"${VERSION}\"
|
||||||
|
#LDFLAGS = -g ${LIBS}
|
||||||
|
|
||||||
|
|
||||||
# Solaris
|
# Solaris
|
||||||
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
|
#CFLAGS = -fast -xtarget=ultra ${INCLUDES} -DVERSION=\"${VERSION}\"
|
||||||
#LDFLAGS = ${LIBS}
|
#LIBS += -lnsl -lsocket
|
||||||
|
|
||||||
# compiler and linker
|
AR = ar cr
|
||||||
CC = cc
|
CC = cc
|
||||||
|
RANLIB = ranlib
|
||||||
|
151
dev.c
Normal file
151
dev.c
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
/*
|
||||||
|
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
|
* See LICENSE file for license details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dwm.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <X11/keysym.h>
|
||||||
|
|
||||||
|
/********** CUSTOMIZE **********/
|
||||||
|
|
||||||
|
const char *term[] = {
|
||||||
|
"urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn",
|
||||||
|
"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL
|
||||||
|
};
|
||||||
|
const char *browse[] = { "firefox", NULL };
|
||||||
|
const char *xlock[] = { "xlock", NULL };
|
||||||
|
|
||||||
|
static Key key[] = {
|
||||||
|
/* modifier key function arguments */
|
||||||
|
{ Mod1Mask, XK_Return, zoom, { 0 } },
|
||||||
|
{ Mod1Mask, XK_k, prevc, { 0 } },
|
||||||
|
{ Mod1Mask, XK_j, nextc, { 0 } },
|
||||||
|
{ Mod1Mask, XK_m, max, { 0 } },
|
||||||
|
{ Mod1Mask, XK_0, view, { .i = Tscratch } },
|
||||||
|
{ Mod1Mask, XK_1, view, { .i = Tdev } },
|
||||||
|
{ Mod1Mask, XK_2, view, { .i = Twww } },
|
||||||
|
{ Mod1Mask, XK_3, view, { .i = Twork } },
|
||||||
|
{ Mod1Mask, XK_space, tiling, { 0 } },
|
||||||
|
{ Mod1Mask|ShiftMask, XK_space, floating, { 0 } },
|
||||||
|
{ Mod1Mask|ShiftMask, XK_0, ttrunc, { .i = Tscratch } },
|
||||||
|
{ Mod1Mask|ShiftMask, XK_1, ttrunc, { .i = Tdev } },
|
||||||
|
{ Mod1Mask|ShiftMask, XK_2, ttrunc, { .i = Twww } },
|
||||||
|
{ Mod1Mask|ShiftMask, XK_3, ttrunc, { .i = Twork } },
|
||||||
|
{ Mod1Mask|ShiftMask, XK_c, ckill, { 0 } },
|
||||||
|
{ Mod1Mask|ShiftMask, XK_q, quit, { 0 } },
|
||||||
|
{ Mod1Mask|ShiftMask, XK_Return, spawn, { .argv = term } },
|
||||||
|
{ Mod1Mask|ShiftMask, XK_w, spawn, { .argv = browse } },
|
||||||
|
{ Mod1Mask|ShiftMask, XK_l, spawn, { .argv = xlock } },
|
||||||
|
{ ControlMask, XK_0, tappend, { .i = Tscratch } },
|
||||||
|
{ ControlMask, XK_1, tappend, { .i = Tdev } },
|
||||||
|
{ ControlMask, XK_2, tappend, { .i = Twww } },
|
||||||
|
{ ControlMask, XK_3, tappend, { .i = Twork } },
|
||||||
|
};
|
||||||
|
|
||||||
|
/********** CUSTOMIZE **********/
|
||||||
|
|
||||||
|
void
|
||||||
|
update_keys(void)
|
||||||
|
{
|
||||||
|
static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
|
||||||
|
unsigned int i;
|
||||||
|
KeyCode code;
|
||||||
|
|
||||||
|
for(i = 0; i < len; i++) {
|
||||||
|
code = XKeysymToKeycode(dpy, key[i].keysym);
|
||||||
|
XUngrabKey(dpy, code, key[i].mod, root);
|
||||||
|
XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
keypress(XEvent *e)
|
||||||
|
{
|
||||||
|
XKeyEvent *ev = &e->xkey;
|
||||||
|
static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
|
||||||
|
unsigned int i;
|
||||||
|
KeySym keysym;
|
||||||
|
|
||||||
|
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
|
||||||
|
for(i = 0; i < len; i++)
|
||||||
|
if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
|
||||||
|
if(key[i].func)
|
||||||
|
key[i].func(&key[i].arg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ButtonMask (ButtonPressMask | ButtonReleaseMask)
|
||||||
|
#define MouseMask (ButtonMask | PointerMotionMask)
|
||||||
|
|
||||||
|
void
|
||||||
|
mresize(Client *c)
|
||||||
|
{
|
||||||
|
XEvent ev;
|
||||||
|
int ocx, ocy;
|
||||||
|
|
||||||
|
ocx = c->x;
|
||||||
|
ocy = c->y;
|
||||||
|
if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
|
||||||
|
None, cursor[CurResize], CurrentTime) != GrabSuccess)
|
||||||
|
return;
|
||||||
|
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
|
||||||
|
for(;;) {
|
||||||
|
XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
|
||||||
|
switch(ev.type) {
|
||||||
|
default: break;
|
||||||
|
case Expose:
|
||||||
|
handler[Expose](&ev);
|
||||||
|
break;
|
||||||
|
case MotionNotify:
|
||||||
|
XFlush(dpy);
|
||||||
|
c->w = abs(ocx - ev.xmotion.x);
|
||||||
|
c->h = abs(ocy - ev.xmotion.y);
|
||||||
|
c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
|
||||||
|
c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
|
||||||
|
resize(c, True);
|
||||||
|
break;
|
||||||
|
case ButtonRelease:
|
||||||
|
XUngrabPointer(dpy, CurrentTime);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mmove(Client *c)
|
||||||
|
{
|
||||||
|
XEvent ev;
|
||||||
|
int x1, y1, ocx, ocy, di;
|
||||||
|
unsigned int dui;
|
||||||
|
Window dummy;
|
||||||
|
|
||||||
|
ocx = c->x;
|
||||||
|
ocy = c->y;
|
||||||
|
if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
|
||||||
|
None, cursor[CurMove], CurrentTime) != GrabSuccess)
|
||||||
|
return;
|
||||||
|
XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
|
||||||
|
for(;;) {
|
||||||
|
XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
|
||||||
|
switch (ev.type) {
|
||||||
|
default: break;
|
||||||
|
case Expose:
|
||||||
|
handler[Expose](&ev);
|
||||||
|
break;
|
||||||
|
case MotionNotify:
|
||||||
|
XFlush(dpy);
|
||||||
|
c->x = ocx + (ev.xmotion.x - x1);
|
||||||
|
c->y = ocy + (ev.xmotion.y - y1);
|
||||||
|
resize(c, False);
|
||||||
|
break;
|
||||||
|
case ButtonRelease:
|
||||||
|
XUngrabPointer(dpy, CurrentTime);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
158
draw.c
Normal file
158
draw.c
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
/*
|
||||||
|
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
|
* See LICENSE file for license details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <X11/Xlocale.h>
|
||||||
|
|
||||||
|
#include "dwm.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
drawborder(void)
|
||||||
|
{
|
||||||
|
XPoint points[5];
|
||||||
|
XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
|
||||||
|
XSetForeground(dpy, dc.gc, dc.border);
|
||||||
|
points[0].x = dc.x;
|
||||||
|
points[0].y = dc.y;
|
||||||
|
points[1].x = dc.w - 1;
|
||||||
|
points[1].y = 0;
|
||||||
|
points[2].x = 0;
|
||||||
|
points[2].y = dc.h - 1;
|
||||||
|
points[3].x = -(dc.w - 1);
|
||||||
|
points[3].y = 0;
|
||||||
|
points[4].x = 0;
|
||||||
|
points[4].y = -(dc.h - 1);
|
||||||
|
XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
drawtext(const char *text, Bool invert, Bool border)
|
||||||
|
{
|
||||||
|
int x, y, w, h;
|
||||||
|
unsigned int len;
|
||||||
|
static char buf[256];
|
||||||
|
XGCValues gcv;
|
||||||
|
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
|
||||||
|
|
||||||
|
XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg);
|
||||||
|
XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
|
||||||
|
|
||||||
|
w = 0;
|
||||||
|
if(border)
|
||||||
|
drawborder();
|
||||||
|
|
||||||
|
if(!text)
|
||||||
|
return;
|
||||||
|
|
||||||
|
len = strlen(text);
|
||||||
|
if(len >= sizeof(buf))
|
||||||
|
len = sizeof(buf) - 1;
|
||||||
|
memcpy(buf, text, len);
|
||||||
|
buf[len] = 0;
|
||||||
|
|
||||||
|
h = dc.font.ascent + dc.font.descent;
|
||||||
|
y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
|
||||||
|
x = dc.x + (h / 2);
|
||||||
|
|
||||||
|
/* shorten text if necessary */
|
||||||
|
while(len && (w = textnw(buf, len)) > dc.w - h)
|
||||||
|
buf[--len] = 0;
|
||||||
|
|
||||||
|
if(w > dc.w)
|
||||||
|
return; /* too long */
|
||||||
|
|
||||||
|
gcv.foreground = invert ? dc.bg : dc.fg;
|
||||||
|
gcv.background = invert ? dc.fg : dc.bg;
|
||||||
|
if(dc.font.set) {
|
||||||
|
XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv);
|
||||||
|
XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc,
|
||||||
|
x, y, buf, len);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gcv.font = dc.font.xfont->fid;
|
||||||
|
XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv);
|
||||||
|
XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long
|
||||||
|
initcolor(const char *colstr)
|
||||||
|
{
|
||||||
|
XColor color;
|
||||||
|
Colormap cmap = DefaultColormap(dpy, screen);
|
||||||
|
|
||||||
|
XAllocNamedColor(dpy, cmap, colstr, &color, &color);
|
||||||
|
return color.pixel;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
textnw(char *text, unsigned int len)
|
||||||
|
{
|
||||||
|
XRectangle r;
|
||||||
|
if(dc.font.set) {
|
||||||
|
XmbTextExtents(dc.font.set, text, len, NULL, &r);
|
||||||
|
return r.width;
|
||||||
|
}
|
||||||
|
return XTextWidth(dc.font.xfont, text, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
textw(char *text)
|
||||||
|
{
|
||||||
|
return textnw(text, strlen(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
initfont(const char *fontstr)
|
||||||
|
{
|
||||||
|
char **missing, *def;
|
||||||
|
int i, n;
|
||||||
|
|
||||||
|
missing = NULL;
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
|
if(dc.font.set)
|
||||||
|
XFreeFontSet(dpy, dc.font.set);
|
||||||
|
dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
|
||||||
|
if(missing) {
|
||||||
|
while(n--)
|
||||||
|
fprintf(stderr, "missing fontset: %s\n", missing[n]);
|
||||||
|
XFreeStringList(missing);
|
||||||
|
if(dc.font.set) {
|
||||||
|
XFreeFontSet(dpy, dc.font.set);
|
||||||
|
dc.font.set = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(dc.font.set) {
|
||||||
|
XFontSetExtents *font_extents;
|
||||||
|
XFontStruct **xfonts;
|
||||||
|
char **font_names;
|
||||||
|
|
||||||
|
dc.font.ascent = dc.font.descent = 0;
|
||||||
|
font_extents = XExtentsOfFontSet(dc.font.set);
|
||||||
|
n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
|
||||||
|
for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
|
||||||
|
if(dc.font.ascent < (*xfonts)->ascent)
|
||||||
|
dc.font.ascent = (*xfonts)->ascent;
|
||||||
|
if(dc.font.descent < (*xfonts)->descent)
|
||||||
|
dc.font.descent = (*xfonts)->descent;
|
||||||
|
xfonts++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(dc.font.xfont)
|
||||||
|
XFreeFont(dpy, dc.font.xfont);
|
||||||
|
dc.font.xfont = NULL;
|
||||||
|
dc.font.xfont = XLoadQueryFont(dpy, fontstr);
|
||||||
|
if (!dc.font.xfont)
|
||||||
|
dc.font.xfont = XLoadQueryFont(dpy, "fixed");
|
||||||
|
if (!dc.font.xfont)
|
||||||
|
error("error, cannot init 'fixed' font\n");
|
||||||
|
dc.font.ascent = dc.font.xfont->ascent;
|
||||||
|
dc.font.descent = dc.font.xfont->descent;
|
||||||
|
}
|
||||||
|
dc.font.height = dc.font.ascent + dc.font.descent;
|
||||||
|
}
|
448
drw.c
448
drw.c
@ -1,448 +0,0 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <X11/Xlib.h>
|
|
||||||
#include <X11/Xft/Xft.h>
|
|
||||||
|
|
||||||
#include "drw.h"
|
|
||||||
#include "util.h"
|
|
||||||
|
|
||||||
#define UTF_INVALID 0xFFFD
|
|
||||||
|
|
||||||
static int
|
|
||||||
utf8decode(const char *s_in, long *u, int *err)
|
|
||||||
{
|
|
||||||
static const unsigned char lens[] = {
|
|
||||||
/* 0XXXX */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
||||||
/* 10XXX */ 0, 0, 0, 0, 0, 0, 0, 0, /* invalid */
|
|
||||||
/* 110XX */ 2, 2, 2, 2,
|
|
||||||
/* 1110X */ 3, 3,
|
|
||||||
/* 11110 */ 4,
|
|
||||||
/* 11111 */ 0, /* invalid */
|
|
||||||
};
|
|
||||||
static const unsigned char leading_mask[] = { 0x7F, 0x1F, 0x0F, 0x07 };
|
|
||||||
static const unsigned int overlong[] = { 0x0, 0x80, 0x0800, 0x10000 };
|
|
||||||
|
|
||||||
const unsigned char *s = (const unsigned char *)s_in;
|
|
||||||
int len = lens[*s >> 3];
|
|
||||||
*u = UTF_INVALID;
|
|
||||||
*err = 1;
|
|
||||||
if (len == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
long cp = s[0] & leading_mask[len - 1];
|
|
||||||
for (int i = 1; i < len; ++i) {
|
|
||||||
if (s[i] == '\0' || (s[i] & 0xC0) != 0x80)
|
|
||||||
return i;
|
|
||||||
cp = (cp << 6) | (s[i] & 0x3F);
|
|
||||||
}
|
|
||||||
/* out of range, surrogate, overlong encoding */
|
|
||||||
if (cp > 0x10FFFF || (cp >> 11) == 0x1B || cp < overlong[len - 1])
|
|
||||||
return len;
|
|
||||||
|
|
||||||
*err = 0;
|
|
||||||
*u = cp;
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
Drw *
|
|
||||||
drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h)
|
|
||||||
{
|
|
||||||
Drw *drw = ecalloc(1, sizeof(Drw));
|
|
||||||
|
|
||||||
drw->dpy = dpy;
|
|
||||||
drw->screen = screen;
|
|
||||||
drw->root = root;
|
|
||||||
drw->w = w;
|
|
||||||
drw->h = h;
|
|
||||||
drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
|
|
||||||
drw->gc = XCreateGC(dpy, root, 0, NULL);
|
|
||||||
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
|
|
||||||
|
|
||||||
return drw;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
drw_resize(Drw *drw, unsigned int w, unsigned int h)
|
|
||||||
{
|
|
||||||
if (!drw)
|
|
||||||
return;
|
|
||||||
|
|
||||||
drw->w = w;
|
|
||||||
drw->h = h;
|
|
||||||
if (drw->drawable)
|
|
||||||
XFreePixmap(drw->dpy, drw->drawable);
|
|
||||||
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
drw_free(Drw *drw)
|
|
||||||
{
|
|
||||||
XFreePixmap(drw->dpy, drw->drawable);
|
|
||||||
XFreeGC(drw->dpy, drw->gc);
|
|
||||||
drw_fontset_free(drw->fonts);
|
|
||||||
free(drw);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This function is an implementation detail. Library users should use
|
|
||||||
* drw_fontset_create instead.
|
|
||||||
*/
|
|
||||||
static Fnt *
|
|
||||||
xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
|
|
||||||
{
|
|
||||||
Fnt *font;
|
|
||||||
XftFont *xfont = NULL;
|
|
||||||
FcPattern *pattern = NULL;
|
|
||||||
|
|
||||||
if (fontname) {
|
|
||||||
/* Using the pattern found at font->xfont->pattern does not yield the
|
|
||||||
* same substitution results as using the pattern returned by
|
|
||||||
* FcNameParse; using the latter results in the desired fallback
|
|
||||||
* behaviour whereas the former just results in missing-character
|
|
||||||
* rectangles being drawn, at least with some fonts. */
|
|
||||||
if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) {
|
|
||||||
fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (!(pattern = FcNameParse((FcChar8 *) fontname))) {
|
|
||||||
fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname);
|
|
||||||
XftFontClose(drw->dpy, xfont);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
} else if (fontpattern) {
|
|
||||||
if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) {
|
|
||||||
fprintf(stderr, "error, cannot load font from pattern.\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
die("no font specified.");
|
|
||||||
}
|
|
||||||
|
|
||||||
font = ecalloc(1, sizeof(Fnt));
|
|
||||||
font->xfont = xfont;
|
|
||||||
font->pattern = pattern;
|
|
||||||
font->h = xfont->ascent + xfont->descent;
|
|
||||||
font->dpy = drw->dpy;
|
|
||||||
|
|
||||||
return font;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
xfont_free(Fnt *font)
|
|
||||||
{
|
|
||||||
if (!font)
|
|
||||||
return;
|
|
||||||
if (font->pattern)
|
|
||||||
FcPatternDestroy(font->pattern);
|
|
||||||
XftFontClose(font->dpy, font->xfont);
|
|
||||||
free(font);
|
|
||||||
}
|
|
||||||
|
|
||||||
Fnt*
|
|
||||||
drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount)
|
|
||||||
{
|
|
||||||
Fnt *cur, *ret = NULL;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (!drw || !fonts)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
for (i = 1; i <= fontcount; i++) {
|
|
||||||
if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) {
|
|
||||||
cur->next = ret;
|
|
||||||
ret = cur;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (drw->fonts = ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
drw_fontset_free(Fnt *font)
|
|
||||||
{
|
|
||||||
if (font) {
|
|
||||||
drw_fontset_free(font->next);
|
|
||||||
xfont_free(font);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
|
|
||||||
{
|
|
||||||
if (!drw || !dest || !clrname)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
|
|
||||||
DefaultColormap(drw->dpy, drw->screen),
|
|
||||||
clrname, dest))
|
|
||||||
die("error, cannot allocate color '%s'", clrname);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wrapper to create color schemes. The caller has to call free(3) on the
|
|
||||||
* returned color scheme when done using it. */
|
|
||||||
Clr *
|
|
||||||
drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
Clr *ret;
|
|
||||||
|
|
||||||
/* need at least two colors for a scheme */
|
|
||||||
if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(XftColor))))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
for (i = 0; i < clrcount; i++)
|
|
||||||
drw_clr_create(drw, &ret[i], clrnames[i]);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
drw_setfontset(Drw *drw, Fnt *set)
|
|
||||||
{
|
|
||||||
if (drw)
|
|
||||||
drw->fonts = set;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
drw_setscheme(Drw *drw, Clr *scm)
|
|
||||||
{
|
|
||||||
if (drw)
|
|
||||||
drw->scheme = scm;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert)
|
|
||||||
{
|
|
||||||
if (!drw || !drw->scheme)
|
|
||||||
return;
|
|
||||||
XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel);
|
|
||||||
if (filled)
|
|
||||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
|
||||||
else
|
|
||||||
XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert)
|
|
||||||
{
|
|
||||||
int ty, ellipsis_x = 0;
|
|
||||||
unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len, hash, h0, h1;
|
|
||||||
XftDraw *d = NULL;
|
|
||||||
Fnt *usedfont, *curfont, *nextfont;
|
|
||||||
int utf8strlen, utf8charlen, utf8err, render = x || y || w || h;
|
|
||||||
long utf8codepoint = 0;
|
|
||||||
const char *utf8str;
|
|
||||||
FcCharSet *fccharset;
|
|
||||||
FcPattern *fcpattern;
|
|
||||||
FcPattern *match;
|
|
||||||
XftResult result;
|
|
||||||
int charexists = 0, overflow = 0;
|
|
||||||
/* keep track of a couple codepoints for which we have no match. */
|
|
||||||
static unsigned int nomatches[128], ellipsis_width, invalid_width;
|
|
||||||
static const char invalid[] = "<EFBFBD>";
|
|
||||||
|
|
||||||
if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!render) {
|
|
||||||
w = invert ? invert : ~invert;
|
|
||||||
} else {
|
|
||||||
XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
|
|
||||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
|
||||||
if (w < lpad)
|
|
||||||
return x + w;
|
|
||||||
d = XftDrawCreate(drw->dpy, drw->drawable,
|
|
||||||
DefaultVisual(drw->dpy, drw->screen),
|
|
||||||
DefaultColormap(drw->dpy, drw->screen));
|
|
||||||
x += lpad;
|
|
||||||
w -= lpad;
|
|
||||||
}
|
|
||||||
|
|
||||||
usedfont = drw->fonts;
|
|
||||||
if (!ellipsis_width && render)
|
|
||||||
ellipsis_width = drw_fontset_getwidth(drw, "...");
|
|
||||||
if (!invalid_width && render)
|
|
||||||
invalid_width = drw_fontset_getwidth(drw, invalid);
|
|
||||||
while (1) {
|
|
||||||
ew = ellipsis_len = utf8err = utf8charlen = utf8strlen = 0;
|
|
||||||
utf8str = text;
|
|
||||||
nextfont = NULL;
|
|
||||||
while (*text) {
|
|
||||||
utf8charlen = utf8decode(text, &utf8codepoint, &utf8err);
|
|
||||||
for (curfont = drw->fonts; curfont; curfont = curfont->next) {
|
|
||||||
charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint);
|
|
||||||
if (charexists) {
|
|
||||||
drw_font_getexts(curfont, text, utf8charlen, &tmpw, NULL);
|
|
||||||
if (ew + ellipsis_width <= w) {
|
|
||||||
/* keep track where the ellipsis still fits */
|
|
||||||
ellipsis_x = x + ew;
|
|
||||||
ellipsis_w = w - ew;
|
|
||||||
ellipsis_len = utf8strlen;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ew + tmpw > w) {
|
|
||||||
overflow = 1;
|
|
||||||
/* called from drw_fontset_getwidth_clamp():
|
|
||||||
* it wants the width AFTER the overflow
|
|
||||||
*/
|
|
||||||
if (!render)
|
|
||||||
x += tmpw;
|
|
||||||
else
|
|
||||||
utf8strlen = ellipsis_len;
|
|
||||||
} else if (curfont == usedfont) {
|
|
||||||
text += utf8charlen;
|
|
||||||
utf8strlen += utf8err ? 0 : utf8charlen;
|
|
||||||
ew += utf8err ? 0 : tmpw;
|
|
||||||
} else {
|
|
||||||
nextfont = curfont;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (overflow || !charexists || nextfont || utf8err)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
charexists = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (utf8strlen) {
|
|
||||||
if (render) {
|
|
||||||
ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
|
|
||||||
XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg],
|
|
||||||
usedfont->xfont, x, ty, (XftChar8 *)utf8str, utf8strlen);
|
|
||||||
}
|
|
||||||
x += ew;
|
|
||||||
w -= ew;
|
|
||||||
}
|
|
||||||
if (utf8err && (!render || invalid_width < w)) {
|
|
||||||
if (render)
|
|
||||||
drw_text(drw, x, y, w, h, 0, invalid, invert);
|
|
||||||
x += invalid_width;
|
|
||||||
w -= invalid_width;
|
|
||||||
}
|
|
||||||
if (render && overflow)
|
|
||||||
drw_text(drw, ellipsis_x, y, ellipsis_w, h, 0, "...", invert);
|
|
||||||
|
|
||||||
if (!*text || overflow) {
|
|
||||||
break;
|
|
||||||
} else if (nextfont) {
|
|
||||||
charexists = 0;
|
|
||||||
usedfont = nextfont;
|
|
||||||
} else {
|
|
||||||
/* Regardless of whether or not a fallback font is found, the
|
|
||||||
* character must be drawn. */
|
|
||||||
charexists = 1;
|
|
||||||
|
|
||||||
hash = (unsigned int)utf8codepoint;
|
|
||||||
hash = ((hash >> 16) ^ hash) * 0x21F0AAAD;
|
|
||||||
hash = ((hash >> 15) ^ hash) * 0xD35A2D97;
|
|
||||||
h0 = ((hash >> 15) ^ hash) % LENGTH(nomatches);
|
|
||||||
h1 = (hash >> 17) % LENGTH(nomatches);
|
|
||||||
/* avoid expensive XftFontMatch call when we know we won't find a match */
|
|
||||||
if (nomatches[h0] == utf8codepoint || nomatches[h1] == utf8codepoint)
|
|
||||||
goto no_match;
|
|
||||||
|
|
||||||
fccharset = FcCharSetCreate();
|
|
||||||
FcCharSetAddChar(fccharset, utf8codepoint);
|
|
||||||
|
|
||||||
if (!drw->fonts->pattern) {
|
|
||||||
/* Refer to the comment in xfont_create for more information. */
|
|
||||||
die("the first font in the cache must be loaded from a font string.");
|
|
||||||
}
|
|
||||||
|
|
||||||
fcpattern = FcPatternDuplicate(drw->fonts->pattern);
|
|
||||||
FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
|
|
||||||
FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue);
|
|
||||||
|
|
||||||
FcConfigSubstitute(NULL, fcpattern, FcMatchPattern);
|
|
||||||
FcDefaultSubstitute(fcpattern);
|
|
||||||
match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result);
|
|
||||||
|
|
||||||
FcCharSetDestroy(fccharset);
|
|
||||||
FcPatternDestroy(fcpattern);
|
|
||||||
|
|
||||||
if (match) {
|
|
||||||
usedfont = xfont_create(drw, NULL, match);
|
|
||||||
if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) {
|
|
||||||
for (curfont = drw->fonts; curfont->next; curfont = curfont->next)
|
|
||||||
; /* NOP */
|
|
||||||
curfont->next = usedfont;
|
|
||||||
} else {
|
|
||||||
xfont_free(usedfont);
|
|
||||||
nomatches[nomatches[h0] ? h1 : h0] = utf8codepoint;
|
|
||||||
no_match:
|
|
||||||
usedfont = drw->fonts;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (d)
|
|
||||||
XftDrawDestroy(d);
|
|
||||||
|
|
||||||
return x + (render ? w : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
|
|
||||||
{
|
|
||||||
if (!drw)
|
|
||||||
return;
|
|
||||||
|
|
||||||
XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y);
|
|
||||||
XSync(drw->dpy, False);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int
|
|
||||||
drw_fontset_getwidth(Drw *drw, const char *text)
|
|
||||||
{
|
|
||||||
if (!drw || !drw->fonts || !text)
|
|
||||||
return 0;
|
|
||||||
return drw_text(drw, 0, 0, 0, 0, 0, text, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int
|
|
||||||
drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n)
|
|
||||||
{
|
|
||||||
unsigned int tmp = 0;
|
|
||||||
if (drw && drw->fonts && text && n)
|
|
||||||
tmp = drw_text(drw, 0, 0, 0, 0, 0, text, n);
|
|
||||||
return MIN(n, tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h)
|
|
||||||
{
|
|
||||||
XGlyphInfo ext;
|
|
||||||
|
|
||||||
if (!font || !text)
|
|
||||||
return;
|
|
||||||
|
|
||||||
XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext);
|
|
||||||
if (w)
|
|
||||||
*w = ext.xOff;
|
|
||||||
if (h)
|
|
||||||
*h = font->h;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cur *
|
|
||||||
drw_cur_create(Drw *drw, int shape)
|
|
||||||
{
|
|
||||||
Cur *cur;
|
|
||||||
|
|
||||||
if (!drw || !(cur = ecalloc(1, sizeof(Cur))))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
cur->cursor = XCreateFontCursor(drw->dpy, shape);
|
|
||||||
|
|
||||||
return cur;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
drw_cur_free(Drw *drw, Cur *cursor)
|
|
||||||
{
|
|
||||||
if (!cursor)
|
|
||||||
return;
|
|
||||||
|
|
||||||
XFreeCursor(drw->dpy, cursor->cursor);
|
|
||||||
free(cursor);
|
|
||||||
}
|
|
58
drw.h
58
drw.h
@ -1,58 +0,0 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Cursor cursor;
|
|
||||||
} Cur;
|
|
||||||
|
|
||||||
typedef struct Fnt {
|
|
||||||
Display *dpy;
|
|
||||||
unsigned int h;
|
|
||||||
XftFont *xfont;
|
|
||||||
FcPattern *pattern;
|
|
||||||
struct Fnt *next;
|
|
||||||
} Fnt;
|
|
||||||
|
|
||||||
enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */
|
|
||||||
typedef XftColor Clr;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
unsigned int w, h;
|
|
||||||
Display *dpy;
|
|
||||||
int screen;
|
|
||||||
Window root;
|
|
||||||
Drawable drawable;
|
|
||||||
GC gc;
|
|
||||||
Clr *scheme;
|
|
||||||
Fnt *fonts;
|
|
||||||
} Drw;
|
|
||||||
|
|
||||||
/* Drawable abstraction */
|
|
||||||
Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h);
|
|
||||||
void drw_resize(Drw *drw, unsigned int w, unsigned int h);
|
|
||||||
void drw_free(Drw *drw);
|
|
||||||
|
|
||||||
/* Fnt abstraction */
|
|
||||||
Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount);
|
|
||||||
void drw_fontset_free(Fnt* set);
|
|
||||||
unsigned int drw_fontset_getwidth(Drw *drw, const char *text);
|
|
||||||
unsigned int drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n);
|
|
||||||
void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h);
|
|
||||||
|
|
||||||
/* Colorscheme abstraction */
|
|
||||||
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
|
|
||||||
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
|
|
||||||
|
|
||||||
/* Cursor abstraction */
|
|
||||||
Cur *drw_cur_create(Drw *drw, int shape);
|
|
||||||
void drw_cur_free(Drw *drw, Cur *cursor);
|
|
||||||
|
|
||||||
/* Drawing context manipulation */
|
|
||||||
void drw_setfontset(Drw *drw, Fnt *set);
|
|
||||||
void drw_setscheme(Drw *drw, Clr *scm);
|
|
||||||
|
|
||||||
/* Drawing functions */
|
|
||||||
void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert);
|
|
||||||
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert);
|
|
||||||
|
|
||||||
/* Map functions */
|
|
||||||
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);
|
|
232
dwm.1
232
dwm.1
@ -1,176 +1,98 @@
|
|||||||
.TH DWM 1 dwm\-VERSION
|
.TH DWM 1 dwm-0.1
|
||||||
.SH NAME
|
.SH NAME
|
||||||
dwm \- dynamic window manager
|
dwm \- dynamic window manager
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B dwm
|
.B dwm
|
||||||
.RB [ \-v ]
|
.RB [ \-v ]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
dwm is a dynamic window manager for X. It manages windows in tiled, monocle
|
.SS Overview
|
||||||
and floating layouts. Either layout can be applied dynamically, optimising the
|
.B dwm
|
||||||
environment for the application in use and the task performed.
|
is a dynamic window manager for X11.
|
||||||
.P
|
.SS Options
|
||||||
In tiled layouts windows are managed in a master and stacking area. The master
|
|
||||||
area on the left contains one window by default, and the stacking area on the
|
|
||||||
right contains all other windows. The number of master area windows can be
|
|
||||||
adjusted from zero to an arbitrary number. In monocle layout all windows are
|
|
||||||
maximised to the screen size. In floating layout windows can be resized and
|
|
||||||
moved freely. Dialog windows are always managed floating, regardless of the
|
|
||||||
layout applied.
|
|
||||||
.P
|
|
||||||
Windows are grouped by tags. Each window can be tagged with one or multiple
|
|
||||||
tags. Selecting certain tags displays all windows with these tags.
|
|
||||||
.P
|
|
||||||
Each screen contains a small status bar which displays all available tags, the
|
|
||||||
layout, the title of the focused window, and the text read from the root window
|
|
||||||
name property, if the screen is focused. A floating window is indicated with an
|
|
||||||
empty square and a maximised floating window is indicated with a filled square
|
|
||||||
before the windows title. The selected tags are indicated with a different
|
|
||||||
color. The tags of the focused window are indicated with a filled square in the
|
|
||||||
top left corner. The tags which are applied to one or more windows are
|
|
||||||
indicated with an empty square in the top left corner.
|
|
||||||
.P
|
|
||||||
dwm draws a small border around windows to indicate the focus state.
|
|
||||||
.SH OPTIONS
|
|
||||||
.TP
|
.TP
|
||||||
.B \-v
|
.B \-v
|
||||||
prints version information to stderr, then exits.
|
prints version information to stdout, then exits.
|
||||||
.SH USAGE
|
.SS Status text
|
||||||
.SS Status bar
|
.B dwm
|
||||||
|
reads from stdin to display status text if provided.
|
||||||
|
.SS Default Key Bindings
|
||||||
|
.TP 16
|
||||||
|
.I Key
|
||||||
|
.I Action
|
||||||
.TP
|
.TP
|
||||||
.B X root window name
|
.B Mod1-Return
|
||||||
is read and displayed in the status text area. It can be set with the
|
Zoom
|
||||||
.BR xsetroot (1)
|
.B window
|
||||||
command.
|
to the
|
||||||
|
.B master
|
||||||
|
track
|
||||||
.TP
|
.TP
|
||||||
.B Button1
|
.B Mod1-k
|
||||||
click on a tag label to display all windows with that tag, click on the layout
|
Focus previous
|
||||||
label toggles between tiled and floating layout.
|
.B window
|
||||||
.TP
|
.TP
|
||||||
.B Button3
|
.B Mod1-j
|
||||||
click on a tag label adds/removes all windows with that tag to/from the view.
|
Focus next
|
||||||
|
.B window
|
||||||
.TP
|
.TP
|
||||||
.B Mod1\-Button1
|
.B Mod1-m
|
||||||
click on a tag label applies that tag to the focused window.
|
Maximize current
|
||||||
|
.B window
|
||||||
.TP
|
.TP
|
||||||
.B Mod1\-Button3
|
.B Mod1-[0..n]
|
||||||
click on a tag label adds/removes that tag to/from the focused window.
|
Focus
|
||||||
.SS Keyboard commands
|
.B nth
|
||||||
|
tag
|
||||||
.TP
|
.TP
|
||||||
.B Mod1\-Shift\-Return
|
.B Mod1-space
|
||||||
|
(Re-)arrange
|
||||||
|
.B all
|
||||||
|
windows tiled
|
||||||
|
.TP
|
||||||
|
.B Mod1-Shift-space
|
||||||
|
(Re-)arrange
|
||||||
|
.B all
|
||||||
|
windows floating
|
||||||
|
.TP
|
||||||
|
.B Mod1-Shift-[0..n]
|
||||||
|
Apply
|
||||||
|
.B nth
|
||||||
|
tag to current
|
||||||
|
.B window
|
||||||
|
.TP
|
||||||
|
.B Mod1-Shift-q
|
||||||
|
Quit
|
||||||
|
.B dwm
|
||||||
|
.TP
|
||||||
|
.B Mod1-Shift-Return
|
||||||
Start
|
Start
|
||||||
.BR st(1).
|
.B terminal
|
||||||
.TP
|
.TP
|
||||||
.B Mod1\-p
|
.B Mod1-Shift-w
|
||||||
Spawn
|
Start
|
||||||
.BR dmenu(1)
|
.B web browser
|
||||||
for launching other programs.
|
|
||||||
.TP
|
.TP
|
||||||
.B Mod1\-,
|
.B Mod1-Shift-l
|
||||||
Focus previous screen, if any.
|
Lock
|
||||||
|
.B screen
|
||||||
.TP
|
.TP
|
||||||
.B Mod1\-.
|
.B Control-[0..n]
|
||||||
Focus next screen, if any.
|
Append
|
||||||
|
.B nth
|
||||||
|
tag to cureent
|
||||||
|
.B window
|
||||||
|
.SS Default Mouse Bindings
|
||||||
.TP
|
.TP
|
||||||
.B Mod1\-Shift\-,
|
.B Mod1-Button1
|
||||||
Send focused window to previous screen, if any.
|
Moves current
|
||||||
|
.B window
|
||||||
|
while dragging
|
||||||
.TP
|
.TP
|
||||||
.B Mod1\-Shift\-.
|
.B Mod1-Button2
|
||||||
Send focused window to next screen, if any.
|
Lowers current
|
||||||
|
.B window
|
||||||
.TP
|
.TP
|
||||||
.B Mod1\-b
|
.B Mod1-Button3
|
||||||
Toggles bar on and off.
|
Resizes current
|
||||||
.TP
|
.B window
|
||||||
.B Mod1\-t
|
while dragging
|
||||||
Sets tiled layout.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-f
|
|
||||||
Sets floating layout.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-m
|
|
||||||
Sets monocle layout.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-space
|
|
||||||
Toggles between current and previous layout.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-j
|
|
||||||
Focus next window.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-k
|
|
||||||
Focus previous window.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-i
|
|
||||||
Increase number of windows in master area.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-d
|
|
||||||
Decrease number of windows in master area.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-l
|
|
||||||
Increase master area size.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-h
|
|
||||||
Decrease master area size.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-Return
|
|
||||||
Zooms/cycles focused window to/from master area (tiled layouts only).
|
|
||||||
.TP
|
|
||||||
.B Mod1\-Shift\-c
|
|
||||||
Close focused window.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-Shift\-space
|
|
||||||
Toggle focused window between tiled and floating state.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-Tab
|
|
||||||
Toggles to the previously selected tags.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-Shift\-[1..n]
|
|
||||||
Apply nth tag to focused window.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-Shift\-0
|
|
||||||
Apply all tags to focused window.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-Control\-Shift\-[1..n]
|
|
||||||
Add/remove nth tag to/from focused window.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-[1..n]
|
|
||||||
View all windows with nth tag.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-0
|
|
||||||
View all windows with any tag.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-Control\-[1..n]
|
|
||||||
Add/remove all windows with nth tag to/from the view.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-Shift\-q
|
|
||||||
Quit dwm.
|
|
||||||
.SS Mouse commands
|
|
||||||
.TP
|
|
||||||
.B Mod1\-Button1
|
|
||||||
Move focused window while dragging. Tiled windows will be toggled to the floating state.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-Button2
|
|
||||||
Toggles focused window between floating and tiled state.
|
|
||||||
.TP
|
|
||||||
.B Mod1\-Button3
|
|
||||||
Resize focused window while dragging. Tiled windows will be toggled to the floating state.
|
|
||||||
.SH CUSTOMIZATION
|
|
||||||
dwm is customized by creating a custom config.h and (re)compiling the source
|
|
||||||
code. This keeps it fast, secure and simple.
|
|
||||||
.SH SEE ALSO
|
|
||||||
.BR dmenu (1),
|
|
||||||
.BR st (1)
|
|
||||||
.SH ISSUES
|
|
||||||
Java applications which use the XToolkit/XAWT backend may draw grey windows
|
|
||||||
only. The XToolkit/XAWT backend breaks ICCCM-compliance in recent JDK 1.5 and early
|
|
||||||
JDK 1.6 versions, because it assumes a reparenting window manager. Possible workarounds
|
|
||||||
are using JDK 1.4 (which doesn't contain the XToolkit/XAWT backend) or setting the
|
|
||||||
environment variable
|
|
||||||
.BR AWT_TOOLKIT=MToolkit
|
|
||||||
(to use the older Motif backend instead) or running
|
|
||||||
.B xprop -root -f _NET_WM_NAME 32a -set _NET_WM_NAME LG3D
|
|
||||||
or
|
|
||||||
.B wmname LG3D
|
|
||||||
(to pretend that a non-reparenting window manager is running that the
|
|
||||||
XToolkit/XAWT backend can recognize) or when using OpenJDK setting the environment variable
|
|
||||||
.BR _JAVA_AWT_WM_NONREPARENTING=1 .
|
|
||||||
.SH BUGS
|
|
||||||
Send all bug reports with a patch to hackers@suckless.org.
|
|
||||||
|
155
dwm.h
Normal file
155
dwm.h
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
/*
|
||||||
|
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
|
* See LICENSE file for license details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
/********** CUSTOMIZE **********/
|
||||||
|
|
||||||
|
#define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
|
||||||
|
#define BGCOLOR "#666699"
|
||||||
|
#define FGCOLOR "#eeeeee"
|
||||||
|
#define BORDERCOLOR "#9999CC"
|
||||||
|
#define MASTERW 52 /* percent */
|
||||||
|
#define WM_PROTOCOL_DELWIN 1
|
||||||
|
|
||||||
|
/* tags */
|
||||||
|
enum { Tscratch, Tdev, Twww, Twork, TLast };
|
||||||
|
|
||||||
|
/********** CUSTOMIZE **********/
|
||||||
|
|
||||||
|
typedef union Arg Arg;
|
||||||
|
typedef struct DC DC;
|
||||||
|
typedef struct Client Client;
|
||||||
|
typedef struct Fnt Fnt;
|
||||||
|
typedef struct Key Key;
|
||||||
|
typedef struct Rule Rule;
|
||||||
|
|
||||||
|
union Arg {
|
||||||
|
const char **argv;
|
||||||
|
int i;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* atoms */
|
||||||
|
enum { WMProtocols, WMDelete, WMLast };
|
||||||
|
enum { NetSupported, NetWMName, NetLast };
|
||||||
|
|
||||||
|
/* cursor */
|
||||||
|
enum { CurNormal, CurResize, CurMove, CurInput, CurLast };
|
||||||
|
|
||||||
|
struct Fnt {
|
||||||
|
XFontStruct *xfont;
|
||||||
|
XFontSet set;
|
||||||
|
int ascent;
|
||||||
|
int descent;
|
||||||
|
int height;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DC { /* draw context */
|
||||||
|
GC gc;
|
||||||
|
Drawable drawable;
|
||||||
|
int x, y, w, h;
|
||||||
|
Fnt font;
|
||||||
|
unsigned long bg;
|
||||||
|
unsigned long fg;
|
||||||
|
unsigned long border;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Client {
|
||||||
|
char name[256];
|
||||||
|
char *tags[TLast];
|
||||||
|
int proto;
|
||||||
|
int x, y, w, h;
|
||||||
|
int tx, ty, tw, th;
|
||||||
|
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
|
||||||
|
int grav;
|
||||||
|
unsigned int border;
|
||||||
|
long flags;
|
||||||
|
Bool floating;
|
||||||
|
Window win;
|
||||||
|
Window title;
|
||||||
|
Client *next;
|
||||||
|
Client *revert;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Rule {
|
||||||
|
const char *class;
|
||||||
|
const char *instance;
|
||||||
|
char *tags[TLast];
|
||||||
|
Bool floating;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Key {
|
||||||
|
unsigned long mod;
|
||||||
|
KeySym keysym;
|
||||||
|
void (*func)(Arg *arg);
|
||||||
|
Arg arg;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Display *dpy;
|
||||||
|
extern Window root, barwin;
|
||||||
|
extern Atom wm_atom[WMLast], net_atom[NetLast];
|
||||||
|
extern Cursor cursor[CurLast];
|
||||||
|
extern Bool running, issel;
|
||||||
|
extern void (*handler[LASTEvent])(XEvent *);
|
||||||
|
extern void (*arrange)(Arg *);
|
||||||
|
|
||||||
|
extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
|
||||||
|
extern char *tags[TLast], stext[1024];
|
||||||
|
|
||||||
|
extern DC dc;
|
||||||
|
extern Client *clients, *sel;
|
||||||
|
|
||||||
|
/* bar.c */
|
||||||
|
extern void draw_bar();
|
||||||
|
extern void barclick(XButtonPressedEvent *e);
|
||||||
|
|
||||||
|
/* client.c */
|
||||||
|
extern void manage(Window w, XWindowAttributes *wa);
|
||||||
|
extern void unmanage(Client *c);
|
||||||
|
extern Client *getclient(Window w);
|
||||||
|
extern void focus(Client *c);
|
||||||
|
extern void update_name(Client *c);
|
||||||
|
extern void draw_client(Client *c);
|
||||||
|
extern void resize(Client *c, Bool inc);
|
||||||
|
extern void update_size(Client *c);
|
||||||
|
extern Client *gettitle(Window w);
|
||||||
|
extern void craise(Client *c);
|
||||||
|
extern void lower(Client *c);
|
||||||
|
extern void ckill(Arg *arg);
|
||||||
|
extern void nextc(Arg *arg);
|
||||||
|
extern void prevc(Arg *arg);
|
||||||
|
extern void max(Arg *arg);
|
||||||
|
extern void floating(Arg *arg);
|
||||||
|
extern void tiling(Arg *arg);
|
||||||
|
extern void ttrunc(Arg *arg);
|
||||||
|
extern void tappend(Arg *arg);
|
||||||
|
extern void view(Arg *arg);
|
||||||
|
extern void zoom(Arg *arg);
|
||||||
|
extern void gravitate(Client *c, Bool invert);
|
||||||
|
|
||||||
|
/* draw.c */
|
||||||
|
extern void drawtext(const char *text, Bool invert, Bool border);
|
||||||
|
extern unsigned long initcolor(const char *colstr);
|
||||||
|
extern void initfont(const char *fontstr);
|
||||||
|
extern unsigned int textnw(char *text, unsigned int len);
|
||||||
|
extern unsigned int textw(char *text);
|
||||||
|
extern unsigned int texth(void);
|
||||||
|
|
||||||
|
/* dev.c */
|
||||||
|
extern void update_keys(void);
|
||||||
|
extern void keypress(XEvent *e);
|
||||||
|
extern void mresize(Client *c);
|
||||||
|
extern void mmove(Client *c);
|
||||||
|
|
||||||
|
/* main.c */
|
||||||
|
extern int error_handler(Display *dsply, XErrorEvent *e);
|
||||||
|
extern void send_message(Window w, Atom a, long value);
|
||||||
|
extern int win_proto(Window w);
|
||||||
|
extern void quit(Arg *arg);
|
||||||
|
|
||||||
|
/* util.c */
|
||||||
|
extern void error(const char *errstr, ...);
|
||||||
|
extern void *emallocz(unsigned int size);
|
||||||
|
extern void spawn(Arg *arg);
|
106
dwm.html
Normal file
106
dwm.html
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>dwm - dynamic window manager</title>
|
||||||
|
<meta name="author" content="Anselm R. Garbe">
|
||||||
|
<meta name="generator" content="ed">
|
||||||
|
<meta name="copyright" content="(C)opyright 2006 by Anselm R. Garbe">
|
||||||
|
<style type="text/css">
|
||||||
|
body {
|
||||||
|
color: #000000;
|
||||||
|
font-family: sans-serif;
|
||||||
|
margin: 20px 20px 20px 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<center>
|
||||||
|
<img src="dwm.png"/><br />
|
||||||
|
<h3>dynamic window manager</h3>
|
||||||
|
</center>
|
||||||
|
<h3>Description</h3>
|
||||||
|
<p>
|
||||||
|
dwm is a dynamic window manager for X11.
|
||||||
|
</p>
|
||||||
|
<h3>Philosophy</h3>
|
||||||
|
<p>
|
||||||
|
As founder and main developer of wmii I came to the conclusion that
|
||||||
|
wmii is too clunky for my needs. I don't need so many funky features
|
||||||
|
and all this hype about remote control through a 9P service, I only
|
||||||
|
want to manage my windows in a simple, but dynamic way. wmii never got
|
||||||
|
finished because I listened to users, who proposed arbitrary ideas I
|
||||||
|
considered useful. This resulted in an extreme <a href="http://www.jwz.org/doc/cadt.html">CADT</a>
|
||||||
|
development model, which was a mistake. Thus the philosophy of
|
||||||
|
dwm is simply <i>to fit my needs</i> (maybe yours as well). That's it.
|
||||||
|
</p>
|
||||||
|
<h3>Differences to wmii</h3
|
||||||
|
<p>
|
||||||
|
In contrast to wmii, dwm is only a window manager, and nothing else.
|
||||||
|
Hence, it is much smaller, faster and simpler.
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
dwm has no 9P support, no menu, no editable tagbars,
|
||||||
|
no shell-based configuration and remote control and comes without
|
||||||
|
any additional tools like printing the selection or warping the
|
||||||
|
mouse.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
dwm is only a single binary, it's source code is intended to never
|
||||||
|
exceed 2000 SLOC.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
dwm is customized through editing its source code, that makes it
|
||||||
|
extremely fast and secure - it does not process any input data which
|
||||||
|
hasn't been known at compile time, except window title names.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
dwm is based on tagging and dynamic window management (however simpler
|
||||||
|
than wmii or larswm).
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
dwm don't distinguishes between layers, there is no floating or
|
||||||
|
managed layer. Wether the clients of currently selected tag are
|
||||||
|
managed or not, you can re-arrange all clients on the fly. Popup-
|
||||||
|
and fixed-size windows are treated unmanaged.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
dwm uses 1-pixel borders to provide the maximum of screen real
|
||||||
|
estate to clients. Small titlebars are only drawn in front of unfocused
|
||||||
|
clients.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
dwm reads from <b>stdin</b> to print arbitrary status text (like the
|
||||||
|
date, load, battery charge). That's much simpler than larsremote,
|
||||||
|
wmiir and what not...
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
garbeam <b>does not</b> want any feedback to dwm. If you ask for support,
|
||||||
|
feature requests, or if you report bugs, they will be <b>ignored</b>
|
||||||
|
with a high chance. dwm is only intended to fit garbeams needs.
|
||||||
|
However you are free to download and distribute/relicense it, with the
|
||||||
|
conditions of the <a href="http://wmii.de/cgi-bin/hgwebdir.cgi/dwm?f=f10eb1139362;file=LICENSE;style=raw">MIT/X Consortium license</a>.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<h3>Screenshot</h3>
|
||||||
|
<p>
|
||||||
|
<a href="http://wmii.de/shots/dwm-20060714.png">Click here for a screenshot</a> (20060714)
|
||||||
|
</p>
|
||||||
|
<h3>Development</h3>
|
||||||
|
<p>
|
||||||
|
dwm is actively developed in parallel to wmii. You can <a href="http://wmii.de/cgi-bin/hgwebdir.cgi/dwm">browse</a> its source code repository or get a copy using <a href="http://www.selenic.com/mercurial/">Mercurial</a> with following command:
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<code>hg clone http://wmii.de/cgi-bin/hgwebdir.cgi/dwm</code>
|
||||||
|
</p>
|
||||||
|
<h3>Download</h3>
|
||||||
|
<ul>
|
||||||
|
<li><a href="http://wmii.de/download/dwm-0.1.tar.gz">dwm 0.1</a> (12kb) (20060714)</li>
|
||||||
|
</ul>
|
||||||
|
<h3>Miscellaneous</h3>
|
||||||
|
<p>
|
||||||
|
You can purchase this <a href="https://www.spreadshirt.net/shop.php?op=article&article_id=3298632&view=403">tricot</a>
|
||||||
|
if you like dwm and the dwm logo, which has been designed by garbeam.
|
||||||
|
</p>
|
||||||
|
<p><small>--Anselm (20060714)</small></p>
|
||||||
|
</body>
|
||||||
|
</html>
|
BIN
dwm.png
BIN
dwm.png
Binary file not shown.
Before Width: | Height: | Size: 373 B After Width: | Height: | Size: 387 B |
216
event.c
Normal file
216
event.c
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
/*
|
||||||
|
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
|
* See LICENSE file for license details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <X11/keysym.h>
|
||||||
|
#include <X11/Xatom.h>
|
||||||
|
|
||||||
|
#include "dwm.h"
|
||||||
|
|
||||||
|
/* local functions */
|
||||||
|
static void buttonpress(XEvent *e);
|
||||||
|
static void configurerequest(XEvent *e);
|
||||||
|
static void destroynotify(XEvent *e);
|
||||||
|
static void enternotify(XEvent *e);
|
||||||
|
static void leavenotify(XEvent *e);
|
||||||
|
static void expose(XEvent *e);
|
||||||
|
static void keymapnotify(XEvent *e);
|
||||||
|
static void maprequest(XEvent *e);
|
||||||
|
static void propertynotify(XEvent *e);
|
||||||
|
static void unmapnotify(XEvent *e);
|
||||||
|
|
||||||
|
void (*handler[LASTEvent]) (XEvent *) = {
|
||||||
|
[ButtonPress] = buttonpress,
|
||||||
|
[ConfigureRequest] = configurerequest,
|
||||||
|
[DestroyNotify] = destroynotify,
|
||||||
|
[EnterNotify] = enternotify,
|
||||||
|
[LeaveNotify] = leavenotify,
|
||||||
|
[Expose] = expose,
|
||||||
|
[KeyPress] = keypress,
|
||||||
|
[KeymapNotify] = keymapnotify,
|
||||||
|
[MapRequest] = maprequest,
|
||||||
|
[PropertyNotify] = propertynotify,
|
||||||
|
[UnmapNotify] = unmapnotify
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
buttonpress(XEvent *e)
|
||||||
|
{
|
||||||
|
XButtonPressedEvent *ev = &e->xbutton;
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
if(barwin == ev->window)
|
||||||
|
barclick(ev);
|
||||||
|
else if((c = getclient(ev->window))) {
|
||||||
|
craise(c);
|
||||||
|
switch(ev->button) {
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
case Button1:
|
||||||
|
mmove(c);
|
||||||
|
break;
|
||||||
|
case Button2:
|
||||||
|
lower(c);
|
||||||
|
break;
|
||||||
|
case Button3:
|
||||||
|
mresize(c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
configurerequest(XEvent *e)
|
||||||
|
{
|
||||||
|
XConfigureRequestEvent *ev = &e->xconfigurerequest;
|
||||||
|
XWindowChanges wc;
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
ev->value_mask &= ~CWSibling;
|
||||||
|
if((c = getclient(ev->window))) {
|
||||||
|
gravitate(c, True);
|
||||||
|
if(ev->value_mask & CWX)
|
||||||
|
c->x = ev->x;
|
||||||
|
if(ev->value_mask & CWY)
|
||||||
|
c->y = ev->y;
|
||||||
|
if(ev->value_mask & CWWidth)
|
||||||
|
c->w = ev->width;
|
||||||
|
if(ev->value_mask & CWHeight)
|
||||||
|
c->h = ev->height;
|
||||||
|
if(ev->value_mask & CWBorderWidth)
|
||||||
|
c->border = 1;
|
||||||
|
gravitate(c, False);
|
||||||
|
resize(c, True);
|
||||||
|
}
|
||||||
|
|
||||||
|
wc.x = ev->x;
|
||||||
|
wc.y = ev->y;
|
||||||
|
wc.width = ev->width;
|
||||||
|
wc.height = ev->height;
|
||||||
|
wc.border_width = 1;
|
||||||
|
wc.sibling = None;
|
||||||
|
wc.stack_mode = Above;
|
||||||
|
ev->value_mask &= ~CWStackMode;
|
||||||
|
ev->value_mask |= CWBorderWidth;
|
||||||
|
XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
|
||||||
|
XFlush(dpy);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
destroynotify(XEvent *e)
|
||||||
|
{
|
||||||
|
Client *c;
|
||||||
|
XDestroyWindowEvent *ev = &e->xdestroywindow;
|
||||||
|
|
||||||
|
if((c = getclient(ev->window)))
|
||||||
|
unmanage(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
enternotify(XEvent *e)
|
||||||
|
{
|
||||||
|
XCrossingEvent *ev = &e->xcrossing;
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if((c = getclient(ev->window)))
|
||||||
|
focus(c);
|
||||||
|
else if(ev->window == root)
|
||||||
|
issel = True;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
leavenotify(XEvent *e)
|
||||||
|
{
|
||||||
|
XCrossingEvent *ev = &e->xcrossing;
|
||||||
|
|
||||||
|
if((ev->window == root) && !ev->same_screen)
|
||||||
|
issel = True;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
expose(XEvent *e)
|
||||||
|
{
|
||||||
|
XExposeEvent *ev = &e->xexpose;
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
if(ev->count == 0) {
|
||||||
|
if((c = gettitle(ev->window)))
|
||||||
|
draw_client(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
keymapnotify(XEvent *e)
|
||||||
|
{
|
||||||
|
update_keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
maprequest(XEvent *e)
|
||||||
|
{
|
||||||
|
XMapRequestEvent *ev = &e->xmaprequest;
|
||||||
|
static XWindowAttributes wa;
|
||||||
|
|
||||||
|
if(!XGetWindowAttributes(dpy, ev->window, &wa))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(wa.override_redirect) {
|
||||||
|
XSelectInput(dpy, ev->window,
|
||||||
|
(StructureNotifyMask | PropertyChangeMask));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!getclient(ev->window))
|
||||||
|
manage(ev->window, &wa);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
propertynotify(XEvent *e)
|
||||||
|
{
|
||||||
|
XPropertyEvent *ev = &e->xproperty;
|
||||||
|
Window trans;
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
if(ev->state == PropertyDelete)
|
||||||
|
return; /* ignore */
|
||||||
|
|
||||||
|
if((c = getclient(ev->window))) {
|
||||||
|
if(ev->atom == wm_atom[WMProtocols]) {
|
||||||
|
c->proto = win_proto(c->win);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (ev->atom) {
|
||||||
|
default: break;
|
||||||
|
case XA_WM_TRANSIENT_FOR:
|
||||||
|
XGetTransientForHint(dpy, c->win, &trans);
|
||||||
|
if(!c->floating && (c->floating = (trans != 0)))
|
||||||
|
arrange(NULL);
|
||||||
|
break;
|
||||||
|
case XA_WM_NORMAL_HINTS:
|
||||||
|
update_size(c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
|
||||||
|
update_name(c);
|
||||||
|
draw_client(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
unmapnotify(XEvent *e)
|
||||||
|
{
|
||||||
|
Client *c;
|
||||||
|
XUnmapEvent *ev = &e->xunmap;
|
||||||
|
|
||||||
|
if((c = getclient(ev->window)))
|
||||||
|
unmanage(c);
|
||||||
|
}
|
327
main.c
Normal file
327
main.c
Normal file
@ -0,0 +1,327 @@
|
|||||||
|
/*
|
||||||
|
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
|
* See LICENSE file for license details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <X11/cursorfont.h>
|
||||||
|
#include <X11/Xatom.h>
|
||||||
|
#include <X11/Xproto.h>
|
||||||
|
|
||||||
|
#include "dwm.h"
|
||||||
|
|
||||||
|
/********** CUSTOMIZE **********/
|
||||||
|
|
||||||
|
char *tags[TLast] = {
|
||||||
|
[Tscratch] = "scratch",
|
||||||
|
[Tdev] = "dev",
|
||||||
|
[Twww] = "www",
|
||||||
|
[Twork] = "work",
|
||||||
|
};
|
||||||
|
|
||||||
|
/********** CUSTOMIZE **********/
|
||||||
|
|
||||||
|
/* X structs */
|
||||||
|
Display *dpy;
|
||||||
|
Window root, barwin;
|
||||||
|
Atom wm_atom[WMLast], net_atom[NetLast];
|
||||||
|
Cursor cursor[CurLast];
|
||||||
|
Bool running = True;
|
||||||
|
Bool issel;
|
||||||
|
|
||||||
|
int tsel = Tdev; /* default tag */
|
||||||
|
int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
|
||||||
|
char stext[1024];
|
||||||
|
|
||||||
|
DC dc = {0};
|
||||||
|
Client *clients = NULL;
|
||||||
|
Client *sel = NULL;
|
||||||
|
|
||||||
|
static Bool other_wm_running;
|
||||||
|
static const char version[] =
|
||||||
|
"dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
|
||||||
|
static int (*x_error_handler) (Display *, XErrorEvent *);
|
||||||
|
|
||||||
|
static void
|
||||||
|
usage() { error("usage: dwm [-v]\n"); }
|
||||||
|
|
||||||
|
static void
|
||||||
|
scan_wins()
|
||||||
|
{
|
||||||
|
unsigned int i, num;
|
||||||
|
Window *wins;
|
||||||
|
XWindowAttributes wa;
|
||||||
|
Window d1, d2;
|
||||||
|
|
||||||
|
if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
|
||||||
|
for(i = 0; i < num; i++) {
|
||||||
|
if(!XGetWindowAttributes(dpy, wins[i], &wa))
|
||||||
|
continue;
|
||||||
|
if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
|
||||||
|
continue;
|
||||||
|
if(wa.map_state == IsViewable)
|
||||||
|
manage(wins[i], &wa);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(wins)
|
||||||
|
XFree(wins);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
|
||||||
|
{
|
||||||
|
Atom real;
|
||||||
|
int format;
|
||||||
|
unsigned long res, extra;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
|
||||||
|
&res, &extra, prop);
|
||||||
|
|
||||||
|
if(status != Success || *prop == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(res == 0) {
|
||||||
|
free((void *) *prop);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
win_proto(Window w)
|
||||||
|
{
|
||||||
|
unsigned char *protocols;
|
||||||
|
long res;
|
||||||
|
int protos = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L, &protocols);
|
||||||
|
if(res <= 0) {
|
||||||
|
return protos;
|
||||||
|
}
|
||||||
|
for(i = 0; i < res; i++) {
|
||||||
|
if(protocols[i] == wm_atom[WMDelete])
|
||||||
|
protos |= WM_PROTOCOL_DELWIN;
|
||||||
|
}
|
||||||
|
free((char *) protocols);
|
||||||
|
return protos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
send_message(Window w, Atom a, long value)
|
||||||
|
{
|
||||||
|
XEvent e;
|
||||||
|
|
||||||
|
e.type = ClientMessage;
|
||||||
|
e.xclient.window = w;
|
||||||
|
e.xclient.message_type = a;
|
||||||
|
e.xclient.format = 32;
|
||||||
|
e.xclient.data.l[0] = value;
|
||||||
|
e.xclient.data.l[1] = CurrentTime;
|
||||||
|
XSendEvent(dpy, w, False, NoEventMask, &e);
|
||||||
|
XFlush(dpy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* There's no way to check accesses to destroyed windows, thus
|
||||||
|
* those cases are ignored (especially on UnmapNotify's).
|
||||||
|
* Other types of errors call Xlib's default error handler, which
|
||||||
|
* calls exit().
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
error_handler(Display *dpy, XErrorEvent *error)
|
||||||
|
{
|
||||||
|
if(error->error_code == BadWindow
|
||||||
|
|| (error->request_code == X_SetInputFocus
|
||||||
|
&& error->error_code == BadMatch)
|
||||||
|
|| (error->request_code == X_PolyText8
|
||||||
|
&& error->error_code == BadDrawable)
|
||||||
|
|| (error->request_code == X_PolyFillRectangle
|
||||||
|
&& error->error_code == BadDrawable)
|
||||||
|
|| (error->request_code == X_PolySegment
|
||||||
|
&& error->error_code == BadDrawable)
|
||||||
|
|| (error->request_code == X_ConfigureWindow
|
||||||
|
&& error->error_code == BadMatch)
|
||||||
|
|| (error->request_code == X_GrabKey
|
||||||
|
&& error->error_code == BadAccess))
|
||||||
|
return 0;
|
||||||
|
fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
|
||||||
|
error->request_code, error->error_code);
|
||||||
|
return x_error_handler(dpy, error); /* may call exit() */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Startup Error handler to check if another window manager
|
||||||
|
* is already running.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
startup_error_handler(Display *dpy, XErrorEvent *error)
|
||||||
|
{
|
||||||
|
other_wm_running = True;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cleanup()
|
||||||
|
{
|
||||||
|
while(sel) {
|
||||||
|
resize(sel, True);
|
||||||
|
unmanage(sel);
|
||||||
|
}
|
||||||
|
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
quit(Arg *arg)
|
||||||
|
{
|
||||||
|
running = False;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int i, n;
|
||||||
|
fd_set rd;
|
||||||
|
XSetWindowAttributes wa;
|
||||||
|
unsigned int mask;
|
||||||
|
Bool readstdin = True;
|
||||||
|
Window w;
|
||||||
|
XEvent ev;
|
||||||
|
|
||||||
|
for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
|
||||||
|
switch (argv[i][1]) {
|
||||||
|
case 'v':
|
||||||
|
fprintf(stdout, "%s", version);
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dpy = XOpenDisplay(0);
|
||||||
|
if(!dpy)
|
||||||
|
error("dwm: cannot connect X server\n");
|
||||||
|
|
||||||
|
screen = DefaultScreen(dpy);
|
||||||
|
root = RootWindow(dpy, screen);
|
||||||
|
|
||||||
|
/* check if another WM is already running */
|
||||||
|
other_wm_running = False;
|
||||||
|
XSetErrorHandler(startup_error_handler);
|
||||||
|
/* this causes an error if some other WM is running */
|
||||||
|
XSelectInput(dpy, root, SubstructureRedirectMask);
|
||||||
|
XFlush(dpy);
|
||||||
|
|
||||||
|
if(other_wm_running)
|
||||||
|
error("dwm: another window manager is already running\n");
|
||||||
|
|
||||||
|
XSetErrorHandler(0);
|
||||||
|
x_error_handler = XSetErrorHandler(error_handler);
|
||||||
|
|
||||||
|
/* init atoms */
|
||||||
|
wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
||||||
|
wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
||||||
|
net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
|
||||||
|
net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
|
||||||
|
XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32,
|
||||||
|
PropModeReplace, (unsigned char *) net_atom, NetLast);
|
||||||
|
|
||||||
|
/* init cursors */
|
||||||
|
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
|
||||||
|
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
|
||||||
|
cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
|
||||||
|
|
||||||
|
update_keys();
|
||||||
|
|
||||||
|
/* style */
|
||||||
|
dc.bg = initcolor(BGCOLOR);
|
||||||
|
dc.fg = initcolor(FGCOLOR);
|
||||||
|
dc.border = initcolor(BORDERCOLOR);
|
||||||
|
initfont(FONT);
|
||||||
|
|
||||||
|
sx = sy = 0;
|
||||||
|
sw = DisplayWidth(dpy, screen);
|
||||||
|
sh = DisplayHeight(dpy, screen);
|
||||||
|
mw = (sw * MASTERW) / 100;
|
||||||
|
|
||||||
|
wa.override_redirect = 1;
|
||||||
|
wa.background_pixmap = ParentRelative;
|
||||||
|
wa.event_mask = ButtonPressMask | ExposureMask;
|
||||||
|
|
||||||
|
bx = by = 0;
|
||||||
|
bw = sw;
|
||||||
|
dc.h = bh = dc.font.height + 4;
|
||||||
|
barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen),
|
||||||
|
CopyFromParent, DefaultVisual(dpy, screen),
|
||||||
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
||||||
|
XDefineCursor(dpy, barwin, cursor[CurNormal]);
|
||||||
|
XMapRaised(dpy, barwin);
|
||||||
|
|
||||||
|
dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
|
||||||
|
dc.gc = XCreateGC(dpy, root, 0, 0);
|
||||||
|
draw_bar();
|
||||||
|
|
||||||
|
issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
|
||||||
|
|
||||||
|
wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
|
||||||
|
| LeaveWindowMask;
|
||||||
|
wa.cursor = cursor[CurNormal];
|
||||||
|
|
||||||
|
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
|
||||||
|
|
||||||
|
strcpy(stext, "dwm-"VERSION);
|
||||||
|
scan_wins();
|
||||||
|
|
||||||
|
/* main event loop, reads status text from stdin as well */
|
||||||
|
Mainloop:
|
||||||
|
while(running) {
|
||||||
|
FD_ZERO(&rd);
|
||||||
|
if(readstdin)
|
||||||
|
FD_SET(STDIN_FILENO, &rd);
|
||||||
|
FD_SET(ConnectionNumber(dpy), &rd);
|
||||||
|
|
||||||
|
i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0);
|
||||||
|
if(i == -1 && errno == EINTR)
|
||||||
|
continue;
|
||||||
|
if(i < 0)
|
||||||
|
error("select failed\n");
|
||||||
|
else if(i > 0) {
|
||||||
|
if(FD_ISSET(ConnectionNumber(dpy), &rd)) {
|
||||||
|
while(XPending(dpy)) {
|
||||||
|
XNextEvent(dpy, &ev);
|
||||||
|
if(handler[ev.type])
|
||||||
|
(handler[ev.type])(&ev); /* call handler */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(readstdin && FD_ISSET(STDIN_FILENO, &rd)) {
|
||||||
|
i = n = 0;
|
||||||
|
for(;;) {
|
||||||
|
if((i = getchar()) == EOF) {
|
||||||
|
/* broken pipe/end of producer */
|
||||||
|
readstdin = False;
|
||||||
|
strcpy(stext, "broken pipe");
|
||||||
|
goto Mainloop;
|
||||||
|
}
|
||||||
|
if(i == '\n' || n >= sizeof(stext) - 1)
|
||||||
|
break;
|
||||||
|
stext[n++] = i;
|
||||||
|
}
|
||||||
|
stext[n] = 0;
|
||||||
|
draw_bar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup();
|
||||||
|
XCloseDisplay(dpy);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
42
transient.c
42
transient.c
@ -1,42 +0,0 @@
|
|||||||
/* cc transient.c -o transient -lX11 */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <X11/Xlib.h>
|
|
||||||
#include <X11/Xutil.h>
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
Display *d;
|
|
||||||
Window r, f, t = None;
|
|
||||||
XSizeHints h;
|
|
||||||
XEvent e;
|
|
||||||
|
|
||||||
d = XOpenDisplay(NULL);
|
|
||||||
if (!d)
|
|
||||||
exit(1);
|
|
||||||
r = DefaultRootWindow(d);
|
|
||||||
|
|
||||||
f = XCreateSimpleWindow(d, r, 100, 100, 400, 400, 0, 0, 0);
|
|
||||||
h.min_width = h.max_width = h.min_height = h.max_height = 400;
|
|
||||||
h.flags = PMinSize | PMaxSize;
|
|
||||||
XSetWMNormalHints(d, f, &h);
|
|
||||||
XStoreName(d, f, "floating");
|
|
||||||
XMapWindow(d, f);
|
|
||||||
|
|
||||||
XSelectInput(d, f, ExposureMask);
|
|
||||||
while (1) {
|
|
||||||
XNextEvent(d, &e);
|
|
||||||
|
|
||||||
if (t == None) {
|
|
||||||
sleep(5);
|
|
||||||
t = XCreateSimpleWindow(d, r, 50, 50, 100, 100, 0, 0, 0);
|
|
||||||
XSetTransientForHint(d, t, f);
|
|
||||||
XStoreName(d, t, "transient");
|
|
||||||
XMapWindow(d, t);
|
|
||||||
XSelectInput(d, t, ExposureMask);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
XCloseDisplay(d);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
66
util.c
66
util.c
@ -1,37 +1,59 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
/*
|
||||||
#include <errno.h>
|
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
|
* See LICENSE file for license details.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "util.h"
|
#include "dwm.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
die(const char *fmt, ...)
|
error(const char *errstr, ...) {
|
||||||
{
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int saved_errno;
|
va_start(ap, errstr);
|
||||||
|
vfprintf(stderr, errstr, ap);
|
||||||
saved_errno = errno;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vfprintf(stderr, fmt, ap);
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (fmt[0] && fmt[strlen(fmt)-1] == ':')
|
static void
|
||||||
fprintf(stderr, " %s", strerror(saved_errno));
|
bad_malloc(unsigned int size)
|
||||||
fputc('\n', stderr);
|
{
|
||||||
|
fprintf(stderr, "fatal: could not malloc() %d bytes\n",
|
||||||
|
(int) size);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
ecalloc(size_t nmemb, size_t size)
|
emallocz(unsigned int size)
|
||||||
{
|
{
|
||||||
void *p;
|
void *res = calloc(1, size);
|
||||||
|
if(!res)
|
||||||
if (!(p = calloc(nmemb, size)))
|
bad_malloc(size);
|
||||||
die("calloc:");
|
return res;
|
||||||
return p;
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
spawn(Arg *arg)
|
||||||
|
{
|
||||||
|
char **argv = (char **)arg->argv;
|
||||||
|
if(!argv || !argv[0])
|
||||||
|
return;
|
||||||
|
if(fork() == 0) {
|
||||||
|
if(fork() == 0) {
|
||||||
|
if(dpy)
|
||||||
|
close(ConnectionNumber(dpy));
|
||||||
|
setsid();
|
||||||
|
execvp(argv[0], argv);
|
||||||
|
fprintf(stderr, "dwm: execvp %s", argv[0]);
|
||||||
|
perror(" failed");
|
||||||
|
}
|
||||||
|
exit (0);
|
||||||
|
}
|
||||||
|
wait(0);
|
||||||
}
|
}
|
||||||
|
9
util.h
9
util.h
@ -1,9 +0,0 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
|
||||||
|
|
||||||
#define MAX(A, B) ((A) > (B) ? (A) : (B))
|
|
||||||
#define MIN(A, B) ((A) < (B) ? (A) : (B))
|
|
||||||
#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B))
|
|
||||||
#define LENGTH(X) (sizeof (X) / sizeof (X)[0])
|
|
||||||
|
|
||||||
void die(const char *fmt, ...);
|
|
||||||
void *ecalloc(size_t nmemb, size_t size);
|
|
Loading…
x
Reference in New Issue
Block a user