From d7bd2998191af2ce1d6c0018e7c3a43a01ed3be5 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 9 Nov 2015 20:03:29 +0000 Subject: Extend region to include both view and work areas; switch to region_find() which no longer needs to recalculate gap each time a client (or menu) is created or altered. If no RandR, fall back to display dimensions while building regions instead of during execution. --- screen.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'screen.c') diff --git a/screen.c b/screen.c index aad2159..4fc6f4e 100644 --- a/screen.c +++ b/screen.c @@ -124,35 +124,29 @@ screen_updatestackingorder(struct screen_ctx *sc) } } -struct geom -screen_area(struct screen_ctx *sc, int x, int y, int flags) +struct region_ctx * +region_find(struct screen_ctx *sc, int x, int y) { struct region_ctx *rc; - struct geom area = sc->work; 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; + if ((x >= rc->view.x) && (x < (rc->view.x + rc->view.w)) && + (y >= rc->view.y) && (y < (rc->view.y + rc->view.h))) { break; } } - if (flags & CWM_GAP) - area = screen_apply_gap(sc, area); - return(area); + return(rc); } void screen_update_geometry(struct screen_ctx *sc) { struct region_ctx *rc; - int i; sc->view.x = 0; sc->view.y = 0; sc->view.w = DisplayWidth(X_Dpy, sc->which); sc->view.h = DisplayHeight(X_Dpy, sc->which); - sc->work = screen_apply_gap(sc, sc->view); while ((rc = TAILQ_FIRST(&sc->regionq)) != NULL) { @@ -163,6 +157,7 @@ screen_update_geometry(struct screen_ctx *sc) if (HasRandr) { XRRScreenResources *sr; XRRCrtcInfo *ci; + int i; sr = XRRGetScreenResources(X_Dpy, sc->rootwin); for (i = 0, ci = NULL; i < sr->ncrtc; i++) { @@ -176,15 +171,25 @@ screen_update_geometry(struct screen_ctx *sc) 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; + rc->view.x = ci->x; + rc->view.y = ci->y; + rc->view.w = ci->width; + rc->view.h = ci->height; + rc->work = screen_apply_gap(sc, rc->view); TAILQ_INSERT_TAIL(&sc->regionq, rc, entry); XRRFreeCrtcInfo(ci); } XRRFreeScreenResources(sr); + } else { + rc = xmalloc(sizeof(*rc)); + rc->num = 0; + rc->view.x = 0; + rc->view.y = 0; + rc->view.w = DisplayWidth(X_Dpy, sc->which); + rc->view.h = DisplayHeight(X_Dpy, sc->which); + rc->work = screen_apply_gap(sc, rc->view); + TAILQ_INSERT_TAIL(&sc->regionq, rc, entry); } xu_ewmh_net_desktop_geometry(sc); -- cgit 1.4.1 From 00bdd48b1d93b91946c7655ec8829060040aec22 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 11 Nov 2015 14:22:01 +0000 Subject: Partial revert of replacing screen_area() with region_find(); until a fix for a regression is found; this bug has been around for a long time it seems, but this change exposed it. Likely need to track clients in to and out of regions. --- calmwm.h | 7 ++++- client.c | 94 ++++++++++++++++++++++++++++++------------------------------- kbfunc.c | 11 ++++---- menu.c | 4 +-- mousefunc.c | 11 ++++---- screen.c | 22 +++++++++++++++ 6 files changed, 87 insertions(+), 62 deletions(-) (limited to 'screen.c') diff --git a/calmwm.h b/calmwm.h index 967eba3..cf7a194 100644 --- a/calmwm.h +++ b/calmwm.h @@ -74,6 +74,9 @@ #define CWM_MENU_FILE 0x0002 #define CWM_MENU_LIST 0x0004 +#define CWM_GAP 0x0001 +#define CWM_NOGAP 0x0002 + #define CWM_KBD 0x0001 #define CWM_MOUSE 0x0002 @@ -217,6 +220,7 @@ TAILQ_HEAD(autogroupwin_q, autogroupwin); struct region_ctx { TAILQ_ENTRY(region_ctx) entry; int num; + struct geom area; struct geom view; /* viewable area */ struct geom work; /* workable area, gap-applied */ }; @@ -451,9 +455,10 @@ void search_print_client(struct menu *, int); void search_print_cmd(struct menu *, int); void search_print_group(struct menu *, int); +struct region_ctx *region_find(struct screen_ctx *, int, int); struct geom screen_apply_gap(struct screen_ctx *, struct geom); struct screen_ctx *screen_find(Window); -struct region_ctx *region_find(struct screen_ctx *, 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 da6d05c..2a5bede 100644 --- a/client.c +++ b/client.c @@ -290,7 +290,7 @@ void client_toggle_fullscreen(struct client_ctx *cc) { struct screen_ctx *sc = cc->sc; - struct region_ctx *rc; + struct geom area; if ((cc->flags & CLIENT_FREEZE) && !(cc->flags & CLIENT_FULLSCREEN)) @@ -305,12 +305,12 @@ client_toggle_fullscreen(struct client_ctx *cc) cc->fullgeom = cc->geom; - rc = region_find(sc, + area = screen_area(sc, cc->geom.x + cc->geom.w / 2, - cc->geom.y + cc->geom.h / 2); + cc->geom.y + cc->geom.h / 2, CWM_NOGAP); cc->bwidth = 0; - cc->geom = rc->view; + cc->geom = area; cc->flags |= (CLIENT_FULLSCREEN | CLIENT_FREEZE); resize: @@ -322,7 +322,7 @@ void client_toggle_maximize(struct client_ctx *cc) { struct screen_ctx *sc = cc->sc; - struct region_ctx *rc; + struct geom area; if (cc->flags & CLIENT_FREEZE) return; @@ -348,14 +348,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 */ - rc = region_find(sc, + area = screen_area(sc, cc->geom.x + cc->geom.w / 2, - cc->geom.y + cc->geom.h / 2); + cc->geom.y + cc->geom.h / 2, CWM_GAP); - cc->geom.x = rc->work.x; - cc->geom.y = rc->work.y; - cc->geom.w = rc->work.w - (cc->bwidth * 2); - cc->geom.h = rc->work.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: @@ -367,7 +367,7 @@ void client_toggle_vmaximize(struct client_ctx *cc) { struct screen_ctx *sc = cc->sc; - struct region_ctx *rc; + struct geom area; if (cc->flags & CLIENT_FREEZE) return; @@ -382,12 +382,12 @@ client_toggle_vmaximize(struct client_ctx *cc) cc->savegeom.y = cc->geom.y; cc->savegeom.h = cc->geom.h; - rc = region_find(sc, + area = screen_area(sc, cc->geom.x + cc->geom.w / 2, - cc->geom.y + cc->geom.h / 2); + cc->geom.y + cc->geom.h / 2, CWM_GAP); - cc->geom.y = rc->work.y; - cc->geom.h = rc->work.h - (cc->bwidth * 2); + cc->geom.y = area.y; + cc->geom.h = area.h - (cc->bwidth * 2); cc->flags |= CLIENT_VMAXIMIZED; resize: @@ -399,7 +399,7 @@ void client_toggle_hmaximize(struct client_ctx *cc) { struct screen_ctx *sc = cc->sc; - struct region_ctx *rc; + struct geom area; if (cc->flags & CLIENT_FREEZE) return; @@ -414,12 +414,12 @@ client_toggle_hmaximize(struct client_ctx *cc) cc->savegeom.x = cc->geom.x; cc->savegeom.w = cc->geom.w; - rc = region_find(sc, + area = screen_area(sc, cc->geom.x + cc->geom.w / 2, - cc->geom.y + cc->geom.h / 2); + cc->geom.y + cc->geom.h / 2, CWM_GAP); - cc->geom.x = rc->work.x; - cc->geom.w = rc->work.w - (cc->bwidth * 2); + cc->geom.x = area.x; + cc->geom.w = area.w - (cc->bwidth * 2); cc->flags |= CLIENT_HMAXIMIZED; resize: @@ -749,7 +749,6 @@ static void client_placecalc(struct client_ctx *cc) { struct screen_ctx *sc = cc->sc; - struct region_ctx *rc; int xslack, yslack; if (cc->hint.flags & (USPosition | PPosition)) { @@ -769,8 +768,7 @@ client_placecalc(struct client_ctx *cc) int xmouse, ymouse; xu_ptr_getpos(sc->rootwin, &xmouse, &ymouse); - rc = region_find(sc, xmouse, ymouse); - area = rc->work; + 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; @@ -975,7 +973,7 @@ client_htile(struct client_ctx *cc) struct client_ctx *ci; struct group_ctx *gc = cc->gc; struct screen_ctx *sc = cc->sc; - struct region_ctx *rc; + struct geom area; int i, n, mh, x, h, w; if (!gc) @@ -991,36 +989,36 @@ client_htile(struct client_ctx *cc) if (n == 0) return; - rc = region_find(sc, + area = screen_area(sc, cc->geom.x + cc->geom.w / 2, - cc->geom.y + cc->geom.h / 2); + cc->geom.y + cc->geom.h / 2, CWM_GAP); if (cc->flags & CLIENT_VMAXIMIZED || - cc->geom.h + (cc->bwidth * 2) >= rc->work.h) + cc->geom.h + (cc->bwidth * 2) >= area.h) return; cc->flags &= ~CLIENT_HMAXIMIZED; - cc->geom.x = rc->work.x; - cc->geom.y = rc->work.y; - cc->geom.w = rc->work.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 = rc->work.x; - w = rc->work.w / n; - h = rc->work.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 = rc->work.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 = rc->work.x + rc->work.w - + ci->geom.w = area.x + area.w - ci->geom.x - (ci->bwidth * 2); x += w; client_resize(ci, 1); @@ -1034,7 +1032,7 @@ client_vtile(struct client_ctx *cc) struct client_ctx *ci; struct group_ctx *gc = cc->gc; struct screen_ctx *sc = cc->sc; - struct region_ctx *rc; + struct geom area; int i, n, mw, y, h, w; if (!gc) @@ -1050,36 +1048,36 @@ client_vtile(struct client_ctx *cc) if (n == 0) return; - rc = region_find(sc, + area = screen_area(sc, cc->geom.x + cc->geom.w / 2, - cc->geom.y + cc->geom.h / 2); + cc->geom.y + cc->geom.h / 2, CWM_GAP); if (cc->flags & CLIENT_HMAXIMIZED || - cc->geom.w + (cc->bwidth * 2) >= rc->work.w) + cc->geom.w + (cc->bwidth * 2) >= area.w) return; cc->flags &= ~CLIENT_VMAXIMIZED; - cc->geom.x = rc->work.x; - cc->geom.y = rc->work.y; - cc->geom.h = rc->work.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 = rc->work.y; - h = rc->work.h / n; - w = rc->work.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 = rc->work.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 = rc->work.y + rc->work.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 1bf311c..8e2f579 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 region_ctx *rc; + struct geom area; int x, y, flags, amt; unsigned int mx, my; @@ -101,14 +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; - xu_ptr_getpos(cc->win, &x, &y); - rc = region_find(sc, x + 1, y + 1); + 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), - rc->work.x, rc->work.x + rc->work.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), - rc->work.y, rc->work.y + rc->work.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 5e0dc98..cb4ee7d 100644 --- a/menu.c +++ b/menu.c @@ -331,7 +331,6 @@ static void menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) { struct screen_ctx *sc = mc->sc; - struct region_ctx *rc; struct menu *mi; struct geom area; int n, xsave, ysave; @@ -372,8 +371,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) mc->num++; } - rc = region_find(sc, mc->geom.x, mc->geom.y); - area = rc->work; + 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; diff --git a/mousefunc.c b/mousefunc.c index b58c717..8f97897 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 region_ctx *rc; + struct geom area; int px, py; client_raise(cc); @@ -149,14 +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; - rc = region_find(sc, - ev.xmotion.x_root, ev.xmotion.y_root); + 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), - rc->work.x, rc->work.x + rc->work.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), - rc->work.y, rc->work.y + rc->work.h, sc->snapdist); + area.y, area.y + area.h, sc->snapdist); client_move(cc); break; diff --git a/screen.c b/screen.c index 4fc6f4e..a1b8b30 100644 --- a/screen.c +++ b/screen.c @@ -138,6 +138,24 @@ region_find(struct screen_ctx *sc, int x, int y) return(rc); } +struct geom +screen_area(struct screen_ctx *sc, int x, int y, int flags) +{ + struct region_ctx *rc; + struct geom area = sc->work; + + 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; + } + } + if (flags & CWM_GAP) + area = screen_apply_gap(sc, area); + return(area); +} + void screen_update_geometry(struct screen_ctx *sc) { @@ -171,6 +189,10 @@ screen_update_geometry(struct screen_ctx *sc) 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; rc->view.x = ci->x; rc->view.y = ci->y; rc->view.w = ci->width; -- cgit 1.4.1