summary refs log tree commit diff
path: root/conf.c
diff options
context:
space:
mode:
authorokan <okan>2016-10-24 20:44:08 +0000
committerokan <okan>2016-10-24 20:44:08 +0000
commitdcb741d2b1378432e226bbeea274c2e5e2508c2d (patch)
treeb9a0fcb7200417e49167e78a687632b23cdbf812 /conf.c
parentfa06851b0ee5b49138f782e500e12646455dd171 (diff)
parentdb93599a0fb302271e10a9dcbcbe6cafdc8aa2cb (diff)
downloadcwm-dcb741d2b1378432e226bbeea274c2e5e2508c2d.tar.gz
cwm-dcb741d2b1378432e226bbeea274c2e5e2508c2d.tar.xz
cwm-dcb741d2b1378432e226bbeea274c2e5e2508c2d.zip
cvsimport
* refs/heads/master: (34 commits)
  Make it clear these are flags.
  Remove duplicate check that strsubmatch() already does; while here, fix a comment.
  Sprinkle __func__ in appropriate error messages.
  Get rid of 'matchname'; it's too surprising to have the menu change during client search as different potential str matches are cycled through. If there's interest, the only string that doesn't exist in the listing is the window's class - that can be added of course, but it makes the line too long imho.
  clean up search_match_client(); no behaviour change
  Refactor callbacks to take a void * so as to not try and generalize into client_ctx in keypress and buttonpress event handlers; pass appropriate *ctx's based on context.
  remove another unused proto
  Rename 2 kbfunc to match closer to what they do
  Add an argument to the callbacks to pass the xevent context, button or key press. This allows to remove a few hacks to duplicate functions only for behaviour changes; now differing behaviours are pushed down to the callback. Also will allow for previously unavailable actions to be bind-able down the road.
  Check the ptr bounds in the new client during cycling, since not all actions do ptrsave, such as restoring client geometry; adapted from a diff by Vadim Vygonets.
  More accurate to say 'toggle', rather than 'select', for group[n]/nogroup.
  Add CM-a for 'nogroup' (CM-0 stays for now); update manpage to reflect.
  Stash wmname into conf.
  When removing xrandr regions, ensure clients are within the bounds of the screen; adapted from an ancient diff from Sviatoslav Chagaev. Things in this area will likely change, but put this in so it works now and serves as a reminder.
  Calculate client nameqlen in client_setname(), the only place it's needed/used.
  Turn CALMWM_NGROUPS define into variable, ngroups.
  Start simplifying menu code; and in turn, remove a cursor no longer needed.
  Defaults are split between defines and conf_init(); normalize these, as well as give 'sticky' groups its own variable.
  For both kb and mouse move, it is possible to grab a client and move it completely off the screen/region; instead, if the pointer is outside of the client bounds, warp the pointer to the closest edge before moving.
  client_ptrwarp should not deal with unhiding or raising clients (non ptr requests); most callers do this already - deal with the few that do not. client_ptrwarp becomes a simple wrapper (setpos) but it will be expanded.
  ...
Diffstat (limited to 'conf.c')
-rw-r--r--conf.c365
1 files changed, 187 insertions, 178 deletions
diff --git a/conf.c b/conf.c
index 24f1902..cebfc07 100644
--- a/conf.c
+++ b/conf.c
@@ -34,13 +34,13 @@
 
 static const char	*conf_bind_getmask(const char *, unsigned int *);
 static void		 conf_cmd_remove(struct conf *, const char *);
-static void		 conf_unbind_kbd(struct conf *, struct binding *);
-static void		 conf_unbind_mouse(struct conf *, struct binding *);
+static void		 conf_unbind_kbd(struct conf *, struct bind_ctx *);
+static void		 conf_unbind_mouse(struct conf *, struct bind_ctx *);
 
 int
 conf_cmd_add(struct conf *c, const char *name, const char *path)
 {
-	struct cmd	*cmd;
+	struct cmd_ctx	*cmd;
 
 	cmd = xmalloc(sizeof(*cmd));
 
@@ -61,7 +61,7 @@ conf_cmd_add(struct conf *c, const char *name, const char *path)
 static void
 conf_cmd_remove(struct conf *c, const char *name)
 {
-	struct cmd	*cmd = NULL, *cmdnxt;
+	struct cmd_ctx	*cmd = NULL, *cmdnxt;
 
 	TAILQ_FOREACH_SAFE(cmd, &c->cmdq, entry, cmdnxt) {
 		if (strcmp(cmd->name, name) == 0) {
@@ -74,31 +74,31 @@ conf_cmd_remove(struct conf *c, const char *name)
 void
 conf_autogroup(struct conf *c, int num, const char *name, const char *class)
 {
-	struct autogroupwin	*aw;
+	struct autogroup	*ag;
 	char			*p;
 
-	aw = xmalloc(sizeof(*aw));
+	ag = xmalloc(sizeof(*ag));
 
 	if ((p = strchr(class, ',')) == NULL) {
 		if (name == NULL)
-			aw->name = NULL;
+			ag->name = NULL;
 		else
-			aw->name = xstrdup(name);
+			ag->name = xstrdup(name);
 
-		aw->class = xstrdup(class);
+		ag->class = xstrdup(class);
 	} else {
 		*(p++) = '\0';
 
 		if (name == NULL)
-			aw->name = xstrdup(class);
+			ag->name = xstrdup(class);
 		else
-			aw->name = xstrdup(name);
+			ag->name = xstrdup(name);
 
-		aw->class = xstrdup(p);
+		ag->class = xstrdup(p);
 	}
-	aw->num = num;
+	ag->num = num;
 
-	TAILQ_INSERT_TAIL(&c->autogroupq, aw, entry);
+	TAILQ_INSERT_TAIL(&c->autogroupq, ag, entry);
 }
 
 void
@@ -138,7 +138,7 @@ conf_screen(struct screen_ctx *sc)
 	if (sc->xftfont == NULL) {
 		sc->xftfont = XftFontOpenName(X_Dpy, sc->which, Conf.font);
 		if (sc->xftfont == NULL)
-			errx(1, "XftFontOpenName: %s", Conf.font);
+			errx(1, "%s: XftFontOpenName: %s", __func__, Conf.font);
 	}
 
 	for (i = 0; i < nitems(color_binds); i++) {
@@ -162,14 +162,14 @@ conf_screen(struct screen_ctx *sc)
 		}
 	}
 
-	sc->menuwin = XCreateSimpleWindow(X_Dpy, sc->rootwin, 0, 0, 1, 1,
+	sc->menu.win = 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, visual, colormap);
-	if (sc->xftdraw == NULL)
-		errx(1, "XftDrawCreate");
+	sc->menu.xftdraw = XftDrawCreate(X_Dpy, sc->menu.win, visual, colormap);
+	if (sc->menu.xftdraw == NULL)
+		errx(1, "%s: XftDrawCreate", __func__);
 
 	conf_grab_kbd(sc->rootwin);
 }
@@ -192,6 +192,7 @@ static const struct {
 	{ "MS-Tab",	"rcycle" },
 	{ "CM-n",	"label" },
 	{ "CM-x",	"delete" },
+	{ "CM-a",	"nogroup" },
 	{ "CM-0",	"nogroup" },
 	{ "CM-1",	"group1" },
 	{ "CM-2",	"group2" },
@@ -254,15 +255,18 @@ conf_init(struct conf *c)
 {
 	unsigned int	i;
 
-	c->bwidth = CONF_BWIDTH;
-	c->mamount = CONF_MAMOUNT;
-	c->snapdist = CONF_SNAPDIST;
+	c->stickygroups = 0;
+	c->bwidth = 1;
+	c->mamount = 1;
+	c->snapdist = 0;
+	c->ngroups = 10;
+	c->nameqlen = 5;
 
 	TAILQ_INIT(&c->ignoreq);
 	TAILQ_INIT(&c->cmdq);
-	TAILQ_INIT(&c->keybindingq);
+	TAILQ_INIT(&c->keybindq);
 	TAILQ_INIT(&c->autogroupq);
-	TAILQ_INIT(&c->mousebindingq);
+	TAILQ_INIT(&c->mousebindq);
 
 	for (i = 0; i < nitems(kbd_binds); i++)
 		conf_bind_kbd(c, kbd_binds[i].key, kbd_binds[i].func);
@@ -279,16 +283,17 @@ conf_init(struct conf *c)
 	(void)snprintf(c->known_hosts, sizeof(c->known_hosts), "%s/%s",
 	    homedir, ".ssh/known_hosts");
 
-	c->font = xstrdup(CONF_FONT);
+	c->font = xstrdup("sans-serif:pixelsize=14:bold");
+	c->wmname = xstrdup("CWM");
 }
 
 void
 conf_clear(struct conf *c)
 {
-	struct autogroupwin	*aw;
-	struct binding		*kb, *mb;
+	struct autogroup	*ag;
+	struct bind_ctx		*kb, *mb;
 	struct winname		*wn;
-	struct cmd		*cmd;
+	struct cmd_ctx		*cmd;
 	int			 i;
 
 	while ((cmd = TAILQ_FIRST(&c->cmdq)) != NULL) {
@@ -297,16 +302,16 @@ conf_clear(struct conf *c)
 		free(cmd);
 	}
 
-	while ((kb = TAILQ_FIRST(&c->keybindingq)) != NULL) {
-		TAILQ_REMOVE(&c->keybindingq, kb, entry);
+	while ((kb = TAILQ_FIRST(&c->keybindq)) != NULL) {
+		TAILQ_REMOVE(&c->keybindq, kb, entry);
 		free(kb);
 	}
 
-	while ((aw = TAILQ_FIRST(&c->autogroupq)) != NULL) {
-		TAILQ_REMOVE(&c->autogroupq, aw, entry);
-		free(aw->class);
-		free(aw->name);
-		free(aw);
+	while ((ag = TAILQ_FIRST(&c->autogroupq)) != NULL) {
+		TAILQ_REMOVE(&c->autogroupq, ag, entry);
+		free(ag->class);
+		free(ag->name);
+		free(ag);
 	}
 
 	while ((wn = TAILQ_FIRST(&c->ignoreq)) != NULL) {
@@ -315,8 +320,8 @@ conf_clear(struct conf *c)
 		free(wn);
 	}
 
-	while ((mb = TAILQ_FIRST(&c->mousebindingq)) != NULL) {
-		TAILQ_REMOVE(&c->mousebindingq, mb, entry);
+	while ((mb = TAILQ_FIRST(&c->mousebindq)) != NULL) {
+		TAILQ_REMOVE(&c->mousebindq, mb, entry);
 		free(mb);
 	}
 
@@ -324,6 +329,7 @@ conf_clear(struct conf *c)
 		free(c->color[i]);
 
 	free(c->font);
+	free(c->wmname);
 }
 
 void
@@ -345,149 +351,133 @@ conf_client(struct client_ctx *cc)
 
 static const struct {
 	const char	*tag;
-	void		 (*handler)(struct client_ctx *, union arg *);
+	void		 (*handler)(void *, union arg *, enum xev);
 	int		 context;
 	union arg	 argument;
 } name_to_func[] = {
-	{ "lower", kbfunc_client_lower, CWM_CONTEXT_CLIENT, {0} },
-	{ "raise", kbfunc_client_raise, CWM_CONTEXT_CLIENT, {0} },
-	{ "search", kbfunc_menu_client, CWM_CONTEXT_SCREEN, {0} },
-	{ "menusearch", kbfunc_menu_cmd, CWM_CONTEXT_SCREEN, {0} },
-	{ "groupsearch", kbfunc_menu_group, CWM_CONTEXT_SCREEN, {0} },
-	{ "hide", kbfunc_client_hide, CWM_CONTEXT_CLIENT, {0} },
-	{ "cycle", kbfunc_client_cycle, CWM_CONTEXT_SCREEN,
-	    {.i = CWM_CLIENT_CYCLE} },
-	{ "rcycle", kbfunc_client_cycle, CWM_CONTEXT_SCREEN,
-	    {.i = CWM_CLIENT_RCYCLE} },
-	{ "label", kbfunc_client_label, CWM_CONTEXT_CLIENT, {0} },
-	{ "delete", kbfunc_client_delete, CWM_CONTEXT_CLIENT, {0} },
-	{ "group1", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 1} },
-	{ "group2", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 2} },
-	{ "group3", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 3} },
-	{ "group4", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 4} },
-	{ "group5", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 5} },
-	{ "group6", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 6} },
-	{ "group7", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 7} },
-	{ "group8", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 8} },
-	{ "group9", kbfunc_group_toggle, CWM_CONTEXT_SCREEN, {.i = 9} },
-	{ "grouponly1", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 1} },
-	{ "grouponly2", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 2} },
-	{ "grouponly3", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 3} },
-	{ "grouponly4", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 4} },
-	{ "grouponly5", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 5} },
-	{ "grouponly6", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 6} },
-	{ "grouponly7", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 7} },
-	{ "grouponly8", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 8} },
-	{ "grouponly9", kbfunc_group_only, CWM_CONTEXT_SCREEN, {.i = 9} },
-	{ "movetogroup1", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
-	    {.i = 1} },
-	{ "movetogroup2", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
-	    {.i = 2} },
-	{ "movetogroup3", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
-	    {.i = 3} },
-	{ "movetogroup4", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
-	    {.i = 4} },
-	{ "movetogroup5", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
-	    {.i = 5} },
-	{ "movetogroup6", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
-	    {.i = 6} },
-	{ "movetogroup7", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
-	    {.i = 7} },
-	{ "movetogroup8", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
-	    {.i = 8} },
-	{ "movetogroup9", kbfunc_client_movetogroup, CWM_CONTEXT_CLIENT,
-	    {.i = 9} },
-	{ "nogroup", kbfunc_group_alltoggle, CWM_CONTEXT_SCREEN, {0} },
-	{ "cyclegroup", kbfunc_group_cycle, CWM_CONTEXT_SCREEN,
-	    {.i = CWM_CLIENT_CYCLE} },
-	{ "rcyclegroup", kbfunc_group_cycle, CWM_CONTEXT_SCREEN,
-	    {.i = CWM_CLIENT_RCYCLE} },
-	{ "cycleingroup", kbfunc_client_cycle, CWM_CONTEXT_CLIENT,
-	    {.i = (CWM_CLIENT_CYCLE | CWM_CLIENT_CYCLE_INGRP)} },
-	{ "rcycleingroup", kbfunc_client_cycle, CWM_CONTEXT_CLIENT,
-	    {.i = (CWM_CLIENT_RCYCLE | CWM_CLIENT_CYCLE_INGRP)} },
-	{ "grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT,
-	    {.i = CWM_KBD}},
-	{ "stick", kbfunc_client_toggle_sticky, CWM_CONTEXT_CLIENT, {0} },
-	{ "fullscreen", kbfunc_client_toggle_fullscreen, CWM_CONTEXT_CLIENT,
-	    {0} },
-	{ "maximize", kbfunc_client_toggle_maximize, CWM_CONTEXT_CLIENT, {0} },
-	{ "vmaximize", kbfunc_client_toggle_vmaximize, CWM_CONTEXT_CLIENT,
-	    {0} },
-	{ "hmaximize", kbfunc_client_toggle_hmaximize, CWM_CONTEXT_CLIENT,
-	    {0} },
-	{ "freeze", kbfunc_client_toggle_freeze, CWM_CONTEXT_CLIENT, {0} },
-	{ "restart", kbfunc_cwm_status, CWM_CONTEXT_SCREEN,
-	    {.i = CWM_EXEC_WM} },
-	{ "quit", kbfunc_cwm_status, CWM_CONTEXT_SCREEN, {.i = CWM_QUIT} },
-	{ "exec", kbfunc_menu_exec, CWM_CONTEXT_SCREEN, {.i = CWM_MENU_EXEC} },
-	{ "exec_wm", kbfunc_menu_exec, CWM_CONTEXT_SCREEN,
+	{ "lower", kbfunc_client_lower, CWM_CONTEXT_CC, {0} },
+	{ "raise", kbfunc_client_raise, CWM_CONTEXT_CC, {0} },
+	{ "search", kbfunc_menu_client, CWM_CONTEXT_SC, {0} },
+	{ "menusearch", kbfunc_menu_cmd, CWM_CONTEXT_SC, {0} },
+	{ "groupsearch", kbfunc_menu_group, CWM_CONTEXT_SC, {0} },
+	{ "hide", kbfunc_client_hide, CWM_CONTEXT_CC, {0} },
+	{ "cycle", kbfunc_client_cycle, CWM_CONTEXT_SC,
+	    {.i = (CWM_CYCLE_FORWARD)} },
+	{ "rcycle", kbfunc_client_cycle, CWM_CONTEXT_SC,
+	    {.i = (CWM_CYCLE_REVERSE)} },
+	{ "label", kbfunc_menu_client_label, CWM_CONTEXT_CC, {0} },
+	{ "delete", kbfunc_client_delete, CWM_CONTEXT_CC, {0} },
+	{ "group1", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 1} },
+	{ "group2", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 2} },
+	{ "group3", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 3} },
+	{ "group4", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 4} },
+	{ "group5", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 5} },
+	{ "group6", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 6} },
+	{ "group7", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 7} },
+	{ "group8", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 8} },
+	{ "group9", kbfunc_group_toggle, CWM_CONTEXT_SC, {.i = 9} },
+	{ "grouponly1", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 1} },
+	{ "grouponly2", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 2} },
+	{ "grouponly3", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 3} },
+	{ "grouponly4", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 4} },
+	{ "grouponly5", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 5} },
+	{ "grouponly6", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 6} },
+	{ "grouponly7", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 7} },
+	{ "grouponly8", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 8} },
+	{ "grouponly9", kbfunc_group_only, CWM_CONTEXT_SC, {.i = 9} },
+	{ "movetogroup1", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 1} },
+	{ "movetogroup2", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 2} },
+	{ "movetogroup3", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 3} },
+	{ "movetogroup4", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 4} },
+	{ "movetogroup5", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 5} },
+	{ "movetogroup6", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 6} },
+	{ "movetogroup7", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 7} },
+	{ "movetogroup8", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 8} },
+	{ "movetogroup9", kbfunc_client_movetogroup, CWM_CONTEXT_CC, {.i = 9} },
+	{ "nogroup", kbfunc_group_alltoggle, CWM_CONTEXT_SC, {0} },
+	{ "cyclegroup", kbfunc_group_cycle, CWM_CONTEXT_SC,
+	    {.i = (CWM_CYCLE_FORWARD)} },
+	{ "rcyclegroup", kbfunc_group_cycle, CWM_CONTEXT_SC,
+	    {.i = (CWM_CYCLE_REVERSE)} },
+	{ "cycleingroup", kbfunc_client_cycle, CWM_CONTEXT_SC,
+	    {.i = (CWM_CYCLE_FORWARD | CWM_CYCLE_INGROUP)} },
+	{ "rcycleingroup", kbfunc_client_cycle, CWM_CONTEXT_SC,
+	    {.i = (CWM_CYCLE_REVERSE | CWM_CYCLE_INGROUP)} },
+	{ "grouptoggle", kbfunc_client_toggle_group, CWM_CONTEXT_CC, {0} },
+	{ "stick", kbfunc_client_toggle_sticky, CWM_CONTEXT_CC, {0} },
+	{ "fullscreen", kbfunc_client_toggle_fullscreen, CWM_CONTEXT_CC, {0} },
+	{ "maximize", kbfunc_client_toggle_maximize, CWM_CONTEXT_CC, {0} },
+	{ "vmaximize", kbfunc_client_toggle_vmaximize, CWM_CONTEXT_CC, {0} },
+	{ "hmaximize", kbfunc_client_toggle_hmaximize, CWM_CONTEXT_CC, {0} },
+	{ "freeze", kbfunc_client_toggle_freeze, CWM_CONTEXT_CC, {0} },
+	{ "restart", kbfunc_cwm_status, CWM_CONTEXT_SC, {.i = CWM_EXEC_WM} },
+	{ "quit", kbfunc_cwm_status, CWM_CONTEXT_SC, {.i = CWM_QUIT} },
+	{ "exec", kbfunc_menu_exec, CWM_CONTEXT_SC,
+	    {.i = CWM_MENU_EXEC_EXEC} },
+	{ "exec_wm", kbfunc_menu_exec, CWM_CONTEXT_SC,
 	    {.i = CWM_MENU_EXEC_WM} },
-	{ "ssh", kbfunc_menu_ssh, CWM_CONTEXT_SCREEN, {0} },
-	{ "terminal", kbfunc_exec_term, CWM_CONTEXT_SCREEN, {0} },
-	{ "lock", kbfunc_exec_lock, CWM_CONTEXT_SCREEN, {0} },
-	{ "moveup", kbfunc_client_move, CWM_CONTEXT_CLIENT,
+	{ "ssh", kbfunc_menu_ssh, CWM_CONTEXT_SC, {0} },
+	{ "terminal", kbfunc_exec_term, CWM_CONTEXT_SC, {0} },
+	{ "lock", kbfunc_exec_lock, CWM_CONTEXT_SC, {0} },
+	{ "moveup", kbfunc_client_move, CWM_CONTEXT_CC,
 	    {.i = (CWM_UP)} },
-	{ "movedown", kbfunc_client_move, CWM_CONTEXT_CLIENT,
+	{ "movedown", kbfunc_client_move, CWM_CONTEXT_CC,
 	    {.i = (CWM_DOWN)} },
-	{ "moveright", kbfunc_client_move, CWM_CONTEXT_CLIENT,
+	{ "moveright", kbfunc_client_move, CWM_CONTEXT_CC,
 	    {.i = (CWM_RIGHT)} },
-	{ "moveleft", kbfunc_client_move, CWM_CONTEXT_CLIENT,
+	{ "moveleft", kbfunc_client_move, CWM_CONTEXT_CC,
 	    {.i = (CWM_LEFT)} },
-	{ "bigmoveup", kbfunc_client_move, CWM_CONTEXT_CLIENT,
+	{ "bigmoveup", kbfunc_client_move, CWM_CONTEXT_CC,
 	    {.i = (CWM_UP | CWM_BIGAMOUNT)} },
-	{ "bigmovedown", kbfunc_client_move, CWM_CONTEXT_CLIENT,
+	{ "bigmovedown", kbfunc_client_move, CWM_CONTEXT_CC,
 	    {.i = (CWM_DOWN | CWM_BIGAMOUNT)} },
-	{ "bigmoveright", kbfunc_client_move, CWM_CONTEXT_CLIENT,
+	{ "bigmoveright", kbfunc_client_move, CWM_CONTEXT_CC,
 	    {.i = (CWM_RIGHT | CWM_BIGAMOUNT)} },
-	{ "bigmoveleft", kbfunc_client_move, CWM_CONTEXT_CLIENT,
+	{ "bigmoveleft", kbfunc_client_move, CWM_CONTEXT_CC,
 	    {.i = (CWM_LEFT | CWM_BIGAMOUNT)} },
-	{ "resizeup", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
+	{ "resizeup", kbfunc_client_resize, CWM_CONTEXT_CC,
 	    {.i = (CWM_UP)} },
-	{ "resizedown", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
+	{ "resizedown", kbfunc_client_resize, CWM_CONTEXT_CC,
 	    {.i = (CWM_DOWN)} },
-	{ "resizeright", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
+	{ "resizeright", kbfunc_client_resize, CWM_CONTEXT_CC,
 	    {.i = (CWM_RIGHT)} },
-	{ "resizeleft", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
+	{ "resizeleft", kbfunc_client_resize, CWM_CONTEXT_CC,
 	    {.i = (CWM_LEFT)} },
-	{ "bigresizeup", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
+	{ "bigresizeup", kbfunc_client_resize, CWM_CONTEXT_CC,
 	    {.i = (CWM_UP | CWM_BIGAMOUNT)} },
-	{ "bigresizedown", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
+	{ "bigresizedown", kbfunc_client_resize, CWM_CONTEXT_CC,
 	    {.i = (CWM_DOWN | CWM_BIGAMOUNT)} },
-	{ "bigresizeright", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
+	{ "bigresizeright", kbfunc_client_resize, CWM_CONTEXT_CC,
 	    {.i = (CWM_RIGHT | CWM_BIGAMOUNT)} },
-	{ "bigresizeleft", kbfunc_client_resize, CWM_CONTEXT_CLIENT,
+	{ "bigresizeleft", kbfunc_client_resize, CWM_CONTEXT_CC,
 	    {.i = (CWM_LEFT | CWM_BIGAMOUNT)} },
-	{ "ptrmoveup", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
+	{ "ptrmoveup", kbfunc_ptrmove, CWM_CONTEXT_SC,
 	    {.i = (CWM_UP)} },
-	{ "ptrmovedown", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
+	{ "ptrmovedown", kbfunc_ptrmove, CWM_CONTEXT_SC,
 	    {.i = (CWM_DOWN)} },
-	{ "ptrmoveleft", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
+	{ "ptrmoveleft", kbfunc_ptrmove, CWM_CONTEXT_SC,
 	    {.i = (CWM_LEFT)} },
-	{ "ptrmoveright", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
+	{ "ptrmoveright", kbfunc_ptrmove, CWM_CONTEXT_SC,
 	    {.i = (CWM_RIGHT)} },
-	{ "bigptrmoveup", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
+	{ "bigptrmoveup", kbfunc_ptrmove, CWM_CONTEXT_SC,
 	    {.i = (CWM_UP | CWM_BIGAMOUNT)} },
-	{ "bigptrmovedown", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
+	{ "bigptrmovedown", kbfunc_ptrmove, CWM_CONTEXT_SC,
 	    {.i = (CWM_DOWN | CWM_BIGAMOUNT)} },
-	{ "bigptrmoveleft", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
+	{ "bigptrmoveleft", kbfunc_ptrmove, CWM_CONTEXT_SC,
 	    {.i = (CWM_LEFT | CWM_BIGAMOUNT)} },
-	{ "bigptrmoveright", kbfunc_ptrmove, CWM_CONTEXT_SCREEN,
+	{ "bigptrmoveright", kbfunc_ptrmove, CWM_CONTEXT_SC,
 	    {.i = (CWM_RIGHT | CWM_BIGAMOUNT)} },
-	{ "htile", kbfunc_client_tile, CWM_CONTEXT_CLIENT,
-	    {.i = CWM_CLIENT_TILE_HORIZ} },
-	{ "vtile", kbfunc_client_tile, CWM_CONTEXT_CLIENT,
-	    {.i = CWM_CLIENT_TILE_VERT} },
-	{ "window_lower", kbfunc_client_lower, CWM_CONTEXT_CLIENT, {0} },
-	{ "window_raise", kbfunc_client_raise, CWM_CONTEXT_CLIENT, {0} },
-	{ "window_hide", kbfunc_client_hide, CWM_CONTEXT_CLIENT, {0} },
-	{ "window_move", mousefunc_client_move, CWM_CONTEXT_CLIENT, {0} },
-	{ "window_resize", mousefunc_client_resize, CWM_CONTEXT_CLIENT, {0} },
-	{ "window_grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT,
-	   {.i = CWM_MOUSE} },
-	{ "menu_group", mousefunc_menu_group, CWM_CONTEXT_SCREEN, {0} },
-	{ "menu_unhide", mousefunc_menu_client, CWM_CONTEXT_SCREEN, {0} },
-	{ "menu_cmd", mousefunc_menu_cmd, CWM_CONTEXT_SCREEN, {0} },
+	{ "htile", kbfunc_client_htile, CWM_CONTEXT_CC, {0} },
+	{ "vtile", kbfunc_client_vtile, CWM_CONTEXT_CC, {0} },
+	{ "window_lower", kbfunc_client_lower, CWM_CONTEXT_CC, {0} },
+	{ "window_raise", kbfunc_client_raise, CWM_CONTEXT_CC, {0} },
+	{ "window_hide", kbfunc_client_hide, CWM_CONTEXT_CC, {0} },
+	{ "window_move", mousefunc_client_move, CWM_CONTEXT_CC, {0} },
+	{ "window_resize", mousefunc_client_resize, CWM_CONTEXT_CC, {0} },
+	{ "window_grouptoggle", kbfunc_client_toggle_group, CWM_CONTEXT_CC, {0} },
+	{ "menu_group", kbfunc_menu_group, CWM_CONTEXT_SC, {0} },
+	{ "menu_unhide", kbfunc_menu_client, CWM_CONTEXT_SC, {0} },
+	{ "menu_cmd", kbfunc_menu_cmd, CWM_CONTEXT_SC, {0} },
 };
 
 static const struct {
@@ -522,7 +512,7 @@ conf_bind_getmask(const char *name, unsigned int *mask)
 int
 conf_bind_kbd(struct conf *c, const char *bind, const char *cmd)
 {
-	struct binding	*kb;
+	struct bind_ctx	*kb;
 	const char	*key;
 	unsigned int	 i;
 
@@ -551,28 +541,28 @@ conf_bind_kbd(struct conf *c, const char *bind, const char *cmd)
 		kb->callback = name_to_func[i].handler;
 		kb->context = name_to_func[i].context;
 		kb->argument = name_to_func[i].argument;
-		TAILQ_INSERT_TAIL(&c->keybindingq, kb, entry);
+		TAILQ_INSERT_TAIL(&c->keybindq, kb, entry);
 		return(1);
 	}
 
-	kb->callback = kbfunc_exec;
+	kb->callback = kbfunc_exec_cmd;
 	kb->context = CWM_CONTEXT_NONE;
 	kb->argument.c = xstrdup(cmd);
-	TAILQ_INSERT_TAIL(&c->keybindingq, kb, entry);
+	TAILQ_INSERT_TAIL(&c->keybindq, kb, entry);
 	return(1);
 }
 
 static void
-conf_unbind_kbd(struct conf *c, struct binding *unbind)
+conf_unbind_kbd(struct conf *c, struct bind_ctx *unbind)
 {
-	struct binding	*key = NULL, *keynxt;
+	struct bind_ctx	*key = NULL, *keynxt;
 
-	TAILQ_FOREACH_SAFE(key, &c->keybindingq, entry, keynxt) {
+	TAILQ_FOREACH_SAFE(key, &c->keybindq, entry, keynxt) {
 		if (key->modmask != unbind->modmask)
 			continue;
 
 		if (key->press.keysym == unbind->press.keysym) {
-			TAILQ_REMOVE(&c->keybindingq, key, entry);
+			TAILQ_REMOVE(&c->keybindq, key, entry);
 			if (key->context == CWM_CONTEXT_NONE)
 				free(key->argument.c);
 			free(key);
@@ -583,7 +573,7 @@ conf_unbind_kbd(struct conf *c, struct binding *unbind)
 int
 conf_bind_mouse(struct conf *c, const char *bind, const char *cmd)
 {
-	struct binding	*mb;
+	struct bind_ctx	*mb;
 	const char	*button, *errstr;
 	unsigned int	 i;
 
@@ -612,7 +602,7 @@ conf_bind_mouse(struct conf *c, const char *bind, const char *cmd)
 		mb->callback = name_to_func[i].handler;
 		mb->context = name_to_func[i].context;
 		mb->argument = name_to_func[i].argument;
-		TAILQ_INSERT_TAIL(&c->mousebindingq, mb, entry);
+		TAILQ_INSERT_TAIL(&c->mousebindq, mb, entry);
 		return(1);
 	}
 
@@ -620,27 +610,26 @@ conf_bind_mouse(struct conf *c, const char *bind, const char *cmd)
 }
 
 static void
-conf_unbind_mouse(struct conf *c, struct binding *unbind)
+conf_unbind_mouse(struct conf *c, struct bind_ctx *unbind)
 {
-	struct binding		*mb = NULL, *mbnxt;
+	struct bind_ctx		*mb = NULL, *mbnxt;
 
-	TAILQ_FOREACH_SAFE(mb, &c->mousebindingq, entry, mbnxt) {
+	TAILQ_FOREACH_SAFE(mb, &c->mousebindq, entry, mbnxt) {
 		if (mb->modmask != unbind->modmask)
 			continue;
 
 		if (mb->press.button == unbind->press.button) {
-			TAILQ_REMOVE(&c->mousebindingq, mb, entry);
+			TAILQ_REMOVE(&c->mousebindq, mb, entry);
 			free(mb);
 		}
 	}
 }
 
 static int cursor_binds[] = {
-	XC_X_cursor,		/* CF_DEFAULT */
-	XC_fleur,		/* CF_MOVE */
 	XC_left_ptr,		/* CF_NORMAL */
-	XC_question_arrow,	/* CF_QUESTION */
+	XC_fleur,		/* CF_MOVE */
 	XC_bottom_right_corner,	/* CF_RESIZE */
+	XC_question_arrow,	/* CF_QUESTION */
 };
 
 void
@@ -652,28 +641,48 @@ conf_cursor(struct conf *c)
 		c->cursor[i] = XCreateFontCursor(X_Dpy, cursor_binds[i]);
 }
 
+static unsigned int ign_mods[] = { 0, LockMask, Mod2Mask, Mod2Mask | LockMask };
+
 void
 conf_grab_mouse(Window win)
 {
-	struct binding	*mb;
+	struct bind_ctx	*mb;
+	unsigned int	i;
 
-	xu_btn_ungrab(win);
+	XUngrabButton(X_Dpy, AnyButton, AnyModifier, win);
 
-	TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) {
-		if (mb->context == CWM_CONTEXT_CLIENT)
-			xu_btn_grab(win, mb->modmask, mb->press.button);
+	TAILQ_FOREACH(mb, &Conf.mousebindq, entry) {
+		if (mb->context != CWM_CONTEXT_CC)
+			continue;
+		for (i = 0; i < nitems(ign_mods); i++) {
+			XGrabButton(X_Dpy, mb->press.button,
+			    (mb->modmask | ign_mods[i]), win, False,
+			    BUTTONMASK, GrabModeAsync, GrabModeSync,
+			    None, None);
+		}
 	}
+
 }
 
 void
 conf_grab_kbd(Window win)
 {
-	struct binding	*kb;
+	struct bind_ctx	*kb;
+	KeyCode		 kc;
+	unsigned int	 i;
+
+	XUngrabKey(X_Dpy, AnyKey, AnyModifier, win);
 
-	xu_key_ungrab(win);
+	TAILQ_FOREACH(kb, &Conf.keybindq, entry) {
+		kc = XKeysymToKeycode(X_Dpy, kb->press.keysym);
+		if ((XkbKeycodeToKeysym(X_Dpy, kc, 0, 0) != kb->press.keysym) &&
+		    (XkbKeycodeToKeysym(X_Dpy, kc, 0, 1) == kb->press.keysym))
+			kb->modmask |= ShiftMask;
 
-	TAILQ_FOREACH(kb, &Conf.keybindingq, entry)
-		xu_key_grab(win, kb->modmask, kb->press.keysym);
+		for (i = 0; i < nitems(ign_mods); i++)
+			XGrabKey(X_Dpy, kc, (kb->modmask | ign_mods[i]), win,
+			    True, GrabModeAsync, GrabModeAsync);
+	}
 }
 
 static char *cwmhints[] = {