diff --git a/event.h b/event.h index 1bb4eefb..8bada532 100644 --- a/event.h +++ b/event.h @@ -39,13 +39,9 @@ void client_refresh(void); void client_focus_refresh(void); void client_destroy_later(void); -/* xkb.c */ -void xkb_refresh(void); - static inline int awesome_refresh(void) { - xkb_refresh(); luaA_emit_refresh(); drawin_refresh(); client_refresh(); diff --git a/globalconf.h b/globalconf.h index 1415c087..6ef0d206 100644 --- a/globalconf.h +++ b/globalconf.h @@ -189,6 +189,8 @@ typedef struct struct xkb_context *xkb_ctx; /* xkb state of dead keys on keyboard */ struct xkb_state *xkb_state; + /* Do we have a pending xkb update call? */ + bool xkb_update_pending; /* Do we have a pending reload? */ bool xkb_reload_keymap; /* Do we have a pending map change? */ diff --git a/xkb.c b/xkb.c index b92b2f38..04dd3b59 100644 --- a/xkb.c +++ b/xkb.c @@ -297,21 +297,33 @@ xkb_reload_keymap(void) } } -void -xkb_refresh(void) +static gboolean +xkb_refresh(gpointer unused) { lua_State *L = globalconf_get_lua_State(); + globalconf.xkb_update_pending = false; if (globalconf.xkb_reload_keymap) xkb_reload_keymap(); if (globalconf.xkb_map_changed) - signal_object_emit(L, &global_signals, "xkb::map_changed", 0); + signal_object_emit(L, &global_signals, "xkb::map_changed", 0); if (globalconf.xkb_group_changed) - signal_object_emit(L, &global_signals, "xkb::group_changed", 0); + signal_object_emit(L, &global_signals, "xkb::group_changed", 0); globalconf.xkb_reload_keymap = false; globalconf.xkb_map_changed = false; globalconf.xkb_group_changed = false; + + return G_SOURCE_REMOVE; +} + +static void +xkb_schedule_refresh(void) +{ + if (globalconf.xkb_update_pending) + return; + globalconf.xkb_update_pending = true; + g_idle_add_full(G_PRIORITY_LOW, xkb_refresh, NULL, NULL); } /** The xkb notify event handler. @@ -335,12 +347,14 @@ event_handle_xkb_notify(xcb_generic_event_t* event) if (new_keyboard_event->changed & XCB_XKB_NKN_DETAIL_KEYCODES) globalconf.xkb_map_changed = true; + xkb_schedule_refresh(); break; } case XCB_XKB_MAP_NOTIFY: { globalconf.xkb_reload_keymap = true; globalconf.xkb_map_changed = true; + xkb_schedule_refresh(); break; } case XCB_XKB_STATE_NOTIFY: @@ -356,7 +370,10 @@ event_handle_xkb_notify(xcb_generic_event_t* event) state_notify_event->lockedGroup); if (state_notify_event->changed & XCB_XKB_STATE_PART_GROUP_STATE) + { globalconf.xkb_group_changed = true; + xkb_schedule_refresh(); + } break; } @@ -369,6 +386,7 @@ event_handle_xkb_notify(xcb_generic_event_t* event) void xkb_init(void) { + globalconf.xkb_update_pending = false; globalconf.xkb_reload_keymap = false; globalconf.xkb_map_changed = false; globalconf.xkb_group_changed = false; diff --git a/xkb.h b/xkb.h index e854046e..fc91e1f9 100644 --- a/xkb.h +++ b/xkb.h @@ -26,7 +26,6 @@ #include void event_handle_xkb_notify(xcb_generic_event_t* event); -void xkb_refresh(void); void xkb_init(void); void xkb_free(void);