From c7fd4b39c61a97977fb18779a73f2c7799332e38 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 3 Mar 2015 09:46:16 +0100 Subject: [PATCH] Fix keyboard layout change detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …by listening to XKB_NEW_KEYBOARD events and re-allocating the keysym map on both XKB_NEW_KEYBOARD and XKB_MAP_NOTIFY. fixes #1302 --- src/handlers.c | 11 ++++++++++- src/main.c | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/handlers.c b/src/handlers.c index 3569710b..b0a27df5 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -1257,12 +1257,21 @@ void handle_event(int type, xcb_generic_event_t *event) { DLOG("xkb event, need to handle it.\n"); xcb_xkb_state_notify_event_t *state = (xcb_xkb_state_notify_event_t *)event; - if (state->xkbType == XCB_XKB_MAP_NOTIFY) { + if (state->xkbType == XCB_XKB_NEW_KEYBOARD_NOTIFY) { + DLOG("xkb new keyboard notify, sequence %d, time %d\n", state->sequence, state->time); + xcb_key_symbols_free(keysyms); + keysyms = xcb_key_symbols_alloc(conn); + ungrab_all_keys(conn); + translate_keysyms(); + grab_all_keys(conn, false); + } else if (state->xkbType == XCB_XKB_MAP_NOTIFY) { if (event_is_ignored(event->sequence, type)) { DLOG("Ignoring map notify event for sequence %d.\n", state->sequence); } else { DLOG("xkb map notify, sequence %d, time %d\n", state->sequence, state->time); add_ignore_event(event->sequence, type); + xcb_key_symbols_free(keysyms); + keysyms = xcb_key_symbols_alloc(conn); ungrab_all_keys(conn); translate_keysyms(); grab_all_keys(conn, false); diff --git a/src/main.c b/src/main.c index b696e031..473be1e5 100644 --- a/src/main.c +++ b/src/main.c @@ -536,9 +536,9 @@ int main(int argc, char *argv[]) { xcb_xkb_use_extension(conn, XCB_XKB_MAJOR_VERSION, XCB_XKB_MINOR_VERSION); xcb_xkb_select_events(conn, XCB_XKB_ID_USE_CORE_KBD, - XCB_XKB_EVENT_TYPE_STATE_NOTIFY | XCB_XKB_EVENT_TYPE_MAP_NOTIFY, + XCB_XKB_EVENT_TYPE_STATE_NOTIFY | XCB_XKB_EVENT_TYPE_MAP_NOTIFY | XCB_XKB_EVENT_TYPE_NEW_KEYBOARD_NOTIFY, 0, - XCB_XKB_EVENT_TYPE_STATE_NOTIFY | XCB_XKB_EVENT_TYPE_MAP_NOTIFY, + XCB_XKB_EVENT_TYPE_STATE_NOTIFY | XCB_XKB_EVENT_TYPE_MAP_NOTIFY | XCB_XKB_EVENT_TYPE_NEW_KEYBOARD_NOTIFY, 0xff, 0xff, NULL);