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.
This commit is contained in:
okan 2016-10-06 14:41:19 +00:00
parent 66f5360fd4
commit 987ee736b9
5 changed files with 82 additions and 87 deletions

View File

@ -74,8 +74,8 @@
#define CWM_GAP 0x0001 #define CWM_GAP 0x0001
#define CWM_NOGAP 0x0002 #define CWM_NOGAP 0x0002
#define CWM_KBD 0x0001 #define CWM_KEY 0x0001
#define CWM_MOUSE 0x0002 #define CWM_BTN 0x0002
#define CWM_CONTEXT_NONE 0x0000 #define CWM_CONTEXT_NONE 0x0000
#define CWM_CONTEXT_CLIENT 0x0001 #define CWM_CONTEXT_CLIENT 0x0001
@ -245,7 +245,7 @@ TAILQ_HEAD(screen_ctx_q, screen_ctx);
struct binding { struct binding {
TAILQ_ENTRY(binding) entry; TAILQ_ENTRY(binding) entry;
void (*callback)(struct client_ctx *, union arg *); void (*callback)(struct client_ctx *, union arg *, int);
union arg argument; union arg argument;
unsigned int modmask; unsigned int modmask;
union press press; union press press;
@ -457,52 +457,52 @@ void screen_update_geometry(struct screen_ctx *);
void screen_updatestackingorder(struct screen_ctx *); void screen_updatestackingorder(struct screen_ctx *);
void screen_assert_clients_within(struct screen_ctx *); void screen_assert_clients_within(struct screen_ctx *);
void kbfunc_client_cycle(struct client_ctx *, union arg *); void kbfunc_client_cycle(struct client_ctx *, union arg *, int);
void kbfunc_client_delete(struct client_ctx *, union arg *); void kbfunc_client_delete(struct client_ctx *, union arg *, int);
void kbfunc_client_grouptoggle(struct client_ctx *, void kbfunc_client_grouptoggle(struct client_ctx *,
union arg *); union arg *, int);
void kbfunc_client_hide(struct client_ctx *, union arg *); void kbfunc_client_hide(struct client_ctx *, union arg *, int);
void kbfunc_client_label(struct client_ctx *, union arg *); void kbfunc_client_label(struct client_ctx *, union arg *, int);
void kbfunc_client_lower(struct client_ctx *, union arg *); void kbfunc_client_lower(struct client_ctx *, union arg *, int);
void kbfunc_client_move(struct client_ctx *, union arg *); void kbfunc_client_move(struct client_ctx *, union arg *, int);
void kbfunc_client_movetogroup(struct client_ctx *, void kbfunc_client_movetogroup(struct client_ctx *,
union arg *); union arg *, int);
void kbfunc_client_raise(struct client_ctx *, union arg *); void kbfunc_client_raise(struct client_ctx *, union arg *, int);
void kbfunc_client_rcycle(struct client_ctx *, union arg *); void kbfunc_client_rcycle(struct client_ctx *, union arg *, int);
void kbfunc_client_resize(struct client_ctx *, union arg *); void kbfunc_client_resize(struct client_ctx *, union arg *, int);
void kbfunc_client_tile(struct client_ctx *, union arg *); void kbfunc_client_tile(struct client_ctx *, union arg *, int);
void kbfunc_client_toggle_freeze(struct client_ctx *, void kbfunc_client_toggle_freeze(struct client_ctx *,
union arg *); union arg *, int);
void kbfunc_client_toggle_fullscreen(struct client_ctx *, void kbfunc_client_toggle_fullscreen(struct client_ctx *,
union arg *); union arg *, int);
void kbfunc_client_toggle_hmaximize(struct client_ctx *, void kbfunc_client_toggle_hmaximize(struct client_ctx *,
union arg *); union arg *, int);
void kbfunc_client_toggle_maximize(struct client_ctx *, void kbfunc_client_toggle_maximize(struct client_ctx *,
union arg *); union arg *, int);
void kbfunc_client_toggle_sticky(struct client_ctx *, void kbfunc_client_toggle_sticky(struct client_ctx *,
union arg *); union arg *, int);
void kbfunc_client_toggle_vmaximize(struct client_ctx *, void kbfunc_client_toggle_vmaximize(struct client_ctx *,
union arg *); union arg *, int);
void kbfunc_cwm_status(struct client_ctx *, union arg *); void kbfunc_cwm_status(struct client_ctx *, union arg *, int);
void kbfunc_exec(struct client_ctx *, union arg *); void kbfunc_exec(struct client_ctx *, union arg *, int);
void kbfunc_exec_lock(struct client_ctx *, union arg *); void kbfunc_exec_lock(struct client_ctx *, union arg *, int);
void kbfunc_exec_term(struct client_ctx *, union arg *); void kbfunc_exec_term(struct client_ctx *, union arg *, int);
void kbfunc_group_alltoggle(struct client_ctx *, void kbfunc_group_alltoggle(struct client_ctx *,
union arg *); union arg *, int);
void kbfunc_group_cycle(struct client_ctx *, union arg *); void kbfunc_group_cycle(struct client_ctx *, union arg *, int);
void kbfunc_group_only(struct client_ctx *, union arg *); void kbfunc_group_only(struct client_ctx *, union arg *, int);
void kbfunc_group_toggle(struct client_ctx *, union arg *); void kbfunc_group_toggle(struct client_ctx *, union arg *, int);
void kbfunc_menu_exec(struct client_ctx *, union arg *); void kbfunc_menu_exec(struct client_ctx *, union arg *, int);
void kbfunc_menu_client(struct client_ctx *, union arg *); void kbfunc_menu_client(struct client_ctx *, union arg *, int);
void kbfunc_menu_cmd(struct client_ctx *, union arg *); void kbfunc_menu_cmd(struct client_ctx *, union arg *, int);
void kbfunc_menu_group(struct client_ctx *, union arg *); void kbfunc_menu_group(struct client_ctx *, union arg *, int);
void kbfunc_menu_ssh(struct client_ctx *, union arg *); void kbfunc_menu_ssh(struct client_ctx *, union arg *, int);
void kbfunc_ptrmove(struct client_ctx *, union arg *); void kbfunc_ptrmove(struct client_ctx *, union arg *, int);
void mousefunc_client_move(struct client_ctx *, void mousefunc_client_move(struct client_ctx *,
union arg *); union arg *, int);
void mousefunc_client_resize(struct client_ctx *, void mousefunc_client_resize(struct client_ctx *,
union arg *); union arg *, int);
void menu_windraw(struct screen_ctx *, Window, void menu_windraw(struct screen_ctx *, Window,
const char *, ...); const char *, ...);

17
conf.c
View File

@ -351,7 +351,7 @@ conf_client(struct client_ctx *cc)
static const struct { static const struct {
const char *tag; const char *tag;
void (*handler)(struct client_ctx *, union arg *); void (*handler)(struct client_ctx *, union arg *, int);
int context; int context;
union arg argument; union arg argument;
} name_to_func[] = { } name_to_func[] = {
@ -412,8 +412,7 @@ static const struct {
{.i = (CWM_CLIENT_CYCLE | CWM_CLIENT_CYCLE_INGRP)} }, {.i = (CWM_CLIENT_CYCLE | CWM_CLIENT_CYCLE_INGRP)} },
{ "rcycleingroup", kbfunc_client_cycle, CWM_CONTEXT_CLIENT, { "rcycleingroup", kbfunc_client_cycle, CWM_CONTEXT_CLIENT,
{.i = (CWM_CLIENT_RCYCLE | CWM_CLIENT_CYCLE_INGRP)} }, {.i = (CWM_CLIENT_RCYCLE | CWM_CLIENT_CYCLE_INGRP)} },
{ "grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT, { "grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT, {0}},
{.i = CWM_KBD}},
{ "stick", kbfunc_client_toggle_sticky, CWM_CONTEXT_CLIENT, {0} }, { "stick", kbfunc_client_toggle_sticky, CWM_CONTEXT_CLIENT, {0} },
{ "fullscreen", kbfunc_client_toggle_fullscreen, CWM_CONTEXT_CLIENT, { "fullscreen", kbfunc_client_toggle_fullscreen, CWM_CONTEXT_CLIENT,
{0} }, {0} },
@ -489,14 +488,10 @@ static const struct {
{ "window_hide", kbfunc_client_hide, CWM_CONTEXT_CLIENT, {0} }, { "window_hide", kbfunc_client_hide, CWM_CONTEXT_CLIENT, {0} },
{ "window_move", mousefunc_client_move, CWM_CONTEXT_CLIENT, {0} }, { "window_move", mousefunc_client_move, CWM_CONTEXT_CLIENT, {0} },
{ "window_resize", mousefunc_client_resize, CWM_CONTEXT_CLIENT, {0} }, { "window_resize", mousefunc_client_resize, CWM_CONTEXT_CLIENT, {0} },
{ "window_grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT, { "window_grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT, {0} },
{.i = CWM_MOUSE} }, { "menu_group", kbfunc_menu_group, CWM_CONTEXT_SCREEN, {0} },
{ "menu_group", kbfunc_menu_group, CWM_CONTEXT_SCREEN, { "menu_unhide", kbfunc_menu_client, CWM_CONTEXT_SCREEN, {0} },
{.i = CWM_MOUSE} }, { "menu_cmd", kbfunc_menu_cmd, CWM_CONTEXT_SCREEN, {0} },
{ "menu_unhide", kbfunc_menu_client, CWM_CONTEXT_SCREEN,
{.i = CWM_MOUSE} },
{ "menu_cmd", kbfunc_menu_cmd, CWM_CONTEXT_SCREEN,
{.i = CWM_MOUSE} },
}; };
static const struct { static const struct {

View File

@ -41,14 +41,14 @@ extern sig_atomic_t cwm_status;
static void kbfunc_amount(int, int, unsigned int *, unsigned int *); static void kbfunc_amount(int, int, unsigned int *, unsigned int *);
void 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_ptrsave(cc);
client_lower(cc); client_lower(cc);
} }
void 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); client_raise(cc);
} }
@ -78,7 +78,7 @@ kbfunc_amount(int flags, int amt, unsigned int *mx, unsigned int *my)
} }
void 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; struct screen_ctx *sc = cc->sc;
int x, y; int x, y;
@ -91,7 +91,7 @@ kbfunc_ptrmove(struct client_ctx *cc, union arg *arg)
} }
void 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 screen_ctx *sc = cc->sc;
struct geom area; struct geom area;
@ -144,7 +144,7 @@ kbfunc_client_move(struct client_ctx *cc, union arg *arg)
} }
void 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; unsigned int mx = 0, my = 0;
int amt = 1; int amt = 1;
@ -173,13 +173,13 @@ kbfunc_client_resize(struct client_ctx *cc, union arg *arg)
} }
void 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 screen_ctx *sc = cc->sc;
struct client_ctx *old_cc; struct client_ctx *old_cc;
struct menu *mi; struct menu *mi;
struct menu_q menuq; struct menu_q menuq;
int m = (arg->i == CWM_MOUSE); int m = (xev == CWM_BTN);
old_cc = client_current(); old_cc = client_current();
@ -210,13 +210,13 @@ kbfunc_menu_client(struct client_ctx *cc, union arg *arg)
} }
void 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 screen_ctx *sc = cc->sc;
struct cmd *cmd; struct cmd *cmd;
struct menu *mi; struct menu *mi;
struct menu_q menuq; struct menu_q menuq;
int m = (arg->i == CWM_MOUSE); int m = (xev == CWM_BTN);
TAILQ_INIT(&menuq); TAILQ_INIT(&menuq);
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) { TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
@ -239,13 +239,13 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg)
} }
void 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 screen_ctx *sc = cc->sc;
struct group_ctx *gc; struct group_ctx *gc;
struct menu *mi; struct menu *mi;
struct menu_q menuq; struct menu_q menuq;
int m = (arg->i == CWM_MOUSE); int m = (xev == CWM_BTN);
TAILQ_INIT(&menuq); TAILQ_INIT(&menuq);
TAILQ_FOREACH(gc, &sc->groupq, entry) { TAILQ_FOREACH(gc, &sc->groupq, entry) {
@ -266,25 +266,25 @@ kbfunc_menu_group(struct client_ctx *cc, union arg *arg)
} }
void 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); client_cycle(cc->sc, arg->i);
} }
void 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); client_hide(cc);
} }
void 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); u_spawn(arg->c);
} }
void 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; struct cmd *cmd;
@ -295,7 +295,7 @@ kbfunc_exec_term(struct client_ctx *cc, union arg *arg)
} }
void 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; struct cmd *cmd;
@ -306,7 +306,7 @@ kbfunc_exec_lock(struct client_ctx *cc, union arg *arg)
} }
void 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 #define NPATHS 256
struct screen_ctx *sc = cc->sc; struct screen_ctx *sc = cc->sc;
@ -389,7 +389,7 @@ out:
} }
void 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 screen_ctx *sc = cc->sc;
struct cmd *cmd; struct cmd *cmd;
@ -456,7 +456,7 @@ out:
} }
void 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 *mi;
struct menu_q menuq; struct menu_q menuq;
@ -475,39 +475,39 @@ kbfunc_client_label(struct client_ctx *cc, union arg *arg)
} }
void 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); client_send_delete(cc);
} }
void 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); group_hidetoggle(cc->sc, arg->i);
} }
void 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); group_only(cc->sc, arg->i);
} }
void 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); group_cycle(cc->sc, arg->i);
} }
void 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); group_alltoggle(cc->sc);
} }
void 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. */ /* For X apps that steal events. */
XGrabKeyboard(X_Dpy, cc->win, True, XGrabKeyboard(X_Dpy, cc->win, True,
GrabModeAsync, GrabModeAsync, CurrentTime); GrabModeAsync, GrabModeAsync, CurrentTime);
@ -517,55 +517,55 @@ kbfunc_client_grouptoggle(struct client_ctx *cc, union arg *arg)
} }
void 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); group_movetogroup(cc, arg->i);
} }
void 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); client_toggle_sticky(cc);
} }
void 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); client_toggle_fullscreen(cc);
} }
void 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); client_toggle_maximize(cc);
} }
void 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); client_toggle_vmaximize(cc);
} }
void 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); client_toggle_hmaximize(cc);
} }
void 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); client_toggle_freeze(cc);
} }
void 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; cwm_status = arg->i;
} }
void 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) { switch (arg->i) {
case CWM_CLIENT_TILE_HORIZ: case CWM_CLIENT_TILE_HORIZ:

View File

@ -33,7 +33,7 @@
#include "calmwm.h" #include "calmwm.h"
void 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; XEvent ev;
Time ltime = 0; Time ltime = 0;
@ -88,7 +88,7 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg)
} }
void 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; XEvent ev;
Time ltime = 0; Time ltime = 0;

View File

@ -244,7 +244,7 @@ xev_handle_buttonpress(XEvent *ee)
return; return;
} }
(*mb->callback)(cc, &mb->argument); (*mb->callback)(cc, &mb->argument, CWM_BTN);
} }
static void static void
@ -298,7 +298,7 @@ xev_handle_keypress(XEvent *ee)
return; return;
} }
(*kb->callback)(cc, &kb->argument); (*kb->callback)(cc, &kb->argument, CWM_KEY);
} }
/* /*