--- dwm-6.0/dwm.c 2011-12-19 15:02:46.000000000 +0000
+++ dwm.c 2013-02-22 17:17:00.617441008 +0000
@@ -36,6 +36,7 @@
#include <X11/Xlib.h>
#include <X11/Xproto.h>
#include <X11/Xutil.h>
+#include <X11/XKBlib.h>
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
#endif /* XINERAMA */
@@ -49,6 +50,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)
@@ -90,7 +92,7 @@
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
int bw, oldbw;
unsigned int tags;
- Bool isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
+ Bool isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, iscentred;
Client *next;
Client *snext;
Monitor *mon;
@@ -99,9 +101,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 +128,6 @@
struct Monitor {
char ltsymbol[16];
float mfact;
- int nmaster;
int num;
int by; /* bar geometry */
int mx, my, mw, mh; /* screen size */
@@ -151,6 +151,7 @@
const char *title;
unsigned int tags;
Bool isfloating;
+ Bool iscentred;
int monitor;
} Rule;
@@ -178,8 +179,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 +194,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 +284,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"
@@ -301,6 +303,7 @@
/* rule matching */
c->isfloating = c->tags = 0;
+ c->iscentred = 1;
XGetClassHint(dpy, c->win, &ch);
class = ch.res_class ? ch.res_class : broken;
instance = ch.res_name ? ch.res_name : broken;
@@ -312,6 +315,7 @@
&& (!r->instance || strstr(instance, r->instance)))
{
c->isfloating = r->isfloating;
+ c->iscentred = r->iscentred;
c->tags |= r->tags;
for(m = mons; m && m->num != r->monitor; m = m->next);
if(m)
@@ -651,7 +655,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,36 +733,35 @@
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 */
- dc.w = TEXTW(stext);
+ dc.w = TEXTW(stext) - dc.font.height /2;
dc.x = m->ww - dc.w;
if(dc.x < x) {
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 +776,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 +817,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 +836,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
@@ -814,6 +845,8 @@
void
enternotify(XEvent *e) {
+ if(clicktofocus) return;
+
Client *c;
Monitor *m;
XCrossingEvent *ev = &e->xcrossing;
@@ -855,7 +888,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 +1060,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;
@@ -1084,8 +1111,8 @@
XKeyEvent *ev;
ev = &e->xkey;
- keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
- for(i = 0; i < LENGTH(keys); i++)
+ keysym = XkbKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0, 0);
+ for(i = 0; i < LENGTH(keys); i++)
if(keysym == keys[i].keysym
&& CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
&& keys[i].func)
@@ -1126,8 +1153,14 @@
applyrules(c);
}
/* geometry */
- c->x = c->oldx = wa->x;
- c->y = c->oldy = wa->y;
+ if((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && c->iscentred) {
+ c->x = c->oldx = c->mon->wx + (c->mon->ww / 2 - wa->width / 2);
+ c->y = c->oldy = c->mon->wy + (c->mon->wh / 2 - wa->height / 2);
+ }
+ else {
+ c->x = c->oldx = wa->x;
+ c->y = c->oldy = wa->y;
+ }
c->w = c->oldw = wa->width;
c->h = c->oldh = wa->height;
c->oldbw = wa->border_width;
@@ -1144,7 +1177,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);
@@ -1205,6 +1238,8 @@
void
motionnotify(XEvent *e) {
+ if(clicktofocus) return;
+
static Monitor *mon = NULL;
Monitor *m;
XMotionEvent *ev = &e->xmotion;
@@ -1350,11 +1385,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 +1653,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; i<NUMCOLORS; i++) {
+ dc.colors[i][ColBorder] = getcolor( colors[i][ColBorder] );
+ dc.colors[i][ColFG] = getcolor( colors[i][ColFG] );
+ dc.colors[i][ColBG] = getcolor( colors[i][ColBG] );
+ }
dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
dc.gc = XCreateGC(dpy, root, 0, NULL);
XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
@@ -1703,28 +1743,32 @@
void
tile(Monitor *m) {
- unsigned int i, n, h, mw, my, ty;
+ int x, y, h, w, mw;
+ unsigned int i, n;
Client *c;
for(n = 0, c = nexttiled(m->clients); 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 +1820,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);
}