2wm

dual window manager prototype (minimalist dwm with no tags, just one view)
git clone git://git.suckless.org/2wm
Log | Files | Refs | README | LICENSE

commit 11ef0099880202ed0abca5bd3c6477de3329408d
parent 50617966198acc1e5722b4d60e22a23e11af3afd
Author: Anselm R. Garbe <arg@suckless.org>
Date:   Mon, 12 Feb 2007 13:07:45 +0100

yet several other changes
Diffstat:
2wm.h | 20++++++--------------
client.c | 10++++------
config.default.h | 47++---------------------------------------------
event.c | 11+++++------
main.c | 8++------
tag.c | 50+++++++++-----------------------------------------
view.c | 88++++++++++++++++---------------------------------------------------------------
7 files changed, 46 insertions(+), 188 deletions(-)

diff --git a/2wm.h b/2wm.h @@ -26,22 +26,19 @@ struct Client { int minax, minay, maxax, maxay; long flags; unsigned int border; - Bool isfixed, isfloat, ismax; - Bool *tags; + Bool isfixed, isfloat, ismax, visible; Client *next; Client *prev; Client *snext; Window win; }; -extern const char *tags[]; /* all tags */ extern int screen, sx, sy, sw, sh; /* screen geometry */ extern unsigned int master, nmaster; /* master percent, number of master clients */ -extern unsigned int ntags, numlockmask; /* number of tags, dynamic lock mask */ +extern unsigned int numlockmask; /* dynamic key lock mask */ extern void (*handler[LASTEvent])(XEvent *); /* event handler */ -extern void (*arrange)(void); /* arrange function, indicates mode */ extern Atom wmatom[WMLast], netatom[NetLast]; -extern Bool running, selscreen, *seltag; /* seltag is array of Bool */ +extern Bool running, selscreen, visible; extern Client *clients, *sel, *stack; /* global client list and stack */ extern Cursor cursor[CurLast]; extern unsigned long normcol, selcol; /* sel/normal color */ @@ -72,9 +69,8 @@ extern int xerror(Display *dsply, XErrorEvent *ee); /* 2wm's X error handler */ extern void initrregs(void); /* initialize regexps of rules defined in config.h */ extern Client *getnext(Client *c); /* returns next visible client */ extern Client *getprev(Client *c); /* returns previous visible client */ -extern void settags(Client *c, Client *trans); /* sets tags of c */ -extern void tag(Arg *arg); /* tags c with arg's index */ -extern void toggletag(Arg *arg); /* toggles c tags with arg's index */ +extern void setvisible(Client *c, Client *trans);/* sets visibility of c */ +extern void togglevisible(Arg *arg); /* toggles c tags with arg's index */ /* util.c */ extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ @@ -83,16 +79,12 @@ extern void spawn(Arg *arg); /* forks a new subprocess with to arg's cmd */ /* view.c */ extern void detach(Client *c); /* detaches c from global client list */ -extern void dofloat(void); /* arranges all windows floating */ -extern void dotile(void); /* arranges all windows tiled */ +extern void arrange(void); /* arranges all windows tiled */ extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */ extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */ extern void incnmaster(Arg *arg); /* increments nmaster with arg's index value */ -extern Bool isvisible(Client *c); /* returns True if client is visible */ extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */ extern void restack(void); /* restores z layers of all clients */ extern void togglefloat(Arg *arg); /* toggles focusesd client between floating/non-floating state */ -extern void togglemode(Arg *arg); /* toggles global arrange function (dotile/dofloat) */ extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */ -extern void view(Arg *arg); /* views the tag with arg's index */ extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */ diff --git a/client.c b/client.c @@ -86,7 +86,7 @@ configure(Client *c) { void focus(Client *c) { - if(c && !isvisible(c)) + if(c && c->visible != visible) return; if(sel && sel != c) { grabbuttons(sel, False); @@ -150,7 +150,6 @@ manage(Window w, XWindowAttributes *wa) { Window trans; c = emallocz(sizeof(Client)); - c->tags = emallocz(ntags * sizeof(Bool)); c->win = w; c->x = wa->x; c->y = wa->y; @@ -179,7 +178,7 @@ manage(Window w, XWindowAttributes *wa) { grabbuttons(c, False); XSetWindowBorder(dpy, c->win, normcol); updatetitle(c); - settags(c, getclient(trans)); + setvisible(c, getclient(trans)); if(!c->isfloat) c->isfloat = trans || c->isfixed; if(clients) @@ -190,7 +189,7 @@ manage(Window w, XWindowAttributes *wa) { XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); XMapWindow(dpy, c->win); setclientstate(c, NormalState); - if(isvisible(c)) + if(c->visible == visible) focus(c); arrange(); } @@ -341,12 +340,11 @@ unmanage(Client *c) { detach(c); detachstack(c); if(sel == c) { - for(nc = stack; nc && !isvisible(nc); nc = nc->snext); + for(nc = stack; nc && (nc->visible != visible); nc = nc->snext); focus(nc); } XUngrabButton(dpy, AnyButton, AnyModifier, c->win); setclientstate(c, WithdrawnState); - free(c->tags); free(c); XSync(dpy, False); XSetErrorHandler(xerror); diff --git a/config.default.h b/config.default.h @@ -2,12 +2,7 @@ * See LICENSE file for license details. */ -#define TAGS \ -const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL }; - #define BORDERPX 1 -#define DEFMODE dotile /* dofloat */ - #define NORMCOLOR "#333" #define SELCOLOR "#69c" @@ -31,48 +26,10 @@ static Key key[] = { \ { MODKEY, XK_g, resizemaster, { .i = 15 } }, \ { MODKEY, XK_s, resizemaster, { .i = -15 } }, \ { MODKEY, XK_i, incnmaster, { .i = 1 } }, \ - { MODKEY, XK_d, incnmaster, { .i = -1 } }, \ - { MODKEY|ShiftMask, XK_0, tag, { .i = -1 } }, \ - { MODKEY|ShiftMask, XK_1, tag, { .i = 0 } }, \ - { MODKEY|ShiftMask, XK_2, tag, { .i = 1 } }, \ - { MODKEY|ShiftMask, XK_3, tag, { .i = 2 } }, \ - { MODKEY|ShiftMask, XK_4, tag, { .i = 3 } }, \ - { MODKEY|ShiftMask, XK_5, tag, { .i = 4 } }, \ - { MODKEY|ShiftMask, XK_6, tag, { .i = 5 } }, \ - { MODKEY|ShiftMask, XK_7, tag, { .i = 6 } }, \ - { MODKEY|ShiftMask, XK_8, tag, { .i = 7 } }, \ - { MODKEY|ShiftMask, XK_9, tag, { .i = 8 } }, \ - { MODKEY|ControlMask|ShiftMask, XK_1, toggletag, { .i = 0 } }, \ - { MODKEY|ControlMask|ShiftMask, XK_2, toggletag, { .i = 1 } }, \ - { MODKEY|ControlMask|ShiftMask, XK_3, toggletag, { .i = 2 } }, \ - { MODKEY|ControlMask|ShiftMask, XK_4, toggletag, { .i = 3 } }, \ - { MODKEY|ControlMask|ShiftMask, XK_5, toggletag, { .i = 4 } }, \ - { MODKEY|ControlMask|ShiftMask, XK_6, toggletag, { .i = 5 } }, \ - { MODKEY|ControlMask|ShiftMask, XK_7, toggletag, { .i = 6 } }, \ - { MODKEY|ControlMask|ShiftMask, XK_8, toggletag, { .i = 7 } }, \ - { MODKEY|ControlMask|ShiftMask, XK_9, toggletag, { .i = 8 } }, \ + { MODKEY, XK_d, togglevisible, { .i = -1 } }, \ { MODKEY|ShiftMask, XK_c, killclient, { 0 } }, \ - { MODKEY, XK_space, togglemode, { 0 } }, \ + { MODKEY, XK_space, toggleview, { 0 } }, \ { MODKEY|ShiftMask, XK_space, togglefloat, { 0 } }, \ - { MODKEY, XK_0, view, { .i = -1 } }, \ - { MODKEY, XK_1, view, { .i = 0 } }, \ - { MODKEY, XK_2, view, { .i = 1 } }, \ - { MODKEY, XK_3, view, { .i = 2 } }, \ - { MODKEY, XK_4, view, { .i = 3 } }, \ - { MODKEY, XK_5, view, { .i = 4 } }, \ - { MODKEY, XK_6, view, { .i = 5 } }, \ - { MODKEY, XK_7, view, { .i = 6 } }, \ - { MODKEY, XK_8, view, { .i = 7 } }, \ - { MODKEY, XK_9, view, { .i = 8 } }, \ - { MODKEY|ControlMask, XK_1, toggleview, { .i = 0 } }, \ - { MODKEY|ControlMask, XK_2, toggleview, { .i = 1 } }, \ - { MODKEY|ControlMask, XK_3, toggleview, { .i = 2 } }, \ - { MODKEY|ControlMask, XK_4, toggleview, { .i = 3 } }, \ - { MODKEY|ControlMask, XK_5, toggleview, { .i = 4 } }, \ - { MODKEY|ControlMask, XK_6, toggleview, { .i = 5 } }, \ - { MODKEY|ControlMask, XK_7, toggleview, { .i = 6 } }, \ - { MODKEY|ControlMask, XK_8, toggleview, { .i = 7 } }, \ - { MODKEY|ControlMask, XK_9, toggleview, { .i = 8 } }, \ { MODKEY|ShiftMask, XK_q, quit, { 0 } }, \ }; diff --git a/event.c b/event.c @@ -111,14 +111,13 @@ buttonpress(XEvent *e) { focus(c); if(CLEANMASK(ev->state) != MODKEY) return; - if(ev->button == Button1 && (arrange == dofloat || c->isfloat)) { + if(ev->button == Button1 && c->isfloat) { restack(); movemouse(c); } else if(ev->button == Button2) zoom(NULL); - else if(ev->button == Button3 && (arrange == dofloat || c->isfloat) && - !c->isfixed) { + else if(ev->button == Button3 && c->isfloat && !c->isfixed) { restack(); resizemouse(c); } @@ -156,7 +155,7 @@ configurerequest(XEvent *e) { XSync(dpy, False); if(c->isfloat) { resize(c, False); - if(!isvisible(c)) + if(c->visible != visible) XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); } else @@ -191,11 +190,11 @@ enternotify(XEvent *e) { if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) return; - if((c = getclient(ev->window)) && isvisible(c)) + if((c = getclient(ev->window)) && c->visible == visible) focus(c); else if(ev->window == root) { selscreen = True; - for(c = stack; c && !isvisible(c); c = c->snext); + for(c = stack; c && c->visible != visible; c = c->snext); focus(c); } } diff --git a/main.c b/main.c @@ -18,11 +18,11 @@ /* extern */ int screen, sx, sy, sw, sh; -unsigned int master, nmaster, ntags, numlockmask; +unsigned int master, nmaster, numlockmask; unsigned long normcol, selcol; Atom wmatom[WMLast], netatom[NetLast]; Bool running = True; -Bool *seltag; +Bool visible = True; Bool selscreen = True; Client *clients = NULL; Client *sel = NULL; @@ -59,7 +59,6 @@ cleanup(void) { XFreeCursor(dpy, cursor[CurMove]); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); XSync(dpy, False); - free(seltag); } static void @@ -120,9 +119,6 @@ setup(void) { XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); grabkeys(); initrregs(); - for(ntags = 0; tags[ntags]; ntags++); - seltag = emallocz(sizeof(Bool) * ntags); - seltag[0] = True; /* style */ normcol = getcolor(NORMCOLOR); selcol = getcolor(SELCOLOR); diff --git a/tag.c b/tag.c @@ -23,7 +23,6 @@ typedef struct { /* static */ -TAGS RULES static RReg *rreg = NULL; @@ -33,13 +32,13 @@ static unsigned int len = 0; Client * getnext(Client *c) { - for(; c && !isvisible(c); c = c->next); + for(; c && c->visible != visible; c = c->next); return c; } Client * getprev(Client *c) { - for(; c && !isvisible(c); c = c->prev); + for(; c && c->visible != visible; c = c->prev); return c; } @@ -71,64 +70,33 @@ initrregs(void) { } void -settags(Client *c, Client *trans) { +setvisible(Client *c, Client *trans) { char prop[512]; - unsigned int i, j; + unsigned int i; regmatch_t tmp; - Bool matched = trans != NULL; XClassHint ch = { 0 }; - if(matched) { - for(i = 0; i < ntags; i++) - c->tags[i] = trans->tags[i]; - } + if(trans) + c->visible = trans->visible; else { XGetClassHint(dpy, c->win, &ch); snprintf(prop, sizeof prop, "%s:%s:%s", ch.res_class ? ch.res_class : "", ch.res_name ? ch.res_name : "", c->name); for(i = 0; i < len; i++) - if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) { + if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) c->isfloat = rule[i].isfloat; - for(j = 0; rreg[i].tregex && j < ntags; j++) { - if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) { - matched = True; - c->tags[j] = True; - } - } - } if(ch.res_class) XFree(ch.res_class); if(ch.res_name) XFree(ch.res_name); } - if(!matched) - for(i = 0; i < ntags; i++) - c->tags[i] = seltag[i]; -} - -void -tag(Arg *arg) { - unsigned int i; - - if(!sel) - return; - for(i = 0; i < ntags; i++) - sel->tags[i] = (arg->i == -1) ? True : False; - if(arg->i >= 0 && arg->i < ntags) - sel->tags[arg->i] = True; - arrange(); } void -toggletag(Arg *arg) { - unsigned int i; - +togglevisible(Arg *arg) { if(!sel) return; - sel->tags[arg->i] = !sel->tags[arg->i]; - for(i = 0; i < ntags && !sel->tags[i]; i++); - if(i == ntags) - sel->tags[arg->i] = True; + sel->visible = !sel->visible; arrange(); } diff --git a/view.c b/view.c @@ -37,8 +37,6 @@ togglemax(Client *c) { /* extern */ -void (*arrange)(void) = DEFMODE; - void detach(Client *c) { if(c->prev) @@ -51,25 +49,7 @@ detach(Client *c) { } void -dofloat(void) { - Client *c; - - for(c = clients; c; c = c->next) { - if(isvisible(c)) { - resize(c, True); - } - else - XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); - } - if(!sel || !isvisible(sel)) { - for(c = stack; c && !isvisible(c); c = c->snext); - focus(c); - } - restack(); -} - -void -dotile(void) { +arrange(void) { unsigned int i, n, mw, mh, tw, th; Client *c; @@ -82,7 +62,7 @@ dotile(void) { tw = sw - mw; for(i = 0, c = clients; c; c = c->next) - if(isvisible(c)) { + if(c->visible == visible) { if(c->isfloat) { resize(c, True); continue; @@ -110,8 +90,8 @@ dotile(void) { } else XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); - if(!sel || !isvisible(sel)) { - for(c = stack; c && !isvisible(c); c = c->snext); + if(!sel || sel->visible != visible) { + for(c = stack; c && c->visible != visible; c = c->snext); focus(c); } restack(); @@ -149,24 +129,13 @@ focusprev(Arg *arg) { void incnmaster(Arg *arg) { - if((arrange == dofloat) || (nmaster + arg->i < 1) - || (sh / (nmaster + arg->i) <= 2 * BORDERPX)) + if((nmaster + arg->i < 1) || (sh / (nmaster + arg->i) <= 2 * BORDERPX)) return; nmaster += arg->i; if(sel) arrange(); } -Bool -isvisible(Client *c) { - unsigned int i; - - for(i = 0; i < ntags; i++) - if(c->tags[i] && seltag[i]) - return True; - return False; -} - void resizemaster(Arg *arg) { if(arg->i == 0) @@ -187,16 +156,14 @@ restack(void) { if(!sel) return; - if(sel->isfloat || arrange == dofloat) + if(sel->isfloat) XRaiseWindow(dpy, sel->win); - if(arrange != dofloat) { - if(!sel->isfloat) - XLowerWindow(dpy, sel->win); - for(c = nexttiled(clients); c; c = nexttiled(c->next)) { - if(c == sel) - continue; - XLowerWindow(dpy, c->win); - } + else + XLowerWindow(dpy, sel->win); + for(c = nexttiled(clients); c; c = nexttiled(c->next)) { + if(c == sel) + continue; + XLowerWindow(dpy, c->win); } XSync(dpy, False); while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); @@ -204,38 +171,19 @@ restack(void) { void togglefloat(Arg *arg) { - if (!sel || arrange == dofloat) + if(!sel) return; sel->isfloat = !sel->isfloat; arrange(); } void -togglemode(Arg *arg) { - arrange = (arrange == dofloat) ? dotile : dofloat; - if(sel) - arrange(); -} - -void toggleview(Arg *arg) { - unsigned int i; - - seltag[arg->i] = !seltag[arg->i]; - for(i = 0; i < ntags && !seltag[i]; i++); - if(i == ntags) - seltag[arg->i] = True; /* cannot toggle last view */ - arrange(); -} - -void -view(Arg *arg) { - unsigned int i; + Client *c; - for(i = 0; i < ntags; i++) - seltag[i] = (arg->i == -1) ? True : False; - if(arg->i >= 0 && arg->i < ntags) - seltag[arg->i] = True; + for(c = clients; c; c = c->next) + c->visible = !c->visible; + visible = !visible; arrange(); } @@ -246,7 +194,7 @@ zoom(Arg *arg) { if(!sel) return; - if(sel->isfloat || (arrange == dofloat)) { + if(sel->isfloat) { togglemax(sel); return; }