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:
parent
5a3dfbc064
commit
8d7d6405b6
|
@ -51,6 +51,9 @@ XserverRegion all_damage;
|
||||||
Bool has_name_pixmap;
|
Bool has_name_pixmap;
|
||||||
#endif
|
#endif
|
||||||
int root_height, root_width;
|
int root_height, root_width;
|
||||||
|
/// Whether the program is idling. I.e. no fading, no potential window
|
||||||
|
/// changes.
|
||||||
|
Bool idling;
|
||||||
|
|
||||||
/* errors */
|
/* errors */
|
||||||
ignore *ignore_head = NULL, **ignore_tail = &ignore_head;
|
ignore *ignore_head = NULL, **ignore_tail = &ignore_head;
|
||||||
|
@ -207,6 +210,9 @@ run_fade(Display *dpy, win *w, unsigned steps) {
|
||||||
w->fade_fin = True;
|
w->fade_fin = True;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
idling = False;
|
||||||
|
}
|
||||||
|
|
||||||
w->fade_fin = False;
|
w->fade_fin = False;
|
||||||
}
|
}
|
||||||
|
@ -224,8 +230,12 @@ set_fade_callback(Display *dpy, win *w,
|
||||||
|
|
||||||
w->fade_callback = callback;
|
w->fade_callback = callback;
|
||||||
// Must be the last line as the callback could destroy w!
|
// 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);
|
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);
|
t = paint_preprocess(dpy, list);
|
||||||
paint_all(dpy, None, t);
|
paint_all(dpy, None, t);
|
||||||
|
|
||||||
|
// Initialize idling
|
||||||
|
idling = False;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
do {
|
do {
|
||||||
if (!QLength(dpy)) {
|
if (!QLength(dpy)) {
|
||||||
if (poll(&ufd, 1, fade_timeout()) == 0) {
|
if (poll(&ufd, 1, (idling ? -1: fade_timeout())) == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3625,6 +3638,9 @@ main(int argc, char **argv) {
|
||||||
ev_handle((XEvent *)&ev);
|
ev_handle((XEvent *)&ev);
|
||||||
} while (QLength(dpy));
|
} while (QLength(dpy));
|
||||||
|
|
||||||
|
// idling will be turned off during paint_preprocess() if needed
|
||||||
|
idling = True;
|
||||||
|
|
||||||
t = paint_preprocess(dpy, list);
|
t = paint_preprocess(dpy, list);
|
||||||
if (all_damage) {
|
if (all_damage) {
|
||||||
static int paint;
|
static int paint;
|
||||||
|
|
|
@ -321,6 +321,7 @@ typedef enum {
|
||||||
|
|
||||||
extern int root_height, root_width;
|
extern int root_height, root_width;
|
||||||
extern Atom atom_client_attr;
|
extern Atom atom_client_attr;
|
||||||
|
extern Bool idling;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functions
|
* Functions
|
||||||
|
|
Loading…
Reference in New Issue