diff --git a/calmwm.c b/calmwm.c index 0d8aa1c..3ec4aba 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 41d672e..4b7b98d 100644 --- a/calmwm.h +++ b/calmwm.h @@ -233,8 +233,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; @@ -271,10 +269,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/client.c b/client.c index 456fe60..5d8444b 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/conf.c b/conf.c index a2e0742..fb7e791 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); } } @@ -126,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; @@ -142,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]); } } @@ -163,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"); @@ -291,6 +291,7 @@ conf_clear(struct conf *c) while ((cmd = TAILQ_FIRST(&c->cmdq)) != NULL) { TAILQ_REMOVE(&c->cmdq, cmd, entry); + free(cmd->name); free(cmd); } diff --git a/menu.c b/menu.c index fc90e35..ebf1cbd 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; diff --git a/screen.c b/screen.c index 910f353..55e0430 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); @@ -65,7 +63,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 +70,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); diff --git a/xevents.c b/xevents.c index 17dea12..716d72b 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); }