From 8aa40078d19b99124efb149bfc43fed47937fc15 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 26 Jun 2015 15:21:58 +0000 Subject: [PATCH 01/12] Replace screen region info gathering with XRandR equivalent of Xinerama queries (currently act on XRandR events anyway). Fall-back mode without XRandR is still what X provides. This removes -lXinerama. --- Makefile | 2 +- calmwm.h | 1 - screen.c | 43 +++++++++++++++++++++++++++---------------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 25584c7..f00441b 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ CPPFLAGS+= -I${X11BASE}/include -I${X11BASE}/include/freetype2 -I${.CURDIR} CFLAGS+= -Wall LDADD+= -L${X11BASE}/lib -lXft -lXrender -lX11 -lxcb -lXau -lXdmcp \ - -lfontconfig -lexpat -lfreetype -lz -lXinerama -lXrandr -lXext + -lfontconfig -lexpat -lfreetype -lz -lXrandr -lXext MANDIR= ${X11BASE}/man/man MAN= cwm.1 cwmrc.5 diff --git a/calmwm.h b/calmwm.h index 94ff526..526ef46 100644 --- a/calmwm.h +++ b/calmwm.h @@ -28,7 +28,6 @@ #include #include #include -#include #include #include diff --git a/screen.c b/screen.c index bb7bd9c..19d92a4 100644 --- a/screen.c +++ b/screen.c @@ -152,9 +152,8 @@ screen_find_xinerama(struct screen_ctx *sc, int x, int y, int flags) void screen_update_geometry(struct screen_ctx *sc) { - XineramaScreenInfo *info = NULL; struct region_ctx *region; - int info_num = 0, i; + int i; sc->view.x = 0; sc->view.y = 0; @@ -166,25 +165,37 @@ screen_update_geometry(struct screen_ctx *sc) sc->work.w = sc->view.w - (sc->gap.left + sc->gap.right); sc->work.h = sc->view.h - (sc->gap.top + sc->gap.bottom); - /* RandR event may have a CTRC added or removed. */ - if (XineramaIsActive(X_Dpy)) - info = XineramaQueryScreens(X_Dpy, &info_num); - while ((region = TAILQ_FIRST(&sc->regionq)) != NULL) { TAILQ_REMOVE(&sc->regionq, region, entry); free(region); } - for (i = 0; i < info_num; i++) { - region = xmalloc(sizeof(*region)); - region->num = i; - region->area.x = info[i].x_org; - region->area.y = info[i].y_org; - region->area.w = info[i].width; - region->area.h = info[i].height; - TAILQ_INSERT_TAIL(&sc->regionq, region, entry); + + if (HasRandr) { + XRRScreenResources *sr; + XRRCrtcInfo *ci; + + sr = XRRGetScreenResources(X_Dpy, sc->rootwin); + for (i = 0, ci = NULL; i < sr->ncrtc; i++) { + ci = XRRGetCrtcInfo(X_Dpy, sr, sr->crtcs[i]); + if (ci == NULL) + continue; + if (ci->noutput == 0) { + XRRFreeCrtcInfo(ci); + continue; + } + + region = xmalloc(sizeof(*region)); + region->num = i; + region->area.x = ci->x; + region->area.y = ci->y; + region->area.w = ci->width; + region->area.h = ci->height; + TAILQ_INSERT_TAIL(&sc->regionq, region, entry); + + XRRFreeCrtcInfo(ci); + } + XRRFreeScreenResources(sr); } - if (info) - XFree(info); xu_ewmh_net_desktop_geometry(sc); xu_ewmh_net_workarea(sc); From 90288e2fc36a3b8be8f16b4f110b8af7e7a2ca12 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 26 Jun 2015 16:11:21 +0000 Subject: [PATCH 02/12] collect 'gap' applications --- calmwm.h | 1 + screen.c | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/calmwm.h b/calmwm.h index 526ef46..0afbd18 100644 --- a/calmwm.h +++ b/calmwm.h @@ -450,6 +450,7 @@ void search_match_text(struct menu_q *, struct menu_q *, char *); void search_print_client(struct menu *, int); +struct geom screen_apply_gap(struct screen_ctx *, struct geom); struct screen_ctx *screen_find(Window); struct geom screen_find_xinerama(struct screen_ctx *, int, int, int); diff --git a/screen.c b/screen.c index 19d92a4..b61df5c 100644 --- a/screen.c +++ b/screen.c @@ -140,12 +140,8 @@ screen_find_xinerama(struct screen_ctx *sc, int x, int y, int flags) break; } } - if (flags & CWM_GAP) { - geom.x += sc->gap.left; - geom.y += sc->gap.top; - geom.w -= (sc->gap.left + sc->gap.right); - geom.h -= (sc->gap.top + sc->gap.bottom); - } + if (flags & CWM_GAP) + geom = screen_apply_gap(sc, geom); return(geom); } @@ -160,10 +156,7 @@ screen_update_geometry(struct screen_ctx *sc) sc->view.w = DisplayWidth(X_Dpy, sc->which); sc->view.h = DisplayHeight(X_Dpy, sc->which); - sc->work.x = sc->view.x + sc->gap.left; - sc->work.y = sc->view.y + sc->gap.top; - sc->work.w = sc->view.w - (sc->gap.left + sc->gap.right); - sc->work.h = sc->view.h - (sc->gap.top + sc->gap.bottom); + sc->work = screen_apply_gap(sc, sc->view); while ((region = TAILQ_FIRST(&sc->regionq)) != NULL) { TAILQ_REMOVE(&sc->regionq, region, entry); @@ -200,3 +193,14 @@ screen_update_geometry(struct screen_ctx *sc) xu_ewmh_net_desktop_geometry(sc); xu_ewmh_net_workarea(sc); } + +struct geom +screen_apply_gap(struct screen_ctx *sc, struct geom geom) +{ + geom.x += sc->gap.left; + geom.y += sc->gap.top; + geom.w -= (sc->gap.left + sc->gap.right); + geom.h -= (sc->gap.top + sc->gap.bottom); + + return(geom); +} From 66bc4162170b72f192c156b692b621643f1e5d52 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 26 Jun 2015 17:17:46 +0000 Subject: [PATCH 03/12] Mechanical change from xinerama to region backed areas. --- calmwm.h | 3 +- client.c | 114 ++++++++++++++++++++++++++-------------------------- kbfunc.c | 8 ++-- menu.c | 30 +++++++------- mousefunc.c | 8 ++-- screen.c | 13 +++--- 6 files changed, 86 insertions(+), 90 deletions(-) diff --git a/calmwm.h b/calmwm.h index 0afbd18..6c23615 100644 --- a/calmwm.h +++ b/calmwm.h @@ -452,8 +452,7 @@ void search_print_client(struct menu *, int); struct geom screen_apply_gap(struct screen_ctx *, struct geom); struct screen_ctx *screen_find(Window); -struct geom screen_find_xinerama(struct screen_ctx *, - int, int, int); +struct geom screen_area(struct screen_ctx *, int, int, int); void screen_init(int); void screen_update_geometry(struct screen_ctx *); void screen_updatestackingorder(struct screen_ctx *); diff --git a/client.c b/client.c index 16eee3a..d38d671 100644 --- a/client.c +++ b/client.c @@ -265,7 +265,7 @@ void client_toggle_fullscreen(struct client_ctx *cc) { struct screen_ctx *sc = cc->sc; - struct geom xine; + struct geom area; if ((cc->flags & CLIENT_FREEZE) && !(cc->flags & CLIENT_FULLSCREEN)) @@ -280,12 +280,12 @@ client_toggle_fullscreen(struct client_ctx *cc) cc->fullgeom = cc->geom; - xine = screen_find_xinerama(sc, + area = screen_area(sc, cc->geom.x + cc->geom.w / 2, cc->geom.y + cc->geom.h / 2, CWM_NOGAP); cc->bwidth = 0; - cc->geom = xine; + cc->geom = area; cc->flags |= (CLIENT_FULLSCREEN | CLIENT_FREEZE); resize: @@ -297,7 +297,7 @@ void client_toggle_maximize(struct client_ctx *cc) { struct screen_ctx *sc = cc->sc; - struct geom xine; + struct geom area; if (cc->flags & (CLIENT_FREEZE|CLIENT_STICKY)) return; @@ -323,14 +323,14 @@ client_toggle_maximize(struct client_ctx *cc) * that's probably more fair than if just the origin of * a window is poking over a boundary */ - xine = screen_find_xinerama(sc, + area = screen_area(sc, cc->geom.x + cc->geom.w / 2, cc->geom.y + cc->geom.h / 2, CWM_GAP); - cc->geom.x = xine.x; - cc->geom.y = xine.y; - cc->geom.w = xine.w - (cc->bwidth * 2); - cc->geom.h = xine.h - (cc->bwidth * 2); + cc->geom.x = area.x; + cc->geom.y = area.y; + cc->geom.w = area.w - (cc->bwidth * 2); + cc->geom.h = area.h - (cc->bwidth * 2); cc->flags |= CLIENT_MAXIMIZED; resize: @@ -342,7 +342,7 @@ void client_toggle_vmaximize(struct client_ctx *cc) { struct screen_ctx *sc = cc->sc; - struct geom xine; + struct geom area; if (cc->flags & (CLIENT_FREEZE|CLIENT_STICKY)) return; @@ -357,12 +357,12 @@ client_toggle_vmaximize(struct client_ctx *cc) cc->savegeom.y = cc->geom.y; cc->savegeom.h = cc->geom.h; - xine = screen_find_xinerama(sc, + area = screen_area(sc, cc->geom.x + cc->geom.w / 2, cc->geom.y + cc->geom.h / 2, CWM_GAP); - cc->geom.y = xine.y; - cc->geom.h = xine.h - (cc->bwidth * 2); + cc->geom.y = area.y; + cc->geom.h = area.h - (cc->bwidth * 2); cc->flags |= CLIENT_VMAXIMIZED; resize: @@ -374,7 +374,7 @@ void client_toggle_hmaximize(struct client_ctx *cc) { struct screen_ctx *sc = cc->sc; - struct geom xine; + struct geom area; if (cc->flags & (CLIENT_FREEZE|CLIENT_STICKY)) return; @@ -389,12 +389,12 @@ client_toggle_hmaximize(struct client_ctx *cc) cc->savegeom.x = cc->geom.x; cc->savegeom.w = cc->geom.w; - xine = screen_find_xinerama(sc, + area = screen_area(sc, cc->geom.x + cc->geom.w / 2, cc->geom.y + cc->geom.h / 2, CWM_GAP); - cc->geom.x = xine.x; - cc->geom.w = xine.w - (cc->bwidth * 2); + cc->geom.x = area.x; + cc->geom.w = area.w - (cc->bwidth * 2); cc->flags |= CLIENT_HMAXIMIZED; resize: @@ -740,33 +740,33 @@ client_placecalc(struct client_ctx *cc) cc->geom.x = MIN(cc->geom.x, xslack); cc->geom.y = MIN(cc->geom.y, yslack); } else { - struct geom xine; + struct geom area; int xmouse, ymouse; xu_ptr_getpos(sc->rootwin, &xmouse, &ymouse); - xine = screen_find_xinerama(sc, xmouse, ymouse, CWM_GAP); - xine.w += xine.x; - xine.h += xine.y; - xmouse = MAX(xmouse, xine.x) - cc->geom.w / 2; - ymouse = MAX(ymouse, xine.y) - cc->geom.h / 2; + area = screen_area(sc, xmouse, ymouse, CWM_GAP); + area.w += area.x; + area.h += area.y; + xmouse = MAX(xmouse, area.x) - cc->geom.w / 2; + ymouse = MAX(ymouse, area.y) - cc->geom.h / 2; - xmouse = MAX(xmouse, xine.x); - ymouse = MAX(ymouse, xine.y); + xmouse = MAX(xmouse, area.x); + ymouse = MAX(ymouse, area.y); - xslack = xine.w - cc->geom.w - cc->bwidth * 2; - yslack = xine.h - cc->geom.h - cc->bwidth * 2; + xslack = area.w - cc->geom.w - cc->bwidth * 2; + yslack = area.h - cc->geom.h - cc->bwidth * 2; - if (xslack >= xine.x) { - cc->geom.x = MAX(MIN(xmouse, xslack), xine.x); + if (xslack >= area.x) { + cc->geom.x = MAX(MIN(xmouse, xslack), area.x); } else { - cc->geom.x = xine.x; - cc->geom.w = xine.w; + cc->geom.x = area.x; + cc->geom.w = area.w; } - if (yslack >= xine.y) { - cc->geom.y = MAX(MIN(ymouse, yslack), xine.y); + if (yslack >= area.y) { + cc->geom.y = MAX(MIN(ymouse, yslack), area.y); } else { - cc->geom.y = xine.y; - cc->geom.h = xine.h; + cc->geom.y = area.y; + cc->geom.h = area.h; } } } @@ -949,7 +949,7 @@ client_htile(struct client_ctx *cc) struct client_ctx *ci; struct group_ctx *gc = cc->group; struct screen_ctx *sc = cc->sc; - struct geom xine; + struct geom area; int i, n, mh, x, h, w; if (!gc) @@ -965,36 +965,36 @@ client_htile(struct client_ctx *cc) if (n == 0) return; - xine = screen_find_xinerama(sc, + area = screen_area(sc, cc->geom.x + cc->geom.w / 2, cc->geom.y + cc->geom.h / 2, CWM_GAP); if (cc->flags & CLIENT_VMAXIMIZED || - cc->geom.h + (cc->bwidth * 2) >= xine.h) + cc->geom.h + (cc->bwidth * 2) >= area.h) return; cc->flags &= ~CLIENT_HMAXIMIZED; - cc->geom.x = xine.x; - cc->geom.y = xine.y; - cc->geom.w = xine.w - (cc->bwidth * 2); + cc->geom.x = area.x; + cc->geom.y = area.y; + cc->geom.w = area.w - (cc->bwidth * 2); client_resize(cc, 1); client_ptrwarp(cc); mh = cc->geom.h + (cc->bwidth * 2); - x = xine.x; - w = xine.w / n; - h = xine.h - mh; + x = area.x; + w = area.w / n; + h = area.h - mh; TAILQ_FOREACH(ci, &gc->clientq, group_entry) { if (ci->flags & CLIENT_HIDDEN || ci->flags & CLIENT_IGNORE || (ci == cc)) continue; ci->bwidth = Conf.bwidth; - ci->geom.y = xine.y + mh; + ci->geom.y = area.y + mh; ci->geom.x = x; ci->geom.h = h - (ci->bwidth * 2); ci->geom.w = w - (ci->bwidth * 2); if (i + 1 == n) - ci->geom.w = xine.x + xine.w - + ci->geom.w = area.x + area.w - ci->geom.x - (ci->bwidth * 2); x += w; client_resize(ci, 1); @@ -1008,7 +1008,7 @@ client_vtile(struct client_ctx *cc) struct client_ctx *ci; struct group_ctx *gc = cc->group; struct screen_ctx *sc = cc->sc; - struct geom xine; + struct geom area; int i, n, mw, y, h, w; if (!gc) @@ -1024,36 +1024,36 @@ client_vtile(struct client_ctx *cc) if (n == 0) return; - xine = screen_find_xinerama(sc, + area = screen_area(sc, cc->geom.x + cc->geom.w / 2, cc->geom.y + cc->geom.h / 2, CWM_GAP); if (cc->flags & CLIENT_HMAXIMIZED || - cc->geom.w + (cc->bwidth * 2) >= xine.w) + cc->geom.w + (cc->bwidth * 2) >= area.w) return; cc->flags &= ~CLIENT_VMAXIMIZED; - cc->geom.x = xine.x; - cc->geom.y = xine.y; - cc->geom.h = xine.h - (cc->bwidth * 2); + cc->geom.x = area.x; + cc->geom.y = area.y; + cc->geom.h = area.h - (cc->bwidth * 2); client_resize(cc, 1); client_ptrwarp(cc); mw = cc->geom.w + (cc->bwidth * 2); - y = xine.y; - h = xine.h / n; - w = xine.w - mw; + y = area.y; + h = area.h / n; + w = area.w - mw; TAILQ_FOREACH(ci, &gc->clientq, group_entry) { if (ci->flags & CLIENT_HIDDEN || ci->flags & CLIENT_IGNORE || (ci == cc)) continue; ci->bwidth = Conf.bwidth; ci->geom.y = y; - ci->geom.x = xine.x + mw; + ci->geom.x = area.x + mw; ci->geom.h = h - (ci->bwidth * 2); ci->geom.w = w - (ci->bwidth * 2); if (i + 1 == n) - ci->geom.h = xine.y + xine.h - + ci->geom.h = area.y + area.h - ci->geom.y - (ci->bwidth * 2); y += h; client_resize(ci, 1); diff --git a/kbfunc.c b/kbfunc.c index a6364ac..5011a8a 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -57,7 +57,7 @@ void kbfunc_client_moveresize(struct client_ctx *cc, union arg *arg) { struct screen_ctx *sc = cc->sc; - struct geom xine; + struct geom area; int x, y, flags, amt; unsigned int mx, my; @@ -101,15 +101,15 @@ kbfunc_client_moveresize(struct client_ctx *cc, union arg *arg) if (cc->geom.y > sc->view.h - 1) cc->geom.y = sc->view.h - 1; - xine = screen_find_xinerama(sc, + area = screen_area(sc, cc->geom.x + cc->geom.w / 2, cc->geom.y + cc->geom.h / 2, CWM_GAP); cc->geom.x += client_snapcalc(cc->geom.x, cc->geom.x + cc->geom.w + (cc->bwidth * 2), - xine.x, xine.x + xine.w, sc->snapdist); + area.x, area.x + area.w, sc->snapdist); cc->geom.y += client_snapcalc(cc->geom.y, cc->geom.y + cc->geom.h + (cc->bwidth * 2), - xine.y, xine.y + xine.h, sc->snapdist); + area.y, area.y + area.h, sc->snapdist); client_move(cc); xu_ptr_getpos(cc->win, &x, &y); diff --git a/menu.c b/menu.c index a348b40..5a7bef3 100644 --- a/menu.c +++ b/menu.c @@ -331,7 +331,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) { struct screen_ctx *sc = mc->sc; struct menu *mi; - struct geom xine; + struct geom area; int n, xsave, ysave; if (mc->list) { @@ -374,25 +374,25 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) mc->num++; } - xine = screen_find_xinerama(sc, mc->geom.x, mc->geom.y, CWM_GAP); - xine.w += xine.x - Conf.bwidth * 2; - xine.h += xine.y - Conf.bwidth * 2; + area = screen_area(sc, mc->geom.x, mc->geom.y, CWM_GAP); + area.w += area.x - Conf.bwidth * 2; + area.h += area.y - Conf.bwidth * 2; xsave = mc->geom.x; ysave = mc->geom.y; /* Never hide the top, or left side, of the menu. */ - if (mc->geom.x + mc->geom.w >= xine.w) - mc->geom.x = xine.w - mc->geom.w; - if (mc->geom.x < xine.x) { - mc->geom.x = xine.x; - mc->geom.w = MIN(mc->geom.w, (xine.w - xine.x)); + if (mc->geom.x + mc->geom.w >= area.w) + mc->geom.x = area.w - mc->geom.w; + if (mc->geom.x < area.x) { + mc->geom.x = area.x; + mc->geom.w = MIN(mc->geom.w, (area.w - area.x)); } - if (mc->geom.y + mc->geom.h >= xine.h) - mc->geom.y = xine.h - mc->geom.h; - if (mc->geom.y < xine.y) { - mc->geom.y = xine.y; - mc->geom.h = MIN(mc->geom.h, (xine.h - xine.y)); + if (mc->geom.y + mc->geom.h >= area.h) + mc->geom.y = area.h - mc->geom.h; + if (mc->geom.y < area.y) { + mc->geom.y = area.y; + mc->geom.h = MIN(mc->geom.h, (area.h - area.y)); } if (mc->geom.x != xsave || mc->geom.y != ysave) @@ -415,7 +415,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) int y = n * (sc->xftfont->height + 1) + sc->xftfont->ascent + 1; /* Stop drawing when menu doesn't fit inside the screen. */ - if (mc->geom.y + y > xine.h) + if (mc->geom.y + y > area.h) break; xu_xft_draw(sc, text, CWM_COLOR_MENU_FONT, 0, y); diff --git a/mousefunc.c b/mousefunc.c index e48833c..8ba56be 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -123,7 +123,7 @@ mousefunc_client_move(struct client_ctx *cc, union arg *arg) XEvent ev; Time ltime = 0; struct screen_ctx *sc = cc->sc; - struct geom xine; + struct geom area; int px, py; client_raise(cc); @@ -149,15 +149,15 @@ mousefunc_client_move(struct client_ctx *cc, union arg *arg) cc->geom.x = ev.xmotion.x_root - px - cc->bwidth; cc->geom.y = ev.xmotion.y_root - py - cc->bwidth; - xine = screen_find_xinerama(sc, + area = screen_area(sc, cc->geom.x + cc->geom.w / 2, cc->geom.y + cc->geom.h / 2, CWM_GAP); cc->geom.x += client_snapcalc(cc->geom.x, cc->geom.x + cc->geom.w + (cc->bwidth * 2), - xine.x, xine.x + xine.w, sc->snapdist); + area.x, area.x + area.w, sc->snapdist); cc->geom.y += client_snapcalc(cc->geom.y, cc->geom.y + cc->geom.h + (cc->bwidth * 2), - xine.y, xine.y + xine.h, sc->snapdist); + area.y, area.y + area.h, sc->snapdist); client_move(cc); break; diff --git a/screen.c b/screen.c index b61df5c..14d0b5c 100644 --- a/screen.c +++ b/screen.c @@ -124,25 +124,22 @@ screen_updatestackingorder(struct screen_ctx *sc) } } -/* - * Find which xinerama screen the coordinates (x,y) is on. - */ struct geom -screen_find_xinerama(struct screen_ctx *sc, int x, int y, int flags) +screen_area(struct screen_ctx *sc, int x, int y, int flags) { struct region_ctx *region; - struct geom geom = sc->work; + struct geom area = sc->work; TAILQ_FOREACH(region, &sc->regionq, entry) { if (x >= region->area.x && x < region->area.x+region->area.w && y >= region->area.y && y < region->area.y+region->area.h) { - geom = region->area; + area = region->area; break; } } if (flags & CWM_GAP) - geom = screen_apply_gap(sc, geom); - return(geom); + area = screen_apply_gap(sc, area); + return(area); } void From 18f63629fdb322e2bd9d39972bf28c3bc96d0942 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 26 Jun 2015 18:54:25 +0000 Subject: [PATCH 04/12] region is a _ctx, so name it so --- screen.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/screen.c b/screen.c index 14d0b5c..81712ab 100644 --- a/screen.c +++ b/screen.c @@ -127,13 +127,13 @@ screen_updatestackingorder(struct screen_ctx *sc) struct geom screen_area(struct screen_ctx *sc, int x, int y, int flags) { - struct region_ctx *region; + struct region_ctx *rc; struct geom area = sc->work; - TAILQ_FOREACH(region, &sc->regionq, entry) { - if (x >= region->area.x && x < region->area.x+region->area.w && - y >= region->area.y && y < region->area.y+region->area.h) { - area = region->area; + TAILQ_FOREACH(rc, &sc->regionq, entry) { + if ((x >= rc->area.x) && (x < (rc->area.x + rc->area.w)) && + (y >= rc->area.y) && (y < (rc->area.y + rc->area.h))) { + area = rc->area; break; } } @@ -145,7 +145,7 @@ screen_area(struct screen_ctx *sc, int x, int y, int flags) void screen_update_geometry(struct screen_ctx *sc) { - struct region_ctx *region; + struct region_ctx *rc; int i; sc->view.x = 0; @@ -155,9 +155,9 @@ screen_update_geometry(struct screen_ctx *sc) sc->work = screen_apply_gap(sc, sc->view); - while ((region = TAILQ_FIRST(&sc->regionq)) != NULL) { - TAILQ_REMOVE(&sc->regionq, region, entry); - free(region); + while ((rc = TAILQ_FIRST(&sc->regionq)) != NULL) { + TAILQ_REMOVE(&sc->regionq, rc, entry); + free(rc); } if (HasRandr) { @@ -174,13 +174,13 @@ screen_update_geometry(struct screen_ctx *sc) continue; } - region = xmalloc(sizeof(*region)); - region->num = i; - region->area.x = ci->x; - region->area.y = ci->y; - region->area.w = ci->width; - region->area.h = ci->height; - TAILQ_INSERT_TAIL(&sc->regionq, region, entry); + rc = xmalloc(sizeof(*rc)); + rc->num = i; + rc->area.x = ci->x; + rc->area.y = ci->y; + rc->area.w = ci->width; + rc->area.h = ci->height; + TAILQ_INSERT_TAIL(&sc->regionq, rc, entry); XRRFreeCrtcInfo(ci); } From 17720de4abd818ec04447f255e3d670ed2929911 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 28 Jun 2015 19:50:46 +0000 Subject: [PATCH 05/12] replace assert usage --- client.c | 5 ++--- group.c | 5 ++--- search.c | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/client.c b/client.c index d38d671..c4765af 100644 --- a/client.c +++ b/client.c @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -635,8 +634,8 @@ match: /* Now, do some garbage collection. */ if (cc->nameqlen > CLIENT_MAXNAMEQLEN) { - wn = TAILQ_FIRST(&cc->nameq); - assert(wn != NULL); + if ((wn = TAILQ_FIRST(&cc->nameq)) == NULL) + errx(1, "client_setname: window name queue empty"); TAILQ_REMOVE(&cc->nameq, wn, entry); free(wn->name); free(wn); diff --git a/group.c b/group.c index 7ab65f9..1bf2fd7 100644 --- a/group.c +++ b/group.c @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -264,9 +263,9 @@ group_cycle(struct screen_ctx *sc, int flags) { struct group_ctx *gc, *showgroup = NULL; - assert(sc->group_active != NULL); + if (((gc = sc->group_active)) == NULL) + errx(1, "group_cycle: no active group"); - gc = sc->group_active; for (;;) { gc = (flags & CWM_RCYCLE) ? TAILQ_PREV(gc, group_ctx_q, entry) : TAILQ_NEXT(gc, entry); diff --git a/search.c b/search.c index 770159b..9ddfd79 100644 --- a/search.c +++ b/search.c @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -106,7 +105,8 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) if ((cc->flags & CLIENT_HIDDEN) && (tier > 0)) tier--; - assert(tier < nitems(tierp)); + if (tier >= nitems(tierp)) + errx(1, "search_match_client: invalid tier"); /* * If you have a tierp, insert after it, and make it From e7b4045ecea3b063bc8238172998ce5b1ed5bb97 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 28 Jun 2015 19:54:37 +0000 Subject: [PATCH 06/12] move client_find down --- client.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/client.c b/client.c index c4765af..2b4be67 100644 --- a/client.c +++ b/client.c @@ -42,21 +42,6 @@ static int client_inbound(struct client_ctx *, int, int); struct client_ctx *curcc = NULL; -struct client_ctx * -client_find(Window win) -{ - struct screen_ctx *sc; - struct client_ctx *cc; - - TAILQ_FOREACH(sc, &Screenq, entry) { - TAILQ_FOREACH(cc, &sc->clientq, entry) { - if (cc->win == win) - return(cc); - } - } - return(NULL); -} - struct client_ctx * client_init(Window win, struct screen_ctx *sc) { @@ -142,6 +127,21 @@ client_init(Window win, struct screen_ctx *sc) return(cc); } +struct client_ctx * +client_find(Window win) +{ + struct screen_ctx *sc; + struct client_ctx *cc; + + TAILQ_FOREACH(sc, &Screenq, entry) { + TAILQ_FOREACH(cc, &sc->clientq, entry) { + if (cc->win == win) + return(cc); + } + } + return(NULL); +} + void client_delete(struct client_ctx *cc) { From 9ea5f25347c056fc1ad2bf61a25dcb7181d5179b Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 29 Jun 2015 14:24:40 +0000 Subject: [PATCH 07/12] Shuffle code in kbfunc_ssh so that a missing known_hosts file still allows a (now blank) menu to appear, as opposed to nothing at all. Behavior reported by Alex Greif. --- kbfunc.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/kbfunc.c b/kbfunc.c index 5011a8a..c7de00d 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -329,18 +329,17 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg) int l; size_t len; - if ((fp = fopen(Conf.known_hosts, "r")) == NULL) { - warn("kbfunc_ssh: %s", Conf.known_hosts); - return; - } - TAILQ_FOREACH(cmd, &Conf.cmdq, entry) { if (strcmp(cmd->name, "term") == 0) break; } - TAILQ_INIT(&menuq); + if ((fp = fopen(Conf.known_hosts, "r")) == NULL) { + warn("kbfunc_ssh: %s", Conf.known_hosts); + goto menu; + } + lbuf = NULL; while ((buf = fgetln(fp, &len))) { if (buf[len - 1] == '\n') @@ -366,7 +365,7 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg) } free(lbuf); (void)fclose(fp); - +menu: if ((mi = menu_filter(sc, &menuq, "ssh", NULL, CWM_MENU_DUMMY, search_match_exec, NULL)) != NULL) { if (mi->text[0] == '\0') From 8515d717ae5bb336e089e9c10a92b499de5d4c81 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 30 Jun 2015 14:01:43 +0000 Subject: [PATCH 08/12] Re-implement XClientMessage handling so that we can feed screen_find and client_find valid resources as needed, relieving the need for screen_find to ungracefully handle invalid root windows. Removes a long standing XXX. Should theoretically allow XClientMessage handling on more than one X screen. Alter callers of screen_find to handle failures. --- client.c | 3 ++- screen.c | 4 +-- xevents.c | 80 +++++++++++++++++++++++++++++-------------------------- 3 files changed, 46 insertions(+), 41 deletions(-) diff --git a/client.c b/client.c index 2b4be67..de1e8a1 100644 --- a/client.c +++ b/client.c @@ -55,7 +55,8 @@ client_init(Window win, struct screen_ctx *sc) return(NULL); if (sc == NULL) { - sc = screen_find(wattr.root); + if ((sc = screen_find(wattr.root)) == NULL) + return(NULL); mapped = 1; } else { if (wattr.override_redirect || wattr.map_state != IsViewable) diff --git a/screen.c b/screen.c index 81712ab..7ba8a31 100644 --- a/screen.c +++ b/screen.c @@ -100,8 +100,8 @@ screen_find(Window win) if (sc->rootwin == win) return(sc); } - /* XXX FAIL HERE */ - return(TAILQ_FIRST(&Screenq)); + warnx("screen_find failure win 0x%lu\n", win); + return(NULL); } void diff --git a/xevents.c b/xevents.c index e6ed84d..424a539 100644 --- a/xevents.c +++ b/xevents.c @@ -240,7 +240,8 @@ xev_handle_buttonpress(XEvent *ee) if (e->window != e->root) return; cc = &fakecc; - cc->sc = screen_find(e->window); + if ((cc->sc = screen_find(e->window)) == NULL) + return; } (*mb->callback)(cc, &mb->argument); @@ -290,7 +291,8 @@ xev_handle_keypress(XEvent *ee) return; } else { cc = &fakecc; - cc->sc = screen_find(e->window); + if ((cc->sc = screen_find(e->window)) == NULL) + return; } (*kb->callback)(cc, &kb->argument); @@ -307,7 +309,8 @@ xev_handle_keyrelease(XEvent *ee) KeySym keysym; unsigned int i; - sc = screen_find(e->root); + if ((sc = screen_find(e->root)) == NULL) + return; keysym = XkbKeycodeToKeysym(X_Dpy, e->keycode, 0, 0); for (i = 0; i < nitems(modkeys); i++) { @@ -325,42 +328,43 @@ xev_handle_clientmessage(XEvent *ee) struct client_ctx *cc, *old_cc; struct screen_ctx *sc; - sc = screen_find(e->window); - - if ((cc = client_find(e->window)) == NULL && e->window != sc->rootwin) - return; - - if (e->message_type == cwmh[WM_CHANGE_STATE] && e->format == 32 && - e->data.l[0] == IconicState) - client_hide(cc); - - if (e->message_type == ewmh[_NET_CLOSE_WINDOW]) - client_send_delete(cc); - - if (e->message_type == ewmh[_NET_ACTIVE_WINDOW] && e->format == 32) { - if ((old_cc = client_current())) - client_ptrsave(old_cc); - client_ptrwarp(cc); + if (e->message_type == cwmh[WM_CHANGE_STATE]) { + if ((cc = client_find(e->window)) != NULL) { + if (e->data.l[0] == IconicState) + client_hide(cc); + } + } else if (e->message_type == ewmh[_NET_CLOSE_WINDOW]) { + if ((cc = client_find(e->window)) != NULL) { + client_send_delete(cc); + } + } else if (e->message_type == ewmh[_NET_ACTIVE_WINDOW]) { + if ((cc = client_find(e->window)) != NULL) { + if ((old_cc = client_current())) + client_ptrsave(old_cc); + client_ptrwarp(cc); + } + } else if (e->message_type == ewmh[_NET_WM_DESKTOP]) { + if ((cc = client_find(e->window)) != NULL) { + /* + * The EWMH spec states that if the cardinal returned + * is 0xFFFFFFFF (-1) then the window should appear + * on all desktops, in our case, group 0. + */ + if (e->data.l[0] == (unsigned long)-1) + group_movetogroup(cc, 0); + else + group_movetogroup(cc, e->data.l[0]); + } + } else if (e->message_type == ewmh[_NET_WM_STATE]) { + if ((cc = client_find(e->window)) != NULL) { + xu_ewmh_handle_net_wm_state_msg(cc, + e->data.l[0], e->data.l[1], e->data.l[2]); + } + } else if (e->message_type == ewmh[_NET_CURRENT_DESKTOP]) { + if ((sc = screen_find(e->window)) != NULL) { + group_only(sc, e->data.l[0]); + } } - - if (e->message_type == ewmh[_NET_WM_DESKTOP] && e->format == 32) { - /* - * The EWMH spec states that if the cardinal returned is - * 0xFFFFFFFF (-1) then the window should appear on all - * desktops, which in our case is assigned to group 0. - */ - if (e->data.l[0] == (unsigned long)-1) - group_movetogroup(cc, 0); - else - group_movetogroup(cc, e->data.l[0]); - } - - if (e->message_type == ewmh[_NET_WM_STATE] && e->format == 32) - xu_ewmh_handle_net_wm_state_msg(cc, - e->data.l[0], e->data.l[1], e->data.l[2]); - - if (e->message_type == ewmh[_NET_CURRENT_DESKTOP] && e->format == 32) - group_only(sc, e->data.l[0]); } static void From 6b8b8562172c860b8341fc9acf45ee7e2880e45a Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 30 Jun 2015 18:42:50 +0000 Subject: [PATCH 09/12] style and spacing nits --- conf.c | 6 +++--- menu.c | 5 +++-- search.c | 10 ++-------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/conf.c b/conf.c index a202e73..dab93e2 100644 --- a/conf.c +++ b/conf.c @@ -33,9 +33,9 @@ #include "calmwm.h" static const char *conf_bind_getmask(const char *, unsigned int *); -static void conf_cmd_remove(struct conf *, const char *); -static void conf_unbind_kbd(struct conf *, struct binding *); -static void conf_unbind_mouse(struct conf *, struct binding *); +static void conf_cmd_remove(struct conf *, const char *); +static void conf_unbind_kbd(struct conf *, struct binding *); +static void conf_unbind_mouse(struct conf *, struct binding *); int conf_cmd_add(struct conf *c, const char *name, const char *path) diff --git a/menu.c b/menu.c index 5a7bef3..0151ecf 100644 --- a/menu.c +++ b/menu.c @@ -72,7 +72,7 @@ static void menu_draw(struct menu_ctx *, struct menu_q *, static void menu_draw_entry(struct menu_ctx *, struct menu_q *, int, int); static int menu_calc_entry(struct menu_ctx *, int, int); -static struct menu *menu_complete_path(struct menu_ctx *); +static struct menu *menu_complete_path(struct menu_ctx *); static int menu_keycode(XKeyEvent *, enum ctltype *, char *); struct menu * @@ -184,6 +184,7 @@ out: static struct menu * menu_complete_path(struct menu_ctx *mc) { + struct screen_ctx *sc = mc->sc; struct menu *mi, *mr; struct menu_q menuq; @@ -191,7 +192,7 @@ menu_complete_path(struct menu_ctx *mc) TAILQ_INIT(&menuq); - if ((mi = menu_filter(mc->sc, &menuq, mc->searchstr, NULL, + if ((mi = menu_filter(sc, &menuq, mc->searchstr, NULL, CWM_MENU_DUMMY, search_match_path_any, NULL)) != NULL) { mr->abort = mi->abort; mr->dummy = mi->dummy; diff --git a/search.c b/search.c index 9ddfd79..edb3421 100644 --- a/search.c +++ b/search.c @@ -42,10 +42,6 @@ static void search_match_path_exec(struct menu_q *, struct menu_q *, char *); static int strsubmatch(char *, char *, int); -/* - * Match: label, title, class. - */ - void search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) { @@ -66,7 +62,7 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) TAILQ_FOREACH(mi, menuq, entry) { int tier = -1, t; - struct client_ctx *cc = mi->ctx; + struct client_ctx *cc = (struct client_ctx *)mi->ctx; /* First, try to match on labels. */ if (cc->label != NULL && strsubmatch(search, cc->label, 0)) { @@ -130,11 +126,9 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) void search_print_client(struct menu *mi, int list) { - struct client_ctx *cc; + struct client_ctx *cc = (struct client_ctx *)mi->ctx; char flag = ' '; - cc = mi->ctx; - if (cc == client_current()) flag = '!'; else if (cc->flags & CLIENT_HIDDEN) From c87953eb647c360cef8834c381bd22de4a0b524b Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 30 Jun 2015 18:44:29 +0000 Subject: [PATCH 10/12] keep cmdq sorted --- conf.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/conf.c b/conf.c index dab93e2..95054d2 100644 --- a/conf.c +++ b/conf.c @@ -40,7 +40,7 @@ static void conf_unbind_mouse(struct conf *, struct binding *); int conf_cmd_add(struct conf *c, const char *name, const char *path) { - struct cmd *cmd; + struct cmd *cmd, *prev; cmd = xmalloc(sizeof(*cmd)); @@ -54,6 +54,14 @@ conf_cmd_add(struct conf *c, const char *name, const char *path) conf_cmd_remove(c, name); TAILQ_INSERT_TAIL(&c->cmdq, cmd, entry); + + /* keep queue sorted by name */ + while ((prev = TAILQ_PREV(cmd, cmd_q, entry)) && + (strcmp(prev->name, cmd->name) > 0)) { + TAILQ_REMOVE(&c->cmdq, cmd, entry); + TAILQ_INSERT_BEFORE(prev, cmd, entry); + } + return(1); } From 5d8027b75d20174446aa3788f856280aae7dd622 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 30 Jun 2015 18:54:12 +0000 Subject: [PATCH 11/12] Introduce a callback for cmd menu printing, special-casing 'lock' and 'term'. --- calmwm.h | 1 + kbfunc.c | 2 +- mousefunc.c | 2 +- search.c | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/calmwm.h b/calmwm.h index 6c23615..32cf00f 100644 --- a/calmwm.h +++ b/calmwm.h @@ -449,6 +449,7 @@ void search_match_path_any(struct menu_q *, struct menu_q *, void search_match_text(struct menu_q *, struct menu_q *, char *); void search_print_client(struct menu *, int); +void search_print_cmd(struct menu *, int); struct geom screen_apply_gap(struct screen_ctx *, struct geom); struct screen_ctx *screen_find(Window); diff --git a/kbfunc.c b/kbfunc.c index c7de00d..a107b95 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -181,7 +181,7 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg) menuq_add(&menuq, cmd, "%s", cmd->name); if ((mi = menu_filter(sc, &menuq, "application", NULL, 0, - search_match_text, NULL)) != NULL) + search_match_text, search_print_cmd)) != NULL) u_spawn(((struct cmd *)mi->ctx)->path); menuq_clear(&menuq); diff --git a/mousefunc.c b/mousefunc.c index 8ba56be..bc31118 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -239,7 +239,7 @@ mousefunc_menu_cmd(struct client_ctx *cc, union arg *arg) menuq_add(&menuq, cmd, "%s", cmd->name); if ((mi = menu_filter(sc, &menuq, NULL, NULL, CWM_MENU_LIST, - NULL, NULL)) != NULL) + NULL, search_print_cmd)) != NULL) u_spawn(((struct cmd *)mi->ctx)->path); menuq_clear(&menuq); diff --git a/search.c b/search.c index edb3421..9013a9d 100644 --- a/search.c +++ b/search.c @@ -123,6 +123,20 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) } } +void +search_print_cmd(struct menu *mi, int i) +{ + struct cmd *cmd = (struct cmd *)mi->ctx; + int special = 0; + + if ((strcmp(cmd->name, "lock") == 0) || + (strcmp(cmd->name, "term") == 0)) + special = 1; + + (void)snprintf(mi->print, sizeof(mi->print), + (special) ? "[%s]" : "%s", cmd->name); +} + void search_print_client(struct menu *mi, int list) { From 8efaf33cfbced84ff073f5c4d3b2c8e9d7b3bff4 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 30 Jun 2015 19:02:24 +0000 Subject: [PATCH 12/12] no longer need to pass down format strings after introducing search_print_cmd --- kbfunc.c | 2 +- mousefunc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kbfunc.c b/kbfunc.c index a107b95..74db167 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -178,7 +178,7 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg) TAILQ_INIT(&menuq); TAILQ_FOREACH(cmd, &Conf.cmdq, entry) - menuq_add(&menuq, cmd, "%s", cmd->name); + menuq_add(&menuq, cmd, NULL); if ((mi = menu_filter(sc, &menuq, "application", NULL, 0, search_match_text, search_print_cmd)) != NULL) diff --git a/mousefunc.c b/mousefunc.c index bc31118..d709a3f 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -236,7 +236,7 @@ mousefunc_menu_cmd(struct client_ctx *cc, union arg *arg) TAILQ_INIT(&menuq); TAILQ_FOREACH(cmd, &Conf.cmdq, entry) - menuq_add(&menuq, cmd, "%s", cmd->name); + menuq_add(&menuq, cmd, NULL); if ((mi = menu_filter(sc, &menuq, NULL, NULL, CWM_MENU_LIST, NULL, search_print_cmd)) != NULL)