sxhkd-rc

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

commit 2d484d0c9aa9b0a58042563acf3189592c3b2aec
parent b2cf2a90087a14c8a2d1e981cfb047f8c06912b7
Author: Bastien Dejean <nihilhill@gmail.com>
Date:   Mon, 16 Sep 2013 19:32:03 +0200

Handle mapping notify events

On each mapping notify events, the keyboard symbols are updated and the
configuration files are reloaded.

The keyboard layout can be changed on the fly (via setxkbmap).

Diffstat:
Mdoc/sxhkd.1 | 9+++++++--
Mdoc/sxhkd.1.txt | 3+++
Mgrab.c | 3+--
Msxhkd.c | 23++++++++++++++++++++++-
Msxhkd.h | 2++
5 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/doc/sxhkd.1 b/doc/sxhkd.1 @@ -2,12 +2,12 @@ .\" Title: sxhkd .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/> -.\" Date: 09/10/2013 +.\" Date: 09/16/2013 .\" Manual: Sxhkd Manual .\" Source: Sxhkd 0.4.3 .\" Language: English .\" -.TH "SXHKD" "1" "09/10/2013" "Sxhkd 0\&.4\&.3" "Sxhkd Manual" +.TH "SXHKD" "1" "09/16/2013" "Sxhkd 0\&.4\&.3" "Sxhkd Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -47,6 +47,11 @@ Print the synopsis to standard output and exit\&. Print the version information to standard output and exit\&. .RE .PP +\fB\-n\fR +.RS 4 +Ignore mapping notify events\&. +.RE +.PP \fB\-t\fR \fITIMEOUT\fR .RS 4 Timeout in seconds for the recording of chord chains\&. diff --git a/doc/sxhkd.1.txt b/doc/sxhkd.1.txt @@ -30,6 +30,9 @@ Options *-v*:: Print the version information to standard output and exit. +*-n*:: + Ignore mapping notify events. + *-t* _TIMEOUT_:: Timeout in seconds for the recording of chord chains. diff --git a/grab.c b/grab.c @@ -16,9 +16,8 @@ void grab_chord(chord_t *chord) xcb_keycode_t *keycodes = keycodes_from_keysym(c->keysym); if (keycodes != NULL) for (xcb_keycode_t *kc = keycodes; *kc != XCB_NO_SYMBOL; kc++) - if (c->keysym == xcb_key_symbols_get_keysym(symbols, *kc, 0)) { + if (c->keysym == xcb_key_symbols_get_keysym(symbols, *kc, 0)) grab_key_button(*kc, c->button, c->modfield); - } free(keycodes); } else { grab_key_button(XCB_NONE, c->button, c->modfield); diff --git a/sxhkd.c b/sxhkd.c @@ -24,9 +24,10 @@ int main(int argc, char *argv[]) char *fifo_path = NULL; status_fifo = NULL; config_path = NULL; + ignore_mapping = false; timeout = TIMEOUT; - while ((opt = getopt(argc, argv, "vht:c:r:s:")) != -1) { + while ((opt = getopt(argc, argv, "vhnt:c:r:s:")) != -1) { switch (opt) { case 'v': printf("%s\n", VERSION); @@ -36,6 +37,9 @@ int main(int argc, char *argv[]) printf("sxhkd [-h|-v|-t TIMEOUT|-c CONFIG_FILE|-r REDIR_FILE|-s STATUS_FIFO] [EXTRA_CONFIG ...]\n"); exit(EXIT_SUCCESS); break; + case 'n': + ignore_mapping = true; + break; case 't': timeout = atoi(optarg); break; @@ -116,6 +120,9 @@ int main(int argc, char *argv[]) case XCB_MOTION_NOTIFY: motion_notify(evt, event_type); break; + case XCB_MAPPING_NOTIFY: + mapping_notify(evt); + break; default: PRINTF("received event %u\n", event_type); break; @@ -212,6 +219,20 @@ void motion_notify(xcb_generic_event_t *evt, uint8_t event_type) } } + +void mapping_notify(xcb_generic_event_t *evt) +{ + if (ignore_mapping || !running || chained) + return; + xcb_mapping_notify_event_t *e = (xcb_mapping_notify_event_t *) evt; + PRINTF("mapping notify %u %u\n", e->request, e->count); + xcb_refresh_keyboard_mapping(symbols, e); + destroy_chord(escape_chord); + get_lock_fields(); + reload_cmd(); + escape_chord = make_chord(ESCAPE_KEYSYM, XCB_NONE, 0, XCB_KEY_PRESS, false, false); +} + void setup(void) { dpy = xcb_connect(NULL, NULL); diff --git a/sxhkd.h b/sxhkd.h @@ -28,6 +28,7 @@ int num_extra_confs; int redir_fd; FILE *status_fifo; char progress[MAXLEN]; +bool ignore_mapping; int timeout; hotkey_t *hotkeys, *hotkeys_tail; @@ -40,6 +41,7 @@ uint16_t scroll_lock; void key_button_event(xcb_generic_event_t *, uint8_t); void motion_notify(xcb_generic_event_t *, uint8_t); +void mapping_notify(xcb_generic_event_t *); void setup(void); void cleanup(void); void reload_cmd(void);