From 7a7e5cd59254ab17f1f37affa868858160eca07a Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 8 Jul 2013 15:46:16 +0000 Subject: [PATCH 01/15] whitespace and style fixes; from Tiago Cunha and one from me. --- calmwm.c | 4 +--- xevents.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/calmwm.c b/calmwm.c index 6a189d2..4a5f43d 100644 --- a/calmwm.c +++ b/calmwm.c @@ -102,7 +102,6 @@ main(int argc, char **argv) conf_path = NULL; } - conf_init(&Conf); if (conf_path && (parse_config(conf_path, &Conf) == -1)) warnx("config file %s has errors, not loading", conf_path); @@ -121,8 +120,7 @@ x_init(const char *dpyname) int i; if ((X_Dpy = XOpenDisplay(dpyname)) == NULL) - errx(1, "unable to open display \"%s\"", - XDisplayName(dpyname)); + errx(1, "unable to open display \"%s\"", XDisplayName(dpyname)); XSetErrorHandler(x_wmerrorhandler); XSelectInput(X_Dpy, DefaultRootWindow(X_Dpy), SubstructureRedirectMask); diff --git a/xevents.c b/xevents.c index 812e959..ddbd8b6 100644 --- a/xevents.c +++ b/xevents.c @@ -357,7 +357,7 @@ xev_handle_clientmessage(XEvent *ee) client_send_delete(cc); if (e->message_type == ewmh[_NET_ACTIVE_WINDOW].atom && - e->format == 32) { + e->format == 32) { old_cc = client_current(); if (old_cc) client_ptrsave(old_cc); From fe439f2b965b9ee6e9dc9a6d8e2ecb443f86e788 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 8 Jul 2013 15:48:16 +0000 Subject: [PATCH 02/15] replace a few (x)malloc with (x)calloc to prevent potential integer overflows; from Tiago Cunha --- group.c | 4 ++-- xutil.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/group.c b/group.c index f7a0a2d..a25972a 100644 --- a/group.c +++ b/group.c @@ -430,8 +430,8 @@ group_update_names(struct screen_ctx *sc) } } - strings = xmalloc((nstrings < CALMWM_NGROUPS ? CALMWM_NGROUPS : - nstrings) * sizeof(*strings)); + strings = xcalloc((nstrings < CALMWM_NGROUPS ? CALMWM_NGROUPS : + nstrings), sizeof(*strings)); p = (char *)prop_ret; while (n < nstrings) { diff --git a/xutil.c b/xutil.c index 6eeaf72..f7f2000 100644 --- a/xutil.c +++ b/xutil.c @@ -291,7 +291,7 @@ xu_ewmh_net_client_list(struct screen_ctx *sc) if (i == 0) return; - winlist = xmalloc(i * sizeof(*winlist)); + winlist = xcalloc(i, sizeof(*winlist)); TAILQ_FOREACH(cc, &Clientq, entry) winlist[j++] = cc->win; XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_CLIENT_LIST].atom, @@ -382,7 +382,7 @@ xu_ewmh_get_net_wm_state(struct client_ctx *cc, int *n) (u_char **)&p)) <= 0) return (NULL); - state = xmalloc(*n * sizeof(Atom)); + state = xcalloc(*n, sizeof(Atom)); memcpy(state, p, *n * sizeof(Atom)); XFree((char *)p); @@ -449,7 +449,7 @@ xu_ewmh_set_net_wm_state(struct client_ctx *cc) int n, i, j; oatoms = xu_ewmh_get_net_wm_state(cc, &n); - atoms = xmalloc((n + _NET_WM_STATES_NITEMS) * sizeof(Atom)); + atoms = xcalloc((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) From 912ec90ea1f6e25b33a2bb0d6d7a1138622bd099 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 8 Jul 2013 16:10:55 +0000 Subject: [PATCH 03/15] move duplicate kbd and mouse modifier parsing to a generic function; from Tiago Cunha --- conf.c | 64 +++++++++++++++++++++++++++------------------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/conf.c b/conf.c index a771963..d84bc4f 100644 --- a/conf.c +++ b/conf.c @@ -31,8 +31,9 @@ #include "calmwm.h" -static void conf_mouseunbind(struct conf *, struct mousebinding *); -static void conf_unbind(struct conf *, struct keybinding *); +static const char *conf_bind_getmask(const char *, u_int *); +static void conf_mouseunbind(struct conf *, struct mousebinding *); +static void conf_unbind(struct conf *, struct keybinding *); /* Add an command menu entry to the end of the menu */ void @@ -442,27 +443,35 @@ static struct { { 'S', ShiftMask }, }; +static const char * +conf_bind_getmask(const char *name, u_int *mask) +{ + char *dash; + const char *ch; + u_int i; + + *mask = 0; + if ((dash = strchr(name, '-')) == NULL) + return (name); + for (i = 0; i < nitems(bind_mods); i++) { + if ((ch = strchr(name, bind_mods[i].chr)) != NULL && ch < dash) + *mask |= bind_mods[i].mask; + } + + /* Skip past modifiers. */ + return (dash + 1); +} + void conf_bindname(struct conf *c, char *name, char *binding) { struct keybinding *current_binding; - char *substring, *tmp; - u_int i; + const char *substring; + u_int i, mask; current_binding = xcalloc(1, sizeof(*current_binding)); - - if ((substring = strchr(name, '-')) != NULL) { - for (i = 0; i < nitems(bind_mods); i++) { - if ((tmp = strchr(name, bind_mods[i].chr)) != - NULL && tmp < substring) { - current_binding->modmask |= bind_mods[i].mask; - } - } - - /* skip past the modifiers */ - substring++; - } else - substring = name; + substring = conf_bind_getmask(name, &mask); + current_binding->modmask |= mask; if (substring[0] == '[' && substring[strlen(substring)-1] == ']') { @@ -551,25 +560,12 @@ 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; + const char *errstr, *substring; + u_int button, i, mask; current_binding = xcalloc(1, sizeof(*current_binding)); - - if ((substring = strchr(name, '-')) != NULL) { - for (i = 0; i < nitems(bind_mods); i++) { - if ((tmp = strchr(name, bind_mods[i].chr)) != - NULL && tmp < substring) { - current_binding->modmask |= bind_mods[i].mask; - } - } - - /* skip past the modifiers */ - substring++; - } else - substring = name; + substring = conf_bind_getmask(name, &mask); + current_binding->modmask |= mask; button = strtonum(substring, 1, 5, &errstr); if (errstr) From a49373406607e71601ac062c0a75ad36219065e2 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 8 Jul 2013 16:32:51 +0000 Subject: [PATCH 04/15] clarify kbd vs mouse functions --- calmwm.h | 4 ++-- conf.c | 32 ++++++++++++++++---------------- parse.y | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/calmwm.h b/calmwm.h index caf1808..0f74a87 100644 --- a/calmwm.h +++ b/calmwm.h @@ -443,7 +443,8 @@ void menuq_clear(struct menu_q *); int parse_config(const char *, struct conf *); void conf_autogroup(struct conf *, int, char *); -void conf_bindname(struct conf *, char *, char *); +void conf_bind_kbd(struct conf *, char *, char *); +int conf_bind_mouse(struct conf *, char *, char *); void conf_clear(struct conf *); void conf_client(struct client_ctx *); void conf_cmd_add(struct conf *, char *, char *); @@ -452,7 +453,6 @@ 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 xev_loop(void); diff --git a/conf.c b/conf.c index d84bc4f..82e6fa8 100644 --- a/conf.c +++ b/conf.c @@ -32,8 +32,8 @@ #include "calmwm.h" static const char *conf_bind_getmask(const char *, u_int *); -static void conf_mouseunbind(struct conf *, struct mousebinding *); -static void conf_unbind(struct conf *, struct keybinding *); +static void conf_unbind_mouse(struct conf *, struct mousebinding *); +static void conf_unbind_kbd(struct conf *, struct keybinding *); /* Add an command menu entry to the end of the menu */ void @@ -145,7 +145,7 @@ conf_screen(struct screen_ctx *sc) static struct { char *key; char *func; -} kb_binds[] = { +} kbd_binds[] = { { "CM-Return", "terminal" }, { "CM-Delete", "lock" }, { "M-question", "exec" }, @@ -204,7 +204,7 @@ static struct { { "CS-Up", "bigptrmoveup" }, { "CS-Right", "bigptrmoveright" }, }, -m_binds[] = { +mouse_binds[] = { { "1", "menu_unhide" }, { "2", "menu_group" }, { "3", "menu_cmd" }, @@ -232,11 +232,11 @@ conf_init(struct conf *c) TAILQ_INIT(&c->autogroupq); TAILQ_INIT(&c->mousebindingq); - for (i = 0; i < nitems(kb_binds); i++) - conf_bindname(c, kb_binds[i].key, kb_binds[i].func); + for (i = 0; i < nitems(kbd_binds); i++) + conf_bind_kbd(c, kbd_binds[i].key, kbd_binds[i].func); - for (i = 0; i < nitems(m_binds); i++) - conf_mousebind(c, m_binds[i].key, m_binds[i].func); + for (i = 0; i < nitems(mouse_binds); i++) + conf_bind_mouse(c, mouse_binds[i].key, mouse_binds[i].func); for (i = 0; i < nitems(color_binds); i++) c->color[i] = xstrdup(color_binds[i]); @@ -434,7 +434,7 @@ static struct { }; static struct { - char chr; + char ch; int mask; } bind_mods[] = { { 'C', ControlMask }, @@ -454,7 +454,7 @@ conf_bind_getmask(const char *name, u_int *mask) if ((dash = strchr(name, '-')) == NULL) return (name); for (i = 0; i < nitems(bind_mods); i++) { - if ((ch = strchr(name, bind_mods[i].chr)) != NULL && ch < dash) + if ((ch = strchr(name, bind_mods[i].ch)) != NULL && ch < dash) *mask |= bind_mods[i].mask; } @@ -463,7 +463,7 @@ conf_bind_getmask(const char *name, u_int *mask) } void -conf_bindname(struct conf *c, char *name, char *binding) +conf_bind_kbd(struct conf *c, char *name, char *binding) { struct keybinding *current_binding; const char *substring; @@ -489,7 +489,7 @@ conf_bindname(struct conf *c, char *name, char *binding) } /* We now have the correct binding, remove duplicates. */ - conf_unbind(c, current_binding); + conf_unbind_kbd(c, current_binding); if (strcmp("unmap", binding) == 0) { free(current_binding); @@ -516,7 +516,7 @@ conf_bindname(struct conf *c, char *name, char *binding) } static void -conf_unbind(struct conf *c, struct keybinding *unbind) +conf_unbind_kbd(struct conf *c, struct keybinding *unbind) { struct keybinding *key = NULL, *keynxt; @@ -557,7 +557,7 @@ static unsigned int mouse_btns[] = { }; int -conf_mousebind(struct conf *c, char *name, char *binding) +conf_bind_mouse(struct conf *c, char *name, char *binding) { struct mousebinding *current_binding; const char *errstr, *substring; @@ -583,7 +583,7 @@ conf_mousebind(struct conf *c, char *name, char *binding) } /* We now have the correct binding, remove duplicates. */ - conf_mouseunbind(c, current_binding); + conf_unbind_mouse(c, current_binding); if (strcmp("unmap", binding) == 0) { free(current_binding); @@ -604,7 +604,7 @@ conf_mousebind(struct conf *c, char *name, char *binding) } static void -conf_mouseunbind(struct conf *c, struct mousebinding *unbind) +conf_unbind_mouse(struct conf *c, struct mousebinding *unbind) { struct mousebinding *mb = NULL, *mbnxt; diff --git a/parse.y b/parse.y index e40177f..58afd25 100644 --- a/parse.y +++ b/parse.y @@ -155,7 +155,7 @@ main : FONTNAME STRING { free($2); } | BIND STRING string { - conf_bindname(conf, $2, $3); + conf_bind_kbd(conf, $2, $3); free($2); free($3); } @@ -171,7 +171,7 @@ main : FONTNAME STRING { conf->gap.right = $5; } | MOUSEBIND STRING string { - if (!conf_mousebind(conf, $2, $3)) { + if (!conf_bind_mouse(conf, $2, $3)) { yyerror("invalid mousebind: %s %s", $2, $3); free($2); free($3); From 1f244fe29c7234b05614f4040208f60052a8d377 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 8 Jul 2013 18:19:22 +0000 Subject: [PATCH 05/15] move kbfunc and mousefunc closer together --- calmwm.h | 19 +++++++------- conf.c | 71 ++++++++++++++++++++++++++++------------------------- kbfunc.c | 2 +- mousefunc.c | 12 ++++----- xevents.c | 4 +-- 5 files changed, 56 insertions(+), 52 deletions(-) diff --git a/calmwm.h b/calmwm.h index 0f74a87..aa21c35 100644 --- a/calmwm.h +++ b/calmwm.h @@ -258,7 +258,7 @@ struct mousebinding { u_int button; #define MOUSEBIND_CTX_ROOT 0x0001 #define MOUSEBIND_CTX_WIN 0x0002 - int context; + int flags; }; TAILQ_HEAD(mousebinding_q, mousebinding); @@ -403,6 +403,8 @@ void kbfunc_client_label(struct client_ctx *, union arg *); void kbfunc_client_lower(struct client_ctx *, union arg *); void kbfunc_client_maximize(struct client_ctx *, union arg *); +void kbfunc_client_moveresize(struct client_ctx *, + union arg *); void kbfunc_client_movetogroup(struct client_ctx *, union arg *); void kbfunc_client_nogroup(struct client_ctx *, @@ -416,23 +418,22 @@ void kbfunc_cmdexec(struct client_ctx *, union arg *); void kbfunc_exec(struct client_ctx *, union arg *); void kbfunc_lock(struct client_ctx *, union arg *); void kbfunc_menu_search(struct client_ctx *, union arg *); -void kbfunc_moveresize(struct client_ctx *, union arg *); void kbfunc_quit_wm(struct client_ctx *, union arg *); void kbfunc_restart(struct client_ctx *, union arg *); void kbfunc_ssh(struct client_ctx *, union arg *); void kbfunc_term(struct client_ctx *, union arg *); void kbfunc_tile(struct client_ctx *, union arg *); +void mousefunc_client_grouptoggle(struct client_ctx *, + void *); +void mousefunc_client_hide(struct client_ctx *, void *); +void mousefunc_client_lower(struct client_ctx *, void *); +void mousefunc_client_move(struct client_ctx *, void *); +void mousefunc_client_raise(struct client_ctx *, void *); +void mousefunc_client_resize(struct client_ctx *, void *); void mousefunc_menu_cmd(struct client_ctx *, void *); void mousefunc_menu_group(struct client_ctx *, void *); void mousefunc_menu_unhide(struct client_ctx *, void *); -void mousefunc_window_grouptoggle(struct client_ctx *, - void *); -void mousefunc_window_hide(struct client_ctx *, void *); -void mousefunc_window_lower(struct client_ctx *, void *); -void mousefunc_window_move(struct client_ctx *, void *); -void mousefunc_window_raise(struct client_ctx *, void *); -void mousefunc_window_resize(struct client_ctx *, void *); struct menu *menu_filter(struct screen_ctx *, struct menu_q *, char *, char *, int, diff --git a/conf.c b/conf.c index 82e6fa8..5f3d1cb 100644 --- a/conf.c +++ b/conf.c @@ -32,8 +32,8 @@ #include "calmwm.h" static const char *conf_bind_getmask(const char *, u_int *); -static void conf_unbind_mouse(struct conf *, struct mousebinding *); static void conf_unbind_kbd(struct conf *, struct keybinding *); +static void conf_unbind_mouse(struct conf *, struct mousebinding *); /* Add an command menu entry to the end of the menu */ void @@ -382,50 +382,53 @@ static struct { { "ssh", kbfunc_ssh, 0, {0} }, { "terminal", kbfunc_term, 0, {0} }, { "lock", kbfunc_lock, 0, {0} }, - { "moveup", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "moveup", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_UP|CWM_MOVE)} }, - { "movedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "movedown", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_DOWN|CWM_MOVE)} }, - { "moveright", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "moveright", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_RIGHT|CWM_MOVE)} }, - { "moveleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "moveleft", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_LEFT|CWM_MOVE)} }, - { "bigmoveup", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "bigmoveup", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_UP|CWM_MOVE|CWM_BIGMOVE)} }, - { "bigmovedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "bigmovedown", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_DOWN|CWM_MOVE|CWM_BIGMOVE)} }, - { "bigmoveright", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "bigmoveright", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_RIGHT|CWM_MOVE|CWM_BIGMOVE)} }, - { "bigmoveleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "bigmoveleft", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_LEFT|CWM_MOVE|CWM_BIGMOVE)} }, - { "resizeup", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "resizeup", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_UP|CWM_RESIZE)} }, - { "resizedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "resizedown", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_DOWN|CWM_RESIZE)} }, - { "resizeright", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "resizeright", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_RIGHT|CWM_RESIZE)} }, - { "resizeleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "resizeleft", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_LEFT|CWM_RESIZE)} }, - { "bigresizeup", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "bigresizeup", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_UP|CWM_RESIZE|CWM_BIGMOVE)} }, - { "bigresizedown", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "bigresizedown", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_DOWN|CWM_RESIZE|CWM_BIGMOVE)} }, - { "bigresizeright", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "bigresizeright", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_RIGHT|CWM_RESIZE|CWM_BIGMOVE)} }, - { "bigresizeleft", kbfunc_moveresize, KBFLAG_NEEDCLIENT, + { "bigresizeleft", kbfunc_client_moveresize, KBFLAG_NEEDCLIENT, {.i = (CWM_LEFT|CWM_RESIZE|CWM_BIGMOVE)} }, - { "ptrmoveup", kbfunc_moveresize, 0, {.i = (CWM_UP|CWM_PTRMOVE)} }, - { "ptrmovedown", kbfunc_moveresize, 0, {.i = (CWM_DOWN|CWM_PTRMOVE)} }, - { "ptrmoveleft", kbfunc_moveresize, 0, {.i = (CWM_LEFT|CWM_PTRMOVE)} }, - { "ptrmoveright", kbfunc_moveresize, 0, + { "ptrmoveup", kbfunc_client_moveresize, 0, + {.i = (CWM_UP|CWM_PTRMOVE)} }, + { "ptrmovedown", kbfunc_client_moveresize, 0, + {.i = (CWM_DOWN|CWM_PTRMOVE)} }, + { "ptrmoveleft", kbfunc_client_moveresize, 0, + {.i = (CWM_LEFT|CWM_PTRMOVE)} }, + { "ptrmoveright", kbfunc_client_moveresize, 0, {.i = (CWM_RIGHT|CWM_PTRMOVE)} }, - { "bigptrmoveup", kbfunc_moveresize, 0, + { "bigptrmoveup", kbfunc_client_moveresize, 0, {.i = (CWM_UP|CWM_PTRMOVE|CWM_BIGMOVE)} }, - { "bigptrmovedown", kbfunc_moveresize, 0, + { "bigptrmovedown", kbfunc_client_moveresize, 0, {.i = (CWM_DOWN|CWM_PTRMOVE|CWM_BIGMOVE)} }, - { "bigptrmoveleft", kbfunc_moveresize, 0, + { "bigptrmoveleft", kbfunc_client_moveresize, 0, {.i = (CWM_LEFT|CWM_PTRMOVE|CWM_BIGMOVE)} }, - { "bigptrmoveright", kbfunc_moveresize, 0, + { "bigptrmoveright", kbfunc_client_moveresize, 0, {.i = (CWM_RIGHT|CWM_PTRMOVE|CWM_BIGMOVE)} }, { "htile", kbfunc_tile, KBFLAG_NEEDCLIENT, {.i = CWM_TILE_HORIZ } }, @@ -538,15 +541,15 @@ conf_unbind_kbd(struct conf *c, struct keybinding *unbind) static struct { char *tag; void (*handler)(struct client_ctx *, void *); - int context; + int flags; } name_to_mousefunc[] = { - { "window_move", mousefunc_window_move, MOUSEBIND_CTX_WIN }, - { "window_resize", mousefunc_window_resize, MOUSEBIND_CTX_WIN }, - { "window_grouptoggle", mousefunc_window_grouptoggle, + { "window_move", mousefunc_client_move, MOUSEBIND_CTX_WIN }, + { "window_resize", mousefunc_client_resize, MOUSEBIND_CTX_WIN }, + { "window_grouptoggle", mousefunc_client_grouptoggle, MOUSEBIND_CTX_WIN }, - { "window_lower", mousefunc_window_lower, MOUSEBIND_CTX_WIN }, - { "window_raise", mousefunc_window_raise, MOUSEBIND_CTX_WIN }, - { "window_hide", mousefunc_window_hide, MOUSEBIND_CTX_WIN }, + { "window_lower", mousefunc_client_lower, MOUSEBIND_CTX_WIN }, + { "window_raise", mousefunc_client_raise, MOUSEBIND_CTX_WIN }, + { "window_hide", mousefunc_client_hide, MOUSEBIND_CTX_WIN }, { "menu_group", mousefunc_menu_group, MOUSEBIND_CTX_ROOT }, { "menu_unhide", mousefunc_menu_unhide, MOUSEBIND_CTX_ROOT }, { "menu_cmd", mousefunc_menu_cmd, MOUSEBIND_CTX_ROOT }, @@ -594,8 +597,8 @@ conf_bind_mouse(struct conf *c, char *name, char *binding) if (strcmp(name_to_mousefunc[i].tag, binding) != 0) continue; - current_binding->context = name_to_mousefunc[i].context; current_binding->callback = name_to_mousefunc[i].handler; + current_binding->flags = name_to_mousefunc[i].flags; TAILQ_INSERT_TAIL(&c->mousebindingq, current_binding, entry); return (1); } @@ -642,7 +645,7 @@ conf_grab_mouse(Window win) struct mousebinding *mb; TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) { - if (mb->context != MOUSEBIND_CTX_WIN) + if (mb->flags != MOUSEBIND_CTX_WIN) continue; xu_btn_grab(win, mb->modmask, mb->button); } diff --git a/kbfunc.c b/kbfunc.c index 79cb49b..906ca12 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -53,7 +53,7 @@ kbfunc_client_raise(struct client_ctx *cc, union arg *arg) #define TYPEMASK (CWM_MOVE | CWM_RESIZE | CWM_PTRMOVE) #define MOVEMASK (CWM_UP | CWM_DOWN | CWM_LEFT | CWM_RIGHT) void -kbfunc_moveresize(struct client_ctx *cc, union arg *arg) +kbfunc_client_moveresize(struct client_ctx *cc, union arg *arg) { struct screen_ctx *sc = cc->sc; int x, y, flags, amt; diff --git a/mousefunc.c b/mousefunc.c index 90c7078..109b655 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -68,7 +68,7 @@ mousefunc_sweep_draw(struct client_ctx *cc) } void -mousefunc_window_resize(struct client_ctx *cc, void *arg) +mousefunc_client_resize(struct client_ctx *cc, void *arg) { XEvent ev; Time ltime = 0; @@ -125,7 +125,7 @@ mousefunc_window_resize(struct client_ctx *cc, void *arg) } void -mousefunc_window_move(struct client_ctx *cc, void *arg) +mousefunc_client_move(struct client_ctx *cc, void *arg) { XEvent ev; Time ltime = 0; @@ -177,26 +177,26 @@ mousefunc_window_move(struct client_ctx *cc, void *arg) } void -mousefunc_window_grouptoggle(struct client_ctx *cc, void *arg) +mousefunc_client_grouptoggle(struct client_ctx *cc, void *arg) { group_sticky_toggle_enter(cc); } void -mousefunc_window_lower(struct client_ctx *cc, void *arg) +mousefunc_client_lower(struct client_ctx *cc, void *arg) { client_ptrsave(cc); client_lower(cc); } void -mousefunc_window_raise(struct client_ctx *cc, void *arg) +mousefunc_client_raise(struct client_ctx *cc, void *arg) { client_raise(cc); } void -mousefunc_window_hide(struct client_ctx *cc, void *arg) +mousefunc_client_hide(struct client_ctx *cc, void *arg) { client_hide(cc); } diff --git a/xevents.c b/xevents.c index ddbd8b6..4d31e65 100644 --- a/xevents.c +++ b/xevents.c @@ -253,12 +253,12 @@ xev_handle_buttonpress(XEvent *ee) if (mb == NULL) return; - if (mb->context == MOUSEBIND_CTX_ROOT) { + if (mb->flags == MOUSEBIND_CTX_ROOT) { if (e->window != sc->rootwin) return; cc = &fakecc; cc->sc = screen_fromroot(e->window); - } else if (cc == NULL) /* (mb->context == MOUSEBIND_CTX_WIN */ + } else if (cc == NULL) /* (mb->flags == MOUSEBIND_CTX_WIN */ return; (*mb->callback)(cc, e); From 9bf2498d7e388a7c0a05e3850b5235c5bb381d47 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 8 Jul 2013 18:39:20 +0000 Subject: [PATCH 06/15] add support for mouse based group {,r}cycle; from Rodrigo Mosconi. not bound by default. --- calmwm.h | 4 ++++ conf.c | 2 ++ cwmrc.5 | 6 +++++- mousefunc.c | 12 ++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/calmwm.h b/calmwm.h index aa21c35..9a5517d 100644 --- a/calmwm.h +++ b/calmwm.h @@ -424,12 +424,16 @@ void kbfunc_ssh(struct client_ctx *, union arg *); void kbfunc_term(struct client_ctx *, union arg *); void kbfunc_tile(struct client_ctx *, union arg *); +void mousefunc_client_cyclegroup(struct client_ctx *, + void *); void mousefunc_client_grouptoggle(struct client_ctx *, void *); void mousefunc_client_hide(struct client_ctx *, void *); void mousefunc_client_lower(struct client_ctx *, void *); void mousefunc_client_move(struct client_ctx *, void *); void mousefunc_client_raise(struct client_ctx *, void *); +void mousefunc_client_rcyclegroup(struct client_ctx *, + void *); void mousefunc_client_resize(struct client_ctx *, void *); void mousefunc_menu_cmd(struct client_ctx *, void *); void mousefunc_menu_group(struct client_ctx *, void *); diff --git a/conf.c b/conf.c index 5f3d1cb..576f623 100644 --- a/conf.c +++ b/conf.c @@ -550,6 +550,8 @@ static struct { { "window_lower", mousefunc_client_lower, MOUSEBIND_CTX_WIN }, { "window_raise", mousefunc_client_raise, MOUSEBIND_CTX_WIN }, { "window_hide", mousefunc_client_hide, MOUSEBIND_CTX_WIN }, + { "cyclegroup", mousefunc_client_cyclegroup, MOUSEBIND_CTX_ROOT }, + { "rcyclegroup", mousefunc_client_rcyclegroup, MOUSEBIND_CTX_ROOT }, { "menu_group", mousefunc_menu_group, MOUSEBIND_CTX_ROOT }, { "menu_unhide", mousefunc_menu_unhide, MOUSEBIND_CTX_ROOT }, { "menu_cmd", mousefunc_menu_cmd, MOUSEBIND_CTX_ROOT }, diff --git a/cwmrc.5 b/cwmrc.5 index 68803ad..9f75dbd 100644 --- a/cwmrc.5 +++ b/cwmrc.5 @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 8 2013 $ +.Dd $Mdocdate: June 17 2013 $ .Dt CWMRC 5 .Os .Sh NAME @@ -463,6 +463,10 @@ Raise current window. Hide current window. .It window_grouptoggle Toggle group membership of current window. +.It cyclegroup +Forward cycle through groups. +.It rcyclegroup +Reverse cycle through groups. .It menu_group Launch group list. .It menu_unhide diff --git a/mousefunc.c b/mousefunc.c index 109b655..40fae3f 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -201,6 +201,18 @@ mousefunc_client_hide(struct client_ctx *cc, void *arg) client_hide(cc); } +void +mousefunc_client_cyclegroup(struct client_ctx *cc, void *arg) +{ + group_cycle(cc->sc, CWM_CYCLE); +} + +void +mousefunc_client_rcyclegroup(struct client_ctx *cc, void *arg) +{ + group_cycle(cc->sc, CWM_RCYCLE); +} + void mousefunc_menu_group(struct client_ctx *cc, void *arg) { From dd10412804923a5e1b2aab46ab94c4f8e29696fb Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 9 Jul 2013 01:24:49 +0000 Subject: [PATCH 07/15] since the root and event window are the same in the case of a button event on the screen's root window, there's no need to pass down the entire XButtonEvent event, at least to group_menu(), the only callback which takes an argument at this point; instead use the already populated screen. --- calmwm.h | 2 +- group.c | 5 +---- mousefunc.c | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/calmwm.h b/calmwm.h index 9a5517d..820cf32 100644 --- a/calmwm.h +++ b/calmwm.h @@ -360,7 +360,7 @@ void group_autogroup(struct client_ctx *); void group_cycle(struct screen_ctx *, int); void group_hidetoggle(struct screen_ctx *, int); void group_init(struct screen_ctx *); -void group_menu(XButtonEvent *); +void group_menu(struct screen_ctx *); void group_movetogroup(struct client_ctx *, int); void group_only(struct screen_ctx *, int); void group_sticky(struct client_ctx *); diff --git a/group.c b/group.c index a25972a..020faf6 100644 --- a/group.c +++ b/group.c @@ -309,16 +309,13 @@ group_cycle(struct screen_ctx *sc, int flags) } void -group_menu(XButtonEvent *e) +group_menu(struct screen_ctx *sc) { - struct screen_ctx *sc; struct group_ctx *gc; struct menu *mi; struct menu_q menuq; int i; - sc = screen_fromroot(e->root); - TAILQ_INIT(&menuq); for (i = 0; i < CALMWM_NGROUPS; i++) { diff --git a/mousefunc.c b/mousefunc.c index 40fae3f..faf9b65 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -216,7 +216,7 @@ mousefunc_client_rcyclegroup(struct client_ctx *cc, void *arg) void mousefunc_menu_group(struct client_ctx *cc, void *arg) { - group_menu(arg); + group_menu(cc->sc); } void From 95710383580ecf66a58f27ecaa62dfe6c714c682 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 10 Jul 2013 14:11:42 +0000 Subject: [PATCH 08/15] type fixes --- conf.c | 4 ++-- xutil.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/conf.c b/conf.c index 576f623..89dc18c 100644 --- a/conf.c +++ b/conf.c @@ -99,8 +99,8 @@ static char *color_binds[] = { void conf_screen(struct screen_ctx *sc) { - int i; - XftColor xc; + u_int i; + XftColor xc; sc->gap = Conf.gap; diff --git a/xutil.c b/xutil.c index f7f2000..f755a98 100644 --- a/xutil.c +++ b/xutil.c @@ -393,7 +393,7 @@ void xu_ewmh_handle_net_wm_state_msg(struct client_ctx *cc, int action, Atom first, Atom second) { - int i; + u_int i; static struct handlers { int atom; int property; From bd7b8163bb0be2bd4904a179771a8f79163e8161 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 10 Jul 2013 14:15:58 +0000 Subject: [PATCH 09/15] bring buttonpress and keypress event handlers slightly closer together --- xevents.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/xevents.c b/xevents.c index 4d31e65..16bd10e 100644 --- a/xevents.c +++ b/xevents.c @@ -238,12 +238,8 @@ xev_handle_buttonpress(XEvent *ee) { XButtonEvent *e = &ee->xbutton; struct client_ctx *cc, fakecc; - struct screen_ctx *sc; struct mousebinding *mb; - sc = screen_fromroot(e->root); - cc = client_find(e->window); - e->state &= ~IGNOREMODMASK; TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) { @@ -253,13 +249,16 @@ xev_handle_buttonpress(XEvent *ee) if (mb == NULL) return; - if (mb->flags == MOUSEBIND_CTX_ROOT) { - if (e->window != sc->rootwin) + if (mb->flags == MOUSEBIND_CTX_WIN) { + if (((cc = client_find(e->window)) == NULL) && + (cc = client_current()) == NULL) + return; + } else { /* (mb->flags == MOUSEBIND_CTX_ROOT) */ + if (e->window != e->root) return; cc = &fakecc; cc->sc = screen_fromroot(e->window); - } else if (cc == NULL) /* (mb->flags == MOUSEBIND_CTX_WIN */ - return; + } (*mb->callback)(cc, e); } From 4119b5c065ee32189f26a0a95d4c36539003b142 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 15 Jul 2013 14:50:44 +0000 Subject: [PATCH 10/15] simplify atom handling; allows us to limit to one round-trip to server for gathering Atoms. --- calmwm.c | 4 ++- calmwm.h | 10 ++---- client.c | 12 +++---- conf.c | 37 ++++++++++++++++++++ group.c | 6 ++-- xevents.c | 10 +++--- xutil.c | 103 ++++++++++++++++-------------------------------------- 7 files changed, 88 insertions(+), 94 deletions(-) diff --git a/calmwm.c b/calmwm.c index 4a5f43d..f2a8a3d 100644 --- a/calmwm.c +++ b/calmwm.c @@ -37,6 +37,8 @@ char **cwm_argv; Display *X_Dpy; +Atom cwmh[CWMH_NITEMS]; +Atom ewmh[EWMH_NITEMS]; struct screen_ctx_q Screenq = TAILQ_HEAD_INITIALIZER(Screenq); struct client_ctx_q Clientq = TAILQ_HEAD_INITIALIZER(Clientq); @@ -129,7 +131,7 @@ x_init(const char *dpyname) HasRandr = XRRQueryExtension(X_Dpy, &Randr_ev, &i); - xu_getatoms(); + conf_atoms(); conf_cursor(&Conf); diff --git a/calmwm.h b/calmwm.h index 820cf32..3644d25 100644 --- a/calmwm.h +++ b/calmwm.h @@ -447,6 +447,7 @@ void menuq_clear(struct menu_q *); int parse_config(const char *, struct conf *); +void conf_atoms(void); void conf_autogroup(struct conf *, int, char *); void conf_bind_kbd(struct conf *, char *, char *); int conf_bind_mouse(struct conf *, char *, char *); @@ -464,7 +465,6 @@ void xev_loop(void); void xu_btn_grab(Window, int, u_int); void xu_btn_ungrab(Window, int, u_int); -void xu_getatoms(void); int xu_getprop(Window, Atom, Atom, long, u_char **); int xu_get_wm_state(Window, int *); int xu_getstrprop(Window, Atom, char **); @@ -558,11 +558,7 @@ enum { _NET_WM_STATE_ADD, _NET_WM_STATE_TOGGLE }; -struct atom_ctx { - char *name; - Atom atom; -}; -extern struct atom_ctx cwmh[CWMH_NITEMS]; -extern struct atom_ctx ewmh[EWMH_NITEMS]; +extern Atom cwmh[CWMH_NITEMS]; +extern Atom ewmh[EWMH_NITEMS]; #endif /* _CALMWM_H_ */ diff --git a/client.c b/client.c index c8e3221..b92132a 100644 --- a/client.c +++ b/client.c @@ -529,9 +529,9 @@ client_wm_protocols(struct client_ctx *cc) if (XGetWMProtocols(X_Dpy, cc->win, &p, &j)) { for (i = 0; i < j; i++) { - if (p[i] == cwmh[WM_DELETE_WINDOW].atom) + if (p[i] == cwmh[WM_DELETE_WINDOW]) cc->xproto |= _WM_DELETE_WINDOW; - else if (p[i] == cwmh[WM_TAKE_FOCUS].atom) + else if (p[i] == cwmh[WM_TAKE_FOCUS]) cc->xproto |= _WM_TAKE_FOCUS; } XFree(p); @@ -546,7 +546,7 @@ client_msg(struct client_ctx *cc, Atom proto) bzero(&cm, sizeof(cm)); cm.type = ClientMessage; cm.window = cc->win; - cm.message_type = cwmh[WM_PROTOCOLS].atom; + cm.message_type = cwmh[WM_PROTOCOLS]; cm.format = 32; cm.data.l[0] = proto; cm.data.l[1] = CurrentTime; @@ -558,7 +558,7 @@ void client_send_delete(struct client_ctx *cc) { if (cc->xproto & _WM_DELETE_WINDOW) - client_msg(cc, cwmh[WM_DELETE_WINDOW].atom); + client_msg(cc, cwmh[WM_DELETE_WINDOW]); else XKillClient(X_Dpy, cc->win); } @@ -569,7 +569,7 @@ client_setname(struct client_ctx *cc) struct winname *wn; char *newname; - if (!xu_getstrprop(cc->win, ewmh[_NET_WM_NAME].atom, &newname)) + if (!xu_getstrprop(cc->win, ewmh[_NET_WM_NAME], &newname)) if (!xu_getstrprop(cc->win, XA_WM_NAME, &newname)) newname = xstrdup(""); @@ -841,7 +841,7 @@ client_getmwmhints(struct client_ctx *cc) struct mwm_hints *mwmh; if (xu_getprop(cc->win, - cwmh[_MOTIF_WM_HINTS].atom, cwmh[_MOTIF_WM_HINTS].atom, + cwmh[_MOTIF_WM_HINTS], cwmh[_MOTIF_WM_HINTS], PROP_MWM_HINTS_ELEMENTS, (u_char **)&mwmh) == MWM_NUMHINTS) if (mwmh->flags & MWM_HINTS_DECORATIONS && !(mwmh->decorations & MWM_DECOR_ALL) && diff --git a/conf.c b/conf.c index 89dc18c..504c867 100644 --- a/conf.c +++ b/conf.c @@ -663,3 +663,40 @@ conf_grab_kbd(Window win) TAILQ_FOREACH(kb, &Conf.keybindingq, entry) xu_key_grab(win, kb->modmask, kb->keysym); } + +static char *cwmhints[] = { + "WM_STATE", + "WM_DELETE_WINDOW", + "WM_TAKE_FOCUS", + "WM_PROTOCOLS", + "_MOTIF_WM_HINTS", + "UTF8_STRING", + "WM_CHANGE_STATE", +}; +static char *ewmhints[] = { + "_NET_SUPPORTED", + "_NET_SUPPORTING_WM_CHECK", + "_NET_ACTIVE_WINDOW", + "_NET_CLIENT_LIST", + "_NET_NUMBER_OF_DESKTOPS", + "_NET_CURRENT_DESKTOP", + "_NET_DESKTOP_VIEWPORT", + "_NET_DESKTOP_GEOMETRY", + "_NET_VIRTUAL_ROOTS", + "_NET_SHOWING_DESKTOP", + "_NET_DESKTOP_NAMES", + "_NET_WORKAREA", + "_NET_WM_NAME", + "_NET_WM_DESKTOP", + "_NET_CLOSE_WINDOW", + "_NET_WM_STATE", + "_NET_WM_STATE_MAXIMIZED_VERT", + "_NET_WM_STATE_MAXIMIZED_HORZ", +}; + +void +conf_atoms(void) +{ + XInternAtoms(X_Dpy, cwmhints, nitems(cwmhints), False, cwmh); + XInternAtoms(X_Dpy, ewmhints, nitems(ewmhints), False, ewmh); +} diff --git a/group.c b/group.c index 020faf6..e025be6 100644 --- a/group.c +++ b/group.c @@ -374,7 +374,7 @@ group_autogroup(struct client_ctx *cc) if (cc->app_class == NULL || cc->app_name == NULL) return; - if (xu_getprop(cc->win, ewmh[_NET_WM_DESKTOP].atom, + if (xu_getprop(cc->win, ewmh[_NET_WM_DESKTOP], XA_CARDINAL, 1, (unsigned char **)&grpno) > 0) { if (*grpno == 0xffffffff) no = 0; @@ -418,8 +418,8 @@ group_update_names(struct screen_ctx *sc) unsigned char *prop_ret; int i = 0, j = 0, nstrings = 0, n = 0, setnames = 0; - if ((j = xu_getprop(sc->rootwin, ewmh[_NET_DESKTOP_NAMES].atom, - cwmh[UTF8_STRING].atom, 0xffffff, (u_char **)&prop_ret)) > 0) { + if ((j = xu_getprop(sc->rootwin, ewmh[_NET_DESKTOP_NAMES], + cwmh[UTF8_STRING], 0xffffff, (u_char **)&prop_ret)) > 0) { prop_ret[j - 1] = '\0'; /* paranoia */ while (i < j) { if (prop_ret[i++] == '\0') diff --git a/xevents.c b/xevents.c index 16bd10e..2d9f8dd 100644 --- a/xevents.c +++ b/xevents.c @@ -209,7 +209,7 @@ xev_handle_propertynotify(XEvent *ee) } else { TAILQ_FOREACH(sc, &Screenq, entry) { if (sc->rootwin == e->window) { - if (e->atom == ewmh[_NET_DESKTOP_NAMES].atom) + if (e->atom == ewmh[_NET_DESKTOP_NAMES]) group_update_names(sc); } } @@ -348,21 +348,21 @@ xev_handle_clientmessage(XEvent *ee) if ((cc = client_find(e->window)) == NULL) return; - if (e->message_type == cwmh[WM_CHANGE_STATE].atom && + if (e->message_type == cwmh[WM_CHANGE_STATE] && e->format == 32 && e->data.l[0] == IconicState) client_hide(cc); - if (e->message_type == ewmh[_NET_CLOSE_WINDOW].atom) + if (e->message_type == ewmh[_NET_CLOSE_WINDOW]) client_send_delete(cc); - if (e->message_type == ewmh[_NET_ACTIVE_WINDOW].atom && + if (e->message_type == ewmh[_NET_ACTIVE_WINDOW] && e->format == 32) { old_cc = client_current(); if (old_cc) client_ptrsave(old_cc); client_ptrwarp(cc); } - if (e->message_type == ewmh[_NET_WM_STATE].atom && + if (e->message_type == ewmh[_NET_WM_STATE] && e->format == 32) xu_ewmh_handle_net_wm_state_msg(cc, e->data.l[0], e->data.l[1], e->data.l[2]); diff --git a/xutil.c b/xutil.c index f755a98..932835d 100644 --- a/xutil.c +++ b/xutil.c @@ -159,7 +159,7 @@ xu_get_wm_state(Window win, int *state) { long *p = NULL; - if (xu_getprop(win, cwmh[WM_STATE].atom, cwmh[WM_STATE].atom, 2L, + if (xu_getprop(win, cwmh[WM_STATE], cwmh[WM_STATE], 2L, (u_char **)&p) <= 0) return (-1); @@ -178,51 +178,10 @@ xu_set_wm_state(Window win, int state) dat[1] = None; XChangeProperty(X_Dpy, win, - cwmh[WM_STATE].atom, cwmh[WM_STATE].atom, 32, + cwmh[WM_STATE], cwmh[WM_STATE], 32, PropModeReplace, (unsigned char *)dat, 2); } -struct atom_ctx cwmh[CWMH_NITEMS] = { - {"WM_STATE", None}, - {"WM_DELETE_WINDOW", None}, - {"WM_TAKE_FOCUS", None}, - {"WM_PROTOCOLS", None}, - {"_MOTIF_WM_HINTS", None}, - {"UTF8_STRING", None}, - {"WM_CHANGE_STATE", None}, -}; -struct atom_ctx ewmh[EWMH_NITEMS] = { - {"_NET_SUPPORTED", None}, - {"_NET_SUPPORTING_WM_CHECK", None}, - {"_NET_ACTIVE_WINDOW", None}, - {"_NET_CLIENT_LIST", None}, - {"_NET_NUMBER_OF_DESKTOPS", None}, - {"_NET_CURRENT_DESKTOP", None}, - {"_NET_DESKTOP_VIEWPORT", None}, - {"_NET_DESKTOP_GEOMETRY", None}, - {"_NET_VIRTUAL_ROOTS", None}, - {"_NET_SHOWING_DESKTOP", None}, - {"_NET_DESKTOP_NAMES", None}, - {"_NET_WORKAREA", None}, - {"_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 -xu_getatoms(void) -{ - u_int i; - - for (i = 0; i < nitems(cwmh); i++) - cwmh[i].atom = XInternAtom(X_Dpy, cwmh[i].name, False); - for (i = 0; i < nitems(ewmh); i++) - ewmh[i].atom = XInternAtom(X_Dpy, ewmh[i].name, False); -} - /* Root Window Properties */ void xu_ewmh_net_supported(struct screen_ctx *sc) @@ -231,9 +190,9 @@ xu_ewmh_net_supported(struct screen_ctx *sc) u_int i; for (i = 0; i < nitems(ewmh); i++) - atom[i] = ewmh[i].atom; + atom[i] = ewmh[i]; - XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_SUPPORTED].atom, + XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_SUPPORTED], XA_ATOM, 32, PropModeReplace, (unsigned char *)atom, EWMH_NITEMS); } @@ -243,12 +202,12 @@ xu_ewmh_net_supported_wm_check(struct screen_ctx *sc) Window w; w = XCreateSimpleWindow(X_Dpy, sc->rootwin, -1, -1, 1, 1, 0, 0, 0); - XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_SUPPORTING_WM_CHECK].atom, + XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_SUPPORTING_WM_CHECK], XA_WINDOW, 32, PropModeReplace, (unsigned char *)&w, 1); - XChangeProperty(X_Dpy, w, ewmh[_NET_SUPPORTING_WM_CHECK].atom, + XChangeProperty(X_Dpy, w, ewmh[_NET_SUPPORTING_WM_CHECK], XA_WINDOW, 32, PropModeReplace, (unsigned char *)&w, 1); - XChangeProperty(X_Dpy, w, ewmh[_NET_WM_NAME].atom, - cwmh[UTF8_STRING].atom, 8, PropModeReplace, (unsigned char *)WMNAME, + XChangeProperty(X_Dpy, w, ewmh[_NET_WM_NAME], + cwmh[UTF8_STRING], 8, PropModeReplace, (unsigned char *)WMNAME, strlen(WMNAME)); } @@ -257,7 +216,7 @@ xu_ewmh_net_desktop_geometry(struct screen_ctx *sc) { long geom[2] = { sc->view.w, sc->view.h }; - XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_DESKTOP_GEOMETRY].atom, + XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_DESKTOP_GEOMETRY], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)geom , 2); } @@ -274,7 +233,7 @@ xu_ewmh_net_workarea(struct screen_ctx *sc) workareas[i][3] = sc->work.h; } - XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_WORKAREA].atom, + XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_WORKAREA], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)workareas, CALMWM_NGROUPS * 4); } @@ -294,7 +253,7 @@ xu_ewmh_net_client_list(struct screen_ctx *sc) winlist = xcalloc(i, sizeof(*winlist)); TAILQ_FOREACH(cc, &Clientq, entry) winlist[j++] = cc->win; - XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_CLIENT_LIST].atom, + XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_CLIENT_LIST], XA_WINDOW, 32, PropModeReplace, (unsigned char *)winlist, i); free(winlist); } @@ -302,7 +261,7 @@ xu_ewmh_net_client_list(struct screen_ctx *sc) void xu_ewmh_net_active_window(struct screen_ctx *sc, Window w) { - XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_ACTIVE_WINDOW].atom, + XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_ACTIVE_WINDOW], XA_WINDOW, 32, PropModeReplace, (unsigned char *)&w, 1); } @@ -312,7 +271,7 @@ xu_ewmh_net_wm_desktop_viewport(struct screen_ctx *sc) long viewports[2] = {0, 0}; /* We don't support large desktops, so this is (0, 0). */ - XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_DESKTOP_VIEWPORT].atom, + XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_DESKTOP_VIEWPORT], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)viewports, 2); } @@ -321,7 +280,7 @@ xu_ewmh_net_wm_number_of_desktops(struct screen_ctx *sc) { long ndesks = CALMWM_NGROUPS; - XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_NUMBER_OF_DESKTOPS].atom, + XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_NUMBER_OF_DESKTOPS], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&ndesks, 1); } @@ -334,7 +293,7 @@ xu_ewmh_net_showing_desktop(struct screen_ctx *sc) * Note that when we hide all groups, or when all groups are * hidden we could technically set this later on. */ - XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_SHOWING_DESKTOP].atom, + XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_SHOWING_DESKTOP], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&zero, 1); } @@ -342,21 +301,21 @@ void xu_ewmh_net_virtual_roots(struct screen_ctx *sc) { /* We don't support virtual roots, so delete if set by previous wm. */ - XDeleteProperty(X_Dpy, sc->rootwin, ewmh[_NET_VIRTUAL_ROOTS].atom); + XDeleteProperty(X_Dpy, sc->rootwin, ewmh[_NET_VIRTUAL_ROOTS]); } void xu_ewmh_net_current_desktop(struct screen_ctx *sc, long idx) { - XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_CURRENT_DESKTOP].atom, + XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_CURRENT_DESKTOP], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&idx, 1); } void xu_ewmh_net_desktop_names(struct screen_ctx *sc, char *data, int n) { - XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_DESKTOP_NAMES].atom, - cwmh[UTF8_STRING].atom, 8, PropModeReplace, (unsigned char *)data, n); + XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_DESKTOP_NAMES], + cwmh[UTF8_STRING], 8, PropModeReplace, (unsigned char *)data, n); } /* Application Window Properties */ @@ -369,7 +328,7 @@ xu_ewmh_net_wm_desktop(struct client_ctx *cc) if (gc) no = gc->shortcut; - XChangeProperty(X_Dpy, cc->win, ewmh[_NET_WM_DESKTOP].atom, + XChangeProperty(X_Dpy, cc->win, ewmh[_NET_WM_DESKTOP], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&no, 1); } @@ -378,7 +337,7 @@ 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, + if ((*n = xu_getprop(cc->win, ewmh[_NET_WM_STATE], XA_ATOM, 64L, (u_char **)&p)) <= 0) return (NULL); @@ -408,8 +367,8 @@ xu_ewmh_handle_net_wm_state_msg(struct client_ctx *cc, int action, }; for (i = 0; i < nitems(handlers); i++) { - if (first != ewmh[handlers[i].atom].atom && - second != ewmh[handlers[i].atom].atom) + if (first != ewmh[handlers[i].atom] && + second != ewmh[handlers[i].atom]) continue; switch (action) { case _NET_WM_STATE_ADD: @@ -434,9 +393,9 @@ xu_ewmh_restore_net_wm_state(struct client_ctx *cc) 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) + if (atoms[i] == ewmh[_NET_WM_STATE_MAXIMIZED_HORZ]) client_hmaximize(cc); - if (atoms[i] == ewmh[_NET_WM_STATE_MAXIMIZED_VERT].atom) + if (atoms[i] == ewmh[_NET_WM_STATE_MAXIMIZED_VERT]) client_vmaximize(cc); } free(atoms); @@ -451,20 +410,20 @@ xu_ewmh_set_net_wm_state(struct client_ctx *cc) oatoms = xu_ewmh_get_net_wm_state(cc, &n); atoms = xcalloc((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) + if (oatoms[i] != ewmh[_NET_WM_STATE_MAXIMIZED_HORZ] && + oatoms[i] != ewmh[_NET_WM_STATE_MAXIMIZED_VERT]) atoms[j++] = oatoms[i]; } free(oatoms); if (cc->flags & CLIENT_HMAXIMIZED) - atoms[j++] = ewmh[_NET_WM_STATE_MAXIMIZED_HORZ].atom; + atoms[j++] = ewmh[_NET_WM_STATE_MAXIMIZED_HORZ]; if (cc->flags & CLIENT_VMAXIMIZED) - atoms[j++] = ewmh[_NET_WM_STATE_MAXIMIZED_VERT].atom; + atoms[j++] = ewmh[_NET_WM_STATE_MAXIMIZED_VERT]; if (j > 0) - XChangeProperty(X_Dpy, cc->win, ewmh[_NET_WM_STATE].atom, + XChangeProperty(X_Dpy, cc->win, ewmh[_NET_WM_STATE], XA_ATOM, 32, PropModeReplace, (unsigned char *)atoms, j); else - XDeleteProperty(X_Dpy, cc->win, ewmh[_NET_WM_STATE].atom); + XDeleteProperty(X_Dpy, cc->win, ewmh[_NET_WM_STATE]); free(atoms); } From 4ef96a27726725e2a0919e4de59ee00114b0d0e2 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 15 Jul 2013 23:51:59 +0000 Subject: [PATCH 11/15] collapse lines --- client.c | 3 +-- xevents.c | 10 ++++------ xutil.c | 3 +-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/client.c b/client.c index b92132a..9a90588 100644 --- a/client.c +++ b/client.c @@ -840,8 +840,7 @@ client_getmwmhints(struct client_ctx *cc) { struct mwm_hints *mwmh; - if (xu_getprop(cc->win, - cwmh[_MOTIF_WM_HINTS], cwmh[_MOTIF_WM_HINTS], + if (xu_getprop(cc->win, cwmh[_MOTIF_WM_HINTS], cwmh[_MOTIF_WM_HINTS], PROP_MWM_HINTS_ELEMENTS, (u_char **)&mwmh) == MWM_NUMHINTS) if (mwmh->flags & MWM_HINTS_DECORATIONS && !(mwmh->decorations & MWM_DECOR_ALL) && diff --git a/xevents.c b/xevents.c index 2d9f8dd..4b6ad60 100644 --- a/xevents.c +++ b/xevents.c @@ -348,22 +348,20 @@ xev_handle_clientmessage(XEvent *ee) if ((cc = client_find(e->window)) == NULL) return; - if (e->message_type == cwmh[WM_CHANGE_STATE] && - e->format == 32 && e->data.l[0] == IconicState) + if (e->message_type == cwmh[WM_CHANGE_STATE] && e->format == 32 && + e->data.l[0] == IconicState) client_hide(cc); if (e->message_type == ewmh[_NET_CLOSE_WINDOW]) client_send_delete(cc); - if (e->message_type == ewmh[_NET_ACTIVE_WINDOW] && - e->format == 32) { + if (e->message_type == ewmh[_NET_ACTIVE_WINDOW] && e->format == 32) { old_cc = client_current(); if (old_cc) client_ptrsave(old_cc); client_ptrwarp(cc); } - if (e->message_type == ewmh[_NET_WM_STATE] && - e->format == 32) + if (e->message_type == ewmh[_NET_WM_STATE] && e->format == 32) xu_ewmh_handle_net_wm_state_msg(cc, e->data.l[0], e->data.l[1], e->data.l[2]); } diff --git a/xutil.c b/xutil.c index 932835d..1e408a9 100644 --- a/xutil.c +++ b/xutil.c @@ -177,8 +177,7 @@ xu_set_wm_state(Window win, int state) dat[0] = state; dat[1] = None; - XChangeProperty(X_Dpy, win, - cwmh[WM_STATE], cwmh[WM_STATE], 32, + XChangeProperty(X_Dpy, win, cwmh[WM_STATE], cwmh[WM_STATE], 32, PropModeReplace, (unsigned char *)dat, 2); } From ae4ab065599ec7b0656c513f8243036b19b5703a Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 15 Jul 2013 23:53:19 +0000 Subject: [PATCH 12/15] shuffle down protoypes --- calmwm.h | 97 +++++++++++++++++++++++++++----------------------------- 1 file changed, 47 insertions(+), 50 deletions(-) diff --git a/calmwm.h b/calmwm.h index 3644d25..bfb8653 100644 --- a/calmwm.h +++ b/calmwm.h @@ -318,6 +318,53 @@ struct mwm_hints { #define MWM_DECOR_ALL (1<<0) #define MWM_DECOR_BORDER (1<<1) +extern Display *X_Dpy; +extern struct screen_ctx_q Screenq; +extern struct client_ctx_q Clientq; +extern struct conf Conf; +extern char *homedir; +extern int HasRandr, Randr_ev; + +enum { + WM_STATE, + WM_DELETE_WINDOW, + WM_TAKE_FOCUS, + WM_PROTOCOLS, + _MOTIF_WM_HINTS, + UTF8_STRING, + WM_CHANGE_STATE, + CWMH_NITEMS +}; +enum { + _NET_SUPPORTED, + _NET_SUPPORTING_WM_CHECK, + _NET_ACTIVE_WINDOW, + _NET_CLIENT_LIST, + _NET_NUMBER_OF_DESKTOPS, + _NET_CURRENT_DESKTOP, + _NET_DESKTOP_VIEWPORT, + _NET_DESKTOP_GEOMETRY, + _NET_VIRTUAL_ROOTS, + _NET_SHOWING_DESKTOP, + _NET_DESKTOP_NAMES, + _NET_WORKAREA, + _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 +}; +enum { + _NET_WM_STATE_REMOVE, + _NET_WM_STATE_ADD, + _NET_WM_STATE_TOGGLE +}; +extern Atom cwmh[CWMH_NITEMS]; +extern Atom ewmh[EWMH_NITEMS]; + __dead void usage(void); void client_applysizehints(struct client_ctx *); @@ -511,54 +558,4 @@ int xasprintf(char **, const char *, ...) __attribute__((__format__ (printf, 2, 3))) __attribute__((__nonnull__ (2))); -/* Externs */ -extern Display *X_Dpy; - -extern struct screen_ctx_q Screenq; -extern struct client_ctx_q Clientq; -extern struct conf Conf; -extern char *homedir; - -extern int HasRandr, Randr_ev; - -enum { - WM_STATE, - WM_DELETE_WINDOW, - WM_TAKE_FOCUS, - WM_PROTOCOLS, - _MOTIF_WM_HINTS, - UTF8_STRING, - WM_CHANGE_STATE, - CWMH_NITEMS -}; -enum { - _NET_SUPPORTED, - _NET_SUPPORTING_WM_CHECK, - _NET_ACTIVE_WINDOW, - _NET_CLIENT_LIST, - _NET_NUMBER_OF_DESKTOPS, - _NET_CURRENT_DESKTOP, - _NET_DESKTOP_VIEWPORT, - _NET_DESKTOP_GEOMETRY, - _NET_VIRTUAL_ROOTS, - _NET_SHOWING_DESKTOP, - _NET_DESKTOP_NAMES, - _NET_WORKAREA, - _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 -}; -enum { - _NET_WM_STATE_REMOVE, - _NET_WM_STATE_ADD, - _NET_WM_STATE_TOGGLE -}; -extern Atom cwmh[CWMH_NITEMS]; -extern Atom ewmh[EWMH_NITEMS]; - #endif /* _CALMWM_H_ */ From ca416b6b82ace271f29e591081d4a9fe87614d06 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 16 Jul 2013 14:04:44 +0000 Subject: [PATCH 13/15] max -> nitems --- calmwm.h | 6 +++--- conf.c | 2 +- parse.y | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/calmwm.h b/calmwm.h index bfb8653..e80f5d0 100644 --- a/calmwm.h +++ b/calmwm.h @@ -103,7 +103,7 @@ enum color { CWM_COLOR_MENU_BG, CWM_COLOR_MENU_FONT, CWM_COLOR_MENU_FONT_SEL, - CWM_COLOR_MAX + CWM_COLOR_NITEMS }; struct geom { @@ -223,7 +223,7 @@ struct screen_ctx { struct geom work; /* workable area, gap-applied */ struct gap gap; struct cycle_entry_q mruq; - XftColor xftcolor[CWM_COLOR_MAX]; + XftColor xftcolor[CWM_COLOR_NITEMS]; XftDraw *xftdraw; XftFont *xftfont; int xinerama_no; @@ -297,7 +297,7 @@ struct conf { #define CONF_SNAPDIST 0 int snapdist; struct gap gap; - char *color[CWM_COLOR_MAX]; + char *color[CWM_COLOR_NITEMS]; char termpath[MAXPATHLEN]; char lockpath[MAXPATHLEN]; char known_hosts[MAXPATHLEN]; diff --git a/conf.c b/conf.c index 504c867..01cee6b 100644 --- a/conf.c +++ b/conf.c @@ -288,7 +288,7 @@ conf_clear(struct conf *c) free(mb); } - for (i = 0; i < CWM_COLOR_MAX; i++) + for (i = 0; i < CWM_COLOR_NITEMS; i++) free(c->color[i]); free(c->font); diff --git a/parse.y b/parse.y index 58afd25..e2a6885 100644 --- a/parse.y +++ b/parse.y @@ -597,7 +597,7 @@ parse_config(const char *filename, struct conf *xconf) (void)strlcpy(xconf->lockpath, conf->lockpath, sizeof(xconf->lockpath)); - for (i = 0; i < CWM_COLOR_MAX; i++) + for (i = 0; i < CWM_COLOR_NITEMS; i++) xconf->color[i] = conf->color[i]; xconf->font = conf->font; From fbb9d32d0a04bc1cc17636460f9a92a2595130e9 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 16 Jul 2013 14:22:25 +0000 Subject: [PATCH 14/15] don't need the size here --- conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf.c b/conf.c index 01cee6b..6fe65f6 100644 --- a/conf.c +++ b/conf.c @@ -624,7 +624,7 @@ conf_unbind_mouse(struct conf *c, struct mousebinding *unbind) } } -static int cursor_binds[CF_NITEMS] = { +static int cursor_binds[] = { XC_X_cursor, /* CF_DEFAULT */ XC_fleur, /* CF_MOVE */ XC_left_ptr, /* CF_NORMAL */ From a439012b5806997e60df870faad87a5fec20d4e8 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 16 Jul 2013 14:30:48 +0000 Subject: [PATCH 15/15] we no longer need to construct an array for _NET_SUPPORTED. --- xutil.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/xutil.c b/xutil.c index 1e408a9..7912cb8 100644 --- a/xutil.c +++ b/xutil.c @@ -185,14 +185,8 @@ xu_set_wm_state(Window win, int state) void xu_ewmh_net_supported(struct screen_ctx *sc) { - Atom atom[EWMH_NITEMS]; - u_int i; - - for (i = 0; i < nitems(ewmh); i++) - atom[i] = ewmh[i]; - XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_SUPPORTED], - XA_ATOM, 32, PropModeReplace, (unsigned char *)atom, EWMH_NITEMS); + XA_ATOM, 32, PropModeReplace, (unsigned char *)ewmh, EWMH_NITEMS); } void