diff --git a/event.c b/event.c index 3325e668..444ca08c 100644 --- a/event.c +++ b/event.c @@ -459,7 +459,7 @@ event_handle_configurenotify(xcb_configure_notify_event_t *ev) xcb_screen_t *screen = globalconf.screen; if(ev->window == screen->root) - globalconf.screen_need_refresh = true; + screen_schedule_refresh(); /* Copy what XRRUpdateConfiguration() would do: Update the configuration */ if(ev->window == screen->root) { @@ -881,7 +881,7 @@ event_handle_randr_screen_change_notify(xcb_randr_screen_change_notify_event_t * globalconf.screen->height_in_millimeters = ev->mheight;; } - globalconf.screen_need_refresh = true; + screen_schedule_refresh(); } /** XRandR event handler for RRNotify subtype XRROutputChangeNotifyEvent diff --git a/event.h b/event.h index ad270bcf..8bada532 100644 --- a/event.h +++ b/event.h @@ -39,17 +39,9 @@ void client_refresh(void); void client_focus_refresh(void); void client_destroy_later(void); -/* objects/screen.c */ -void screen_refresh(void); - -/* xkb.c */ -void xkb_refresh(void); - static inline int awesome_refresh(void) { - xkb_refresh(); - screen_refresh(); luaA_emit_refresh(); drawin_refresh(); client_refresh(); diff --git a/globalconf.h b/globalconf.h index 1001f913..6ef0d206 100644 --- a/globalconf.h +++ b/globalconf.h @@ -101,7 +101,7 @@ typedef struct /** Do we have RandR 1.5 or newer? */ bool have_randr_15; /** Do we have a RandR screen update pending? */ - bool screen_need_refresh; + bool screen_refresh_pending; /** Check for XTest extension */ bool have_xtest; /** Check for SHAPE extension */ @@ -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/objects/screen.c b/objects/screen.c index 405cdb36..0800450f 100644 --- a/objects/screen.c +++ b/objects/screen.c @@ -661,12 +661,10 @@ screen_modified(screen_t *existing_screen, screen_t *other_screen) } } -void -screen_refresh(void) +static gboolean +screen_refresh(gpointer unused) { - if(!globalconf.screen_need_refresh || !globalconf.have_randr_13) - return; - globalconf.screen_need_refresh = false; + globalconf.screen_refresh_pending = false; screen_array_t new_screens; screen_array_t removed_screens; @@ -740,6 +738,18 @@ screen_refresh(void) if (list_changed) luaA_class_emit_signal(L, &screen_class, "list", 0); + + return G_SOURCE_REMOVE; +} + +void +screen_schedule_refresh(void) +{ + if(globalconf.screen_refresh_pending || !globalconf.have_randr_13) + return; + + globalconf.screen_refresh_pending = true; + g_idle_add_full(G_PRIORITY_LOW, screen_refresh, NULL, NULL); } /** Return the squared distance of the given screen to the coordinates. diff --git a/objects/screen.h b/objects/screen.h index e7d82805..847998ae 100644 --- a/objects/screen.h +++ b/objects/screen.h @@ -56,6 +56,7 @@ void screen_client_moveto(client_t *, screen_t *, bool); void screen_update_primary(void); void screen_update_workarea(screen_t *); screen_t *screen_get_primary(void); +void screen_schedule_refresh(void); screen_t *luaA_checkscreen(lua_State *, int); 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);