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 <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2019-02-18 10:42:29 +01:00
parent 052f6fb89d
commit a22479c97b
5 changed files with 19 additions and 12 deletions

View File

@ -459,7 +459,7 @@ event_handle_configurenotify(xcb_configure_notify_event_t *ev)
xcb_screen_t *screen = globalconf.screen; xcb_screen_t *screen = globalconf.screen;
if(ev->window == screen->root) if(ev->window == screen->root)
globalconf.screen_need_refresh = true; screen_schedule_refresh();
/* Copy what XRRUpdateConfiguration() would do: Update the configuration */ /* Copy what XRRUpdateConfiguration() would do: Update the configuration */
if(ev->window == screen->root) { 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->height_in_millimeters = ev->mheight;;
} }
globalconf.screen_need_refresh = true; screen_schedule_refresh();
} }
/** XRandR event handler for RRNotify subtype XRROutputChangeNotifyEvent /** XRandR event handler for RRNotify subtype XRROutputChangeNotifyEvent

View File

@ -39,9 +39,6 @@ void client_refresh(void);
void client_focus_refresh(void); void client_focus_refresh(void);
void client_destroy_later(void); void client_destroy_later(void);
/* objects/screen.c */
void screen_refresh(void);
/* xkb.c */ /* xkb.c */
void xkb_refresh(void); void xkb_refresh(void);
@ -49,7 +46,6 @@ static inline int
awesome_refresh(void) awesome_refresh(void)
{ {
xkb_refresh(); xkb_refresh();
screen_refresh();
luaA_emit_refresh(); luaA_emit_refresh();
drawin_refresh(); drawin_refresh();
client_refresh(); client_refresh();

View File

@ -101,7 +101,7 @@ typedef struct
/** Do we have RandR 1.5 or newer? */ /** Do we have RandR 1.5 or newer? */
bool have_randr_15; bool have_randr_15;
/** Do we have a RandR screen update pending? */ /** Do we have a RandR screen update pending? */
bool screen_need_refresh; bool screen_refresh_pending;
/** Check for XTest extension */ /** Check for XTest extension */
bool have_xtest; bool have_xtest;
/** Check for SHAPE extension */ /** Check for SHAPE extension */

View File

@ -661,12 +661,10 @@ screen_modified(screen_t *existing_screen, screen_t *other_screen)
} }
} }
void static gboolean
screen_refresh(void) screen_refresh(gpointer unused)
{ {
if(!globalconf.screen_need_refresh || !globalconf.have_randr_13) globalconf.screen_refresh_pending = false;
return;
globalconf.screen_need_refresh = false;
screen_array_t new_screens; screen_array_t new_screens;
screen_array_t removed_screens; screen_array_t removed_screens;
@ -740,6 +738,18 @@ screen_refresh(void)
if (list_changed) if (list_changed)
luaA_class_emit_signal(L, &screen_class, "list", 0); 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. /** Return the squared distance of the given screen to the coordinates.

View File

@ -56,6 +56,7 @@ void screen_client_moveto(client_t *, screen_t *, bool);
void screen_update_primary(void); void screen_update_primary(void);
void screen_update_workarea(screen_t *); void screen_update_workarea(screen_t *);
screen_t *screen_get_primary(void); screen_t *screen_get_primary(void);
void screen_schedule_refresh(void);
screen_t *luaA_checkscreen(lua_State *, int); screen_t *luaA_checkscreen(lua_State *, int);