summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Grenville <[email protected]>2012-09-29 22:53:57 +0800
committerRichard Grenville <[email protected]>2012-09-29 22:53:57 +0800
commitec29300e2161eb5441871dce7ec7eadcb507dc5e (patch)
treedd0f7f19c95a2e486ad9eb0390b2d0a8e7cada77
parent83f64a227567dfd6ec6c7d60d3bd095cfb9bd93d (diff)
downloadtdebase-ec29300e2161eb5441871dce7ec7eadcb507dc5e.tar.gz
tdebase-ec29300e2161eb5441871dce7ec7eadcb507dc5e.zip
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.
-rw-r--r--compton.c20
-rw-r--r--compton.h1
2 files changed, 19 insertions, 2 deletions
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;
diff --git a/compton.h b/compton.h
index f3c32365d..3fd4541a4 100644
--- a/compton.h
+++ b/compton.h
@@ -321,6 +321,7 @@ typedef enum {
extern int root_height, root_width;
extern Atom atom_client_attr;
+extern Bool idling;
/**
* Functions