--- dwm-6.0/dwm.c 2011-12-19 15:02:46.000000000 +0000 +++ dwm-6.0mod/dwm.c 2012-01-31 18:21:40.802685273 +0000 @@ -49,6 +49,7 @@ #define LENGTH(X) (sizeof X / sizeof X[0]) #define MAX(A, B) ((A) > (B) ? (A) : (B)) #define MIN(A, B) ((A) < (B) ? (A) : (B)) +#define MAXCOLORS 8 #define MOUSEMASK (BUTTONMASK|PointerMotionMask) #define WIDTH(X) ((X)->w + 2 * (X)->bw) #define HEIGHT(X) ((X)->h + 2 * (X)->bw) @@ -99,9 +100,8 @@ typedef struct { int x, y, w, h; - unsigned long norm[ColLast]; - unsigned long sel[ColLast]; - Drawable drawable; + unsigned long colors[MAXCOLORS][ColLast]; + Drawable drawable; GC gc; struct { int ascent; @@ -127,7 +127,6 @@ struct Monitor { char ltsymbol[16]; float mfact; - int nmaster; int num; int by; /* bar geometry */ int mx, my, mw, mh; /* screen size */ @@ -178,8 +177,9 @@ static Monitor *dirtomon(int dir); static void drawbar(Monitor *m); static void drawbars(void); -static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); -static void drawtext(const char *text, unsigned long col[ColLast], Bool invert); +static void drawcoloredtext(char *text); +static void drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]); +static void drawtext(const char *text, unsigned long col[ColLast], Bool pad); static void enternotify(XEvent *e); static void expose(XEvent *e); static void focus(Client *c); @@ -192,7 +192,6 @@ static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); static void grabbuttons(Client *c, Bool focused); static void grabkeys(void); -static void incnmaster(const Arg *arg); static void initfont(const char *fontstr); static void keypress(XEvent *e); static void killclient(const Arg *arg); @@ -283,6 +282,7 @@ static DC dc; static Monitor *mons = NULL, *selmon = NULL; static Window root; +static int globalborder; /* configuration, allows nested code to access above variables */ #include "config.h" @@ -651,7 +651,6 @@ die("fatal: could not malloc() %u bytes\n", sizeof(Monitor)); m->tagset[0] = m->tagset[1] = 1; m->mfact = mfact; - m->nmaster = nmaster; m->showbar = showbar; m->topbar = topbar; m->lt[0] = &layouts[0]; @@ -730,14 +729,13 @@ dc.x = 0; for(i = 0; i < LENGTH(tags); i++) { dc.w = TEXTW(tags[i]); - col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm; - drawtext(tags[i], col, urg & 1 << i); - drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i, - occ & 1 << i, urg & 1 << i, col); + col = dc.colors[ (m->tagset[m->seltags] & 1 << i ? 1:(urg & 1 << i ? 2:0))]; + drawtext(tags[i], col, True); + drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i, occ & 1 << i, col); dc.x += dc.w; } dc.w = blw = TEXTW(m->ltsymbol); - drawtext(m->ltsymbol, dc.norm, False); + drawtext(m->ltsymbol, dc.colors[0], True); dc.x += dc.w; x = dc.x; if(m == selmon) { /* status is only drawn on selected monitor */ @@ -747,19 +745,19 @@ dc.x = x; dc.w = m->ww - x; } - drawtext(stext, dc.norm, False); + drawcoloredtext(stext); } else dc.x = m->ww; if((dc.w = dc.x - x) > bh) { dc.x = x; if(m->sel) { - col = m == selmon ? dc.sel : dc.norm; - drawtext(m->sel->name, col, False); - drawsquare(m->sel->isfixed, m->sel->isfloating, False, col); + col = m == selmon ? dc.colors[1] : dc.colors[0]; + drawtext(m->sel->name, col, True); + drawsquare(m->sel->isfixed, m->sel->isfloating, col); } else - drawtext(NULL, dc.norm, False); + drawtext(NULL, dc.colors[0], False); } XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0); XSync(dpy, False); @@ -774,10 +772,39 @@ } void -drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) { - int x; +drawcoloredtext(char *text) { + Bool first=True; + char *buf = text, *ptr = buf, c = 1; + unsigned long *col = dc.colors[0]; + int i, ox = dc.x; + + while( *ptr ) { + for( i = 0; *ptr < 0 || *ptr > NUMCOLORS; i++, ptr++); + if( !*ptr ) break; + c=*ptr; + *ptr=0; + if( i ) { + dc.w = selmon->ww - dc.x; + drawtext(buf, col, first); + dc.x += textnw(buf, i) + textnw(&c,1); + if( first ) dc.x += ( dc.font.ascent + dc.font.descent ) / 2; + first = False; + } else if( first ) { + ox = dc.x += textnw(&c,1); + } + *ptr = c; + col = dc.colors[ c-1 ]; + buf = ++ptr; + } + if( !first ) dc.x-=(dc.font.ascent+dc.font.descent)/2; + drawtext(buf, col, True); + dc.x = ox; +} - XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); +void +drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) { + int x; + XSetForeground(dpy, dc.gc, col[ ColFG ]); x = (dc.font.ascent + dc.font.descent + 2) / 4; if(filled) XFillRectangle(dpy, dc.drawable, dc.gc, dc.x+1, dc.y+1, x+1, x+1); @@ -786,17 +813,17 @@ } void -drawtext(const char *text, unsigned long col[ColLast], Bool invert) { +drawtext(const char *text, unsigned long col[ColLast], Bool pad) { char buf[256]; int i, x, y, h, len, olen; - XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]); + XSetForeground(dpy, dc.gc, col[ ColBG ]); XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h); if(!text) return; olen = strlen(text); - h = dc.font.ascent + dc.font.descent; - y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; + h = pad ? (dc.font.ascent + dc.font.descent) : 0; + y = dc.y + ((dc.h + dc.font.ascent - dc.font.descent) / 2); x = dc.x + (h / 2); /* shorten text if necessary */ for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--); @@ -805,7 +832,7 @@ memcpy(buf, text, len); if(len < olen) for(i = len; i && i > len - 3; buf[--i] = '.'); - XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); + XSetForeground(dpy, dc.gc, col[ ColFG ]); if(dc.font.set) XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); else @@ -855,7 +882,7 @@ detachstack(c); attachstack(c); grabbuttons(c, True); - XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]); + XSetWindowBorder(dpy, c->win, dc.colors[1][ColBorder]); setfocus(c); } else @@ -1027,12 +1054,6 @@ } void -incnmaster(const Arg *arg) { - selmon->nmaster = MAX(selmon->nmaster + arg->i, 0); - arrange(selmon); -} - -void initfont(const char *fontstr) { char *def, **missing; int n; @@ -1144,7 +1165,7 @@ wc.border_width = c->bw; XConfigureWindow(dpy, w, CWBorderWidth, &wc); - XSetWindowBorder(dpy, w, dc.norm[ColBorder]); + XSetWindowBorder(dpy, w, dc.colors[0][ColBorder]); configure(c); /* propagates border_width, if size doesn't change */ updatewindowtype(c); updatesizehints(c); @@ -1350,11 +1371,17 @@ void resizeclient(Client *c, int x, int y, int w, int h) { XWindowChanges wc; + + if(c->isfloating || selmon->lt[selmon->sellt]->arrange == NULL) { globalborder = 0 ; } + else { + if (selmon->lt[selmon->sellt]->arrange == monocle) { globalborder = 0 - borderpx ; } + else { globalborder = gappx ; } + } - c->oldx = c->x; c->x = wc.x = x; - c->oldy = c->y; c->y = wc.y = y; - c->oldw = c->w; c->w = wc.width = w; - c->oldh = c->h; c->h = wc.height = h; + c->oldx = c->x; c->x = wc.x = x + globalborder ; + c->oldy = c->y; c->y = wc.y = y + globalborder ; + c->oldw = c->w; c->w = wc.width = w - 2 * globalborder ; + c->oldh = c->h; c->h = wc.height = h - 2 * globalborder ; wc.border_width = c->bw; XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc); configure(c); @@ -1612,12 +1639,11 @@ cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); /* init appearance */ - dc.norm[ColBorder] = getcolor(normbordercolor); - dc.norm[ColBG] = getcolor(normbgcolor); - dc.norm[ColFG] = getcolor(normfgcolor); - dc.sel[ColBorder] = getcolor(selbordercolor); - dc.sel[ColBG] = getcolor(selbgcolor); - dc.sel[ColFG] = getcolor(selfgcolor); + for(int i=0; iclients); c; c = nexttiled(c->next), n++); if(n == 0) return; - - if(n > m->nmaster) - mw = m->nmaster ? m->ww * m->mfact : 0; - else - mw = m->ww; - for(i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) - if(i < m->nmaster) { - h = (m->wh - my) / (MIN(n, m->nmaster) - i); - resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), False); - my += HEIGHT(c); - } - else { - h = (m->wh - ty) / (n - i); - resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), False); - ty += HEIGHT(c); - } + /* master */ + c = nexttiled(m->clients); + mw = m->mfact * m->ww; + resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw, False); + if(--n == 0) + return; + /* tile stack */ + x = (m->wx + mw > c->x + c->w) ? c->x + c->w + 2 * c->bw : m->wx + mw; + y = m->wy; + w = (m->wx + mw > c->x + c->w) ? m->wx + m->ww - x : m->ww - mw; + h = m->wh / n; + if(h < bh) + h = m->wh; + for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) { + resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n) + ? m->wy + m->wh - y - 2 * c->bw : h - 2 * c->bw), False); + if(h != m->wh) + y = c->y + HEIGHT(c); + } } void @@ -1776,7 +1806,7 @@ if(!c) return; grabbuttons(c, False); - XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]); + XSetWindowBorder(dpy, c->win, dc.colors[0][ColBorder]); if(setfocus) XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); }