summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2013-09-01 10:01:38 +0200
committerMichael Stapelberg <michael@stapelberg.de>2013-09-01 10:01:38 +0200
commit2f17b73e20abe4db814844367a0deb35dc26293a (patch)
tree76b5d2c28c96443b7fe81e9936a2d2ee15c353db
parentad47d80e22823322b7c5f5bc13dbaae87f0d07ee (diff)
Bugfix: update the initial keyboard modifier state (Thanks lee, Ran)
This should make the numpad work correctly.
-rw-r--r--i3lock.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/i3lock.c b/i3lock.c
index 9b68be5..74e15f2 100644
--- a/i3lock.c
+++ b/i3lock.c
@@ -1,7 +1,7 @@
/*
* vim:ts=4:sw=4:expandtab
*
- * © 2010-2012 Michael Stapelberg
+ * © 2010-2013 Michael Stapelberg
*
* See LICENSE for licensing information
*
@@ -81,6 +81,9 @@ void u8_dec(char *s, int *i) {
* Ideally, xkbcommon would ship something like this itself, but as of now
* (version 0.2.0), it doesn’t.
*
+ * TODO: Once xcb-xkb is enabled by default and released, we should port this
+ * code to xcb-xkb. See also https://github.com/xkbcommon/libxkbcommon/issues/1
+ *
*/
static bool load_keymap(void) {
bool ret = false;
@@ -127,6 +130,16 @@ static bool load_keymap(void) {
goto out;
}
+ /* Get the initial modifier state to be in sync with the X server.
+ * See https://github.com/xkbcommon/libxkbcommon/issues/1 for why we ignore
+ * the base and latched fields. */
+ XkbStateRec state_rec;
+ XkbGetState(display, XkbUseCoreKbd, &state_rec);
+
+ xkb_state_update_mask(new_state,
+ 0, 0, state_rec.locked_mods,
+ 0, 0, state_rec.locked_group);
+
if (xkb_state != NULL)
xkb_state_unref(xkb_state);
xkb_state = new_state;
@@ -682,6 +695,11 @@ int main(int argc, char *argv[]) {
cursor = create_cursor(conn, screen, win, curs_choice);
grab_pointer_and_keyboard(conn, screen, cursor);
+ /* Load the keymap again to sync the current modifier state. Since we first
+ * loaded the keymap, there might have been changes, but starting from now,
+ * we should get all key presses/releases due to having grabbed the
+ * keyboard. */
+ (void)load_keymap();
if (dpms)
dpms_turn_off_screen(conn);