mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
Merge keybinding and mousebinding queues into using the same merged
struct, binding; they were essentially the same accept for what was 'pressed', keysym or button.
This commit is contained in:
parent
4438970b64
commit
db0b2fde5c
26
calmwm.h
26
calmwm.h
@ -94,6 +94,11 @@ union arg {
|
||||
int i;
|
||||
};
|
||||
|
||||
union press {
|
||||
KeySym keysym;
|
||||
unsigned int button;
|
||||
};
|
||||
|
||||
enum cursor_font {
|
||||
CF_DEFAULT,
|
||||
CF_MOVE,
|
||||
@ -247,26 +252,17 @@ struct screen_ctx {
|
||||
};
|
||||
TAILQ_HEAD(screen_ctx_q, screen_ctx);
|
||||
|
||||
struct keybinding {
|
||||
TAILQ_ENTRY(keybinding) entry;
|
||||
struct binding {
|
||||
TAILQ_ENTRY(binding) entry;
|
||||
void (*callback)(struct client_ctx *, union arg *);
|
||||
union arg argument;
|
||||
unsigned int modmask;
|
||||
KeySym keysym;
|
||||
union press press;
|
||||
int flags;
|
||||
int argtype;
|
||||
};
|
||||
TAILQ_HEAD(keybinding_q, keybinding);
|
||||
|
||||
struct mousebinding {
|
||||
TAILQ_ENTRY(mousebinding) entry;
|
||||
void (*callback)(struct client_ctx *, union arg *);
|
||||
union arg argument;
|
||||
unsigned int modmask;
|
||||
unsigned int button;
|
||||
int flags;
|
||||
};
|
||||
TAILQ_HEAD(mousebinding_q, mousebinding);
|
||||
TAILQ_HEAD(keybinding_q, binding);
|
||||
TAILQ_HEAD(mousebinding_q, binding);
|
||||
|
||||
struct cmd {
|
||||
TAILQ_ENTRY(cmd) entry;
|
||||
@ -290,10 +286,10 @@ TAILQ_HEAD(menu_q, menu);
|
||||
|
||||
struct conf {
|
||||
struct keybinding_q keybindingq;
|
||||
struct mousebinding_q mousebindingq;
|
||||
struct autogroupwin_q autogroupq;
|
||||
struct winmatch_q ignoreq;
|
||||
struct cmd_q cmdq;
|
||||
struct mousebinding_q mousebindingq;
|
||||
#define CONF_STICKY_GROUPS 0x0001
|
||||
int flags;
|
||||
#define CONF_BWIDTH 1
|
||||
|
45
conf.c
45
conf.c
@ -33,8 +33,8 @@
|
||||
|
||||
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 keybinding *);
|
||||
static void conf_unbind_mouse(struct conf *, struct mousebinding *);
|
||||
static void conf_unbind_kbd(struct conf *, struct binding *);
|
||||
static void conf_unbind_mouse(struct conf *, struct binding *);
|
||||
|
||||
int
|
||||
conf_cmd_add(struct conf *c, const char *name, const char *path)
|
||||
@ -288,10 +288,9 @@ void
|
||||
conf_clear(struct conf *c)
|
||||
{
|
||||
struct autogroupwin *ag;
|
||||
struct keybinding *kb;
|
||||
struct binding *kb, *mb;
|
||||
struct winmatch *wm;
|
||||
struct cmd *cmd;
|
||||
struct mousebinding *mb;
|
||||
int i;
|
||||
|
||||
while ((cmd = TAILQ_FIRST(&c->cmdq)) != NULL) {
|
||||
@ -491,16 +490,16 @@ conf_bind_getmask(const char *name, unsigned int *mask)
|
||||
int
|
||||
conf_bind_kbd(struct conf *c, const char *bind, const char *cmd)
|
||||
{
|
||||
struct keybinding *kb;
|
||||
const char *key;
|
||||
unsigned int i, mask;
|
||||
struct binding *kb;
|
||||
const char *key;
|
||||
unsigned int i, mask;
|
||||
|
||||
kb = xcalloc(1, sizeof(*kb));
|
||||
key = conf_bind_getmask(bind, &mask);
|
||||
kb->modmask |= mask;
|
||||
|
||||
kb->keysym = XStringToKeysym(key);
|
||||
if (kb->keysym == NoSymbol) {
|
||||
kb->press.keysym = XStringToKeysym(key);
|
||||
if (kb->press.keysym == NoSymbol) {
|
||||
warnx("unknown symbol: %s", key);
|
||||
free(kb);
|
||||
return (0);
|
||||
@ -535,15 +534,15 @@ conf_bind_kbd(struct conf *c, const char *bind, const char *cmd)
|
||||
}
|
||||
|
||||
static void
|
||||
conf_unbind_kbd(struct conf *c, struct keybinding *unbind)
|
||||
conf_unbind_kbd(struct conf *c, struct binding *unbind)
|
||||
{
|
||||
struct keybinding *key = NULL, *keynxt;
|
||||
struct binding *key = NULL, *keynxt;
|
||||
|
||||
TAILQ_FOREACH_SAFE(key, &c->keybindingq, entry, keynxt) {
|
||||
if (key->modmask != unbind->modmask)
|
||||
continue;
|
||||
|
||||
if (key->keysym == unbind->keysym) {
|
||||
if (key->press.keysym == unbind->press.keysym) {
|
||||
TAILQ_REMOVE(&c->keybindingq, key, entry);
|
||||
if (key->argtype & ARG_CHAR)
|
||||
free(key->argument.c);
|
||||
@ -574,15 +573,15 @@ static const struct {
|
||||
int
|
||||
conf_bind_mouse(struct conf *c, const char *bind, const char *cmd)
|
||||
{
|
||||
struct mousebinding *mb;
|
||||
const char *button, *errstr;
|
||||
unsigned int i, mask;
|
||||
struct binding *mb;
|
||||
const char *button, *errstr;
|
||||
unsigned int i, mask;
|
||||
|
||||
mb = xcalloc(1, sizeof(*mb));
|
||||
button = conf_bind_getmask(bind, &mask);
|
||||
mb->modmask |= mask;
|
||||
|
||||
mb->button = strtonum(button, Button1, Button5, &errstr);
|
||||
mb->press.button = strtonum(button, Button1, Button5, &errstr);
|
||||
if (errstr) {
|
||||
warnx("button number is %s: %s", errstr, button);
|
||||
free(mb);
|
||||
@ -612,15 +611,15 @@ conf_bind_mouse(struct conf *c, const char *bind, const char *cmd)
|
||||
}
|
||||
|
||||
static void
|
||||
conf_unbind_mouse(struct conf *c, struct mousebinding *unbind)
|
||||
conf_unbind_mouse(struct conf *c, struct binding *unbind)
|
||||
{
|
||||
struct mousebinding *mb = NULL, *mbnxt;
|
||||
struct binding *mb = NULL, *mbnxt;
|
||||
|
||||
TAILQ_FOREACH_SAFE(mb, &c->mousebindingq, entry, mbnxt) {
|
||||
if (mb->modmask != unbind->modmask)
|
||||
continue;
|
||||
|
||||
if (mb->button == unbind->button) {
|
||||
if (mb->press.button == unbind->press.button) {
|
||||
TAILQ_REMOVE(&c->mousebindingq, mb, entry);
|
||||
free(mb);
|
||||
}
|
||||
@ -647,25 +646,25 @@ conf_cursor(struct conf *c)
|
||||
void
|
||||
conf_grab_mouse(Window win)
|
||||
{
|
||||
struct mousebinding *mb;
|
||||
struct binding *mb;
|
||||
|
||||
xu_btn_ungrab(win);
|
||||
|
||||
TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) {
|
||||
if (mb->flags & CWM_WIN)
|
||||
xu_btn_grab(win, mb->modmask, mb->button);
|
||||
xu_btn_grab(win, mb->modmask, mb->press.button);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
conf_grab_kbd(Window win)
|
||||
{
|
||||
struct keybinding *kb;
|
||||
struct binding *kb;
|
||||
|
||||
xu_key_ungrab(win);
|
||||
|
||||
TAILQ_FOREACH(kb, &Conf.keybindingq, entry)
|
||||
xu_key_grab(win, kb->modmask, kb->keysym);
|
||||
xu_key_grab(win, kb->modmask, kb->press.keysym);
|
||||
}
|
||||
|
||||
static char *cwmhints[] = {
|
||||
|
10
xevents.c
10
xevents.c
@ -224,12 +224,12 @@ xev_handle_buttonpress(XEvent *ee)
|
||||
{
|
||||
XButtonEvent *e = &ee->xbutton;
|
||||
struct client_ctx *cc, fakecc;
|
||||
struct mousebinding *mb;
|
||||
struct binding *mb;
|
||||
|
||||
e->state &= ~IGNOREMODMASK;
|
||||
|
||||
TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) {
|
||||
if (e->button == mb->button && e->state == mb->modmask)
|
||||
if (e->button == mb->press.button && e->state == mb->modmask)
|
||||
break;
|
||||
}
|
||||
|
||||
@ -263,7 +263,7 @@ xev_handle_keypress(XEvent *ee)
|
||||
{
|
||||
XKeyEvent *e = &ee->xkey;
|
||||
struct client_ctx *cc = NULL, fakecc;
|
||||
struct keybinding *kb;
|
||||
struct binding *kb;
|
||||
KeySym keysym, skeysym;
|
||||
unsigned int modshift;
|
||||
|
||||
@ -273,7 +273,7 @@ xev_handle_keypress(XEvent *ee)
|
||||
e->state &= ~IGNOREMODMASK;
|
||||
|
||||
TAILQ_FOREACH(kb, &Conf.keybindingq, entry) {
|
||||
if (keysym != kb->keysym && skeysym == kb->keysym)
|
||||
if (keysym != kb->press.keysym && skeysym == kb->press.keysym)
|
||||
modshift = ShiftMask;
|
||||
else
|
||||
modshift = 0;
|
||||
@ -281,7 +281,7 @@ xev_handle_keypress(XEvent *ee)
|
||||
if ((kb->modmask | modshift) != e->state)
|
||||
continue;
|
||||
|
||||
if (kb->keysym == (modshift == 0 ? keysym : skeysym))
|
||||
if (kb->press.keysym == (modshift == 0 ? keysym : skeysym))
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user