drastically changed updategeom() handling, see comment in updategeom() for details

This commit is contained in:
anselm@garbe.us 2012-06-23 10:12:46 +02:00
parent 820cbb3545
commit 20f6917910
2 changed files with 54 additions and 71 deletions

View File

@ -1,5 +1,5 @@
# dwm version # dwm version
VERSION = 6.0-tip VERSION = 6.1
# Customize below to fit your system # Customize below to fit your system

123
dwm.c
View File

@ -235,7 +235,7 @@ static void toggleview(const Arg *arg);
static void unfocus(Client *c, Bool setfocus); static void unfocus(Client *c, Bool setfocus);
static void unmanage(Client *c, Bool destroyed); static void unmanage(Client *c, Bool destroyed);
static void unmapnotify(XEvent *e); static void unmapnotify(XEvent *e);
static Bool updategeom(void); static void updategeom(void);
static void updatebarpos(Monitor *m); static void updatebarpos(Monitor *m);
static void updatebars(void); static void updatebars(void);
static void updateclientlist(void); static void updateclientlist(void);
@ -573,23 +573,18 @@ void
configurenotify(XEvent *e) { configurenotify(XEvent *e) {
Monitor *m; Monitor *m;
XConfigureEvent *ev = &e->xconfigure; XConfigureEvent *ev = &e->xconfigure;
Bool dirty;
// TODO: updategeom handling sucks, needs to be simplified
if(ev->window == root) { if(ev->window == root) {
dirty = (sw != ev->width || sh != ev->height);
sw = ev->width; sw = ev->width;
sh = ev->height; sh = ev->height;
if(updategeom() || dirty) { if(dc.drawable != 0)
if(dc.drawable != 0) XFreePixmap(dpy, dc.drawable);
XFreePixmap(dpy, dc.drawable); dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); updatebars();
updatebars(); for(m = mons; m; m = m->next)
for(m = mons; m; m = m->next) XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh); focus(NULL);
focus(NULL); arrange(NULL);
arrange(NULL);
}
} }
} }
@ -1076,8 +1071,8 @@ initfont(const char *fontstr) {
static Bool static Bool
isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) { isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) {
while(n--) while(n--)
if(unique[n].x_org == info->x_org && unique[n].y_org == info->y_org /* treat origin (x, y) as fixpoint for uniqueness only, first screen wins */
&& unique[n].width == info->width && unique[n].height == info->height) if(unique[n].x_org == info->x_org && unique[n].y_org == info->y_org)
return False; return False;
return True; return True;
} }
@ -1887,86 +1882,74 @@ updateclientlist() {
(unsigned char *) &(c->win), 1); (unsigned char *) &(c->win), 1);
} }
Bool void
updategeom(void) { updategeom(void) {
Bool dirty = False; /* Starting with dwm 6.1 this function uses a new (simpler) strategy:
* whenever screen changes are reported, we destroy all monitors
* and recreate all unique origin monitors and add all clients to
* the first monitor, only. In several circumstances this may suck,
* but dealing with all corner-cases sucks even more.*/
#ifdef XINERAMA #ifdef XINERAMA
if(XineramaIsActive(dpy)) { if(XineramaIsActive(dpy)) {
int i, j, n, nn; int i, j, n;
Client *c; Client *c;
Monitor *m; Monitor *m, *oldmons = mons;
XineramaScreenInfo *info = XineramaQueryScreens(dpy, &nn); XineramaScreenInfo *info = XineramaQueryScreens(dpy, &n);
XineramaScreenInfo *unique = NULL; XineramaScreenInfo *unique = NULL;
for(n = 0, m = mons; m; m = m->next, n++);
/* only consider unique geometries as separate screens */ /* only consider unique geometries as separate screens */
if(!(unique = (XineramaScreenInfo *)malloc(sizeof(XineramaScreenInfo) * nn))) if(!(unique = (XineramaScreenInfo *)malloc(sizeof(XineramaScreenInfo) * n)))
die("fatal: could not malloc() %u bytes\n", sizeof(XineramaScreenInfo) * nn); die("fatal: could not malloc() %u bytes\n", sizeof(XineramaScreenInfo) * n);
for(i = 0, j = 0; i < nn; i++) for(i = 0, j = 0; i < n; i++)
if(isuniquegeom(unique, j, &info[i])) if(isuniquegeom(unique, j, &info[i]))
memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo)); memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo));
XFree(info); XFree(info);
nn = j; /* create new monitor structure */
if(n <= nn) { n = j;
for(i = 0; i < (nn - n); i++) { /* new monitors available */ mons = m = createmon(); /* new first monitor */
for(m = mons; m && m->next; m = m->next); for(i = 1; i < n; i++) {
if(m) m->next = createmon();
m->next = createmon(); m = m->next;
else
mons = createmon();
}
for(i = 0, m = mons; i < nn && m; m = m->next, i++)
if(i >= n
|| (unique[i].x_org != m->mx || unique[i].y_org != m->my
|| unique[i].width != m->mw || unique[i].height != m->mh))
{
dirty = True;
m->num = i;
m->mx = m->wx = unique[i].x_org;
m->my = m->wy = unique[i].y_org;
m->mw = m->ww = unique[i].width;
m->mh = m->wh = unique[i].height;
updatebarpos(m);
}
} }
else { /* less monitors available nn < n */ for(i = 0, m = mons; i < n && m; m = m->next, i++) {
for(i = nn; i < n; i++) { m->num = i;
for(m = mons; m && m->next; m = m->next); m->mx = m->wx = unique[i].x_org;
while(m->clients) { m->my = m->wy = unique[i].y_org;
dirty = True; m->mw = m->ww = unique[i].width;
c = m->clients; m->mh = m->wh = unique[i].height;
m->clients = c->next; updatebarpos(m);
detachstack(c);
c->mon = mons;
attach(c);
attachstack(c);
}
if(m == selmon)
selmon = mons;
cleanupmon(m);
}
} }
free(unique); free(unique);
/* re-attach old clients and cleanup old monitor structure */
while(oldmons) {
m = oldmons;
while(m->clients) {
c = m->clients;
m->clients = c->next;
detachstack(c);
c->mon = mons;
attach(c);
attachstack(c);
}
oldmons = m->next;
cleanupmon(m);
}
} }
else else
#endif /* XINERAMA */ #endif /* XINERAMA */
/* default monitor setup */ /* default monitor setup */
{ {
if(!mons) if(!mons) /* only true if !XINERAMA compile flag */
mons = createmon(); mons = createmon();
if(mons->mw != sw || mons->mh != sh) { if(mons->mw != sw || mons->mh != sh) {
dirty = True;
mons->mw = mons->ww = sw; mons->mw = mons->ww = sw;
mons->mh = mons->wh = sh; mons->mh = mons->wh = sh;
updatebarpos(mons); updatebarpos(mons);
} }
} }
if(dirty) { selmon = mons;
selmon = mons; selmon = wintomon(root);
selmon = wintomon(root);
}
return dirty;
} }
void void