From 7a7e5cd59254ab17f1f37affa868858160eca07a Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 8 Jul 2013 15:46:16 +0000 Subject: 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); -- cgit 1.4.1 From fe439f2b965b9ee6e9dc9a6d8e2ecb443f86e788 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 8 Jul 2013 15:48:16 +0000 Subject: 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) -- cgit 1.4.1 From 912ec90ea1f6e25b33a2bb0d6d7a1138622bd099 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 8 Jul 2013 16:10:55 +0000 Subject: 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) -- cgit 1.4.1 From a49373406607e71601ac062c0a75ad36219065e2 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 8 Jul 2013 16:32:51 +0000 Subject: 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); -- cgit 1.4.1 From 1f244fe29c7234b05614f4040208f60052a8d377 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 8 Jul 2013 18:19:22 +0000 Subject: 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); -- cgit 1.4.1 From 9bf2498d7e388a7c0a05e3850b5235c5bb381d47 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 8 Jul 2013 18:39:20 +0000 Subject: 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) { -- cgit 1.4.1 From dd10412804923a5e1b2aab46ab94c4f8e29696fb Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 9 Jul 2013 01:24:49 +0000 Subject: 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 -- cgit 1.4.1 From 95710383580ecf66a58f27ecaa62dfe6c714c682 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 10 Jul 2013 14:11:42 +0000 Subject: 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; -- cgit 1.4.1 From bd7b8163bb0be2bd4904a179771a8f79163e8161 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 10 Jul 2013 14:15:58 +0000 Subject: 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); } -- cgit 1.4.1