From: Michael Stapelberg Date: Tue, 19 May 2009 13:22:50 +0000 (+0200) Subject: Bugfix: Correctly handle mode_switch state bit, more debugging output for states X-Git-Tag: 3.b~103 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d98c514f8252fb73502be184481083943167e2e1;p=i3%2Fi3 Bugfix: Correctly handle mode_switch state bit, more debugging output for states We abuse (1 << 8) as mode_switch bit, which is in the range of the filtered state bits (see previous commit). Therefore, we need to filter first and then check for mode_switch. Furthermore, we used 0x2 before, which was just wrong. So, use our bitmask, not the normal one (0x2). --- diff --git a/src/handlers.c b/src/handlers.c index bc98c86f..da556459 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -97,23 +97,24 @@ int handle_key_release(void *ignored, xcb_connection_t *conn, xcb_key_release_ev * */ int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press_event_t *event) { - LOG("Keypress %d\n", event->detail); + LOG("Keypress %d, state raw = %d\n", event->detail, event->state); + + /* Remove the numlock bit, all other bits are modifiers we can bind to */ + uint16_t state_filtered = event->state & ~(xcb_numlock_mask | XCB_MOD_MASK_LOCK); + LOG("(removed numlock, state = %d)\n", state_filtered); + /* Only use the lower 8 bits of the state (modifier masks) so that mouse + * button masks are filtered out */ + state_filtered &= 0xFF; + LOG("(removed upper 8 bits, state = %d)\n", state_filtered); /* We need to get the keysym group (There are group 1 to group 4, each holding two keysyms (without shift and with shift) using Xkb because X fails to provide them reliably (it works in Xephyr, it does not in real X) */ XkbStateRec state; if (XkbGetState(xkbdpy, XkbUseCoreKbd, &state) == Success && (state.group+1) == 2) - event->state |= 0x2; - - LOG("state %d\n", event->state); + state_filtered |= BIND_MODE_SWITCH; - /* Remove the numlock bit, all other bits are modifiers we can bind to */ - uint16_t state_filtered = event->state & ~(xcb_numlock_mask | XCB_MOD_MASK_LOCK); - - /* Only use the lower 8 bits of the state (modifier masks) so that mouse - * button masks are filtered out */ - state_filtered &= 0xFF; + LOG("(checked mode_switch, state %d)\n", state_filtered); /* Find the binding */ Binding *bind; @@ -130,7 +131,7 @@ int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press_event_ } parse_command(conn, bind->command); - if (event->state & 0x2) { + if (state_filtered & BIND_MODE_SWITCH) { LOG("Mode_switch -> allow_events(SyncKeyboard)\n"); xcb_allow_events(conn, SyncKeyboard, event->time); xcb_flush(conn);