From e2562227ab8f123a526cf0a1478c2d37d25d1e02 Mon Sep 17 00:00:00 2001 From: Peter Junos Date: Thu, 21 May 2015 21:21:34 +0200 Subject: [PATCH] Less reloading of keymap, fixes from psychon comments Response to psychon comments in PR#227 - https://github.com/awesomeWM/awesome/pull/227 With this commit, we don't reload keymap, when we are not notified about its change. --- keygrabber.c | 2 -- objects/key.c | 1 + xkb.c | 29 +++++++++++++++++++++-------- xkb.h | 2 -- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/keygrabber.c b/keygrabber.c index 0b31768d..caef9161 100644 --- a/keygrabber.c +++ b/keygrabber.c @@ -20,8 +20,6 @@ */ #include -#include -#include #include #include diff --git a/objects/key.c b/objects/key.c index 231a2622..0e481908 100644 --- a/objects/key.c +++ b/objects/key.c @@ -26,6 +26,7 @@ /* XStringToKeysym() and XKeysymToString */ #include +#include static void luaA_keystore(lua_State *L, int ud, const char *str, ssize_t len) diff --git a/xkb.c b/xkb.c index 155c3fcb..7de9ed37 100644 --- a/xkb.c +++ b/xkb.c @@ -143,7 +143,7 @@ xkb_fill_state(void) if (!globalconf.xkb_state) fatal("Failed while getting XKB state from device"); - /* xkb_keymap is no longer referenced directly; decreasing refcount */ + /* xkb_keymap is no longer referenced directly; decreasing refcount */ xkb_keymap_unref(xkb_keymap); } @@ -158,7 +158,7 @@ xkb_init_keymap(void) if (!globalconf.xkb_ctx) fatal("Failed while getting XKB context"); - xkb_fill_state(); + xkb_fill_state(); } /** Frees xkb context, state and keymap from globalconf. @@ -172,13 +172,14 @@ xkb_free_keymap(void) } /** Rereads the state of keyboard from X. - * This call should be used after changing keyboard layouts or using dead keys + * This call should be used after receiving NewKeyboardNotify or MapNotify, + * as written in http://xkbcommon.org/doc/current/group__x11.html */ static void xkb_reload_keymap(void) { xkb_state_unref(globalconf.xkb_state); - xkb_fill_state(); + xkb_fill_state(); } /** The xkb notify event handler. @@ -189,9 +190,6 @@ event_handle_xkb_notify(xcb_generic_event_t* event) { lua_State *L = globalconf_get_lua_State(); - /* something has changed, reload keymap in case someone pressed dead key */ - xkb_reload_keymap(); - /* The pad0 field of xcb_generic_event_t contains the event sub-type, * unfortunately xkb doesn't provide a usable struct for getting this in a * nicer way*/ @@ -200,11 +198,18 @@ event_handle_xkb_notify(xcb_generic_event_t* event) case XCB_XKB_NEW_KEYBOARD_NOTIFY: { xcb_xkb_new_keyboard_notify_event_t *new_keyboard_event = (void*)event; + + xkb_reload_keymap(); + if (new_keyboard_event->changed & XCB_XKB_NKN_DETAIL_KEYCODES) { signal_object_emit(L, &global_signals, "xkb::map_changed", 0); } - + break; + } + case XCB_XKB_MAP_NOTIFY: + { + xkb_reload_keymap(); break; } case XCB_XKB_NAMES_NOTIFY: @@ -216,6 +221,14 @@ event_handle_xkb_notify(xcb_generic_event_t* event) { xcb_xkb_state_notify_event_t *state_notify_event = (void*)event; + xkb_state_update_mask(globalconf.xkb_state, + state_notify_event->baseMods, + state_notify_event->latchedMods, + state_notify_event->lockedMods, + state_notify_event->baseGroup, + state_notify_event->latchedGroup, + state_notify_event->lockedGroup); + if (state_notify_event->changed & XCB_XKB_STATE_PART_GROUP_STATE) { lua_pushnumber(L, state_notify_event->group); diff --git a/xkb.h b/xkb.h index 776638ab..c3987157 100644 --- a/xkb.h +++ b/xkb.h @@ -23,8 +23,6 @@ #define AWESOME_XKB_H #include -#include -#include #include void event_handle_xkb_notify(xcb_generic_event_t* event);