From ec29300e2161eb5441871dce7ec7eadcb507dc5e Mon Sep 17 00:00:00 2001 From: Richard Grenville Date: Sat, 29 Sep 2012 22:53:57 +0800 Subject: Improvement: Wait infinitely for events when idling Wait infinitely for events when idling, instead of always calling paint_preprocess(), to reduce CPU usage in the case. Thanks to valr for help. --- compton.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'compton.c') diff --git a/compton.c b/compton.c index 7beafd4f5..9e6d45b27 100644 --- a/compton.c +++ b/compton.c @@ -51,6 +51,9 @@ XserverRegion all_damage; Bool has_name_pixmap; #endif int root_height, root_width; +/// Whether the program is idling. I.e. no fading, no potential window +/// changes. +Bool idling; /* errors */ ignore *ignore_head = NULL, **ignore_tail = &ignore_head; @@ -207,6 +210,9 @@ run_fade(Display *dpy, win *w, unsigned steps) { w->fade_fin = True; return; } + else { + idling = False; + } w->fade_fin = False; } @@ -224,8 +230,12 @@ set_fade_callback(Display *dpy, win *w, w->fade_callback = callback; // Must be the last line as the callback could destroy w! - if (exec_callback && old_callback) + if (exec_callback && old_callback) { old_callback(dpy, w); + // Although currently no callback function affects window state on + // next paint, it could, in the future + idling = False; + } } /** @@ -3613,10 +3623,13 @@ main(int argc, char **argv) { t = paint_preprocess(dpy, list); paint_all(dpy, None, t); + // Initialize idling + idling = False; + for (;;) { do { if (!QLength(dpy)) { - if (poll(&ufd, 1, fade_timeout()) == 0) { + if (poll(&ufd, 1, (idling ? -1: fade_timeout())) == 0) { break; } } @@ -3625,6 +3638,9 @@ main(int argc, char **argv) { ev_handle((XEvent *)&ev); } while (QLength(dpy)); + // idling will be turned off during paint_preprocess() if needed + idling = True; + t = paint_preprocess(dpy, list); if (all_damage) { static int paint; -- cgit v1.2.1