From a22479c97bb1e66fdb11e48d4337f49a4ada6d55 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 18 Feb 2019 10:42:29 +0100 Subject: [PATCH] Screen scanning: Use an idle source Instead of refreshing screens at the end of the current main loop iteration, this now uses a GLib idle source with a very low priority. This increases the chance of batching multiple refreshes together. Also, this means that awesome_refresh() does less work. Signed-off-by: Uli Schlachter --- event.c | 4 ++-- event.h | 4 ---- globalconf.h | 2 +- objects/screen.c | 20 +++++++++++++++----- objects/screen.h | 1 + 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/event.c b/event.c index 3325e668e..444ca08c0 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 ad270bcfd..1bb4eefbd 100644 --- a/event.h +++ b/event.h @@ -39,9 +39,6 @@ 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); @@ -49,7 +46,6 @@ 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 1001f9133..1415c087d 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 */ diff --git a/objects/screen.c b/objects/screen.c index 405cdb368..0800450fb 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 e7d828054..847998ae7 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);