diff -r 6f07d607d607 dwm.c --- a/dwm.c Thu Oct 18 17:02:19 2007 +0200 +++ b/dwm.c Thu Oct 25 00:23:00 2007 +0200 @@ -48,6 +48,19 @@ #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) #define MOUSEMASK (BUTTONMASK | PointerMotionMask) +// for button handler +#define TAG_BAR 1 +#define LAYOUT_BAR 2 +#define TITLE_BAR 3 +#define STATUS_BAR 4 +#define BARMASK (TAG_BAR|LAYOUT_BAR|TITLE_BAR|STATUS_BAR) + +// for resizehint configuration in rules +#define HINT_ASPECT 1 +#define HINT_INCREMENTAL 2 +#define HINT_MIN 4 +#define HINT_MAX 8 + /* enums */ enum { BarTop, BarBot, BarOff }; /* bar position */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ @@ -64,6 +77,7 @@ struct Client { int basew, baseh, incw, inch, maxw, maxh, minw, minh; int minax, maxax, minay, maxay; long flags; + int hints; // for resizehint configuration in rules unsigned int border, oldborder; Bool isbanned, isfixed, ismax, isfloating, wasfloating; Bool *tags; @@ -95,6 +109,15 @@ typedef struct { const char *arg; } Key; +// for button handler +typedef struct { + unsigned long pos; + unsigned long mod; + KeySym button; + void (*func)(const char *arg); + const char *arg; +} Button; + typedef struct { const char *symbol; void (*arrange)(void); @@ -104,6 +127,7 @@ typedef struct { const char *prop; const char *tags; Bool isfloating; + int hints; // for resizehint configuration in rules } Rule; typedef struct { @@ -229,6 +253,12 @@ Window barwin, root; Window barwin, root; Regs *regs = NULL; +// for stickyview +extern const size_t seltags_size; +extern unsigned int ntags; +extern seltags[]; +extern Bool prevtags[]; + /* configuration, allows nested code to access above variables */ #include "config.h" @@ -236,6 +266,8 @@ unsigned int ntags = sizeof tags / sizeo unsigned int ntags = sizeof tags / sizeof tags[0]; Bool seltags[sizeof tags / sizeof tags[0]] = {[0] = True}; Bool prevtags[sizeof tags / sizeof tags[0]] = {[0] = True}; + +const size_t seltags_size = sizeof seltags; // for stickyview /* function implementations */ void @@ -251,6 +283,7 @@ applyrules(Client *c) { snprintf(buf, sizeof buf, "%s:%s:%s", ch.res_class ? ch.res_class : "", ch.res_name ? ch.res_name : "", c->name); + c->hints = HINTS; for(i = 0; i < nrules; i++) if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) { c->isfloating = rules[i].isfloating; @@ -260,6 +293,8 @@ applyrules(Client *c) { c->tags[j] = True; } } + if ( rules[i].hints ) + c->hints = rules[i].hints; } if(ch.res_class) XFree(ch.res_class); @@ -313,26 +348,35 @@ buttonpress(XEvent *e) { if(barwin == ev->window) { x = 0; + unsigned int j = 0; for(i = 0; i < ntags; i++) { x += textw(tags[i]); - if(ev->x < x) { - if(ev->button == Button1) { - if(ev->state & MODKEY) - tag(tags[i]); - else - view(tags[i]); - } - else if(ev->button == Button3) { - if(ev->state & MODKEY) - toggletag(tags[i]); - else - toggleview(tags[i]); - } - return; - } - } - if((ev->x < x + blw) && ev->button == Button1) - setlayout(NULL); + if(!j && ev->x < x) + j = i+1; + } + --j; + + int pos; + if(ev->x < x) + pos = TAG_BAR; + else if(ev->x < x + blw) + pos = LAYOUT_BAR; + else if(ev->x < waw - textw(stext)) + pos = TITLE_BAR; + else + pos = STATUS_BAR; + + unsigned int len = sizeof buttons / sizeof buttons[0]; + for( i = 0; i < len; i++ ) { + if(ev->button == buttons[i].button + && buttons[i].pos == pos + && (ev->state & MODKEY) == buttons[i].mod + && buttons[i].func) + if ( pos == TAG_BAR ) + buttons[i].func(tags[j]); + else + buttons[i].func(buttons[i].arg); + } } else if((c = getclient(ev->window))) { focus(c); @@ -346,7 +390,7 @@ buttonpress(XEvent *e) { movemouse(c); } else if(ev->button == Button2) { - if(ISTILE && !c->isfixed && c->isfloating) + if((ISTILE) && !c->isfixed && c->isfloating) togglefloating(NULL); else zoom(NULL); @@ -485,8 +529,10 @@ configurerequest(XEvent *e) { if((ev->value_mask & (CWX | CWY)) && !(ev->value_mask & (CWWidth | CWHeight))) configure(c); - if(isvisible(c)) + if(isvisible(c)) { XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); + arrange(); // react on resize hint changes + } } else configure(c); @@ -703,6 +749,8 @@ focus(Client *c) { drawbar(); if(!selscreen) return; + if ( ISFOCUSARRANGE ) // for monocle + layouts[ltidx].arrange(); if(c) { XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]); XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); @@ -1402,7 +1450,7 @@ setmwfact(const char *arg) { setmwfact(const char *arg) { double delta; - if(!ISTILE) + if(!(ISTILE)) return; /* arg handling, manipulate mwfact */ if(arg == NULL) @@ -1863,7 +1911,7 @@ zoom(const char *arg) { zoom(const char *arg) { Client *c; - if(!sel || !ISTILE || sel->isfloating) + if(!sel || !(ISTILE) || sel->isfloating) return; if((c = sel) == nexttiled(clients)) if(!(c = nexttiled(c->next)))