summary refs log tree commit diff
diff options
context:
space:
mode:
authorokan <okan>2016-10-06 14:41:19 +0000
committerokan <okan>2016-10-06 14:41:19 +0000
commit987ee736b92ec889391283624d84cc6cc87c8c1a (patch)
tree50edaea87e5eb23d2ccf90fa3a5c3bb558121244
parent66f5360fd48401a1d8ac204e36567597a3974164 (diff)
downloadcwm-987ee736b92ec889391283624d84cc6cc87c8c1a.tar.gz
cwm-987ee736b92ec889391283624d84cc6cc87c8c1a.tar.xz
cwm-987ee736b92ec889391283624d84cc6cc87c8c1a.zip
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.
-rw-r--r--calmwm.h74
-rw-r--r--conf.c17
-rw-r--r--kbfunc.c70
-rw-r--r--mousefunc.c4
-rw-r--r--xevents.c4
5 files changed, 82 insertions, 87 deletions
diff --git a/calmwm.h b/calmwm.h
index 15fb8b3..6c5dfa3 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -74,8 +74,8 @@
 #define CWM_GAP			0x0001
 #define CWM_NOGAP		0x0002
 
-#define CWM_KBD			0x0001
-#define CWM_MOUSE		0x0002
+#define CWM_KEY			0x0001
+#define CWM_BTN			0x0002
 
 #define CWM_CONTEXT_NONE	0x0000
 #define CWM_CONTEXT_CLIENT	0x0001
@@ -245,7 +245,7 @@ TAILQ_HEAD(screen_ctx_q, screen_ctx);
 
 struct binding {
 	TAILQ_ENTRY(binding)	 entry;
-	void			(*callback)(struct client_ctx *, union arg *);
+	void			(*callback)(struct client_ctx *, union arg *, int);
 	union arg		 argument;
 	unsigned int		 modmask;
 	union press		 press;
@@ -457,52 +457,52 @@ void			 screen_update_geometry(struct screen_ctx *);
 void			 screen_updatestackingorder(struct screen_ctx *);
 void			 screen_assert_clients_within(struct screen_ctx *);
 
-void			 kbfunc_client_cycle(struct client_ctx *, union arg *);
-void			 kbfunc_client_delete(struct client_ctx *, union arg *);
+void			 kbfunc_client_cycle(struct client_ctx *, union arg *, int);
+void			 kbfunc_client_delete(struct client_ctx *, union arg *, int);
 void			 kbfunc_client_grouptoggle(struct client_ctx *,
-			     union arg *);
-void			 kbfunc_client_hide(struct client_ctx *, union arg *);
-void			 kbfunc_client_label(struct client_ctx *, union arg *);
-void			 kbfunc_client_lower(struct client_ctx *, union arg *);
-void			 kbfunc_client_move(struct client_ctx *, union arg *);
+			     union arg *, int);
+void			 kbfunc_client_hide(struct client_ctx *, union arg *, int);
+void			 kbfunc_client_label(struct client_ctx *, union arg *, int);
+void			 kbfunc_client_lower(struct client_ctx *, union arg *, int);
+void			 kbfunc_client_move(struct client_ctx *, union arg *, int);
 void			 kbfunc_client_movetogroup(struct client_ctx *,
-			     union arg *);
-void			 kbfunc_client_raise(struct client_ctx *, union arg *);
-void			 kbfunc_client_rcycle(struct client_ctx *, union arg *);
-void			 kbfunc_client_resize(struct client_ctx *, union arg *);
-void 			 kbfunc_client_tile(struct client_ctx *, union arg *);
+			     union arg *, int);
+void			 kbfunc_client_raise(struct client_ctx *, union arg *, int);
+void			 kbfunc_client_rcycle(struct client_ctx *, union arg *, int);
+void			 kbfunc_client_resize(struct client_ctx *, union arg *, int);
+void 			 kbfunc_client_tile(struct client_ctx *, union arg *, int);
 void			 kbfunc_client_toggle_freeze(struct client_ctx *,
-    			     union arg *);
+    			     union arg *, int);
 void			 kbfunc_client_toggle_fullscreen(struct client_ctx *,
-			     union arg *);
+			     union arg *, int);
 void			 kbfunc_client_toggle_hmaximize(struct client_ctx *,
-			     union arg *);
+			     union arg *, int);
 void			 kbfunc_client_toggle_maximize(struct client_ctx *,
-			     union arg *);
+			     union arg *, int);
 void			 kbfunc_client_toggle_sticky(struct client_ctx *,
-    			     union arg *);
+    			     union arg *, int);
 void			 kbfunc_client_toggle_vmaximize(struct client_ctx *,
-			     union arg *);
-void			 kbfunc_cwm_status(struct client_ctx *, union arg *);
-void			 kbfunc_exec(struct client_ctx *, union arg *);
-void			 kbfunc_exec_lock(struct client_ctx *, union arg *);
-void			 kbfunc_exec_term(struct client_ctx *, union arg *);
+			     union arg *, int);
+void			 kbfunc_cwm_status(struct client_ctx *, union arg *, int);
+void			 kbfunc_exec(struct client_ctx *, union arg *, int);
+void			 kbfunc_exec_lock(struct client_ctx *, union arg *, int);
+void			 kbfunc_exec_term(struct client_ctx *, union arg *, int);
 void			 kbfunc_group_alltoggle(struct client_ctx *,
-			     union arg *);
-void			 kbfunc_group_cycle(struct client_ctx *, union arg *);
-void			 kbfunc_group_only(struct client_ctx *, union arg *);
-void			 kbfunc_group_toggle(struct client_ctx *, union arg *);
-void			 kbfunc_menu_exec(struct client_ctx *, union arg *);
-void			 kbfunc_menu_client(struct client_ctx *, union arg *);
-void			 kbfunc_menu_cmd(struct client_ctx *, union arg *);
-void			 kbfunc_menu_group(struct client_ctx *, union arg *);
-void			 kbfunc_menu_ssh(struct client_ctx *, union arg *);
-void			 kbfunc_ptrmove(struct client_ctx *, union arg *);
+			     union arg *, int);
+void			 kbfunc_group_cycle(struct client_ctx *, union arg *, int);
+void			 kbfunc_group_only(struct client_ctx *, union arg *, int);
+void			 kbfunc_group_toggle(struct client_ctx *, union arg *, int);
+void			 kbfunc_menu_exec(struct client_ctx *, union arg *, int);
+void			 kbfunc_menu_client(struct client_ctx *, union arg *, int);
+void			 kbfunc_menu_cmd(struct client_ctx *, union arg *, int);
+void			 kbfunc_menu_group(struct client_ctx *, union arg *, int);
+void			 kbfunc_menu_ssh(struct client_ctx *, union arg *, int);
+void			 kbfunc_ptrmove(struct client_ctx *, union arg *, int);
 
 void			 mousefunc_client_move(struct client_ctx *,
-    			    union arg *);
+    			    union arg *, int);
 void			 mousefunc_client_resize(struct client_ctx *,
-    			    union arg *);
+    			    union arg *, int);
 
 void			 menu_windraw(struct screen_ctx *, Window,
 			     const char *, ...);
diff --git a/conf.c b/conf.c
index 3ee6467..4d8a643 100644
--- a/conf.c
+++ b/conf.c
@@ -351,7 +351,7 @@ conf_client(struct client_ctx *cc)
 
 static const struct {
 	const char	*tag;
-	void		 (*handler)(struct client_ctx *, union arg *);
+	void		 (*handler)(struct client_ctx *, union arg *, int);
 	int		 context;
 	union arg	 argument;
 } name_to_func[] = {
@@ -412,8 +412,7 @@ static const struct {
 	    {.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}},
+	{ "grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT, {0}},
 	{ "stick", kbfunc_client_toggle_sticky, CWM_CONTEXT_CLIENT, {0} },
 	{ "fullscreen", kbfunc_client_toggle_fullscreen, CWM_CONTEXT_CLIENT,
 	    {0} },
@@ -489,14 +488,10 @@ static const struct {
 	{ "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", kbfunc_menu_group, CWM_CONTEXT_SCREEN,
-	    {.i = CWM_MOUSE} },
-	{ "menu_unhide", kbfunc_menu_client, CWM_CONTEXT_SCREEN,
-	    {.i = CWM_MOUSE} },
-	{ "menu_cmd", kbfunc_menu_cmd, CWM_CONTEXT_SCREEN,
-	    {.i = CWM_MOUSE} },
+	{ "window_grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT, {0} },
+	{ "menu_group", kbfunc_menu_group, CWM_CONTEXT_SCREEN, {0} },
+	{ "menu_unhide", kbfunc_menu_client, CWM_CONTEXT_SCREEN, {0} },
+	{ "menu_cmd", kbfunc_menu_cmd, CWM_CONTEXT_SCREEN, {0} },
 };
 
 static const struct {
diff --git a/kbfunc.c b/kbfunc.c
index fc2bc8b..1e4f95b 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -41,14 +41,14 @@ extern sig_atomic_t	 cwm_status;
 static void kbfunc_amount(int, int, unsigned int *, unsigned int *);
 
 void
-kbfunc_client_lower(struct client_ctx *cc, union arg *arg)
+kbfunc_client_lower(struct client_ctx *cc, union arg *arg, int xev)
 {
 	client_ptrsave(cc);
 	client_lower(cc);
 }
 
 void
-kbfunc_client_raise(struct client_ctx *cc, union arg *arg)
+kbfunc_client_raise(struct client_ctx *cc, union arg *arg, int xev)
 {
 	client_raise(cc);
 }
@@ -78,7 +78,7 @@ kbfunc_amount(int flags, int amt, unsigned int *mx, unsigned int *my)
 }
 
 void
-kbfunc_ptrmove(struct client_ctx *cc, union arg *arg)
+kbfunc_ptrmove(struct client_ctx *cc, union arg *arg, int xev)
 {
 	struct screen_ctx	*sc = cc->sc;
 	int			 x, y;
@@ -91,7 +91,7 @@ kbfunc_ptrmove(struct client_ctx *cc, union arg *arg)
 }
 
 void
-kbfunc_client_move(struct client_ctx *cc, union arg *arg)
+kbfunc_client_move(struct client_ctx *cc, union arg *arg, int xev)
 {
 	struct screen_ctx	*sc = cc->sc;
 	struct geom		 area;
@@ -144,7 +144,7 @@ kbfunc_client_move(struct client_ctx *cc, union arg *arg)
 }
 
 void
-kbfunc_client_resize(struct client_ctx *cc, union arg *arg)
+kbfunc_client_resize(struct client_ctx *cc, union arg *arg, int xev)
 {
 	unsigned int		 mx = 0, my = 0;
 	int			 amt = 1;
@@ -173,13 +173,13 @@ kbfunc_client_resize(struct client_ctx *cc, union arg *arg)
 }
 
 void
-kbfunc_menu_client(struct client_ctx *cc, union arg *arg)
+kbfunc_menu_client(struct client_ctx *cc, union arg *arg, int xev)
 {
 	struct screen_ctx	*sc = cc->sc;
 	struct client_ctx	*old_cc;
 	struct menu		*mi;
 	struct menu_q		 menuq;
-	int			 m = (arg->i == CWM_MOUSE);
+	int			 m = (xev == CWM_BTN);
 
 	old_cc = client_current();
 
@@ -210,13 +210,13 @@ kbfunc_menu_client(struct client_ctx *cc, union arg *arg)
 }
 
 void
-kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg)
+kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg, int xev)
 {
 	struct screen_ctx	*sc = cc->sc;
 	struct cmd		*cmd;
 	struct menu		*mi;
 	struct menu_q		 menuq;
-	int			 m = (arg->i == CWM_MOUSE);
+	int			 m = (xev == CWM_BTN);
 
 	TAILQ_INIT(&menuq);
 	TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
@@ -239,13 +239,13 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg)
 }
 
 void
-kbfunc_menu_group(struct client_ctx *cc, union arg *arg)
+kbfunc_menu_group(struct client_ctx *cc, union arg *arg, int xev)
 {
 	struct screen_ctx	*sc = cc->sc;
 	struct group_ctx	*gc;
 	struct menu		*mi;
 	struct menu_q		 menuq;
-	int			 m = (arg->i == CWM_MOUSE);
+	int			 m = (xev == CWM_BTN);
 
 	TAILQ_INIT(&menuq);
 	TAILQ_FOREACH(gc, &sc->groupq, entry) {
@@ -266,25 +266,25 @@ kbfunc_menu_group(struct client_ctx *cc, union arg *arg)
 }
 
 void
-kbfunc_client_cycle(struct client_ctx *cc, union arg *arg)
+kbfunc_client_cycle(struct client_ctx *cc, union arg *arg, int xev)
 {
 	client_cycle(cc->sc, arg->i);
 }
 
 void
-kbfunc_client_hide(struct client_ctx *cc, union arg *arg)
+kbfunc_client_hide(struct client_ctx *cc, union arg *arg, int xev)
 {
 	client_hide(cc);
 }
 
 void
-kbfunc_exec(struct client_ctx *cc, union arg *arg)
+kbfunc_exec(struct client_ctx *cc, union arg *arg, int xev)
 {
 	u_spawn(arg->c);
 }
 
 void
-kbfunc_exec_term(struct client_ctx *cc, union arg *arg)
+kbfunc_exec_term(struct client_ctx *cc, union arg *arg, int xev)
 {
 	struct cmd *cmd;
 
@@ -295,7 +295,7 @@ kbfunc_exec_term(struct client_ctx *cc, union arg *arg)
 }
 
 void
-kbfunc_exec_lock(struct client_ctx *cc, union arg *arg)
+kbfunc_exec_lock(struct client_ctx *cc, union arg *arg, int xev)
 {
 	struct cmd *cmd;
 
@@ -306,7 +306,7 @@ kbfunc_exec_lock(struct client_ctx *cc, union arg *arg)
 }
 
 void
-kbfunc_menu_exec(struct client_ctx *cc, union arg *arg)
+kbfunc_menu_exec(struct client_ctx *cc, union arg *arg, int xev)
 {
 #define NPATHS 256
 	struct screen_ctx	*sc = cc->sc;
@@ -389,7 +389,7 @@ out:
 }
 
 void
-kbfunc_menu_ssh(struct client_ctx *cc, union arg *arg)
+kbfunc_menu_ssh(struct client_ctx *cc, union arg *arg, int xev)
 {
 	struct screen_ctx	*sc = cc->sc;
 	struct cmd		*cmd;
@@ -456,7 +456,7 @@ out:
 }
 
 void
-kbfunc_client_label(struct client_ctx *cc, union arg *arg)
+kbfunc_client_label(struct client_ctx *cc, union arg *arg, int xev)
 {
 	struct menu	*mi;
 	struct menu_q	 menuq;
@@ -475,39 +475,39 @@ kbfunc_client_label(struct client_ctx *cc, union arg *arg)
 }
 
 void
-kbfunc_client_delete(struct client_ctx *cc, union arg *arg)
+kbfunc_client_delete(struct client_ctx *cc, union arg *arg, int xev)
 {
 	client_send_delete(cc);
 }
 
 void
-kbfunc_group_toggle(struct client_ctx *cc, union arg *arg)
+kbfunc_group_toggle(struct client_ctx *cc, union arg *arg, int xev)
 {
 	group_hidetoggle(cc->sc, arg->i);
 }
 
 void
-kbfunc_group_only(struct client_ctx *cc, union arg *arg)
+kbfunc_group_only(struct client_ctx *cc, union arg *arg, int xev)
 {
 	group_only(cc->sc, arg->i);
 }
 
 void
-kbfunc_group_cycle(struct client_ctx *cc, union arg *arg)
+kbfunc_group_cycle(struct client_ctx *cc, union arg *arg, int xev)
 {
 	group_cycle(cc->sc, arg->i);
 }
 
 void
-kbfunc_group_alltoggle(struct client_ctx *cc, union arg *arg)
+kbfunc_group_alltoggle(struct client_ctx *cc, union arg *arg, int xev)
 {
 	group_alltoggle(cc->sc);
 }
 
 void
-kbfunc_client_grouptoggle(struct client_ctx *cc, union arg *arg)
+kbfunc_client_grouptoggle(struct client_ctx *cc, union arg *arg, int xev)
 {
-	if (arg->i == CWM_KBD) {
+	if (xev == CWM_KEY) {
 		/* For X apps that steal events. */
 		XGrabKeyboard(X_Dpy, cc->win, True,
 		    GrabModeAsync, GrabModeAsync, CurrentTime);
@@ -517,55 +517,55 @@ kbfunc_client_grouptoggle(struct client_ctx *cc, union arg *arg)
 }
 
 void
-kbfunc_client_movetogroup(struct client_ctx *cc, union arg *arg)
+kbfunc_client_movetogroup(struct client_ctx *cc, union arg *arg, int xev)
 {
 	group_movetogroup(cc, arg->i);
 }
 
 void
-kbfunc_client_toggle_sticky(struct client_ctx *cc, union arg *arg)
+kbfunc_client_toggle_sticky(struct client_ctx *cc, union arg *arg, int xev)
 {
 	client_toggle_sticky(cc);
 }
 
 void
-kbfunc_client_toggle_fullscreen(struct client_ctx *cc, union arg *arg)
+kbfunc_client_toggle_fullscreen(struct client_ctx *cc, union arg *arg, int xev)
 {
 	client_toggle_fullscreen(cc);
 }
 
 void
-kbfunc_client_toggle_maximize(struct client_ctx *cc, union arg *arg)
+kbfunc_client_toggle_maximize(struct client_ctx *cc, union arg *arg, int xev)
 {
 	client_toggle_maximize(cc);
 }
 
 void
-kbfunc_client_toggle_vmaximize(struct client_ctx *cc, union arg *arg)
+kbfunc_client_toggle_vmaximize(struct client_ctx *cc, union arg *arg, int xev)
 {
 	client_toggle_vmaximize(cc);
 }
 
 void
-kbfunc_client_toggle_hmaximize(struct client_ctx *cc, union arg *arg)
+kbfunc_client_toggle_hmaximize(struct client_ctx *cc, union arg *arg, int xev)
 {
 	client_toggle_hmaximize(cc);
 }
 
 void
-kbfunc_client_toggle_freeze(struct client_ctx *cc, union arg *arg)
+kbfunc_client_toggle_freeze(struct client_ctx *cc, union arg *arg, int xev)
 {
 	client_toggle_freeze(cc);
 }
 
 void
-kbfunc_cwm_status(struct client_ctx *cc, union arg *arg)
+kbfunc_cwm_status(struct client_ctx *cc, union arg *arg, int xev)
 {
 	cwm_status = arg->i;
 }
 
 void
-kbfunc_client_tile(struct client_ctx *cc, union arg *arg)
+kbfunc_client_tile(struct client_ctx *cc, union arg *arg, int xev)
 {
 	switch (arg->i) {
 	case CWM_CLIENT_TILE_HORIZ:
diff --git a/mousefunc.c b/mousefunc.c
index 2bf19db..27b1d65 100644
--- a/mousefunc.c
+++ b/mousefunc.c
@@ -33,7 +33,7 @@
 #include "calmwm.h"
 
 void
-mousefunc_client_resize(struct client_ctx *cc, union arg *arg)
+mousefunc_client_resize(struct client_ctx *cc, union arg *arg, int xev)
 {
 	XEvent			 ev;
 	Time			 ltime = 0;
@@ -88,7 +88,7 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg)
 }
 
 void
-mousefunc_client_move(struct client_ctx *cc, union arg *arg)
+mousefunc_client_move(struct client_ctx *cc, union arg *arg, int xev)
 {
 	XEvent			 ev;
 	Time			 ltime = 0;
diff --git a/xevents.c b/xevents.c
index 3dab168..3388063 100644
--- a/xevents.c
+++ b/xevents.c
@@ -244,7 +244,7 @@ xev_handle_buttonpress(XEvent *ee)
 			return;
 	}
 
-	(*mb->callback)(cc, &mb->argument);
+	(*mb->callback)(cc, &mb->argument, CWM_BTN);
 }
 
 static void
@@ -298,7 +298,7 @@ xev_handle_keypress(XEvent *ee)
 			return;
 	}
 
-	(*kb->callback)(cc, &kb->argument);
+	(*kb->callback)(cc, &kb->argument, CWM_KEY);
 }
 
 /*