diff -r 79bf47074a49 config.mk --- a/config.mk Sat Dec 06 16:20:14 2008 +0000 +++ b/config.mk Thu Dec 11 22:50:24 2008 -0500 @@ -13,6 +13,8 @@ # Xinerama, un-comment if you want it #XINERAMALIBS = -L${X11LIB} -lXinerama #XINERAMAFLAGS = -DXINERAMA +XINERAMALIBS = -L${X11LIB} -lXrandr +XINERAMAFLAGS = -DXRANDR # includes and libs INCS = -I. -I/usr/include -I${X11INC} diff -r 79bf47074a49 dwm.c --- a/dwm.c Sat Dec 06 16:20:14 2008 +0000 +++ b/dwm.c Thu Dec 11 22:50:24 2008 -0500 @@ -42,6 +42,9 @@ #ifdef XINERAMA #include #endif +#ifdef XRANDR +#include +#endif /* macros */ #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) @@ -52,6 +55,7 @@ #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAXTAGLEN 16 +#define MAXMONITORS 8 #define MOUSEMASK (BUTTONMASK|PointerMotionMask) #define WIDTH(x) ((x)->w + 2 * (x)->bw) #define HEIGHT(x) ((x)->h + 2 * (x)->bw) @@ -206,10 +210,11 @@ /* variables */ static char stext[256]; -static int screen; +static int screen, mons; static int sx, sy, sw, sh; /* X display screen geometry x, y, width, height */ static int by, bh, blw; /* bar geometry y, height and layout symbol width */ static int wx, wy, ww, wh; /* window area geometry x, y, width, height, bar excluded */ +static int mx[MAXMONITORS], my[MAXMONITORS], mw[MAXMONITORS], mh[MAXMONITORS]; /* monitor area geometry x, y, width, height, bar excluded */ static unsigned int seltags = 0, sellt = 0; static int (*xerrorxlib)(Display *, XErrorEvent *); static unsigned int numlockmask = 0; @@ -926,10 +931,14 @@ void monocle(void) { - Client *c; + int m, i; + Client *c = nexttiled(clients); - for(c = nexttiled(clients); c; c = nexttiled(c->next)) - resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw, resizehints); + for(m=0; mnext), i--) + resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw, resizehints); + } } void @@ -1427,35 +1436,39 @@ void tile(void) { - int x, y, h, w, mw; - unsigned int i, n; + int x, y, h, w, maw; + unsigned int i, n, r, g, m; Client *c; for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), n++); if(n == 0) return; - /* master */ c = nexttiled(clients); - mw = mfact * ww; - resize(c, wx, wy, (n == 1 ? ww : mw) - 2 * c->bw, wh - 2 * c->bw, resizehints); + for(m=0, g=(n+(mons/2))/mons, r=n-g, n=g; c && mbw, wh - 2 * c->bw, resizehints); + c = nexttiled(c->next); - if(--n == 0) - return; + if( --n == 0 ) + continue; - /* tile stack */ - x = (wx + mw > c->x + c->w) ? c->x + c->w + 2 * c->bw : wx + mw; - y = wy; - w = (wx + mw > c->x + c->w) ? wx + ww - x : ww - mw; - h = wh / n; - if(h < bh) - h = wh; + /* tile stack */ + x = (wx + maw > c->x + c->w) ? c->x + c->w + 2 * c->bw : wx + maw; + y = wy; + w = (wx + maw > c->x + c->w) ? wx + ww - x : ww - maw; + h = wh / n; + if(h < bh) + h = 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) - ? wy + wh - y - 2 * c->bw : h - 2 * c->bw), resizehints); - if(h != wh) - y = c->y + HEIGHT(c); + for(i = 0; c && (m==(mons-1)?1:n); c = nexttiled(c->next), i++, n--) { + resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == g) + ? wy + wh - y - 2 * c->bw : h - 2 * c->bw), resizehints); + if(h != wh) + y = c->y + HEIGHT(c); + } } } @@ -1565,11 +1578,45 @@ } else #endif +#ifdef XRANDR + if( True /* xrr is active? */ ) { + int i=0, j=0, k=0, o=0; + XRRScreenResources *screenInfo = XRRGetScreenResources( dpy, root ); + XRRCrtcInfo *crtcInfo = NULL; + XID seenOutputs[MAXMONITORS*16]; // 16 clones should be enough + for(i=0, mons=0; incrtc; i++) { + crtcInfo = XRRGetCrtcInfo( dpy, screenInfo, screenInfo->crtcs[i] ); + + if( crtcInfo->noutput!=0 ) { + Bool dupe=False; + for(j=0; jnoutput; j++) { + for(k=0; seenOutputs[k]!=crtcInfo->outputs[j] && koutputs[j]; + } + + if( !dupe ) { + my[mons]=crtcInfo->y + (mons==0 && showbar && topbar ? bh : 0); + mh[mons]=crtcInfo->height - (mons==0 && showbar?bh:0); + mw[mons]=crtcInfo->width; + mx[mons++]=crtcInfo->x; + } + } + } + XRRFreeCrtcInfo(crtcInfo); + XRRFreeScreenResources(screenInfo); + + wx = mx[0]; wy = my[0]; ww = mw[0]; wh = mh[0]; + } else +#endif { - wx = sx; - wy = showbar && topbar ? sy + bh : sy; - ww = sw; - wh = showbar ? sh - bh : sh; + mons=1; + mx[0] = wx = sx; + my[0] = wy = showbar && topbar ? sy + bh : sy; + mw[0] = ww = sw; + mh[0] = wh = showbar ? sh - bh : sh; } /* bar position */