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.
This commit is contained in:
Richard Grenville 2012-09-29 22:53:57 +08:00
parent 5a3dfbc064
commit 8d7d6405b6
2 changed files with 19 additions and 2 deletions

View File

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

View File

@ -321,6 +321,7 @@ typedef enum {
extern int root_height, root_width;
extern Atom atom_client_attr;
extern Bool idling;
/**
* Functions