From 5acf6c147f88233c477e6f87ca94c45d8475ac73 Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 2 May 2013 17:25:15 +0000 Subject: no need for font_{ascent,descent,height} wrappers; limit font_width to just requiring xftfont. --- calmwm.h | 5 +---- font.c | 22 ++-------------------- menu.c | 32 ++++++++++++++++++-------------- mousefunc.c | 13 +++++++------ 4 files changed, 28 insertions(+), 44 deletions(-) diff --git a/calmwm.h b/calmwm.h index b0a7c12..cb10f19 100644 --- a/calmwm.h +++ b/calmwm.h @@ -450,14 +450,11 @@ void conf_ignore(struct conf *, char *); void conf_mousebind(struct conf *, char *, char *); void conf_ungrab(struct conf *, struct keybinding *); -int font_ascent(struct screen_ctx *); -int font_descent(struct screen_ctx *); void font_draw(struct screen_ctx *, const char *, int, Drawable, int, int, int); -u_int font_height(struct screen_ctx *); void font_init(struct screen_ctx *, const char *, const char **); -int font_width(struct screen_ctx *, const char *, int); +int font_width(XftFont *, const char *, int); void xev_loop(void); diff --git a/font.c b/font.c index 44d4666..c69d30c 100644 --- a/font.c +++ b/font.c @@ -30,24 +30,6 @@ #include "calmwm.h" -int -font_ascent(struct screen_ctx *sc) -{ - return (sc->xftfont->ascent); -} - -int -font_descent(struct screen_ctx *sc) -{ - return (sc->xftfont->descent); -} - -u_int -font_height(struct screen_ctx *sc) -{ - return (sc->xftfont->height + 1); -} - void font_init(struct screen_ctx *sc, const char *name, const char **color) { @@ -82,11 +64,11 @@ font_init(struct screen_ctx *sc, const char *name, const char **color) } int -font_width(struct screen_ctx *sc, const char *text, int len) +font_width(XftFont *xftfont, const char *text, int len) { XGlyphInfo extents; - XftTextExtentsUtf8(X_Dpy, sc->xftfont, (const FcChar8*)text, + XftTextExtentsUtf8(X_Dpy, xftfont, (const FcChar8*)text, len, &extents); return (extents.xOff); diff --git a/menu.c b/menu.c index 465244f..7a7db20 100644 --- a/menu.c +++ b/menu.c @@ -122,9 +122,11 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt, prompt, PROMPT_SCHAR); (void)snprintf(mc.dispstr, sizeof(mc.dispstr), "%s%s%s", mc.promptstr, mc.searchstr, PROMPT_ECHAR); - mc.width = font_width(sc, mc.dispstr, strlen(mc.dispstr)); + mc.width = font_width(sc->xftfont, mc.dispstr, + strlen(mc.dispstr)); mc.hasprompt = 1; } + mc.height = sc->xftfont->height + 1; if (initial != NULL) (void)strlcpy(mc.searchstr, initial, sizeof(mc.searchstr)); @@ -135,8 +137,7 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt, mc.print = print; mc.entry = mc.prev = -1; - XMoveResizeWindow(X_Dpy, sc->menuwin, mc.x, mc.y, mc.width, - font_height(sc)); + XMoveResizeWindow(X_Dpy, sc->menuwin, mc.x, mc.y, mc.width, mc.height); XSelectInput(X_Dpy, sc->menuwin, evmask); XMapRaised(X_Dpy, sc->menuwin); @@ -164,6 +165,7 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt, goto out; /* FALLTHROUGH */ case Expose: + fprintf(stderr, "expose\n"); menu_draw(sc, &mc, menuq, &resultq); break; case MotionNotify: @@ -373,8 +375,9 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, if (mc->hasprompt) { (void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s", mc->promptstr, mc->searchstr, PROMPT_ECHAR); - mc->width = font_width(sc, mc->dispstr, strlen(mc->dispstr)); - mc->height = font_height(sc); + mc->width = font_width(sc->xftfont, mc->dispstr, + strlen(mc->dispstr)); + mc->height = sc->xftfont->height + 1; mc->num = 1; } @@ -389,9 +392,9 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, text = mi->text; } - mc->width = MAX(mc->width, font_width(sc, text, + mc->width = MAX(mc->width, font_width(sc->xftfont, text, MIN(strlen(text), MENU_MAXENTRY))); - mc->height += font_height(sc); + mc->height += sc->xftfont->height + 1; mc->num++; } @@ -425,7 +428,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, if (mc->hasprompt) { font_draw(sc, mc->dispstr, strlen(mc->dispstr), sc->menuwin, 0, - 0, font_ascent(sc)); + 0, sc->xftfont->ascent); n = 1; } else n = 0; @@ -433,7 +436,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, TAILQ_FOREACH(mi, resultq, resultentry) { char *text = mi->print[0] != '\0' ? mi->print : mi->text; - int y = n * font_height(sc) + font_ascent(sc) + 1; + int y = n * (sc->xftfont->height + 1) + sc->xftfont->ascent + 1; /* Stop drawing when menu doesn't fit inside the screen. */ if (mc->y + y > xine.h) @@ -469,10 +472,10 @@ menu_draw_entry(struct screen_ctx *sc, struct menu_ctx *mc, color = active ? CWM_COLOR_MENU_FG : CWM_COLOR_MENU_BG; text = mi->print[0] != '\0' ? mi->print : mi->text; XftDrawRect(sc->xftdraw, &sc->xftcolor[color], 0, - font_height(sc) * entry, mc->width, - font_height(sc) + font_descent(sc)); + (sc->xftfont->height + 1) * entry, mc->width, + (sc->xftfont->height + 1) + sc->xftfont->descent); font_draw(sc, text, strlen(text), sc->menuwin, active, - 0, font_height(sc) * entry + font_ascent(sc) + 1); + 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1); } static void @@ -525,11 +528,12 @@ menu_calc_entry(struct screen_ctx *sc, struct menu_ctx *mc, int x, int y) { int entry; - entry = y / font_height(sc); + entry = y / (sc->xftfont->height + 1); /* in bounds? */ if (x < 0 || x > mc->width || y < 0 || - y > font_height(sc) * mc->num || entry < 0 || entry >= mc->num) + y > (sc->xftfont->height + 1) * mc->num || + entry < 0 || entry >= mc->num) entry = -1; if (mc->hasprompt && entry == 0) diff --git a/mousefunc.c b/mousefunc.c index 878f63a..be1d24a 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -55,23 +55,24 @@ mousefunc_sweep_draw(struct client_ctx *cc) { struct screen_ctx *sc = cc->sc; char asize[10]; /* fits "nnnnxnnnn\0" */ - int width, width_size, width_name; + int width, width_size, width_name, height; (void)snprintf(asize, sizeof(asize), "%dx%d", (cc->geom.w - cc->hint.basew) / cc->hint.incw, (cc->geom.h - cc->hint.baseh) / cc->hint.inch); - width_size = font_width(sc, asize, strlen(asize)) + 4; - width_name = font_width(sc, cc->name, strlen(cc->name)) + 4; + width_size = font_width(sc->xftfont, asize, strlen(asize)) + 4; + width_name = font_width(sc->xftfont, cc->name, strlen(cc->name)) + 4; width = MAX(width_size, width_name); + height = sc->xftfont->height + 1; XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0); - XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0, width, font_height(sc) * 2); + XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0, width, height * 2); XMapWindow(X_Dpy, sc->menuwin); XClearWindow(X_Dpy, sc->menuwin); font_draw(sc, cc->name, strlen(cc->name), sc->menuwin, 0, - 2, font_ascent(sc) + 1); + 2, sc->xftfont->ascent + 1); font_draw(sc, asize, strlen(asize), sc->menuwin, 0, - width / 2 - width_size / 2, font_height(sc) + font_ascent(sc) + 1); + width / 2 - width_size / 2, height + sc->xftfont->ascent + 1); } void -- cgit 1.4.1 From bb56bf4c4b97d0141792cc99a8a31531424476c5 Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 2 May 2013 19:30:10 +0000 Subject: only redraw the name/size box when the client resizes, not every time there's movement; should slightly help with resize syncs. --- mousefunc.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/mousefunc.c b/mousefunc.c index be1d24a..5f01df2 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -31,14 +31,12 @@ #include "calmwm.h" -static int mousefunc_sweep_calc(struct client_ctx *, int, int, int, int); +static void mousefunc_sweep_calc(struct client_ctx *, int, int, int, int); static void mousefunc_sweep_draw(struct client_ctx *); -static int +static void mousefunc_sweep_calc(struct client_ctx *cc, int x, int y, int mx, int my) { - int width = cc->geom.w, height = cc->geom.h; - cc->geom.w = abs(x - mx) - cc->bwidth; cc->geom.h = abs(y - my) - cc->bwidth; @@ -46,8 +44,6 @@ mousefunc_sweep_calc(struct client_ctx *cc, int x, int y, int mx, int my) cc->geom.x = x <= mx ? x : x - cc->geom.w; cc->geom.y = y <= my ? y : y - cc->geom.h; - - return (width != cc->geom.w || height != cc->geom.h); } static void @@ -103,15 +99,14 @@ mousefunc_window_resize(struct client_ctx *cc, void *arg) client_draw_border(cc); break; case MotionNotify: - if (mousefunc_sweep_calc(cc, x, y, - ev.xmotion.x_root, ev.xmotion.y_root)) - /* Recompute window output */ - mousefunc_sweep_draw(cc); + mousefunc_sweep_calc(cc, x, y, + ev.xmotion.x_root, ev.xmotion.y_root); /* don't resize more than 60 times / second */ if ((ev.xmotion.time - ltime) > (1000 / 60)) { ltime = ev.xmotion.time; client_resize(cc, 1); + mousefunc_sweep_draw(cc); } break; case ButtonRelease: -- cgit 1.4.1 From 9de81f3d2e0810f27740b32a2a81d8729eedae4a Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 2 May 2013 19:33:17 +0000 Subject: get rid of cc->name in the resize box and make dimensions more readable. --- mousefunc.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/mousefunc.c b/mousefunc.c index 5f01df2..e43fd1b 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -50,25 +50,20 @@ static void mousefunc_sweep_draw(struct client_ctx *cc) { struct screen_ctx *sc = cc->sc; - char asize[10]; /* fits "nnnnxnnnn\0" */ - int width, width_size, width_name, height; + char asize[14]; /* fits " nnnn x nnnn \0" */ - (void)snprintf(asize, sizeof(asize), "%dx%d", + (void)snprintf(asize, sizeof(asize), " %4d x %-4d ", (cc->geom.w - cc->hint.basew) / cc->hint.incw, (cc->geom.h - cc->hint.baseh) / cc->hint.inch); - width_size = font_width(sc->xftfont, asize, strlen(asize)) + 4; - width_name = font_width(sc->xftfont, cc->name, strlen(cc->name)) + 4; - width = MAX(width_size, width_name); - height = sc->xftfont->height + 1; XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0); - XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0, width, height * 2); + XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0, + font_width(sc->xftfont, asize, strlen(asize)), sc->xftfont->height); XMapWindow(X_Dpy, sc->menuwin); XClearWindow(X_Dpy, sc->menuwin); - font_draw(sc, cc->name, strlen(cc->name), sc->menuwin, 0, - 2, sc->xftfont->ascent + 1); - font_draw(sc, asize, strlen(asize), sc->menuwin, 0, - width / 2 - width_size / 2, height + sc->xftfont->ascent + 1); + + font_draw(sc, asize, strlen(asize), sc->menuwin, 0, 0, + sc->xftfont->ascent + 1); } void -- cgit 1.4.1 From 0d209028be47411cf2e7515dc3ce7ea9d9dc8c3c Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 2 May 2013 19:41:52 +0000 Subject: zap leftover debug printf --- menu.c | 1 - 1 file changed, 1 deletion(-) diff --git a/menu.c b/menu.c index 7a7db20..4a5c54f 100644 --- a/menu.c +++ b/menu.c @@ -165,7 +165,6 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt, goto out; /* FALLTHROUGH */ case Expose: - fprintf(stderr, "expose\n"); menu_draw(sc, &mc, menuq, &resultq); break; case MotionNotify: -- cgit 1.4.1 From e91c7162623a0b83fe83a528d7a382f268b22a8b Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 2 May 2013 20:18:35 +0000 Subject: - no need to position and size the menu window before an Expose event since we'll be calculating required size later anyway; allows us to consolidate all prompt/display/search string building goop into menu_draw. - reset the pos/size of menuwin when leaving a menu. - reverse the 'prompt' NULL check to be consistent with 'initial' one and fix a whitespace nit while here. --- menu.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/menu.c b/menu.c index 4a5c54f..898bf2c 100644 --- a/menu.c +++ b/menu.c @@ -42,7 +42,7 @@ enum ctltype { }; struct menu_ctx { - struct screen_ctx *sc; + struct screen_ctx *sc; char searchstr[MENU_MAXENTRY + 1]; char dispstr[MENU_MAXENTRY*2 + 1]; char promptstr[MENU_MAXENTRY + 1]; @@ -112,21 +112,14 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt, mc.sc = sc; mc.flags = flags; - if (prompt == NULL) { + if (prompt != NULL) { + evmask = MENUMASK | KEYMASK; /* accept keys as well */ + (void)strlcpy(mc.promptstr, prompt, sizeof(mc.promptstr)); + mc.hasprompt = 1; + } else { evmask = MENUMASK; - mc.promptstr[0] = '\0'; mc.list = 1; - } else { - evmask = MENUMASK | KEYMASK; /* only accept keys if prompt */ - (void)snprintf(mc.promptstr, sizeof(mc.promptstr), "%s%s", - prompt, PROMPT_SCHAR); - (void)snprintf(mc.dispstr, sizeof(mc.dispstr), "%s%s%s", - mc.promptstr, mc.searchstr, PROMPT_ECHAR); - mc.width = font_width(sc->xftfont, mc.dispstr, - strlen(mc.dispstr)); - mc.hasprompt = 1; } - mc.height = sc->xftfont->height + 1; if (initial != NULL) (void)strlcpy(mc.searchstr, initial, sizeof(mc.searchstr)); @@ -137,7 +130,6 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt, mc.print = print; mc.entry = mc.prev = -1; - XMoveResizeWindow(X_Dpy, sc->menuwin, mc.x, mc.y, mc.width, mc.height); XSelectInput(X_Dpy, sc->menuwin, evmask); XMapRaised(X_Dpy, sc->menuwin); @@ -193,6 +185,7 @@ out: xu_ptr_setpos(sc->rootwin, xsave, ysave); xu_ptr_ungrab(); + XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0, 1, 1); XUnmapWindow(X_Dpy, sc->menuwin); XUngrabKeyboard(X_Dpy, CurrentTime); @@ -372,8 +365,8 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, mc->width = 0; mc->height = 0; if (mc->hasprompt) { - (void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s", - mc->promptstr, mc->searchstr, PROMPT_ECHAR); + (void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s%s", + mc->promptstr, PROMPT_SCHAR, mc->searchstr, PROMPT_ECHAR); mc->width = font_width(sc->xftfont, mc->dispstr, strlen(mc->dispstr)); mc->height = sc->xftfont->height + 1; -- cgit 1.4.1 From 27854d9061eab7da9ef10bb36b9b8c7f971baebe Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 6 May 2013 16:00:34 +0000 Subject: border width/color makes no sense on menuwin --- menu.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/menu.c b/menu.c index 898bf2c..10af051 100644 --- a/menu.c +++ b/menu.c @@ -81,9 +81,7 @@ static int menu_keycode(XKeyEvent *, enum ctltype *, void menu_init(struct screen_ctx *sc) { - sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1, - Conf.bwidth, - sc->xftcolor[CWM_COLOR_MENU_FG].pixel, + sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1, 0, 0, sc->xftcolor[CWM_COLOR_MENU_BG].pixel); } -- cgit 1.4.1 From 1db7cc2a18d2d3665a4d589d9bc39312eca42268 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 6 May 2013 16:03:11 +0000 Subject: remove group in client_delete directly. --- calmwm.h | 1 - client.c | 6 +++--- group.c | 11 ----------- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/calmwm.h b/calmwm.h index cb10f19..82f43aa 100644 --- a/calmwm.h +++ b/calmwm.h @@ -348,7 +348,6 @@ void client_warp(struct client_ctx *); void group_alltoggle(struct screen_ctx *); void group_autogroup(struct client_ctx *); -void group_client_delete(struct client_ctx *); void group_cycle(struct screen_ctx *, int); void group_hidetoggle(struct screen_ctx *, int); void group_init(struct screen_ctx *); diff --git a/client.c b/client.c index c8d3801..7b94777 100644 --- a/client.c +++ b/client.c @@ -149,13 +149,10 @@ client_delete(struct client_ctx *cc) struct screen_ctx *sc = cc->sc; struct winname *wn; - group_client_delete(cc); - XGrabServer(X_Dpy); cc->state = WithdrawnState; xu_set_wm_state(cc->win, cc->state); XRemoveFromSaveSet(X_Dpy, cc->win); - XSync(X_Dpy, False); XUngrabServer(X_Dpy); @@ -164,6 +161,9 @@ client_delete(struct client_ctx *cc) xu_ewmh_net_client_list(sc); + if (cc->group != NULL) + TAILQ_REMOVE(&cc->group->clients, cc, group_entry); + if (cc == client_current()) client_none(sc); diff --git a/group.c b/group.c index d73f8c4..f7a0a2d 100644 --- a/group.c +++ b/group.c @@ -308,17 +308,6 @@ group_cycle(struct screen_ctx *sc, int flags) group_setactive(sc, showgroup->shortcut); } -/* called when a client is deleted */ -void -group_client_delete(struct client_ctx *cc) -{ - if (cc->group == NULL) - return; - - TAILQ_REMOVE(&cc->group->clients, cc, group_entry); - cc->group = NULL; /* he he */ -} - void group_menu(XButtonEvent *e) { -- cgit 1.4.1 From 1a06f09fa0e1a92d98757f1d9d0a001ecf3e3bb4 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 6 May 2013 19:09:19 +0000 Subject: negative values for borderwith, moveamount, snapdist and gap are configuration errors, so warn and load defaults. --- parse.y | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/parse.y b/parse.y index 2708948..9de56da 100644 --- a/parse.y +++ b/parse.y @@ -117,12 +117,24 @@ main : FONTNAME STRING { conf->flags |= CONF_STICKY_GROUPS; } | BORDERWIDTH NUMBER { + if ($2 < 0) { + yyerror("invalid borderwidth: %d", $2); + YYERROR; + } conf->bwidth = $2; } | MOVEAMOUNT NUMBER { + if ($2 < 0) { + yyerror("invalid movemount: %d", $2); + YYERROR; + } conf->mamount = $2; } | SNAPDIST NUMBER { + if ($2 < 0) { + yyerror("invalid snapdist: %d", $2); + YYERROR; + } conf->snapdist = $2; } | COMMAND STRING string { @@ -133,10 +145,9 @@ main : FONTNAME STRING { | AUTOGROUP NUMBER STRING { if ($2 < 0 || $2 > 9) { free($3); - yyerror("autogroup number out of range: %d", $2); + yyerror("invalid autogroup: %d", $2); YYERROR; } - conf_autogroup(conf, $2, $3); free($3); } @@ -150,6 +161,11 @@ main : FONTNAME STRING { free($3); } | GAP NUMBER NUMBER NUMBER NUMBER { + if ($2 < 0 || $3 < 0 || $4 < 0 || $5 < 0) { + yyerror("invalid gap: %d %d %d %d", + $2, $3, $4, $5); + YYERROR; + } conf->gap.top = $2; conf->gap.bottom = $3; conf->gap.left = $4; -- cgit 1.4.1 From 5f06e5a8caf07223bef5da977868ca8738f95a0f Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 7 May 2013 01:35:41 +0000 Subject: border width/color makes sense for some, so put it back --- menu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/menu.c b/menu.c index 10af051..898bf2c 100644 --- a/menu.c +++ b/menu.c @@ -81,7 +81,9 @@ static int menu_keycode(XKeyEvent *, enum ctltype *, void menu_init(struct screen_ctx *sc) { - sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1, 0, 0, + sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1, + Conf.bwidth, + sc->xftcolor[CWM_COLOR_MENU_FG].pixel, sc->xftcolor[CWM_COLOR_MENU_BG].pixel); } -- cgit 1.4.1 From 457938fbd750388907876ce30a98b216ae758922 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 10 May 2013 15:44:43 +0000 Subject: fix KeySym type --- calmwm.h | 6 +++--- xevents.c | 3 ++- xutil.c | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/calmwm.h b/calmwm.h index 82f43aa..3cb8442 100644 --- a/calmwm.h +++ b/calmwm.h @@ -236,7 +236,7 @@ struct keybinding { void (*callback)(struct client_ctx *, union arg *); union arg argument; int modmask; - int keysym; + KeySym keysym; int keycode; #define KBFLAG_NEEDCLIENT 0x0001 int flags; @@ -465,8 +465,8 @@ unsigned long xu_getcolor(struct screen_ctx *, char *); int xu_getprop(Window, Atom, Atom, long, u_char **); int xu_get_wm_state(Window, int *); int xu_getstrprop(Window, Atom, char **); -void xu_key_grab(Window, int, int); -void xu_key_ungrab(Window, int, int); +void xu_key_grab(Window, int, KeySym); +void xu_key_ungrab(Window, int, KeySym); void xu_ptr_getpos(Window, int *, int *); int xu_ptr_grab(Window, int, Cursor); int xu_ptr_regrab(int, Cursor); diff --git a/xevents.c b/xevents.c index 96d51d2..65dba3b 100644 --- a/xevents.c +++ b/xevents.c @@ -322,7 +322,8 @@ xev_handle_keyrelease(XEvent *ee) XKeyEvent *e = &ee->xkey; struct screen_ctx *sc; struct client_ctx *cc; - int i, keysym; + KeySym keysym; + int i; sc = screen_fromroot(e->root); cc = client_current(); diff --git a/xutil.c b/xutil.c index 765b664..496fe0b 100644 --- a/xutil.c +++ b/xutil.c @@ -88,7 +88,7 @@ xu_ptr_setpos(Window win, int x, int y) } void -xu_key_grab(Window win, int mask, int keysym) +xu_key_grab(Window win, int mask, KeySym keysym) { KeyCode code; int i; @@ -104,7 +104,7 @@ xu_key_grab(Window win, int mask, int keysym) } void -xu_key_ungrab(Window win, int mask, int keysym) +xu_key_ungrab(Window win, int mask, KeySym keysym) { KeyCode code; int i; -- cgit 1.4.1 From e05c0a2c600d22841d6950abf6fc013efe6a7cad Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 10 May 2013 16:05:34 +0000 Subject: int type fixes --- conf.c | 6 +++--- xevents.c | 2 +- xutil.c | 14 ++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/conf.c b/conf.c index 06d4e1c..ee18fcd 100644 --- a/conf.c +++ b/conf.c @@ -195,7 +195,7 @@ m_binds[] = { void conf_init(struct conf *c) { - int i; + u_int i; bzero(c, sizeof(*c)); @@ -459,7 +459,7 @@ conf_bindname(struct conf *c, char *name, char *binding) { struct keybinding *current_binding; char *substring, *tmp; - int i; + u_int i; current_binding = xcalloc(1, sizeof(*current_binding)); @@ -564,7 +564,7 @@ conf_mousebind(struct conf *c, char *name, char *binding) struct mousebinding *current_binding; char *substring, *tmp; const char *errstr; - int i; + u_int i; current_binding = xcalloc(1, sizeof(*current_binding)); diff --git a/xevents.c b/xevents.c index 65dba3b..b182299 100644 --- a/xevents.c +++ b/xevents.c @@ -323,7 +323,7 @@ xev_handle_keyrelease(XEvent *ee) struct screen_ctx *sc; struct client_ctx *cc; KeySym keysym; - int i; + u_int i; sc = screen_fromroot(e->root); cc = client_current(); diff --git a/xutil.c b/xutil.c index 496fe0b..6aee4d9 100644 --- a/xutil.c +++ b/xutil.c @@ -56,7 +56,8 @@ xu_ptr_ungrab(void) void xu_btn_grab(Window win, int mask, u_int btn) { - int i; + u_int i; + for (i = 0; i < nitems(ign_mods); i++) XGrabButton(X_Dpy, btn, (mask | ign_mods[i]), win, False, BUTTONMASK, GrabModeAsync, @@ -66,7 +67,8 @@ xu_btn_grab(Window win, int mask, u_int btn) void xu_btn_ungrab(Window win, int mask, u_int btn) { - int i; + u_int i; + for (i = 0; i < nitems(ign_mods); i++) XUngrabButton(X_Dpy, btn, (mask | ign_mods[i]), win); } @@ -91,7 +93,7 @@ void xu_key_grab(Window win, int mask, KeySym keysym) { KeyCode code; - int i; + u_int i; code = XKeysymToKeycode(X_Dpy, keysym); if ((XkbKeycodeToKeysym(X_Dpy, code, 0, 0) != keysym) && @@ -107,7 +109,7 @@ void xu_key_ungrab(Window win, int mask, KeySym keysym) { KeyCode code; - int i; + u_int i; code = XKeysymToKeycode(X_Dpy, keysym); if ((XkbKeycodeToKeysym(X_Dpy, code, 0, 0) != keysym) && @@ -258,7 +260,7 @@ struct atom_ctx ewmh[EWMH_NITEMS] = { void xu_getatoms(void) { - int i; + u_int i; for (i = 0; i < nitems(cwmh); i++) cwmh[i].atom = XInternAtom(X_Dpy, cwmh[i].name, False); @@ -271,7 +273,7 @@ void xu_ewmh_net_supported(struct screen_ctx *sc) { Atom atom[EWMH_NITEMS]; - int i; + u_int i; for (i = 0; i < nitems(ewmh); i++) atom[i] = ewmh[i].atom; -- cgit 1.4.1 From d0fe80b1f46a3049635c12deb62f73f6cea30f25 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 10 May 2013 16:10:40 +0000 Subject: spacing --- menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/menu.c b/menu.c index 898bf2c..5b545a2 100644 --- a/menu.c +++ b/menu.c @@ -197,7 +197,7 @@ menu_complete_path(struct menu_ctx *mc) { struct menu *mi, *mr; struct menu_q menuq; - char *path = NULL; + char *path = NULL; path = xcalloc(1, sizeof(mr->text)); mr = xcalloc(1, sizeof(*mr)); -- cgit 1.4.1 From 9b9e95d74236b135d799c19c94d9b8070ffc6a58 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 10 May 2013 16:32:47 +0000 Subject: more type fixes for mask/button --- calmwm.h | 14 +++++++------- conf.c | 2 +- xevents.c | 2 +- xutil.c | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/calmwm.h b/calmwm.h index 3cb8442..5fd166d 100644 --- a/calmwm.h +++ b/calmwm.h @@ -235,7 +235,7 @@ struct keybinding { TAILQ_ENTRY(keybinding) entry; void (*callback)(struct client_ctx *, union arg *); union arg argument; - int modmask; + u_int modmask; KeySym keysym; int keycode; #define KBFLAG_NEEDCLIENT 0x0001 @@ -247,8 +247,8 @@ TAILQ_HEAD(keybinding_q, keybinding); struct mousebinding { TAILQ_ENTRY(mousebinding) entry; void (*callback)(struct client_ctx *, void *); - int modmask; - int button; + u_int modmask; + u_int button; #define MOUSEBIND_CTX_ROOT 0x0001 #define MOUSEBIND_CTX_WIN 0x0002 int context; @@ -465,11 +465,11 @@ unsigned long xu_getcolor(struct screen_ctx *, char *); int xu_getprop(Window, Atom, Atom, long, u_char **); int xu_get_wm_state(Window, int *); int xu_getstrprop(Window, Atom, char **); -void xu_key_grab(Window, int, KeySym); -void xu_key_ungrab(Window, int, KeySym); +void xu_key_grab(Window, u_int, KeySym); +void xu_key_ungrab(Window, u_int, KeySym); void xu_ptr_getpos(Window, int *, int *); -int xu_ptr_grab(Window, int, Cursor); -int xu_ptr_regrab(int, Cursor); +int xu_ptr_grab(Window, u_int, Cursor); +int xu_ptr_regrab(u_int, Cursor); void xu_ptr_setpos(Window, int, int); void xu_ptr_ungrab(void); void xu_sendmsg(Window, Atom, long); diff --git a/conf.c b/conf.c index ee18fcd..e580b9e 100644 --- a/conf.c +++ b/conf.c @@ -627,7 +627,7 @@ void conf_grab_mouse(struct client_ctx *cc) { struct mousebinding *mb; - int button; + u_int button; TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) { if (mb->context != MOUSEBIND_CTX_WIN) diff --git a/xevents.c b/xevents.c index b182299..073a919 100644 --- a/xevents.c +++ b/xevents.c @@ -277,7 +277,7 @@ xev_handle_keypress(XEvent *ee) struct client_ctx *cc = NULL, fakecc; struct keybinding *kb; KeySym keysym, skeysym; - int modshift; + u_int modshift; keysym = XkbKeycodeToKeysym(X_Dpy, e->keycode, 0, 0); skeysym = XkbKeycodeToKeysym(X_Dpy, e->keycode, 0, 1); diff --git a/xutil.c b/xutil.c index 6aee4d9..a2a6bec 100644 --- a/xutil.c +++ b/xutil.c @@ -33,7 +33,7 @@ static unsigned int ign_mods[] = { 0, LockMask, Mod2Mask, Mod2Mask | LockMask }; int -xu_ptr_grab(Window win, int mask, Cursor curs) +xu_ptr_grab(Window win, u_int mask, Cursor curs) { return (XGrabPointer(X_Dpy, win, False, mask, GrabModeAsync, GrabModeAsync, @@ -41,7 +41,7 @@ xu_ptr_grab(Window win, int mask, Cursor curs) } int -xu_ptr_regrab(int mask, Cursor curs) +xu_ptr_regrab(u_int mask, Cursor curs) { return (XChangeActivePointerGrab(X_Dpy, mask, curs, CurrentTime) == GrabSuccess ? 0 : -1); @@ -90,7 +90,7 @@ xu_ptr_setpos(Window win, int x, int y) } void -xu_key_grab(Window win, int mask, KeySym keysym) +xu_key_grab(Window win, u_int mask, KeySym keysym) { KeyCode code; u_int i; @@ -106,7 +106,7 @@ xu_key_grab(Window win, int mask, KeySym keysym) } void -xu_key_ungrab(Window win, int mask, KeySym keysym) +xu_key_ungrab(Window win, u_int mask, KeySym keysym) { KeyCode code; u_int i; -- cgit 1.4.1 From 3a38686137d0a0fad56db25a4c7c23ca6419f467 Mon Sep 17 00:00:00 2001 From: okan Date: Sat, 11 May 2013 21:46:27 +0000 Subject: replace conf_{gap,color,font} with conf_screen since really we are configuring the screen *after* parsing, just as we do a conf_client on client manage. --- calmwm.h | 4 +--- conf.c | 20 ++++++-------------- screen.c | 4 +--- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/calmwm.h b/calmwm.h index 5fd166d..9a1fab9 100644 --- a/calmwm.h +++ b/calmwm.h @@ -439,14 +439,12 @@ void conf_bindname(struct conf *, char *, char *); void conf_clear(struct conf *); void conf_client(struct client_ctx *); void conf_cmd_add(struct conf *, char *, char *); -void conf_color(struct conf *, struct screen_ctx *); -void conf_font(struct conf *, struct screen_ctx *); -void conf_gap(struct conf *, struct screen_ctx *); void conf_grab(struct conf *, struct keybinding *); void conf_grab_mouse(struct client_ctx *); void conf_init(struct conf *); void conf_ignore(struct conf *, char *); void conf_mousebind(struct conf *, char *, char *); +void conf_screen(struct screen_ctx *); void conf_ungrab(struct conf *, struct keybinding *); void font_draw(struct screen_ctx *, const char *, int, diff --git a/conf.c b/conf.c index e580b9e..698ab4c 100644 --- a/conf.c +++ b/conf.c @@ -84,18 +84,6 @@ conf_ignore(struct conf *c, char *val) TAILQ_INSERT_TAIL(&c->ignoreq, wm, entry); } -void -conf_gap(struct conf *c, struct screen_ctx *sc) -{ - sc->gap = c->gap; -} - -void -conf_font(struct conf *c, struct screen_ctx *sc) -{ - font_init(sc, c->font, (const char **)c->menucolor); -} - static char *menu_color_binds[CWM_COLOR_MENU_MAX] = { "black", /* CWM_COLOR_MENU_FG */ "white", /* CWM_COLOR_MENU_BG */ @@ -111,12 +99,16 @@ static char *color_binds[CWM_COLOR_BORDER_MAX] = { }; void -conf_color(struct conf *c, struct screen_ctx *sc) +conf_screen(struct screen_ctx *sc) { int i; + sc->gap = Conf.gap; + + font_init(sc, Conf.font, (const char **)Conf.menucolor); + for (i = 0; i < CWM_COLOR_BORDER_MAX; i++) - sc->color[i] = xu_getcolor(sc, c->color[i]); + sc->color[i] = xu_getcolor(sc, Conf.color[i]); } static struct { diff --git a/screen.c b/screen.c index 345bdcc..b3425a1 100644 --- a/screen.c +++ b/screen.c @@ -49,9 +49,7 @@ screen_init(int which) xu_ewmh_net_supported(sc); xu_ewmh_net_supported_wm_check(sc); - conf_gap(&Conf, sc); - conf_color(&Conf, sc); - conf_font(&Conf, sc); + conf_screen(sc); screen_update_geometry(sc); -- cgit 1.4.1 From 2b926784ba44c5ef28e9cb239e3acbeb866c6d12 Mon Sep 17 00:00:00 2001 From: okan Date: Sat, 11 May 2013 22:01:07 +0000 Subject: new -> init --- calmwm.h | 2 +- client.c | 2 +- screen.c | 2 +- xevents.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/calmwm.h b/calmwm.h index 9a1fab9..cf63adc 100644 --- a/calmwm.h +++ b/calmwm.h @@ -331,7 +331,7 @@ void client_lower(struct client_ctx *); void client_map(struct client_ctx *); void client_maximize(struct client_ctx *); void client_move(struct client_ctx *); -struct client_ctx *client_new(Window, struct screen_ctx *, int); +struct client_ctx *client_init(Window, struct screen_ctx *, int); void client_ptrsave(struct client_ctx *); void client_ptrwarp(struct client_ctx *); void client_raise(struct client_ctx *); diff --git a/client.c b/client.c index 7b94777..5a0a070 100644 --- a/client.c +++ b/client.c @@ -55,7 +55,7 @@ client_find(Window win) } struct client_ctx * -client_new(Window win, struct screen_ctx *sc, int mapped) +client_init(Window win, struct screen_ctx *sc, int mapped) { struct client_ctx *cc; XClassHint xch; diff --git a/screen.c b/screen.c index b3425a1..8435859 100644 --- a/screen.c +++ b/screen.c @@ -74,7 +74,7 @@ screen_init(int which) if (winattr.override_redirect || winattr.map_state != IsViewable) continue; - (void)client_new(wins[i], sc, winattr.map_state != IsUnmapped); + (void)client_init(wins[i], sc, winattr.map_state != IsUnmapped); } XFree(wins); diff --git a/xevents.c b/xevents.c index 073a919..c8dcf25 100644 --- a/xevents.c +++ b/xevents.c @@ -86,7 +86,7 @@ xev_handle_maprequest(XEvent *ee) if ((cc = client_find(e->window)) == NULL) { XGetWindowAttributes(X_Dpy, e->window, &xattr); - cc = client_new(e->window, screen_fromroot(xattr.root), 1); + cc = client_init(e->window, screen_fromroot(xattr.root), 1); } if ((cc->flags & CLIENT_IGNORE) == 0) -- cgit 1.4.1 From 112f616d1d3a6377407071f4327c1a2b31cb6e9f Mon Sep 17 00:00:00 2001 From: okan Date: Sat, 11 May 2013 22:03:17 +0000 Subject: swap x/y calculations in kbd move/resize to match those in the respective mouse functions --- kbfunc.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/kbfunc.c b/kbfunc.c index 7a406ea..79cb49b 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -88,17 +88,16 @@ kbfunc_moveresize(struct client_ctx *cc, union arg *arg) } switch (flags & TYPEMASK) { case CWM_MOVE: - cc->geom.y += my; - if (cc->geom.y + cc->geom.h < 0) - cc->geom.y = -cc->geom.h; - if (cc->geom.y > sc->view.h - 1) - cc->geom.y = sc->view.h - 1; - cc->geom.x += mx; if (cc->geom.x + cc->geom.w < 0) cc->geom.x = -cc->geom.w; if (cc->geom.x > sc->view.w - 1) cc->geom.x = sc->view.w - 1; + cc->geom.y += my; + if (cc->geom.y + cc->geom.h < 0) + cc->geom.y = -cc->geom.h; + if (cc->geom.y > sc->view.h - 1) + cc->geom.y = sc->view.h - 1; cc->geom.x += client_snapcalc(cc->geom.x, cc->geom.x + cc->geom.w + (cc->bwidth * 2), @@ -109,15 +108,15 @@ kbfunc_moveresize(struct client_ctx *cc, union arg *arg) client_move(cc); xu_ptr_getpos(cc->win, &x, &y); - cc->ptr.y = y + my; cc->ptr.x = x + mx; + cc->ptr.y = y + my; client_ptrwarp(cc); break; case CWM_RESIZE: - if ((cc->geom.h += my) < 1) - cc->geom.h = 1; if ((cc->geom.w += mx) < 1) cc->geom.w = 1; + if ((cc->geom.h += my) < 1) + cc->geom.h = 1; client_resize(cc, 1); /* Make sure the pointer stays within the window. */ -- cgit 1.4.1 From c637a5404809f3856e5f9b8890f6ef0fe8f55fe8 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 14 May 2013 12:35:56 +0000 Subject: - let callers of font_draw figure out (and pass) the color instead of an 'active' flag. - use strlen() inside of font_draw; the only instance where it wasn't used happened to be ignored on a subsequent draw. --- calmwm.h | 2 +- font.c | 9 +++------ menu.c | 8 ++++---- mousefunc.c | 4 ++-- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/calmwm.h b/calmwm.h index cf63adc..055496a 100644 --- a/calmwm.h +++ b/calmwm.h @@ -447,7 +447,7 @@ void conf_mousebind(struct conf *, char *, char *); void conf_screen(struct screen_ctx *); void conf_ungrab(struct conf *, struct keybinding *); -void font_draw(struct screen_ctx *, const char *, int, +void font_draw(struct screen_ctx *, const char *, Drawable, int, int, int); void font_init(struct screen_ctx *, const char *, const char **); diff --git a/font.c b/font.c index c69d30c..e2b68c0 100644 --- a/font.c +++ b/font.c @@ -75,13 +75,10 @@ font_width(XftFont *xftfont, const char *text, int len) } void -font_draw(struct screen_ctx *sc, const char *text, int len, - Drawable d, int active, int x, int y) +font_draw(struct screen_ctx *sc, const char *text, + Drawable d, int color, int x, int y) { - int color; - - color = active ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; XftDrawChange(sc->xftdraw, d); XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont, x, y, - (const FcChar8*)text, len); + (const FcChar8*)text, strlen(text)); } diff --git a/menu.c b/menu.c index 5b545a2..c2bd37c 100644 --- a/menu.c +++ b/menu.c @@ -419,7 +419,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, mc->width, mc->height); if (mc->hasprompt) { - font_draw(sc, mc->dispstr, strlen(mc->dispstr), sc->menuwin, 0, + font_draw(sc, mc->dispstr, sc->menuwin, CWM_COLOR_MENU_FONT, 0, sc->xftfont->ascent); n = 1; } else @@ -434,8 +434,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, if (mc->y + y > xine.h) break; - font_draw(sc, text, MIN(strlen(text), MENU_MAXENTRY), - sc->menuwin, 0, 0, y); + font_draw(sc, text, sc->menuwin, CWM_COLOR_MENU_FONT, 0, y); n++; } if (mc->hasprompt && n > 1 && (mc->searchstr[0] != '\0')) { @@ -466,7 +465,8 @@ menu_draw_entry(struct screen_ctx *sc, struct menu_ctx *mc, XftDrawRect(sc->xftdraw, &sc->xftcolor[color], 0, (sc->xftfont->height + 1) * entry, mc->width, (sc->xftfont->height + 1) + sc->xftfont->descent); - font_draw(sc, text, strlen(text), sc->menuwin, active, + color = active ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; + font_draw(sc, text, sc->menuwin, color, 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1); } diff --git a/mousefunc.c b/mousefunc.c index e43fd1b..205f073 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -62,8 +62,8 @@ mousefunc_sweep_draw(struct client_ctx *cc) XMapWindow(X_Dpy, sc->menuwin); XClearWindow(X_Dpy, sc->menuwin); - font_draw(sc, asize, strlen(asize), sc->menuwin, 0, 0, - sc->xftfont->ascent + 1); + font_draw(sc, asize, sc->menuwin, CWM_COLOR_MENU_FONT, + 0, sc->xftfont->ascent + 1); } void -- cgit 1.4.1 From be72620432190a8919f257d0734ef9ee96b86cfc Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 14 May 2013 13:39:53 +0000 Subject: if -> ifdef --- calmwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calmwm.c b/calmwm.c index 7bc204a..e9b3902 100644 --- a/calmwm.c +++ b/calmwm.c @@ -181,7 +181,7 @@ x_wmerrorhandler(Display *dpy, XErrorEvent *e) static int x_errorhandler(Display *dpy, XErrorEvent *e) { -#if DEBUG +#ifdef DEBUG char msg[80], number[80], req[80]; XGetErrorText(X_Dpy, e->error_code, msg, sizeof(msg)); -- cgit 1.4.1 From 3253f5a4a1b849ea51594eccff2f6974e578b4af Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 19 May 2013 17:01:29 +0000 Subject: simplify --- xevents.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/xevents.c b/xevents.c index c8dcf25..9849fb5 100644 --- a/xevents.c +++ b/xevents.c @@ -203,13 +203,12 @@ xev_handle_propertynotify(XEvent *ee) break; } } else { - TAILQ_FOREACH(sc, &Screenq, entry) - if (sc->rootwin == e->window) - goto test; - return; -test: - if (e->atom == ewmh[_NET_DESKTOP_NAMES].atom) - group_update_names(sc); + TAILQ_FOREACH(sc, &Screenq, entry) { + if (sc->rootwin == e->window) { + if (e->atom == ewmh[_NET_DESKTOP_NAMES].atom) + group_update_names(sc); + } + } } } -- cgit 1.4.1 From 01bfdd7b42834de62e66b57b15145fe483cabdd6 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 19 May 2013 17:02:04 +0000 Subject: use XGetWMProtocols and simplify WM_PROTOCOL handling --- calmwm.h | 9 ++++++--- client.c | 33 +++++++++++++++------------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/calmwm.h b/calmwm.h index 055496a..033ed5a 100644 --- a/calmwm.h +++ b/calmwm.h @@ -121,6 +121,11 @@ struct winname { }; TAILQ_HEAD(winname_q, winname); +enum wm_protocols { + _WM_DELETE_WINDOW = 0x0001, + _WM_TAKE_FOCUS = 0x0002, +}; + struct client_ctx { TAILQ_ENTRY(client_ctx) entry; TAILQ_ENTRY(client_ctx) group_entry; @@ -147,9 +152,7 @@ struct client_ctx { int x; /* x position */ int y; /* y position */ } ptr; -#define CLIENT_PROTO_DELETE 0x0001 -#define CLIENT_PROTO_TAKEFOCUS 0x0002 - int xproto; + enum wm_protocols xproto; #define CLIENT_HIDDEN 0x0001 #define CLIENT_IGNORE 0x0002 #define CLIENT_VMAXIMIZED 0x0004 diff --git a/client.c b/client.c index 5a0a070..6001372 100644 --- a/client.c +++ b/client.c @@ -36,7 +36,7 @@ static struct client_ctx *client_mruprev(struct client_ctx *); static void client_mtf(struct client_ctx *); static void client_none(struct screen_ctx *); static void client_placecalc(struct client_ctx *); -static void client_update(struct client_ctx *); +static void client_wm_protocols(struct client_ctx *); static void client_getmwmhints(struct client_ctx *); static int client_inbound(struct client_ctx *, int, int); @@ -132,7 +132,7 @@ client_init(Window win, struct screen_ctx *sc, int mapped) xu_ewmh_net_client_list(sc); - client_update(cc); + client_wm_protocols(cc); if (mapped) group_autogroup(cc); @@ -497,29 +497,26 @@ client_draw_border(struct client_ctx *cc) } static void -client_update(struct client_ctx *cc) +client_wm_protocols(struct client_ctx *cc) { Atom *p; - int i; - long n; - - if ((n = xu_getprop(cc->win, cwmh[WM_PROTOCOLS].atom, - XA_ATOM, 20L, (u_char **)&p)) <= 0) - return; - - for (i = 0; i < n; i++) - if (p[i] == cwmh[WM_DELETE_WINDOW].atom) - cc->xproto |= CLIENT_PROTO_DELETE; - else if (p[i] == cwmh[WM_TAKE_FOCUS].atom) - cc->xproto |= CLIENT_PROTO_TAKEFOCUS; - - XFree(p); + int i, j; + + if (XGetWMProtocols(X_Dpy, cc->win, &p, &j)) { + for (i = 0; i < j; i++) { + if (p[i] == cwmh[WM_DELETE_WINDOW].atom) + cc->xproto |= _WM_DELETE_WINDOW; + else if (p[i] == cwmh[WM_TAKE_FOCUS].atom) + cc->xproto |= _WM_TAKE_FOCUS; + } + XFree(p); + } } void client_send_delete(struct client_ctx *cc) { - if (cc->xproto & CLIENT_PROTO_DELETE) + if (cc->xproto & _WM_DELETE_WINDOW) xu_sendmsg(cc->win, cwmh[WM_PROTOCOLS].atom, cwmh[WM_DELETE_WINDOW].atom); else -- cgit 1.4.1 From 556a50d8f7f6804630bfffc6b1f1817fd67a273b Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 19 May 2013 17:03:55 +0000 Subject: treat WM_CHANGE_STATE like other atoms --- calmwm.h | 1 + xevents.c | 7 ++----- xutil.c | 1 + 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/calmwm.h b/calmwm.h index 033ed5a..032e8b8 100644 --- a/calmwm.h +++ b/calmwm.h @@ -527,6 +527,7 @@ enum { WM_PROTOCOLS, _MOTIF_WM_HINTS, UTF8_STRING, + WM_CHANGE_STATE, CWMH_NITEMS }; enum { diff --git a/xevents.c b/xevents.c index 9849fb5..174985d 100644 --- a/xevents.c +++ b/xevents.c @@ -340,16 +340,13 @@ static void xev_handle_clientmessage(XEvent *ee) { XClientMessageEvent *e = &ee->xclient; - Atom xa_wm_change_state; struct client_ctx *cc; - xa_wm_change_state = XInternAtom(X_Dpy, "WM_CHANGE_STATE", False); - if ((cc = client_find(e->window)) == NULL) return; - if (e->message_type == xa_wm_change_state && e->format == 32 && - e->data.l[0] == IconicState) + if (e->message_type == cwmh[WM_CHANGE_STATE].atom && + e->format == 32 && e->data.l[0] == IconicState) client_hide(cc); } diff --git a/xutil.c b/xutil.c index a2a6bec..764116a 100644 --- a/xutil.c +++ b/xutil.c @@ -239,6 +239,7 @@ struct atom_ctx cwmh[CWMH_NITEMS] = { {"WM_PROTOCOLS", None}, {"_MOTIF_WM_HINTS", None}, {"UTF8_STRING", None}, + {"WM_CHANGE_STATE", None}, }; struct atom_ctx ewmh[EWMH_NITEMS] = { {"_NET_SUPPORTED", None}, -- cgit 1.4.1 From c84145661e14cc62032f30c6a8c744ba84b95601 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 19 May 2013 17:05:52 +0000 Subject: add support for _NET_CLOSE_WINDOW --- calmwm.h | 1 + xevents.c | 3 +++ xutil.c | 1 + 3 files changed, 5 insertions(+) diff --git a/calmwm.h b/calmwm.h index 032e8b8..cf980e1 100644 --- a/calmwm.h +++ b/calmwm.h @@ -545,6 +545,7 @@ enum { _NET_WORKAREA, _NET_WM_NAME, _NET_WM_DESKTOP, + _NET_CLOSE_WINDOW, EWMH_NITEMS }; struct atom_ctx { diff --git a/xevents.c b/xevents.c index 174985d..91da64a 100644 --- a/xevents.c +++ b/xevents.c @@ -348,6 +348,9 @@ xev_handle_clientmessage(XEvent *ee) if (e->message_type == cwmh[WM_CHANGE_STATE].atom && e->format == 32 && e->data.l[0] == IconicState) client_hide(cc); + + if (e->message_type == ewmh[_NET_CLOSE_WINDOW].atom) + client_send_delete(cc); } static void diff --git a/xutil.c b/xutil.c index 764116a..d9f2106 100644 --- a/xutil.c +++ b/xutil.c @@ -256,6 +256,7 @@ struct atom_ctx ewmh[EWMH_NITEMS] = { {"_NET_WORKAREA", None}, {"_NET_WM_NAME", None}, {"_NET_WM_DESKTOP", None}, + {"_NET_CLOSE_WINDOW", None}, }; void -- cgit 1.4.1 From dac00a232f975967dec9ae8e838b069ec01e6c62 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 19 May 2013 23:09:59 +0000 Subject: - switch border colors to Xft - merge border/menu color structures/functions since they now both use Xft - switch xu_xorcolor to operating on XftColor instead of just XRenderColor (basically adding pixel) - if color name allocation fails, revert back to default (this, along with font validation should occur during config parse, but we don't have screens setup yet - likely to change at some point) --- calmwm.h | 29 ++++++++++------------------- client.c | 8 ++++---- conf.c | 47 +++++++++++++++++++++++++++++++---------------- font.c | 22 +--------------------- parse.y | 21 +++++++++------------ xutil.c | 24 ++++++------------------ 6 files changed, 61 insertions(+), 90 deletions(-) diff --git a/calmwm.h b/calmwm.h index cf980e1..ebc5bd0 100644 --- a/calmwm.h +++ b/calmwm.h @@ -85,20 +85,16 @@ union arg { int i; }; -enum menucolor { - CWM_COLOR_MENU_FG, - CWM_COLOR_MENU_BG, - CWM_COLOR_MENU_FONT, - CWM_COLOR_MENU_FONT_SEL, - CWM_COLOR_MENU_MAX -}; - -enum bordercolor { +enum color { CWM_COLOR_BORDER_ACTIVE, CWM_COLOR_BORDER_INACTIVE, CWM_COLOR_BORDER_GROUP, CWM_COLOR_BORDER_UNGROUP, - CWM_COLOR_BORDER_MAX + CWM_COLOR_MENU_FG, + CWM_COLOR_MENU_BG, + CWM_COLOR_MENU_FONT, + CWM_COLOR_MENU_FONT_SEL, + CWM_COLOR_MAX }; struct geom { @@ -213,13 +209,12 @@ struct screen_ctx { Colormap colormap; Window rootwin; Window menuwin; - unsigned long color[CWM_COLOR_BORDER_MAX]; int cycling; struct geom view; /* viewable area */ struct geom work; /* workable area, gap-applied */ struct gap gap; struct cycle_entry_q mruq; - XftColor xftcolor[CWM_COLOR_MENU_MAX]; + XftColor xftcolor[CWM_COLOR_MAX]; XftDraw *xftdraw; XftFont *xftfont; int xinerama_no; @@ -293,8 +288,7 @@ struct conf { #define CONF_SNAPDIST 0 int snapdist; struct gap gap; - char *color[CWM_COLOR_BORDER_MAX]; - char *menucolor[CWM_COLOR_MENU_MAX]; + char *color[CWM_COLOR_MAX]; char termpath[MAXPATHLEN]; char lockpath[MAXPATHLEN]; char known_hosts[MAXPATHLEN]; @@ -452,8 +446,7 @@ void conf_ungrab(struct conf *, struct keybinding *); void font_draw(struct screen_ctx *, const char *, Drawable, int, int, int); -void font_init(struct screen_ctx *, const char *, - const char **); +void font_init(struct screen_ctx *, const char *); int font_width(XftFont *, const char *, int); void xev_loop(void); @@ -462,7 +455,6 @@ void xu_btn_grab(Window, int, u_int); void xu_btn_ungrab(Window, int, u_int); void xu_configure(struct client_ctx *); void xu_getatoms(void); -unsigned long xu_getcolor(struct screen_ctx *, char *); int xu_getprop(Window, Atom, Atom, long, u_char **); int xu_get_wm_state(Window, int *); int xu_getstrprop(Window, Atom, char **); @@ -475,8 +467,7 @@ void xu_ptr_setpos(Window, int, int); void xu_ptr_ungrab(void); void xu_sendmsg(Window, Atom, long); void xu_set_wm_state(Window win, int); -void xu_xorcolor(XRenderColor, XRenderColor, - XRenderColor *); +void xu_xorcolor(XftColor, XftColor, XftColor *); void xu_ewmh_net_supported(struct screen_ctx *); void xu_ewmh_net_supported_wm_check(struct screen_ctx *); diff --git a/client.c b/client.c index 6001372..9ebd8bc 100644 --- a/client.c +++ b/client.c @@ -480,17 +480,17 @@ client_draw_border(struct client_ctx *cc) if (cc->active) switch (cc->flags & CLIENT_HIGHLIGHT) { case CLIENT_GROUP: - pixel = sc->color[CWM_COLOR_BORDER_GROUP]; + pixel = sc->xftcolor[CWM_COLOR_BORDER_GROUP].pixel; break; case CLIENT_UNGROUP: - pixel = sc->color[CWM_COLOR_BORDER_UNGROUP]; + pixel = sc->xftcolor[CWM_COLOR_BORDER_UNGROUP].pixel; break; default: - pixel = sc->color[CWM_COLOR_BORDER_ACTIVE]; + pixel = sc->xftcolor[CWM_COLOR_BORDER_ACTIVE].pixel; break; } else - pixel = sc->color[CWM_COLOR_BORDER_INACTIVE]; + pixel = sc->xftcolor[CWM_COLOR_BORDER_INACTIVE].pixel; XSetWindowBorderWidth(X_Dpy, cc->win, cc->bwidth); XSetWindowBorder(X_Dpy, cc->win, pixel); diff --git a/conf.c b/conf.c index 698ab4c..657c686 100644 --- a/conf.c +++ b/conf.c @@ -84,31 +84,49 @@ conf_ignore(struct conf *c, char *val) TAILQ_INSERT_TAIL(&c->ignoreq, wm, entry); } -static char *menu_color_binds[CWM_COLOR_MENU_MAX] = { - "black", /* CWM_COLOR_MENU_FG */ - "white", /* CWM_COLOR_MENU_BG */ - "black", /* CWM_COLOR_MENU_FONT */ - "", /* CWM_COLOR_MENU_FONT_SEL */ -}; - -static char *color_binds[CWM_COLOR_BORDER_MAX] = { +static char *color_binds[CWM_COLOR_MAX] = { "#CCCCCC", /* CWM_COLOR_BORDER_ACTIVE */ "#666666", /* CWM_COLOR_BORDER_INACTIVE */ "blue", /* CWM_COLOR_BORDER_GROUP */ "red", /* CWM_COLOR_BORDER_UNGROUP */ + "black", /* CWM_COLOR_MENU_FG */ + "white", /* CWM_COLOR_MENU_BG */ + "black", /* CWM_COLOR_MENU_FONT */ + "", /* CWM_COLOR_MENU_FONT_SEL */ }; void conf_screen(struct screen_ctx *sc) { - int i; + int i; + XftColor xc; sc->gap = Conf.gap; - font_init(sc, Conf.font, (const char **)Conf.menucolor); + font_init(sc, Conf.font); + + for (i = 0; i < CWM_COLOR_MAX; i++) { + if (*Conf.color[i] == '\0') + break; + if (XftColorAllocName(X_Dpy, sc->visual, sc->colormap, + Conf.color[i], &xc)) { + sc->xftcolor[i] = xc; + XftColorFree(X_Dpy, sc->visual, sc->colormap, &xc); + } else { + warnx("XftColorAllocName: '%s'", Conf.color[i]); + XftColorAllocName(X_Dpy, sc->visual, sc->colormap, + color_binds[i], &sc->xftcolor[i]); + } + } + if (i == CWM_COLOR_MAX) + return; - for (i = 0; i < CWM_COLOR_BORDER_MAX; i++) - sc->color[i] = xu_getcolor(sc, Conf.color[i]); + 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, + &xc.color, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL])) + warnx("XftColorAllocValue: '%s'", Conf.color[i]); } static struct { @@ -210,9 +228,6 @@ conf_init(struct conf *c) for (i = 0; i < nitems(color_binds); i++) c->color[i] = xstrdup(color_binds[i]); - for (i = 0; i < nitems(menu_color_binds); i++) - c->menucolor[i] = xstrdup(menu_color_binds[i]); - /* Default term/lock */ (void)strlcpy(c->termpath, "xterm", sizeof(c->termpath)); (void)strlcpy(c->lockpath, "xlock", sizeof(c->lockpath)); @@ -260,7 +275,7 @@ conf_clear(struct conf *c) free(mb); } - for (i = 0; i < CWM_COLOR_BORDER_MAX; i++) + for (i = 0; i < CWM_COLOR_MAX; i++) free(c->color[i]); free(c->font); diff --git a/font.c b/font.c index e2b68c0..f4251d9 100644 --- a/font.c +++ b/font.c @@ -31,11 +31,8 @@ #include "calmwm.h" void -font_init(struct screen_ctx *sc, const char *name, const char **color) +font_init(struct screen_ctx *sc, const char *name) { - int i; - XRenderColor c; - sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin, sc->visual, sc->colormap); if (sc->xftdraw == NULL) @@ -44,23 +41,6 @@ font_init(struct screen_ctx *sc, const char *name, const char **color) sc->xftfont = XftFontOpenName(X_Dpy, sc->which, name); if (sc->xftfont == NULL) errx(1, "XftFontOpenName"); - - for (i = 0; i < CWM_COLOR_MENU_MAX; i++) { - if (*color[i] == '\0') - break; - if (!XftColorAllocName(X_Dpy, sc->visual, sc->colormap, - color[i], &sc->xftcolor[i])) - errx(1, "XftColorAllocName"); - } - if (i == CWM_COLOR_MENU_MAX) - return; - - xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG].color, - sc->xftcolor[CWM_COLOR_MENU_FG].color, &c); - xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT].color, c, &c); - if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap, - &c, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL])) - errx(1, "XftColorAllocValue"); } int diff --git a/parse.y b/parse.y index 9de56da..e0c13bb 100644 --- a/parse.y +++ b/parse.y @@ -198,20 +198,20 @@ colors : ACTIVEBORDER STRING { conf->color[CWM_COLOR_BORDER_UNGROUP] = $2; } | MENUBG STRING { - free(conf->menucolor[CWM_COLOR_MENU_BG]); - conf->menucolor[CWM_COLOR_MENU_BG] = $2; + free(conf->color[CWM_COLOR_MENU_BG]); + conf->color[CWM_COLOR_MENU_BG] = $2; } | MENUFG STRING { - free(conf->menucolor[CWM_COLOR_MENU_FG]); - conf->menucolor[CWM_COLOR_MENU_FG] = $2; + free(conf->color[CWM_COLOR_MENU_FG]); + conf->color[CWM_COLOR_MENU_FG] = $2; } | FONTCOLOR STRING { - free(conf->menucolor[CWM_COLOR_MENU_FONT]); - conf->menucolor[CWM_COLOR_MENU_FONT] = $2; + free(conf->color[CWM_COLOR_MENU_FONT]); + conf->color[CWM_COLOR_MENU_FONT] = $2; } | FONTSELCOLOR STRING { - free(conf->menucolor[CWM_COLOR_MENU_FONT_SEL]); - conf->menucolor[CWM_COLOR_MENU_FONT_SEL] = $2; + free(conf->color[CWM_COLOR_MENU_FONT_SEL]); + conf->color[CWM_COLOR_MENU_FONT_SEL] = $2; } ; %% @@ -589,12 +589,9 @@ parse_config(const char *filename, struct conf *xconf) (void)strlcpy(xconf->lockpath, conf->lockpath, sizeof(xconf->lockpath)); - for (i = 0; i < CWM_COLOR_BORDER_MAX; i++) + for (i = 0; i < CWM_COLOR_MAX; i++) xconf->color[i] = conf->color[i]; - for (i = 0; i < CWM_COLOR_MENU_MAX; i++) - xconf->menucolor[i] = conf->menucolor[i]; - xconf->font = conf->font; } diff --git a/xutil.c b/xutil.c index d9f2106..bcc7366 100644 --- a/xutil.c +++ b/xutil.c @@ -420,24 +420,12 @@ xu_ewmh_net_wm_desktop(struct client_ctx *cc) XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&no, 1); } -unsigned long -xu_getcolor(struct screen_ctx *sc, char *name) -{ - XColor color, tmp; - - if (!XAllocNamedColor(X_Dpy, sc->colormap, name, &color, &tmp)) { - warnx("XAllocNamedColor error: '%s'", name); - return (0); - } - - return (color.pixel); -} - void -xu_xorcolor(XRenderColor a, XRenderColor b, XRenderColor *r) +xu_xorcolor(XftColor a, XftColor b, XftColor *r) { - r->red = a.red ^ b.red; - r->green = a.green ^ b.green; - r->blue = a.blue ^ b.blue; - r->alpha = 0xffff; + r->pixel = a.pixel ^ b.pixel; + r->color.red = a.color.red ^ b.color.red; + r->color.green = a.color.green ^ b.color.green; + r->color.blue = a.color.blue ^ b.color.blue; + r->color.alpha = 0xffff; } -- cgit 1.4.1 From e41c84c752c46b78c0996489e150515751ae8ac8 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 19 May 2013 23:16:29 +0000 Subject: move the rest of xft init into screen_conf, since most of it is based on config parameters. --- calmwm.h | 1 - conf.c | 9 ++++++++- font.c | 13 ------------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/calmwm.h b/calmwm.h index ebc5bd0..a18f92f 100644 --- a/calmwm.h +++ b/calmwm.h @@ -446,7 +446,6 @@ void conf_ungrab(struct conf *, struct keybinding *); void font_draw(struct screen_ctx *, const char *, Drawable, int, int, int); -void font_init(struct screen_ctx *, const char *); int font_width(XftFont *, const char *, int); void xev_loop(void); diff --git a/conf.c b/conf.c index 657c686..b4d5d9d 100644 --- a/conf.c +++ b/conf.c @@ -103,7 +103,14 @@ conf_screen(struct screen_ctx *sc) sc->gap = Conf.gap; - font_init(sc, Conf.font); + sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin, + sc->visual, sc->colormap); + if (sc->xftdraw == NULL) + errx(1, "XftDrawCreate"); + + sc->xftfont = XftFontOpenName(X_Dpy, sc->which, Conf.font); + if (sc->xftfont == NULL) + errx(1, "XftFontOpenName"); for (i = 0; i < CWM_COLOR_MAX; i++) { if (*Conf.color[i] == '\0') diff --git a/font.c b/font.c index f4251d9..fc4f3c1 100644 --- a/font.c +++ b/font.c @@ -30,19 +30,6 @@ #include "calmwm.h" -void -font_init(struct screen_ctx *sc, const char *name) -{ - sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin, - sc->visual, sc->colormap); - if (sc->xftdraw == NULL) - errx(1, "XftDrawCreate"); - - sc->xftfont = XftFontOpenName(X_Dpy, sc->which, name); - if (sc->xftfont == NULL) - errx(1, "XftFontOpenName"); -} - int font_width(XftFont *xftfont, const char *text, int len) { -- cgit 1.4.1 From 5b4c55616a58c058cb1f3f80c4e04a24b8e824a3 Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 19 May 2013 23:38:20 +0000 Subject: move the 2 small font helper functions to xutil.c --- Makefile | 2 +- calmwm.h | 7 +++---- font.c | 51 --------------------------------------------------- menu.c | 10 +++++----- mousefunc.c | 5 +++-- xutil.c | 20 ++++++++++++++++++++ 6 files changed, 32 insertions(+), 63 deletions(-) delete mode 100644 font.c diff --git a/Makefile b/Makefile index 1bd9271..25584c7 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ PROG= cwm SRCS= calmwm.c screen.c xmalloc.c client.c menu.c \ search.c util.c xutil.c conf.c xevents.c group.c \ - kbfunc.c mousefunc.c font.c parse.y + kbfunc.c mousefunc.c parse.y CPPFLAGS+= -I${X11BASE}/include -I${X11BASE}/include/freetype2 -I${.CURDIR} diff --git a/calmwm.h b/calmwm.h index a18f92f..b45e9df 100644 --- a/calmwm.h +++ b/calmwm.h @@ -444,10 +444,6 @@ void conf_mousebind(struct conf *, char *, char *); void conf_screen(struct screen_ctx *); void conf_ungrab(struct conf *, struct keybinding *); -void font_draw(struct screen_ctx *, const char *, - Drawable, int, int, int); -int font_width(XftFont *, const char *, int); - void xev_loop(void); void xu_btn_grab(Window, int, u_int); @@ -466,6 +462,9 @@ void xu_ptr_setpos(Window, int, int); void xu_ptr_ungrab(void); void xu_sendmsg(Window, Atom, long); void xu_set_wm_state(Window win, int); +void xu_xft_draw(struct screen_ctx *, const char *, + Drawable, int, int, int); +int xu_xft_width(XftFont *, const char *, int); void xu_xorcolor(XftColor, XftColor, XftColor *); void xu_ewmh_net_supported(struct screen_ctx *); diff --git a/font.c b/font.c deleted file mode 100644 index fc4f3c1..0000000 --- a/font.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * calmwm - the calm window manager - * - * Copyright (c) 2005 Marius Eriksen - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * $OpenBSD$ - */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "calmwm.h" - -int -font_width(XftFont *xftfont, const char *text, int len) -{ - XGlyphInfo extents; - - XftTextExtentsUtf8(X_Dpy, xftfont, (const FcChar8*)text, - len, &extents); - - return (extents.xOff); -} - -void -font_draw(struct screen_ctx *sc, const char *text, - Drawable d, int color, int x, int y) -{ - XftDrawChange(sc->xftdraw, d); - XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont, x, y, - (const FcChar8*)text, strlen(text)); -} diff --git a/menu.c b/menu.c index c2bd37c..80e1ce7 100644 --- a/menu.c +++ b/menu.c @@ -367,7 +367,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, if (mc->hasprompt) { (void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s%s", mc->promptstr, PROMPT_SCHAR, mc->searchstr, PROMPT_ECHAR); - mc->width = font_width(sc->xftfont, mc->dispstr, + mc->width = xu_xft_width(sc->xftfont, mc->dispstr, strlen(mc->dispstr)); mc->height = sc->xftfont->height + 1; mc->num = 1; @@ -384,7 +384,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, text = mi->text; } - mc->width = MAX(mc->width, font_width(sc->xftfont, text, + mc->width = MAX(mc->width, xu_xft_width(sc->xftfont, text, MIN(strlen(text), MENU_MAXENTRY))); mc->height += sc->xftfont->height + 1; mc->num++; @@ -419,7 +419,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, mc->width, mc->height); if (mc->hasprompt) { - font_draw(sc, mc->dispstr, sc->menuwin, CWM_COLOR_MENU_FONT, + xu_xft_draw(sc, mc->dispstr, sc->menuwin, CWM_COLOR_MENU_FONT, 0, sc->xftfont->ascent); n = 1; } else @@ -434,7 +434,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, if (mc->y + y > xine.h) break; - font_draw(sc, text, sc->menuwin, CWM_COLOR_MENU_FONT, 0, y); + xu_xft_draw(sc, text, sc->menuwin, CWM_COLOR_MENU_FONT, 0, y); n++; } if (mc->hasprompt && n > 1 && (mc->searchstr[0] != '\0')) { @@ -466,7 +466,7 @@ menu_draw_entry(struct screen_ctx *sc, struct menu_ctx *mc, (sc->xftfont->height + 1) * entry, mc->width, (sc->xftfont->height + 1) + sc->xftfont->descent); color = active ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; - font_draw(sc, text, sc->menuwin, color, + xu_xft_draw(sc, text, sc->menuwin, color, 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1); } diff --git a/mousefunc.c b/mousefunc.c index 205f073..64670b5 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -58,11 +58,12 @@ mousefunc_sweep_draw(struct client_ctx *cc) XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0); XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0, - font_width(sc->xftfont, asize, strlen(asize)), sc->xftfont->height); + xu_xft_width(sc->xftfont, asize, strlen(asize)), + sc->xftfont->height); XMapWindow(X_Dpy, sc->menuwin); XClearWindow(X_Dpy, sc->menuwin); - font_draw(sc, asize, sc->menuwin, CWM_COLOR_MENU_FONT, + xu_xft_draw(sc, asize, sc->menuwin, CWM_COLOR_MENU_FONT, 0, sc->xftfont->ascent + 1); } diff --git a/xutil.c b/xutil.c index bcc7366..3e2b36c 100644 --- a/xutil.c +++ b/xutil.c @@ -429,3 +429,23 @@ xu_xorcolor(XftColor a, XftColor b, XftColor *r) r->color.blue = a.color.blue ^ b.color.blue; r->color.alpha = 0xffff; } + +int +xu_xft_width(XftFont *xftfont, const char *text, int len) +{ + XGlyphInfo extents; + + XftTextExtentsUtf8(X_Dpy, xftfont, (const FcChar8*)text, + len, &extents); + + return (extents.xOff); +} + +void +xu_xft_draw(struct screen_ctx *sc, const char *text, + Drawable d, int color, int x, int y) +{ + XftDrawChange(sc->xftdraw, d); + XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont, + x, y, (const FcChar8*)text, strlen(text)); +} -- cgit 1.4.1 From e14123210a7773a0fda562eb367d71482c872e60 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 20 May 2013 20:04:36 +0000 Subject: no reason to pass around *sc when it's already in menu_ctx. --- menu.c | 64 +++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/menu.c b/menu.c index 80e1ce7..e743ad2 100644 --- a/menu.c +++ b/menu.c @@ -65,18 +65,16 @@ struct menu_ctx { static struct menu *menu_handle_key(XEvent *, struct menu_ctx *, struct menu_q *, struct menu_q *); static void menu_handle_move(XEvent *, struct menu_ctx *, - struct screen_ctx *, struct menu_q *); + struct menu_q *); static struct menu *menu_handle_release(XEvent *, struct menu_ctx *, - struct screen_ctx *, struct menu_q *); -static void menu_draw(struct screen_ctx *, struct menu_ctx *, - struct menu_q *, struct menu_q *); -static void menu_draw_entry(struct screen_ctx *, struct menu_ctx *, - struct menu_q *, int, int); -static int menu_calc_entry(struct screen_ctx *, struct menu_ctx *, + struct menu_q *); +static void menu_draw(struct menu_ctx *, struct menu_q *, + 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 int menu_keycode(XKeyEvent *, enum ctltype *, - char *); +static int menu_keycode(XKeyEvent *, enum ctltype *, char *); void menu_init(struct screen_ctx *sc) @@ -157,13 +155,13 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt, goto out; /* FALLTHROUGH */ case Expose: - menu_draw(sc, &mc, menuq, &resultq); + menu_draw(&mc, menuq, &resultq); break; case MotionNotify: - menu_handle_move(&e, &mc, sc, &resultq); + menu_handle_move(&e, &mc, &resultq); break; case ButtonRelease: - if ((mi = menu_handle_release(&e, &mc, sc, &resultq)) + if ((mi = menu_handle_release(&e, &mc, &resultq)) != NULL) goto out; break; @@ -342,9 +340,9 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq, } static void -menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, - struct menu_q *resultq) +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; int n, xsave, ysave; @@ -439,17 +437,18 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, } if (mc->hasprompt && n > 1 && (mc->searchstr[0] != '\0')) { mc->entry = 1; - menu_draw_entry(sc, mc, resultq, mc->entry, 1); + menu_draw_entry(mc, resultq, mc->entry, 1); } } static void -menu_draw_entry(struct screen_ctx *sc, struct menu_ctx *mc, - struct menu_q *resultq, int entry, int active) +menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq, + int entry, int active) { - struct menu *mi; - char *text; - int color, i = 0; + struct screen_ctx *sc = mc->sc; + struct menu *mi; + char *text; + int color, i = 0; if (mc->hasprompt) i = 1; @@ -471,35 +470,33 @@ menu_draw_entry(struct screen_ctx *sc, struct menu_ctx *mc, } static void -menu_handle_move(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc, - struct menu_q *resultq) +menu_handle_move(XEvent *e, struct menu_ctx *mc, struct menu_q *resultq) { mc->prev = mc->entry; - mc->entry = menu_calc_entry(sc, mc, e->xbutton.x, e->xbutton.y); + mc->entry = menu_calc_entry(mc, e->xbutton.x, e->xbutton.y); if (mc->prev == mc->entry) return; if (mc->prev != -1) - menu_draw_entry(sc, mc, resultq, mc->prev, 0); + menu_draw_entry(mc, resultq, mc->prev, 0); if (mc->entry != -1) { (void)xu_ptr_regrab(MENUGRABMASK, Cursor_normal); - menu_draw_entry(sc, mc, resultq, mc->entry, 1); + menu_draw_entry(mc, resultq, mc->entry, 1); } else (void)xu_ptr_regrab(MENUGRABMASK, Cursor_default); if (mc->hasprompt) - menu_draw_entry(sc, mc, resultq, 1, 1); + menu_draw_entry(mc, resultq, 1, 1); } static struct menu * -menu_handle_release(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc, - struct menu_q *resultq) +menu_handle_release(XEvent *e, struct menu_ctx *mc, struct menu_q *resultq) { - struct menu *mi; - int entry, i = 0; + struct menu *mi; + int entry, i = 0; - entry = menu_calc_entry(sc, mc, e->xbutton.x, e->xbutton.y); + entry = menu_calc_entry(mc, e->xbutton.x, e->xbutton.y); if (mc->hasprompt) i = 1; @@ -516,9 +513,10 @@ menu_handle_release(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc, } static int -menu_calc_entry(struct screen_ctx *sc, struct menu_ctx *mc, int x, int y) +menu_calc_entry(struct menu_ctx *mc, int x, int y) { - int entry; + struct screen_ctx *sc = mc->sc; + int entry; entry = y / (sc->xftfont->height + 1); -- cgit 1.4.1 From 270df196ac17363536c44fe342b4e71e1c8450e3 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 20 May 2013 20:21:04 +0000 Subject: - configure menuwin with the screen, then create the xft drawable using the menu window since that's the only place on which we draw - elminate the need to change the drawable on every font draw --- calmwm.h | 3 +-- conf.c | 15 ++++++++++----- menu.c | 15 +++------------ mousefunc.c | 2 +- screen.c | 1 - xutil.c | 4 +--- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/calmwm.h b/calmwm.h index b45e9df..5671ece 100644 --- a/calmwm.h +++ b/calmwm.h @@ -426,7 +426,6 @@ struct menu *menu_filter(struct screen_ctx *, struct menu_q *, char *, char *, int, void (*)(struct menu_q *, struct menu_q *, char *), void (*)(struct menu *, int)); -void menu_init(struct screen_ctx *); void menuq_clear(struct menu_q *); int parse_config(const char *, struct conf *); @@ -463,7 +462,7 @@ void xu_ptr_ungrab(void); void xu_sendmsg(Window, Atom, long); void xu_set_wm_state(Window win, int); void xu_xft_draw(struct screen_ctx *, const char *, - Drawable, int, int, int); + int, int, int); int xu_xft_width(XftFont *, const char *, int); void xu_xorcolor(XftColor, XftColor, XftColor *); diff --git a/conf.c b/conf.c index b4d5d9d..984e4cc 100644 --- a/conf.c +++ b/conf.c @@ -103,11 +103,6 @@ conf_screen(struct screen_ctx *sc) sc->gap = Conf.gap; - sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin, - sc->visual, sc->colormap); - if (sc->xftdraw == NULL) - errx(1, "XftDrawCreate"); - sc->xftfont = XftFontOpenName(X_Dpy, sc->which, Conf.font); if (sc->xftfont == NULL) errx(1, "XftFontOpenName"); @@ -134,6 +129,16 @@ conf_screen(struct screen_ctx *sc) if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap, &xc.color, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL])) warnx("XftColorAllocValue: '%s'", Conf.color[i]); + + sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1, + Conf.bwidth, + 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); + if (sc->xftdraw == NULL) + errx(1, "XftDrawCreate"); } static struct { diff --git a/menu.c b/menu.c index e743ad2..5313efb 100644 --- a/menu.c +++ b/menu.c @@ -76,15 +76,6 @@ static int menu_calc_entry(struct menu_ctx *, int, int); static struct menu *menu_complete_path(struct menu_ctx *); static int menu_keycode(XKeyEvent *, enum ctltype *, char *); -void -menu_init(struct screen_ctx *sc) -{ - sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1, - Conf.bwidth, - sc->xftcolor[CWM_COLOR_MENU_FG].pixel, - sc->xftcolor[CWM_COLOR_MENU_BG].pixel); -} - struct menu * menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt, char *initial, int flags, @@ -417,7 +408,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) mc->width, mc->height); if (mc->hasprompt) { - xu_xft_draw(sc, mc->dispstr, sc->menuwin, CWM_COLOR_MENU_FONT, + xu_xft_draw(sc, mc->dispstr, CWM_COLOR_MENU_FONT, 0, sc->xftfont->ascent); n = 1; } else @@ -432,7 +423,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) if (mc->y + y > xine.h) break; - xu_xft_draw(sc, text, sc->menuwin, CWM_COLOR_MENU_FONT, 0, y); + xu_xft_draw(sc, text, CWM_COLOR_MENU_FONT, 0, y); n++; } if (mc->hasprompt && n > 1 && (mc->searchstr[0] != '\0')) { @@ -465,7 +456,7 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq, (sc->xftfont->height + 1) * entry, mc->width, (sc->xftfont->height + 1) + sc->xftfont->descent); color = active ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; - xu_xft_draw(sc, text, sc->menuwin, color, + xu_xft_draw(sc, text, color, 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1); } diff --git a/mousefunc.c b/mousefunc.c index 64670b5..a41a3ad 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -63,7 +63,7 @@ mousefunc_sweep_draw(struct client_ctx *cc) XMapWindow(X_Dpy, sc->menuwin); XClearWindow(X_Dpy, sc->menuwin); - xu_xft_draw(sc, asize, sc->menuwin, CWM_COLOR_MENU_FONT, + xu_xft_draw(sc, asize, CWM_COLOR_MENU_FONT, 0, sc->xftfont->ascent + 1); } diff --git a/screen.c b/screen.c index 8435859..f8abae2 100644 --- a/screen.c +++ b/screen.c @@ -56,7 +56,6 @@ screen_init(int which) TAILQ_INIT(&sc->mruq); group_init(sc); - menu_init(sc); rootattr.cursor = Cursor_normal; rootattr.event_mask = SubstructureRedirectMask|SubstructureNotifyMask| diff --git a/xutil.c b/xutil.c index 3e2b36c..d5055f2 100644 --- a/xutil.c +++ b/xutil.c @@ -442,10 +442,8 @@ xu_xft_width(XftFont *xftfont, const char *text, int len) } void -xu_xft_draw(struct screen_ctx *sc, const char *text, - Drawable d, int color, int x, int y) +xu_xft_draw(struct screen_ctx *sc, const char *text, int color, int x, int y) { - XftDrawChange(sc->xftdraw, d); XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->xftfont, x, y, (const FcChar8*)text, strlen(text)); } -- cgit 1.4.1 From 284af4ca0c40d7a90ea0f574924abb707db7db05 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 20 May 2013 21:13:58 +0000 Subject: add support for _NET_WM_STATE_MAXIMIZED_{HORZ,VERT}; from Alexander Polakov. while I'm unsure of the final look of _NET_WM_STATE, there's no reason to delay this support. --- calmwm.h | 7 +++++++ client.c | 5 +++++ xutil.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/calmwm.h b/calmwm.h index 5671ece..e525cbf 100644 --- a/calmwm.h +++ b/calmwm.h @@ -481,6 +481,9 @@ void xu_ewmh_net_desktop_names(struct screen_ctx *, char *, int); void xu_ewmh_net_wm_desktop(struct client_ctx *); +Atom *xu_ewmh_get_net_wm_state(struct client_ctx *, int *); +void xu_ewmh_set_net_wm_state(struct client_ctx *); +void xu_ewmh_restore_net_wm_state(struct client_ctx *); void u_exec(char *); void u_spawn(char *); @@ -534,6 +537,10 @@ enum { _NET_WM_NAME, _NET_WM_DESKTOP, _NET_CLOSE_WINDOW, + _NET_WM_STATE, +#define _NET_WM_STATES_NITEMS 2 + _NET_WM_STATE_MAXIMIZED_VERT, + _NET_WM_STATE_MAXIMIZED_HORZ, EWMH_NITEMS }; struct atom_ctx { diff --git a/client.c b/client.c index 9ebd8bc..605c2a4 100644 --- a/client.c +++ b/client.c @@ -133,6 +133,7 @@ client_init(Window win, struct screen_ctx *sc, int mapped) xu_ewmh_net_client_list(sc); client_wm_protocols(cc); + xu_ewmh_restore_net_wm_state(cc); if (mapped) group_autogroup(cc); @@ -301,6 +302,7 @@ client_maximize(struct client_ctx *cc) resize: client_resize(cc, 0); + xu_ewmh_set_net_wm_state(cc); } void @@ -341,6 +343,7 @@ client_vmaximize(struct client_ctx *cc) resize: client_resize(cc, 0); + xu_ewmh_set_net_wm_state(cc); } void @@ -381,6 +384,7 @@ client_hmaximize(struct client_ctx *cc) resize: client_resize(cc, 0); + xu_ewmh_set_net_wm_state(cc); } void @@ -389,6 +393,7 @@ client_resize(struct client_ctx *cc, int reset) if (reset) { cc->flags &= ~CLIENT_MAXIMIZED; cc->bwidth = Conf.bwidth; + xu_ewmh_set_net_wm_state(cc); } client_draw_border(cc); diff --git a/xutil.c b/xutil.c index d5055f2..95bb0d4 100644 --- a/xutil.c +++ b/xutil.c @@ -257,6 +257,9 @@ struct atom_ctx ewmh[EWMH_NITEMS] = { {"_NET_WM_NAME", None}, {"_NET_WM_DESKTOP", None}, {"_NET_CLOSE_WINDOW", None}, + {"_NET_WM_STATE", None}, + {"_NET_WM_STATE_MAXIMIZED_VERT",None}, + {"_NET_WM_STATE_MAXIMIZED_HORZ",None}, }; void @@ -420,6 +423,64 @@ xu_ewmh_net_wm_desktop(struct client_ctx *cc) XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&no, 1); } +Atom * +xu_ewmh_get_net_wm_state(struct client_ctx *cc, int *n) +{ + Atom *state, *p = NULL; + + if ((*n = xu_getprop(cc->win, ewmh[_NET_WM_STATE].atom, XA_ATOM, 64L, + (u_char **)&p)) <= 0) + return (NULL); + + state = xmalloc(*n * sizeof(Atom)); + memcpy(state, p, *n * sizeof(Atom)); + XFree((char *)p); + + return (state); +} + +void +xu_ewmh_restore_net_wm_state(struct client_ctx *cc) +{ + Atom *atoms; + int i, n; + + atoms = xu_ewmh_get_net_wm_state(cc, &n); + for (i = 0; i < n; i++) { + if (atoms[i] == ewmh[_NET_WM_STATE_MAXIMIZED_HORZ].atom) + client_hmaximize(cc); + if (atoms[i] == ewmh[_NET_WM_STATE_MAXIMIZED_VERT].atom) + client_vmaximize(cc); + } + free(atoms); +} + +void +xu_ewmh_set_net_wm_state(struct client_ctx *cc) +{ + Atom *atoms, *oatoms; + int n, i, j; + + oatoms = xu_ewmh_get_net_wm_state(cc, &n); + atoms = xmalloc((n + _NET_WM_STATES_NITEMS) * sizeof(Atom)); + for (i = j = 0; i < n; i++) { + if (oatoms[i] != ewmh[_NET_WM_STATE_MAXIMIZED_HORZ].atom && + oatoms[i] != ewmh[_NET_WM_STATE_MAXIMIZED_VERT].atom) + atoms[j++] = oatoms[i]; + } + free(oatoms); + if (cc->flags & CLIENT_HMAXIMIZED) + atoms[j++] = ewmh[_NET_WM_STATE_MAXIMIZED_HORZ].atom; + if (cc->flags & CLIENT_VMAXIMIZED) + atoms[j++] = ewmh[_NET_WM_STATE_MAXIMIZED_VERT].atom; + if (j > 0) + XChangeProperty(X_Dpy, cc->win, ewmh[_NET_WM_STATE].atom, + XA_ATOM, 32, PropModeReplace, (unsigned char *)atoms, j); + else + XDeleteProperty(X_Dpy, cc->win, ewmh[_NET_WM_STATE].atom); + free(atoms); +} + void xu_xorcolor(XftColor a, XftColor b, XftColor *r) { -- cgit 1.4.1 From ad8020e17dc6277cc956d00eb869fc8703079f5f Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 20 May 2013 21:19:15 +0000 Subject: handle _NET_ACTIVE_WINDOW ClientMessage; from Alexander Polakov. --- xevents.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/xevents.c b/xevents.c index 91da64a..32b2262 100644 --- a/xevents.c +++ b/xevents.c @@ -340,7 +340,7 @@ static void xev_handle_clientmessage(XEvent *ee) { XClientMessageEvent *e = &ee->xclient; - struct client_ctx *cc; + struct client_ctx *cc, *old_cc; if ((cc = client_find(e->window)) == NULL) return; @@ -351,6 +351,14 @@ xev_handle_clientmessage(XEvent *ee) if (e->message_type == ewmh[_NET_CLOSE_WINDOW].atom) client_send_delete(cc); + + if (e->message_type == ewmh[_NET_ACTIVE_WINDOW].atom && + e->format == 32) { + old_cc = client_current(); + if (old_cc) + client_ptrsave(old_cc); + client_ptrwarp(cc); + } } static void -- cgit 1.4.1 From c2042cd5238e74bcc3763a1e90917425eb41964e Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 20 May 2013 21:32:00 +0000 Subject: stray whitespace --- menu.c | 2 +- xevents.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/menu.c b/menu.c index 5313efb..6816006 100644 --- a/menu.c +++ b/menu.c @@ -451,7 +451,7 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq, return; color = active ? CWM_COLOR_MENU_FG : CWM_COLOR_MENU_BG; - text = mi->print[0] != '\0' ? mi->print : mi->text; + text = mi->print[0] != '\0' ? mi->print : mi->text; XftDrawRect(sc->xftdraw, &sc->xftcolor[color], 0, (sc->xftfont->height + 1) * entry, mc->width, (sc->xftfont->height + 1) + sc->xftfont->descent); diff --git a/xevents.c b/xevents.c index 32b2262..b13548b 100644 --- a/xevents.c +++ b/xevents.c @@ -358,7 +358,7 @@ xev_handle_clientmessage(XEvent *ee) if (old_cc) client_ptrsave(old_cc); client_ptrwarp(cc); - } + } } static void -- cgit 1.4.1 From 421bf22ac7a165f0f4d5608ffa22c887ff857d53 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 21 May 2013 00:29:20 +0000 Subject: handle _NET_WM_STATE ClientMessage; from Alexander Polakov. --- calmwm.h | 7 +++++++ xevents.c | 4 ++++ xutil.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/calmwm.h b/calmwm.h index e525cbf..b925c2c 100644 --- a/calmwm.h +++ b/calmwm.h @@ -482,6 +482,8 @@ void xu_ewmh_net_desktop_names(struct screen_ctx *, char *, void xu_ewmh_net_wm_desktop(struct client_ctx *); Atom *xu_ewmh_get_net_wm_state(struct client_ctx *, int *); +void xu_ewmh_handle_net_wm_state_msg(struct client_ctx *, + int, Atom , Atom); void xu_ewmh_set_net_wm_state(struct client_ctx *); void xu_ewmh_restore_net_wm_state(struct client_ctx *); @@ -543,6 +545,11 @@ enum { _NET_WM_STATE_MAXIMIZED_HORZ, EWMH_NITEMS }; +enum { + _NET_WM_STATE_REMOVE, + _NET_WM_STATE_ADD, + _NET_WM_STATE_TOGGLE +}; struct atom_ctx { char *name; Atom atom; diff --git a/xevents.c b/xevents.c index b13548b..1c6ffaf 100644 --- a/xevents.c +++ b/xevents.c @@ -359,6 +359,10 @@ xev_handle_clientmessage(XEvent *ee) client_ptrsave(old_cc); client_ptrwarp(cc); } + if (e->message_type == ewmh[_NET_WM_STATE].atom && + e->format == 32) + xu_ewmh_handle_net_wm_state_msg(cc, + e->data.l[0], e->data.l[1], e->data.l[2]); } static void diff --git a/xutil.c b/xutil.c index 95bb0d4..2c678dd 100644 --- a/xutil.c +++ b/xutil.c @@ -439,6 +439,43 @@ xu_ewmh_get_net_wm_state(struct client_ctx *cc, int *n) return (state); } +void +xu_ewmh_handle_net_wm_state_msg(struct client_ctx *cc, int action, + Atom first, Atom second) +{ + int i; + static struct handlers { + int atom; + int property; + void (*toggle)(struct client_ctx *); + } handlers[] = { + { _NET_WM_STATE_MAXIMIZED_VERT, + CLIENT_VMAXIMIZED, + client_vmaximize }, + { _NET_WM_STATE_MAXIMIZED_HORZ, + CLIENT_HMAXIMIZED, + client_hmaximize }, + }; + + for (i = 0; i < nitems(handlers); i++) { + if (first != ewmh[handlers[i].atom].atom && + second != ewmh[handlers[i].atom].atom) + continue; + switch (action) { + case _NET_WM_STATE_ADD: + if ((cc->flags & handlers[i].property) == 0) + handlers[i].toggle(cc); + break; + case _NET_WM_STATE_REMOVE: + if (cc->flags & handlers[i].property) + handlers[i].toggle(cc); + break; + case _NET_WM_STATE_TOGGLE: + handlers[i].toggle(cc); + } + } +} + void xu_ewmh_restore_net_wm_state(struct client_ctx *cc) { -- cgit 1.4.1 From 866f5af9c746d84e68ab1a376c18f96581fb0765 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 22 May 2013 13:02:14 +0000 Subject: sync with src changes --- parse.y | 63 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/parse.y b/parse.y index e0c13bb..111be2e 100644 --- a/parse.y +++ b/parse.y @@ -42,18 +42,17 @@ static struct file { char *name; int lineno; int errors; -} *file; - -struct file *pushfile(const char *); -int popfile(void); -int yyparse(void); -int yylex(void); -int yyerror(const char *, ...); -int kw_cmp(const void *, const void *); -int lookup(char *); -int lgetc(int); -int lungetc(int); -int findeol(void); +} *file, *topfile; +struct file *pushfile(const char *); +int popfile(void); +int yyparse(void); +int yylex(void); +int yyerror(const char *, ...); +int kw_cmp(const void *, const void *); +int lookup(char *); +int lgetc(int); +int lungetc(int); +int findeol(void); static struct conf *conf; @@ -224,7 +223,7 @@ struct keywords { int yyerror(const char *fmt, ...) { - va_list ap; + va_list ap; file->errors++; va_start(ap, fmt); @@ -308,8 +307,9 @@ lgetc(int quotec) if (quotec) { if ((c = getc(file->stream)) == EOF) { - yyerror("reached end of file while parsing quoted string"); - if (popfile() == EOF) + yyerror("reached end of file while parsing " + "quoted string"); + if (file == topfile || popfile() == EOF) return (EOF); return (quotec); } @@ -327,7 +327,7 @@ lgetc(int quotec) } while (c == EOF) { - if (popfile() == EOF) + if (file == topfile || popfile() == EOF) return (EOF); c = getc(file->stream); } @@ -356,11 +356,13 @@ findeol(void) int c; parsebuf = NULL; - pushback_index = 0; /* skip to either EOF or the first real EOL */ while (1) { - c = lgetc(0); + if (pushback_index) + c = pushback_buffer[--pushback_index]; + else + c = lgetc(0); if (c == '\n') { file->lineno++; break; @@ -461,9 +463,10 @@ nodigits: #define allowed_in_string(x) \ (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \ x != '{' && x != '}' && x != '<' && x != '>' && \ - x != '!' && x != '=' && x != '#' && x != ',')) + x != '!' && x != '=' && x != '/' && x != '#' && \ + x != ',')) - if (isalnum(c) || c == ':' || c == '_' || c == '*' || c == '/') { + if (isalnum(c) || c == ':' || c == '_' || c == '*') { do { *p++ = c; if ((unsigned)(p-buf) >= sizeof(buf)) { @@ -495,6 +498,7 @@ pushfile(const char *name) nfile->name = xstrdup(name); if ((nfile->stream = fopen(nfile->name, "r")) == NULL) { + warn("%s", nfile->name); free(nfile->name); free(nfile); return (NULL); @@ -509,16 +513,15 @@ popfile(void) { struct file *prev; - if ((prev = TAILQ_PREV(file, files, entry)) != NULL) { + if ((prev = TAILQ_PREV(file, files, entry)) != NULL) prev->errors += file->errors; - TAILQ_REMOVE(&files, file, entry); - fclose(file->stream); - free(file->name); - free(file); - file = prev; - return (0); - } - return (EOF); + + TAILQ_REMOVE(&files, file, entry); + fclose(file->stream); + free(file->name); + free(file); + file = prev; + return (file ? 0 : EOF); } int @@ -532,12 +535,12 @@ parse_config(const char *filename, struct conf *xconf) free(conf); return (-1); } + topfile = file; conf_init(conf); yyparse(); errors = file->errors; - file->errors = 0; popfile(); if (errors) { -- cgit 1.4.1 From 532f132194751bd2f530a13c243a30c76f66bfaa Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 22 May 2013 16:32:15 +0000 Subject: move validation of pointer Button into conf_mousebind so we check validity during the parse phase and not bother adding it to the queue, instead of each time a client needs to grab (when it's too late); furthermore, make this a config error, stop parsing and load the default config. --- calmwm.h | 2 +- conf.c | 44 ++++++++++++++++++++++---------------------- parse.y | 7 ++++++- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/calmwm.h b/calmwm.h index b925c2c..16901b3 100644 --- a/calmwm.h +++ b/calmwm.h @@ -439,7 +439,7 @@ void conf_grab(struct conf *, struct keybinding *); void conf_grab_mouse(struct client_ctx *); void conf_init(struct conf *); void conf_ignore(struct conf *, char *); -void conf_mousebind(struct conf *, char *, char *); +int conf_mousebind(struct conf *, char *, char *); void conf_screen(struct screen_ctx *); void conf_ungrab(struct conf *, struct keybinding *); diff --git a/conf.c b/conf.c index 984e4cc..0afc11d 100644 --- a/conf.c +++ b/conf.c @@ -577,11 +577,14 @@ static struct { { "menu_cmd", mousefunc_menu_cmd, MOUSEBIND_CTX_ROOT }, }; -void +static unsigned int mouse_btns[] = { Button1, Button2, Button3 }; + +int conf_mousebind(struct conf *c, char *name, char *binding) { struct mousebinding *current_binding; char *substring, *tmp; + u_int button; const char *errstr; u_int i; @@ -600,16 +603,27 @@ conf_mousebind(struct conf *c, char *name, char *binding) } else substring = name; - current_binding->button = strtonum(substring, 1, 3, &errstr); + button = strtonum(substring, 1, 3, &errstr); if (errstr) - warnx("number of buttons is %s: %s", errstr, substring); + warnx("button number is %s: %s", errstr, substring); + + for (i = 0; i < nitems(mouse_btns); i++) { + if (button == mouse_btns[i]) { + current_binding->button = button; + break; + } + } + if (!current_binding->button || errstr) { + free(current_binding); + return (0); + } /* We now have the correct binding, remove duplicates. */ conf_mouseunbind(c, current_binding); if (strcmp("unmap", binding) == 0) { free(current_binding); - return; + return (1); } for (i = 0; i < nitems(name_to_mousefunc); i++) { @@ -619,8 +633,10 @@ conf_mousebind(struct conf *c, char *name, char *binding) current_binding->context = name_to_mousefunc[i].context; current_binding->callback = name_to_mousefunc[i].handler; TAILQ_INSERT_TAIL(&c->mousebindingq, current_binding, entry); - return; + return (1); } + + return (0); } static void @@ -646,26 +662,10 @@ void conf_grab_mouse(struct client_ctx *cc) { struct mousebinding *mb; - u_int button; TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) { if (mb->context != MOUSEBIND_CTX_WIN) continue; - - switch(mb->button) { - case 1: - button = Button1; - break; - case 2: - button = Button2; - break; - case 3: - button = Button3; - break; - default: - warnx("strange button in mousebinding\n"); - continue; - } - xu_btn_grab(cc->win, mb->modmask, button); + xu_btn_grab(cc->win, mb->modmask, mb->button); } } diff --git a/parse.y b/parse.y index 111be2e..0e67ba1 100644 --- a/parse.y +++ b/parse.y @@ -171,7 +171,12 @@ main : FONTNAME STRING { conf->gap.right = $5; } | MOUSEBIND STRING string { - conf_mousebind(conf, $2, $3); + if (!conf_mousebind(conf, $2, $3)) { + yyerror("invalid mousebind: %s %s", $2, $3); + free($2); + free($3); + YYERROR; + } free($2); free($3); } -- cgit 1.4.1 From d1eadee9226043af0e2a7043a958e6c4d8e405bc Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 22 May 2013 16:54:09 +0000 Subject: get rid of long standing XXX: now that we configure screens based on config options, add the keybinding GrabKey calls here --- calmwm.c | 8 -------- conf.c | 8 ++++++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/calmwm.c b/calmwm.c index e9b3902..f2dff49 100644 --- a/calmwm.c +++ b/calmwm.c @@ -144,7 +144,6 @@ dpy_init(const char *dpyname) static void x_setup(void) { - struct keybinding *kb; int i; Cursor_default = XCreateFontCursor(X_Dpy, XC_X_cursor); @@ -155,13 +154,6 @@ x_setup(void) for (i = 0; i < ScreenCount(X_Dpy); i++) screen_init(i); - - /* - * XXX key grabs weren't done before, since Screenq was empty, - * do them here for now (this needs changing). - */ - TAILQ_FOREACH(kb, &Conf.keybindingq, entry) - conf_grab(&Conf, kb); } static void diff --git a/conf.c b/conf.c index 0afc11d..b3c5210 100644 --- a/conf.c +++ b/conf.c @@ -98,8 +98,9 @@ static char *color_binds[CWM_COLOR_MAX] = { void conf_screen(struct screen_ctx *sc) { - int i; - XftColor xc; + struct keybinding *kb; + int i; + XftColor xc; sc->gap = Conf.gap; @@ -139,6 +140,9 @@ conf_screen(struct screen_ctx *sc) sc->visual, sc->colormap); if (sc->xftdraw == NULL) errx(1, "XftDrawCreate"); + + TAILQ_FOREACH(kb, &Conf.keybindingq, entry) + xu_key_grab(sc->rootwin, kb->modmask, kb->keysym); } static struct { -- cgit 1.4.1 From 7cc1c7344fe74b91e528ea6792318d7af0d833ef Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 22 May 2013 20:23:21 +0000 Subject: since we don't have any screens yet, there's no reason to conf_{,un}grab here; just build keybindingq. --- conf.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/conf.c b/conf.c index b3c5210..5d005c1 100644 --- a/conf.c +++ b/conf.c @@ -530,7 +530,6 @@ conf_bindname(struct conf *c, char *name, char *binding) current_binding->flags = name_to_kbfunc[i].flags; current_binding->argument = name_to_kbfunc[i].argument; current_binding->argtype |= ARG_INT; - conf_grab(c, current_binding); TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry); return; } @@ -539,7 +538,6 @@ conf_bindname(struct conf *c, char *name, char *binding) current_binding->flags = 0; current_binding->argument.c = xstrdup(binding); current_binding->argtype |= ARG_CHAR; - conf_grab(c, current_binding); TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry); } @@ -555,7 +553,6 @@ conf_unbind(struct conf *c, struct keybinding *unbind) if ((key->keycode != 0 && key->keysym == NoSymbol && key->keycode == unbind->keycode) || key->keysym == unbind->keysym) { - conf_ungrab(c, key); TAILQ_REMOVE(&c->keybindingq, key, entry); if (key->argtype & ARG_CHAR) free(key->argument.c); -- cgit 1.4.1 From be1a7a3f5c7c0777ba86d40c49425e97fbae62a1 Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 23 May 2013 16:52:39 +0000 Subject: alter conf_grab(_kbd) to first ungrab AnyKey/AnyModifier, then proceed to grab keys in keybindingq. we don't need to ungrab/grab on every addition to the queue, just once with a complete keybindingq; simplify grabbing keys per screen (during init) and during a MappingNotify. while here, change conf_grab_{kbd,mouse} to require only a Window. --- calmwm.h | 6 ++---- client.c | 2 +- conf.c | 54 +++++++++++++++--------------------------------------- xevents.c | 12 +++++------- xutil.c | 15 --------------- 5 files changed, 23 insertions(+), 66 deletions(-) diff --git a/calmwm.h b/calmwm.h index 16901b3..25eae87 100644 --- a/calmwm.h +++ b/calmwm.h @@ -435,13 +435,12 @@ void conf_bindname(struct conf *, char *, char *); void conf_clear(struct conf *); void conf_client(struct client_ctx *); void conf_cmd_add(struct conf *, char *, char *); -void conf_grab(struct conf *, struct keybinding *); -void conf_grab_mouse(struct client_ctx *); +void conf_grab_kbd(Window); +void conf_grab_mouse(Window); void conf_init(struct conf *); void conf_ignore(struct conf *, char *); int conf_mousebind(struct conf *, char *, char *); void conf_screen(struct screen_ctx *); -void conf_ungrab(struct conf *, struct keybinding *); void xev_loop(void); @@ -453,7 +452,6 @@ int xu_getprop(Window, Atom, Atom, long, u_char **); int xu_get_wm_state(Window, int *); int xu_getstrprop(Window, Atom, char **); void xu_key_grab(Window, u_int, KeySym); -void xu_key_ungrab(Window, u_int, KeySym); void xu_ptr_getpos(Window, int *, int *); int xu_ptr_grab(Window, u_int, Cursor); int xu_ptr_regrab(u_int, Cursor); diff --git a/client.c b/client.c index 605c2a4..650dbaa 100644 --- a/client.c +++ b/client.c @@ -213,7 +213,7 @@ client_setactive(struct client_ctx *cc, int fg) XInstallColormap(X_Dpy, cc->colormap); XSetInputFocus(X_Dpy, cc->win, RevertToPointerRoot, CurrentTime); - conf_grab_mouse(cc); + conf_grab_mouse(cc->win); /* * If we're in the middle of alt-tabbing, don't change * the order please. diff --git a/conf.c b/conf.c index 5d005c1..763e364 100644 --- a/conf.c +++ b/conf.c @@ -98,7 +98,6 @@ static char *color_binds[CWM_COLOR_MAX] = { void conf_screen(struct screen_ctx *sc) { - struct keybinding *kb; int i; XftColor xc; @@ -141,8 +140,7 @@ conf_screen(struct screen_ctx *sc) if (sc->xftdraw == NULL) errx(1, "XftDrawCreate"); - TAILQ_FOREACH(kb, &Conf.keybindingq, entry) - xu_key_grab(sc->rootwin, kb->modmask, kb->keysym); + conf_grab_kbd(sc->rootwin); } static struct { @@ -436,37 +434,6 @@ static struct { {.i = CWM_TILE_VERT } }, }; -/* - * The following two functions are used when grabbing and ungrabbing keys for - * bindings - */ - -/* - * Grab key combination on all screens and add to the global queue - */ -void -conf_grab(struct conf *c, struct keybinding *kb) -{ - extern struct screen_ctx_q Screenq; - struct screen_ctx *sc; - - TAILQ_FOREACH(sc, &Screenq, entry) - xu_key_grab(sc->rootwin, kb->modmask, kb->keysym); -} - -/* - * Ungrab key combination from all screens and remove from global queue - */ -void -conf_ungrab(struct conf *c, struct keybinding *kb) -{ - extern struct screen_ctx_q Screenq; - struct screen_ctx *sc; - - TAILQ_FOREACH(sc, &Screenq, entry) - xu_key_ungrab(sc->rootwin, kb->modmask, kb->keysym); -} - static struct { char chr; int mask; @@ -656,17 +623,26 @@ conf_mouseunbind(struct conf *c, struct mousebinding *unbind) } } -/* - * Grab the mouse buttons that we need for bindings for this client - */ void -conf_grab_mouse(struct client_ctx *cc) +conf_grab_mouse(Window win) { struct mousebinding *mb; TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) { if (mb->context != MOUSEBIND_CTX_WIN) continue; - xu_btn_grab(cc->win, mb->modmask, mb->button); + xu_btn_grab(win, mb->modmask, mb->button); } } + +void +conf_grab_kbd(Window win) +{ + struct keybinding *kb; + + XUngrabKey(X_Dpy, AnyKey, AnyModifier, win); + + TAILQ_FOREACH(kb, &Conf.keybindingq, entry) + xu_key_grab(win, kb->modmask, kb->keysym); +} + diff --git a/xevents.c b/xevents.c index 1c6ffaf..0a8dc9a 100644 --- a/xevents.c +++ b/xevents.c @@ -389,15 +389,13 @@ static void xev_handle_mappingnotify(XEvent *ee) { XMappingEvent *e = &ee->xmapping; - struct keybinding *kb; - - TAILQ_FOREACH(kb, &Conf.keybindingq, entry) - conf_ungrab(&Conf, kb); + struct screen_ctx *sc; XRefreshKeyboardMapping(e); - - TAILQ_FOREACH(kb, &Conf.keybindingq, entry) - conf_grab(&Conf, kb); + if (e->request == MappingKeyboard) { + TAILQ_FOREACH(sc, &Screenq, entry) + conf_grab_kbd(sc->rootwin); + } } static void diff --git a/xutil.c b/xutil.c index 2c678dd..37d7e24 100644 --- a/xutil.c +++ b/xutil.c @@ -105,21 +105,6 @@ xu_key_grab(Window win, u_int mask, KeySym keysym) True, GrabModeAsync, GrabModeAsync); } -void -xu_key_ungrab(Window win, u_int mask, KeySym keysym) -{ - KeyCode code; - u_int i; - - code = XKeysymToKeycode(X_Dpy, keysym); - if ((XkbKeycodeToKeysym(X_Dpy, code, 0, 0) != keysym) && - (XkbKeycodeToKeysym(X_Dpy, code, 0, 1) == keysym)) - mask |= ShiftMask; - - for (i = 0; i < nitems(ign_mods); i++) - XUngrabKey(X_Dpy, code, (mask | ign_mods[i]), win); -} - void xu_configure(struct client_ctx *cc) { -- cgit 1.4.1 From 692d341dfc6b059db570356e9dfadba92dc93f19 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 27 May 2013 23:20:45 +0000 Subject: fix type in a ClientMessage (xu_sendmsg). --- calmwm.h | 2 +- xutil.c | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/calmwm.h b/calmwm.h index 25eae87..62f574a 100644 --- a/calmwm.h +++ b/calmwm.h @@ -457,7 +457,7 @@ int xu_ptr_grab(Window, u_int, Cursor); int xu_ptr_regrab(u_int, Cursor); void xu_ptr_setpos(Window, int, int); void xu_ptr_ungrab(void); -void xu_sendmsg(Window, Atom, long); +void xu_sendmsg(Window, Atom, Atom); void xu_set_wm_state(Window win, int); void xu_xft_draw(struct screen_ctx *, const char *, int, int, int); diff --git a/xutil.c b/xutil.c index 37d7e24..56325b6 100644 --- a/xutil.c +++ b/xutil.c @@ -125,19 +125,19 @@ xu_configure(struct client_ctx *cc) } void -xu_sendmsg(Window win, Atom atm, long val) +xu_sendmsg(Window win, Atom type, Atom atm) { - XEvent e; + XClientMessageEvent e; - (void)memset(&e, 0, sizeof(e)); - e.xclient.type = ClientMessage; - e.xclient.window = win; - e.xclient.message_type = atm; - e.xclient.format = 32; - e.xclient.data.l[0] = val; - e.xclient.data.l[1] = CurrentTime; + bzero(&e, sizeof(e)); + e.type = ClientMessage; + e.window = win; + e.message_type = type; + e.format = 32; + e.data.l[0] = atm; + e.data.l[1] = CurrentTime; - XSendEvent(X_Dpy, win, False, 0, &e); + XSendEvent(X_Dpy, win, False, 0L, (XEvent *)&e); } int -- cgit 1.4.1