summary refs log tree commit diff
path: root/conf.c
diff options
context:
space:
mode:
authorokan <okan>2008-06-14 21:48:54 +0000
committerokan <okan>2008-06-14 21:48:54 +0000
commitbdcbbe7f53ce140df98f06a31dfe5cb19a40d708 (patch)
tree58a64d48acdfbaca8ec894b89909da5c6d8880f1 /conf.c
parentb4ae492b7ba7bf40147c1ad4b8d036aa32053f58 (diff)
downloadcwm-bdcbbe7f53ce140df98f06a31dfe5cb19a40d708.tar.gz
cwm-bdcbbe7f53ce140df98f06a31dfe5cb19a40d708.tar.xz
cwm-bdcbbe7f53ce140df98f06a31dfe5cb19a40d708.zip
confable menu and window mouse bindings from rivo nurges (thanks!) with
some minor fixups, man page bits and knf.

ok oga@
Diffstat (limited to 'conf.c')
-rw-r--r--conf.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/conf.c b/conf.c
index 33a02dc..ea22d59 100644
--- a/conf.c
+++ b/conf.c
@@ -90,6 +90,7 @@ conf_init(struct conf *c)
 	TAILQ_INIT(&c->cmdq);
 	TAILQ_INIT(&c->keybindingq);
 	TAILQ_INIT(&c->autogroupq);
+	TAILQ_INIT(&c->mousebindingq);
 
 	conf_bindname(c, "CM-Return", "terminal");
 	conf_bindname(c, "CM-Delete", "lock");
@@ -149,6 +150,14 @@ conf_init(struct conf *c)
 	conf_bindname(c, "CS-Up", "bigptrmoveup");
 	conf_bindname(c, "CS-Right", "bigptrmoveright");
 
+	conf_mousebind(c, "1", "menu_unhide");
+	conf_mousebind(c, "2", "menu_group");
+	conf_mousebind(c, "3", "menu_cmd");
+	conf_mousebind(c, "M-1", "window_move");
+	conf_mousebind(c, "CM-1", "window_grouptoggle");
+	conf_mousebind(c, "M-2", "window_resize");
+	conf_mousebind(c, "M-3", "window_lower");
+
 	/* Default term/lock */
 	strlcpy(c->termpath, "xterm", sizeof(c->termpath));
 	strlcpy(c->lockpath, "xlock", sizeof(c->lockpath));
@@ -379,3 +388,82 @@ void conf_unbind(struct conf *c, struct keybinding *unbind)
 		}
 	}
 }
+
+struct {
+	char *tag;
+	void (*handler)(struct client_ctx *, void *);
+	int context;
+} name_to_mousefunc[] = {
+	{ "window_move", mousefunc_window_move, MOUSEBIND_CTX_WIN },
+	{ "window_resize", mousefunc_window_resize, MOUSEBIND_CTX_WIN },
+	{ "window_grouptoggle", mousefunc_window_grouptoggle,
+	    MOUSEBIND_CTX_WIN },
+	{ "window_lower", mousefunc_window_lower, 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 },
+	{ NULL, NULL, 0 },
+};
+
+void
+conf_mousebind(struct conf *c, char *name, char *binding)
+{
+	int iter;
+	struct mousebinding *current_binding;
+	char *substring;
+	const char *errstr;
+
+	XCALLOC(current_binding, struct mousebinding);
+
+	if (strchr(name, 'C') != NULL &&
+	    strchr(name, 'C') < strchr(name, '-'))
+		current_binding->modmask |= ControlMask;
+
+	if (strchr(name, 'M') != NULL &&
+	    strchr(name, 'M') < strchr(name, '-'))
+		current_binding->modmask |= Mod1Mask;
+
+	substring = strchr(name, '-') + 1;
+
+	if (strchr(name, '-') == NULL)
+		substring = name;
+
+	current_binding->button = strtonum(substring);
+	if (errstr)
+		warnx("number of buttons is %s: %s", errstr, substring);
+
+	conf_mouseunbind(c, current_binding);
+
+	if (strcmp("unmap", binding) == 0)
+		return;
+
+	for (iter = 0; name_to_mousefunc[iter].tag != NULL; iter++) {
+		if (strcmp(name_to_mousefunc[iter].tag, binding) != 0)
+			continue;
+
+		current_binding->context = name_to_mousefunc[iter].context;
+		current_binding->callback = name_to_mousefunc[iter].handler;
+		TAILQ_INSERT_TAIL(&c->mousebindingq, current_binding, entry);
+		return;
+	}
+}
+
+void
+conf_mouseunbind(struct conf *c, struct mousebinding *unbind)
+{
+	struct mousebinding *mb = NULL, *mbnxt;
+
+	for (mb = TAILQ_FIRST(&c->mousebindingq);
+	    mb != TAILQ_END(&c->mousebindingq); mb = mbnxt) {
+		mbnxt = TAILQ_NEXT(mb, entry);
+
+		if (mb->modmask != unbind->modmask)
+			continue;
+
+		if (mb->button == unbind->button) {
+			TAILQ_REMOVE(&c->mousebindingq, mb, entry);
+			xfree(mb);
+		}
+	}
+}
+