From fd707acac5d1a4ee53857d90d1aefb68d019073d Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Fri, 4 Mar 2016 08:15:12 +0100 Subject: [PATCH] Move keymap updating into right x11 event loop handler. --- source/rofi.c | 35 ++++++++++++++++++++++++- source/view.c | 71 +++++++++++++++++---------------------------------- 2 files changed, 57 insertions(+), 49 deletions(-) diff --git a/source/rofi.c b/source/rofi.c index 25683337..fad7da5e 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -446,6 +446,31 @@ static inline void load_configuration_dynamic ( ) */ static gboolean main_loop_x11_event_handler ( xcb_generic_event_t *ev, G_GNUC_UNUSED gpointer data ) { + uint8_t type = ev->response_type & ~0x80; + if ( type == xkb.first_event ) { + switch ( ev->pad0 ) + { + case XCB_XKB_MAP_NOTIFY: + xkb_state_unref ( xkb.state ); + xkb_keymap_unref ( xkb.keymap ); + xkb.keymap = xkb_x11_keymap_new_from_device ( xkb.context, xcb->connection, xkb.device_id, 0 ); + xkb.state = xkb_x11_state_new_from_device ( xkb.keymap, xcb->connection, xkb.device_id ); + break; + case XCB_XKB_STATE_NOTIFY: + { + xcb_xkb_state_notify_event_t *ksne = (xcb_xkb_state_notify_event_t *) ev; + xkb_state_update_mask ( xkb.state, + ksne->baseMods, + ksne->latchedMods, + ksne->lockedMods, + ksne->baseGroup, + ksne->latchedGroup, + ksne->lockedGroup ); + break; + } + } + return G_SOURCE_CONTINUE; + } RofiViewState *state = rofi_view_get_active (); if ( xcb->sndisplay != NULL ) { sn_xcb_display_process_event ( xcb->sndisplay, ev ); @@ -696,7 +721,15 @@ int main ( int argc, char *argv[] ) &details ); xkb.keymap = xkb_x11_keymap_new_from_device ( xkb.context, xcb->connection, xkb.device_id, XKB_KEYMAP_COMPILE_NO_FLAGS ); - xkb.state = xkb_x11_state_new_from_device ( xkb.keymap, xcb->connection, xkb.device_id ); + if ( xkb.keymap == NULL ) { + fprintf ( stderr, "Failed to get Keymap for current keyboard device.\n" ); + return EXIT_FAILURE; + } + xkb.state = xkb_x11_state_new_from_device ( xkb.keymap, xcb->connection, xkb.device_id ); + if ( xkb.state == NULL ) { + fprintf ( stderr, "Failed to get state object for current keyboard device.\n" ); + return EXIT_FAILURE; + } xkb.compose.table = xkb_compose_table_new_from_locale ( xkb.context, setlocale ( LC_CTYPE, NULL ), 0 ); if ( xkb.compose.table != NULL ) { diff --git a/source/view.c b/source/view.c index d5e25453..814d6a98 100644 --- a/source/view.c +++ b/source/view.c @@ -368,56 +368,31 @@ static void rofi_view_resize ( RofiViewState *state ) void rofi_view_itterrate ( RofiViewState *state, xcb_generic_event_t *event, xkb_stuff *xkb ) { uint8_t type = event->response_type & ~0x80; - if ( type == xkb->first_event ) { - switch ( event->pad0 ) - { - case XCB_XKB_MAP_NOTIFY: - xkb_state_unref ( xkb->state ); - xkb_keymap_unref ( xkb->keymap ); - xkb->keymap = xkb_x11_keymap_new_from_device ( xkb->context, xcb->connection, xkb->device_id, 0 ); - xkb->state = xkb_x11_state_new_from_device ( xkb->keymap, xcb->connection, xkb->device_id ); - break; - case XCB_XKB_STATE_NOTIFY: - { - xcb_xkb_state_notify_event_t *ksne = (xcb_xkb_state_notify_event_t *) event; - xkb_state_update_mask ( xkb->state, - ksne->baseMods, - ksne->latchedMods, - ksne->lockedMods, - ksne->baseGroup, - ksne->latchedGroup, - ksne->lockedGroup ); - break; - } - } - } - else{ - switch ( type ) - { - case XCB_EXPOSE: - state->update = TRUE; - break; - case XCB_CONFIGURE_NOTIFY: - { - xcb_configure_notify_event_t *xce = (xcb_configure_notify_event_t *) event; - if ( xce->window == state->window ) { - if ( state->x != xce->x || state->y != xce->y ) { - state->x = xce->x; - state->y = xce->y; - state->update = TRUE; - } - if ( state->w != xce->width || state->h != xce->height ) { - state->w = xce->width; - state->h = xce->height; - cairo_xcb_surface_set_size ( surface, state->w, state->h ); - rofi_view_resize ( state ); - } + switch ( type ) + { + case XCB_EXPOSE: + state->update = TRUE; + break; + case XCB_CONFIGURE_NOTIFY: + { + xcb_configure_notify_event_t *xce = (xcb_configure_notify_event_t *) event; + if ( xce->window == state->window ) { + if ( state->x != xce->x || state->y != xce->y ) { + state->x = xce->x; + state->y = xce->y; + state->update = TRUE; + } + if ( state->w != xce->width || state->h != xce->height ) { + state->w = xce->width; + state->h = xce->height; + cairo_xcb_surface_set_size ( surface, state->w, state->h ); + rofi_view_resize ( state ); } - break; - } - default: - state->x11_event_loop ( state, event, xkb ); } + break; + } + default: + state->x11_event_loop ( state, event, xkb ); } rofi_view_update ( state ); }