aboutsummaryrefslogtreecommitdiffstats
path: root/xpybar/config/adjbrilliance
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-06-26 13:18:37 +0200
committerMattias Andrée <maandree@kth.se>2021-06-26 13:18:37 +0200
commit3e21f6d13c0a70db95fec8b5a71b758223ff4293 (patch)
tree6d6d2eddb243935007ce1e316c61470224f93df0 /xpybar/config/adjbrilliance
parentAdd inputrc for readline + m (diff)
downloaddotfiles-3e21f6d13c0a70db95fec8b5a71b758223ff4293.tar.gz
dotfiles-3e21f6d13c0a70db95fec8b5a71b758223ff4293.tar.bz2
dotfiles-3e21f6d13c0a70db95fec8b5a71b758223ff4293.tar.xz
Add xpybar
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'xpybar/config/adjbrilliance')
-rw-r--r--xpybar/config/adjbrilliance94
1 files changed, 94 insertions, 0 deletions
diff --git a/xpybar/config/adjbrilliance b/xpybar/config/adjbrilliance
new file mode 100644
index 0000000..0ffb09d
--- /dev/null
+++ b/xpybar/config/adjbrilliance
@@ -0,0 +1,94 @@
+# -*- python -*-
+import os
+import sys
+import time
+import signal
+
+OUTPUT, HEIGHT, YPOS, TOP = 0, 2 * 12, 0, True
+
+LEFT_BUTTON = 1
+MIDDLE_BUTTON = 2
+RIGHT_BUTTON = 3
+SCROLL_UP = 4
+SCROLL_DOWN = 5
+SCROLL_LEFT = 6
+SCROLL_RIGHT = 7
+FORWARD_BUTTON = 8
+BACKWARD_BUTTON = 9
+
+path = os.getenv('XDG_RUNTIME_DIR', '/tmp') + '/.xpybar.brilliance'
+pid = None
+pending = False
+
+def sigchld(*_):
+ global pid, pending
+ if pid is not None:
+ r, _ = os.waitpid(-1, 0)
+ if r == pid:
+ pid = None
+ if pending:
+ pending = False
+ set_brilliance()
+ else:
+ with open(path, 'wb') as file:
+ return file.write(('%f' % brilliance).encode('utf-8'))
+
+def get_brilliance():
+ try:
+ with open(path, 'rb') as file:
+ return float(file.read().decode('utf-8', 'strict'))
+ except:
+ return 1
+
+def set_brilliance():
+ global pid, pending
+ if pid is None:
+ pid = os.fork()
+ if not pid:
+ if brilliance == 1:
+ os.execlp('cg-brilliance', 'cg-brilliance', '-x')
+ else:
+ os.execlp('cg-brilliance', 'cg-brilliance', '--', '%f' % brilliance)
+ sys.exit(1)
+ else:
+ pending = True
+
+signal.signal(signal.SIGCHLD, sigchld)
+brilliance = get_brilliance()
+
+def redraw():
+ x = int(bar.width * brilliance + 0.5)
+ bar.change_colour(bar.foreground)
+ bar.window.fill_rectangle(bar.gc, 0, 0, x, HEIGHT)
+ bar.change_colour(bar.background)
+ bar.window.fill_rectangle(bar.gc, x, 0, bar.width - x, HEIGHT)
+
+import x as _x
+_get_event_mask = _x.get_event_mask
+def get_event_mask():
+ return _get_event_mask() | Xlib.X.ButtonMotionMask
+_x.get_event_mask = get_event_mask
+
+def unhandled_event(e):
+ global brilliance
+ if isinstance(e, Xlib.protocol.event.ButtonPress):
+ button, x = e.detail, e.event_x
+ if button == LEFT_BUTTON:
+ brilliance = min(max(0, x / bar.width), 1)
+ set_brilliance()
+ bar.invalidate()
+ elif button == SCROLL_UP:
+ brilliance = min(brilliance + 0.05, 1)
+ set_brilliance()
+ bar.invalidate()
+ elif button == SCROLL_DOWN:
+ brilliance = max(brilliance - 0.05, 0)
+ set_brilliance()
+ bar.invalidate()
+ elif button in (MIDDLE_BUTTON, RIGHT_BUTTON, FORWARD_BUTTON, BACKWARD_BUTTON):
+ raise KeyboardInterrupt()
+ elif isinstance(e, Xlib.protocol.event.MotionNotify):
+ if e.detail == 0:
+ brilliance = min(max(0, e.event_x / bar.width), 1)
+ set_brilliance()
+ bar.invalidate()