From fd827fd7578faae62b798c4b24f2aa6d80b7b7ce Mon Sep 17 00:00:00 2001 From: okan Date: Sat, 1 Feb 2014 19:28:46 +0000 Subject: [PATCH 1/5] Take menu's bwidth into account for position/size; reported by Thomas Adam. --- menu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/menu.c b/menu.c index 7a35ddd..5ed51d2 100644 --- a/menu.c +++ b/menu.c @@ -382,8 +382,8 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) } xine = screen_find_xinerama(sc, mc->x, mc->y, CWM_GAP); - xine.w += xine.x; - xine.h += xine.y; + xine.w += xine.x - Conf.bwidth * 2; + xine.h += xine.y - Conf.bwidth * 2; xsave = mc->x; ysave = mc->y; From 0a71742af4f4b54cc1b2ea5efd5acfa2eb4113ba Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 2 Feb 2014 15:46:05 +0000 Subject: [PATCH 2/5] The menu already limits entries with MENU_MAXENTRY, so don't bother holding a command name limit as well. --- calmwm.h | 7 +++---- conf.c | 10 +++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/calmwm.h b/calmwm.h index 734055b..ae5b1b5 100644 --- a/calmwm.h +++ b/calmwm.h @@ -259,10 +259,9 @@ TAILQ_HEAD(keybinding_q, binding); TAILQ_HEAD(mousebinding_q, binding); struct cmd { - TAILQ_ENTRY(cmd) entry; -#define CMD_MAXNAMELEN 256 - char name[CMD_MAXNAMELEN]; - char path[MAXPATHLEN]; + TAILQ_ENTRY(cmd) entry; + char *name; + char path[MAXPATHLEN]; }; TAILQ_HEAD(cmd_q, cmd); diff --git a/conf.c b/conf.c index 0792bd7..4ab762f 100644 --- a/conf.c +++ b/conf.c @@ -51,13 +51,11 @@ conf_cmd_add(struct conf *c, const char *name, const char *path) sizeof(c->lockpath)) return (0); } else { - cmd = xmalloc(sizeof(*cmd)); - conf_cmd_remove(c, name); - if (strlcpy(cmd->name, name, sizeof(cmd->name)) >= - sizeof(cmd->name)) - return (0); + cmd = xmalloc(sizeof(*cmd)); + + cmd->name = xstrdup(name); if (strlcpy(cmd->path, path, sizeof(cmd->path)) >= sizeof(cmd->path)) return (0); @@ -74,6 +72,7 @@ conf_cmd_remove(struct conf *c, const char *name) TAILQ_FOREACH_SAFE(cmd, &c->cmdq, entry, cmdnxt) { if (strcmp(cmd->name, name) == 0) { TAILQ_REMOVE(&c->cmdq, cmd, entry); + free(cmd->name); free(cmd); } } @@ -291,6 +290,7 @@ conf_clear(struct conf *c) while ((cmd = TAILQ_FIRST(&c->cmdq)) != NULL) { TAILQ_REMOVE(&c->cmdq, cmd, entry); + free(cmd->name); free(cmd); } From 5f9c7a21c71d8386ae7eb7b03bdfb9c58dbe1b19 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 2 Feb 2014 16:13:50 +0000 Subject: [PATCH 3/5] Unlike free(3), XFree(3) can't be passed a NULL pointer. --- screen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/screen.c b/screen.c index 257afe3..fa90f96 100644 --- a/screen.c +++ b/screen.c @@ -65,7 +65,6 @@ screen_init(int which) /* Deal with existing clients. */ XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins); - for (i = 0; i < nwins; i++) { XGetWindowAttributes(X_Dpy, wins[i], &winattr); if (winattr.override_redirect || @@ -73,7 +72,8 @@ screen_init(int which) continue; (void)client_init(wins[i], sc, winattr.map_state != IsUnmapped); } - XFree(wins); + if (wins) + XFree(wins); screen_updatestackingorder(sc); From ad1b78c6d1b466fbc2c11eec92ad5ce75bb44515 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 2 Feb 2014 16:29:04 +0000 Subject: [PATCH 4/5] No need to store screen colormap and visual; rather just use the X macros in the one place they are needed. --- calmwm.c | 3 ++- calmwm.h | 2 -- conf.c | 13 +++++++------ screen.c | 2 -- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/calmwm.c b/calmwm.c index 0fca8ae..3656b48 100644 --- a/calmwm.c +++ b/calmwm.c @@ -162,7 +162,8 @@ x_teardown(void) TAILQ_FOREACH(sc, &Screenq, entry) { for (i = 0; i < CWM_COLOR_NITEMS; i++) - XftColorFree(X_Dpy, sc->visual, sc->colormap, + XftColorFree(X_Dpy, DefaultVisual(X_Dpy, sc->which), + DefaultColormap(X_Dpy, sc->which), &sc->xftcolor[i]); XftDrawDestroy(sc->xftdraw); XftFontClose(X_Dpy, sc->xftfont); diff --git a/calmwm.h b/calmwm.h index ae5b1b5..aa77bc0 100644 --- a/calmwm.h +++ b/calmwm.h @@ -221,8 +221,6 @@ TAILQ_HEAD(autogroupwin_q, autogroupwin); struct screen_ctx { TAILQ_ENTRY(screen_ctx) entry; int which; - Visual *visual; - Colormap colormap; Window rootwin; Window menuwin; int cycling; diff --git a/conf.c b/conf.c index 4ab762f..2177930 100644 --- a/conf.c +++ b/conf.c @@ -125,6 +125,8 @@ conf_screen(struct screen_ctx *sc) { unsigned int i; XftColor xc; + Colormap colormap = DefaultColormap(X_Dpy, sc->which); + Visual *visual = DefaultVisual(X_Dpy, sc->which); sc->gap = Conf.gap; sc->snapdist = Conf.snapdist; @@ -141,18 +143,18 @@ conf_screen(struct screen_ctx *sc) xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG], sc->xftcolor[CWM_COLOR_MENU_FG], &xc); xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT], xc, &xc); - if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap, + if (!XftColorAllocValue(X_Dpy, visual, colormap, &xc.color, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL])) warnx("XftColorAllocValue: %s", Conf.color[i]); break; } - if (XftColorAllocName(X_Dpy, sc->visual, sc->colormap, + if (XftColorAllocName(X_Dpy, visual, colormap, Conf.color[i], &xc)) { sc->xftcolor[i] = xc; - XftColorFree(X_Dpy, sc->visual, sc->colormap, &xc); + XftColorFree(X_Dpy, visual, colormap, &xc); } else { warnx("XftColorAllocName: %s", Conf.color[i]); - XftColorAllocName(X_Dpy, sc->visual, sc->colormap, + XftColorAllocName(X_Dpy, visual, colormap, color_binds[i], &sc->xftcolor[i]); } } @@ -162,8 +164,7 @@ conf_screen(struct screen_ctx *sc) sc->xftcolor[CWM_COLOR_MENU_FG].pixel, sc->xftcolor[CWM_COLOR_MENU_BG].pixel); - sc->xftdraw = XftDrawCreate(X_Dpy, sc->menuwin, - sc->visual, sc->colormap); + sc->xftdraw = XftDrawCreate(X_Dpy, sc->menuwin, visual, colormap); if (sc->xftdraw == NULL) errx(1, "XftDrawCreate"); diff --git a/screen.c b/screen.c index fa90f96..df19c08 100644 --- a/screen.c +++ b/screen.c @@ -44,8 +44,6 @@ screen_init(int which) TAILQ_INIT(&sc->mruq); sc->which = which; - sc->visual = DefaultVisual(X_Dpy, sc->which); - sc->colormap = DefaultColormap(X_Dpy, sc->which); sc->rootwin = RootWindow(X_Dpy, sc->which); conf_screen(sc); From ad76995af7e1bbae8ec81dd917def917453c379b Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 2 Feb 2014 21:34:05 +0000 Subject: [PATCH 5/5] Move redundant window attr fetch from maprequest directly into client_init and perform that X roundtrip only once. --- client.c | 5 ++++- xevents.c | 9 +++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/client.c b/client.c index 22ee927..632f3f3 100644 --- a/client.c +++ b/client.c @@ -63,6 +63,10 @@ client_init(Window win, struct screen_ctx *sc, int mapped) if (win == None) return (NULL); + if (!XGetWindowAttributes(X_Dpy, win, &wattr)) + return (NULL); + if (sc == NULL) + sc = screen_fromroot(wattr.root); cc = xcalloc(1, sizeof(*cc)); @@ -86,7 +90,6 @@ client_init(Window win, struct screen_ctx *sc, int mapped) cc->ptr.x = -1; cc->ptr.y = -1; - XGetWindowAttributes(X_Dpy, cc->win, &wattr); cc->geom.x = wattr.x; cc->geom.y = wattr.y; cc->geom.w = wattr.width; diff --git a/xevents.c b/xevents.c index 89d7a63..06551e8 100644 --- a/xevents.c +++ b/xevents.c @@ -75,17 +75,14 @@ xev_handle_maprequest(XEvent *ee) { XMapRequestEvent *e = &ee->xmaprequest; struct client_ctx *cc = NULL, *old_cc; - XWindowAttributes xattr; if ((old_cc = client_current())) client_ptrsave(old_cc); - if ((cc = client_find(e->window)) == NULL) { - XGetWindowAttributes(X_Dpy, e->window, &xattr); - cc = client_init(e->window, screen_fromroot(xattr.root), 1); - } + if ((cc = client_find(e->window)) == NULL) + cc = client_init(e->window, NULL, 1); - if ((cc->flags & CLIENT_IGNORE) == 0) + if ((cc != NULL) && ((cc->flags & CLIENT_IGNORE) == 0)) client_ptrwarp(cc); }