sxhkd-rc

[fork] simple X hotkey daemon (but for the rc shell)
Log | Files | Refs | README | LICENSE

commit 07655dfe813db7750663fb178deda48cc5f0e640
parent 23dc78d4203fd15653d5f9037d8711f7e1b675cb
Author: Bastien Dejean <nihilhill@gmail.com>
Date:   Sun, 23 Mar 2014 12:09:18 +0100

Refactor prefix handling

Diffstat:
Mparse.c | 26+++++++++++++++-----------
Msxhkd.c | 10+++++-----
Mtypes.c | 12+++++++-----
Mtypes.h | 4++--
4 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/parse.c b/parse.c @@ -2665,17 +2665,21 @@ bool parse_chain(char *string, chain_t *chain) for (outer_advance = get_token(chord, ignored, string, LNK_SEP); chord[0] != '\0'; outer_advance = get_token(chord, ignored, outer_advance, LNK_SEP)) { for (inner_advance = get_token(name, NULL, chord, SYM_SEP); name[0] != '\0'; inner_advance = get_token(name, NULL, inner_advance, SYM_SEP)) { int offset = 0; - if (name[0] == RELEASE_PREFIX) { - event_type = XCB_KEY_RELEASE; - offset++; - } else if (name[0] == MOTION_PREFIX) { - event_type = XCB_MOTION_NOTIFY; - offset++; - } else if (name[0] == REPLAY_PREFIX) { - replay_event = true; - offset++; - } else if (name[0] == ROOT_PREFIX) { - from_root = true; + while (offset < (MAXLEN - 1) && !isalnum(name[offset]) && name[offset] != '_') { + switch (name[offset]) { + case RELEASE_PREFIX: + event_type = XCB_KEY_RELEASE; + break; + case MOTION_PREFIX: + event_type = XCB_MOTION_NOTIFY; + break; + case REPLAY_PREFIX: + replay_event = true; + break; + case ROOT_PREFIX: + from_root = true; + break; + } offset++; } char *nm = name + offset; diff --git a/sxhkd.c b/sxhkd.c @@ -200,14 +200,14 @@ void key_button_event(xcb_generic_event_t *evt, uint8_t event_type) xcb_button_t button = XCB_NONE; bool replay_event = false; bool from_root = false; + bool evt_from_root = false; uint16_t modfield = 0; uint16_t lockfield = num_lock | caps_lock | scroll_lock; - parse_event(evt, event_type, &keysym, &button, &modfield, &from_root); - PRINTF("from root: %u\n", from_root); + parse_event(evt, event_type, &keysym, &button, &modfield, &evt_from_root); modfield &= ~lockfield & MOD_STATE_FIELD; if (keysym != XCB_NO_SYMBOL || button != XCB_NONE) { - hotkey_t *hk = find_hotkey(keysym, button, modfield, event_type, &replay_event, from_root); - if (hk != NULL) { + hotkey_t *hk = find_hotkey(keysym, button, modfield, event_type, &replay_event, &from_root); + if (hk != NULL && (!from_root || evt_from_root)) { run(hk->command); if (status_fifo != NULL) put_status(COMMAND_PREFIX, hk->command); @@ -247,7 +247,7 @@ void motion_notify(xcb_generic_event_t *evt, uint8_t event_type) buttonfield = buttonfield >> 1; button++; } - hotkey_t *hk = find_hotkey(XCB_NO_SYMBOL, button, modfield, event_type, NULL, false); + hotkey_t *hk = find_hotkey(XCB_NO_SYMBOL, button, modfield, event_type, NULL, NULL); if (hk != NULL) { char command[2 * MAXLEN]; snprintf(command, sizeof(command), hk->command, e->root_x, e->root_y); diff --git a/types.c b/types.c @@ -34,7 +34,7 @@ #include "grab.h" #include "types.h" -hotkey_t *find_hotkey(xcb_keysym_t keysym, xcb_button_t button, uint16_t modfield, uint8_t event_type, bool *replay_event, bool from_root) +hotkey_t *find_hotkey(xcb_keysym_t keysym, xcb_button_t button, uint16_t modfield, uint8_t event_type, bool *replay_event, bool *from_root) { int num_active = 0; hotkey_t *result = NULL; @@ -43,7 +43,7 @@ hotkey_t *find_hotkey(xcb_keysym_t keysym, xcb_button_t button, uint16_t modfiel chain_t *c = hk->chain; if (chained && c->state == c->head) continue; - if (match_chord(c->state, event_type, keysym, button, modfield, from_root)) { + if (match_chord(c->state, event_type, keysym, button, modfield)) { if (status_fifo != NULL && num_active == 0) { if (!chained) { snprintf(progress, sizeof(progress), "%s", c->state->repr); @@ -55,6 +55,8 @@ hotkey_t *find_hotkey(xcb_keysym_t keysym, xcb_button_t button, uint16_t modfiel } if (replay_event != NULL && c->state->replay_event) *replay_event = true; + if (from_root != NULL && c->state->from_root) + *from_root = true; if (!locked && c->state->lock_chain) { locked = true; if (timeout > 0) @@ -91,7 +93,7 @@ hotkey_t *find_hotkey(xcb_keysym_t keysym, xcb_button_t button, uint16_t modfiel if (!chained) { if (num_active > 0) chained = true; - } else if (num_active == 0 || (locked && match_chord(escape_chord, event_type, keysym, button, modfield, from_root))) { + } else if (num_active == 0 || (locked && match_chord(escape_chord, event_type, keysym, button, modfield))) { abort_chain(); return find_hotkey(keysym, button, modfield, event_type, replay_event, from_root); } @@ -102,10 +104,10 @@ hotkey_t *find_hotkey(xcb_keysym_t keysym, xcb_button_t button, uint16_t modfiel return NULL; } -bool match_chord(chord_t *chord, uint8_t event_type, xcb_keysym_t keysym, xcb_button_t button, uint16_t modfield, bool from_root) +bool match_chord(chord_t *chord, uint8_t event_type, xcb_keysym_t keysym, xcb_button_t button, uint16_t modfield) { for (chord_t *c = chord; c != NULL; c = c->more) - if (c->event_type == event_type && c->keysym == keysym && c->button == button && c->modfield == modfield && (!c->from_root || from_root)) + if (c->event_type == event_type && c->keysym == keysym && c->button == button && c->modfield == modfield) return true; return false; } diff --git a/types.h b/types.h @@ -79,8 +79,8 @@ typedef struct { xcb_keysym_t Alt_L, Alt_R, Super_L, Super_R, Hyper_L, Hyper_R, Meta_L, Meta_R, Mode_switch, Num_Lock, Scroll_Lock; -hotkey_t *find_hotkey(xcb_keysym_t keysym, xcb_button_t button, uint16_t modfield, uint8_t event_type, bool *replay_event, bool from_root); -bool match_chord(chord_t *chord, uint8_t event_type, xcb_keysym_t keysym, xcb_button_t button, uint16_t modfield, bool from_root); +hotkey_t *find_hotkey(xcb_keysym_t keysym, xcb_button_t button, uint16_t modfield, uint8_t event_type, bool *replay_event, bool *from_root); +bool match_chord(chord_t *chord, uint8_t event_type, xcb_keysym_t keysym, xcb_button_t button, uint16_t modfield); chord_t *make_chord(xcb_keysym_t keysym, xcb_button_t button, uint16_t modfield, uint8_t event_type, bool replay_event, bool lock_chain, bool from_root); void add_chord(chain_t *chain, chord_t *chord); chain_t *make_chain(void);