summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-16 02:41:53 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-16 02:41:53 +0100
commit4fcb748f95d8164dedcf294d310dfbd556e11307 (patch)
tree2fe88cbaf81ed196dd4dab4edde58f1817bebc16
parentlicensing (diff)
downloadblueshift-4fcb748f95d8164dedcf294d310dfbd556e11307.tar.gz
blueshift-4fcb748f95d8164dedcf294d310dfbd556e11307.tar.bz2
blueshift-4fcb748f95d8164dedcf294d310dfbd556e11307.tar.xz
fix sleep regression buf + improve xmonad example to listen for changes
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--examples/xmonad9
-rwxr-xr-xsrc/__main__.py17
2 files changed, 16 insertions, 10 deletions
diff --git a/examples/xmonad b/examples/xmonad
index 8c8a824..444edfb 100644
--- a/examples/xmonad
+++ b/examples/xmonad
@@ -35,7 +35,7 @@
# Additionally python3-xlib is required to be installed.
-import Xlib.display
+import Xlib.display, Xlib.X
# Gamma (red, green and blue), per monitor.
@@ -55,7 +55,7 @@ _ = 0.8
non_rat_brightness = [_, _, _, _, _, _, _, _, 1]
-wait_period = 0.2 # TODO it is better to wait for updates
+wait_period = 0
'''
:float The number of seconds to wait before invoking `periodically` again
'''
@@ -79,6 +79,9 @@ x_root = x_screen.root
x_utf8 = x_display.intern_atom('UTF8_STRING')
xmonad = x_display.get_atom('_XMONAD_LOG')
+# We want to list on events from the root window
+x_root.change_attributes(event_mask = Xlib.X.PropertyChangeMask)
+
# Close X connection on exit
close_c_bindings_ = close_c_bindings
def close_c_bindings():
@@ -183,4 +186,6 @@ def periodically(year, month, day, hour, minute, second, weekday, fade):
gamma(*gammas[monitor])
randr(monitor)
+
+ x_display.next_event()
diff --git a/src/__main__.py b/src/__main__.py
index b177523..669479a 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -244,17 +244,18 @@ def continuous_run():
except KeyboardInterrupt:
signal_SIGTERM(0, None)
def sleep(seconds):
- try:
- with sleep_condition:
- signal.setitimer(signal.ITIMER_REAL, seconds)
- sleep_condition.wait()
- except KeyboardInterrupt:
- signal_SIGTERM(0, None)
- except:
+ if not sleep == 0:
try:
- time.sleep(seconds) # setitimer may not be supported
+ with sleep_condition:
+ signal.setitimer(signal.ITIMER_REAL, seconds)
+ sleep_condition.wait()
except KeyboardInterrupt:
signal_SIGTERM(0, None)
+ except:
+ try:
+ time.sleep(seconds) # setitimer may not be supported
+ except KeyboardInterrupt:
+ signal_SIGTERM(0, None)
## Catch signals
def signal_(sig, fun):