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;
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

View File

@ -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();

View File

@ -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 */

View File

@ -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.

View File

@ -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);