aboutsummaryrefslogtreecommitdiffstats
path: root/xpybar/config/mycg.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-11-25 18:08:34 +0100
committerMattias Andrée <maandree@kth.se>2023-11-25 18:08:34 +0100
commit5b7e0db847c46affc207c327835d1efd3b2727de (patch)
tree764855cde8a304641a359e907157dc0525ff8a20 /xpybar/config/mycg.py
parentUpdate dmenu to use different fonts (primary size due to different DPI, distance, and screen size) on different computers (diff)
downloaddotfiles-5b7e0db847c46affc207c327835d1efd3b2727de.tar.gz
dotfiles-5b7e0db847c46affc207c327835d1efd3b2727de.tar.bz2
dotfiles-5b7e0db847c46affc207c327835d1efd3b2727de.tar.xz
Misc updates
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'xpybar/config/mycg.py')
-rw-r--r--xpybar/config/mycg.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/xpybar/config/mycg.py b/xpybar/config/mycg.py
new file mode 100644
index 0000000..5b5edee
--- /dev/null
+++ b/xpybar/config/mycg.py
@@ -0,0 +1,51 @@
+# -*- python -*-
+from common import *
+
+class MyCG(Entry):
+ def __init__(self, title, command, cg_class, *args, priority = None, **kwargs):
+ self.title = title
+ self.cg_class = cg_class
+ rule = '::'.join(cg_class.split('::')[2:])
+ self.start_command = [command, '-R', rule]
+ if priority is not None:
+ self.start_command.extend(['-p', str(priority)])
+ self.stop_command = [command, '-R', rule, '-x']
+ Entry.__init__(self, *args, **kwargs)
+
+ def action(self, col, button, x, y):
+ proc = subprocess.Popen(['cg-query', '-c', '?'], stdout = subprocess.PIPE)
+ output = []
+ while True:
+ chunk = proc.stdout.read(128)
+ if not chunk:
+ break
+ output.append(chunk)
+ proc.stdout.close()
+ proc.wait()
+ output = b''.join(output).decode('utf-8', 'replace')
+ crtcs = output.split('\n')
+ output = []
+ for crtc in crtcs:
+ if not crtc:
+ continue
+ proc = subprocess.Popen(['cg-query', '-c', crtc], stdout = subprocess.PIPE)
+ while True:
+ chunk = proc.stdout.read(128)
+ if not chunk:
+ break
+ output.append(chunk)
+ proc.stdout.close()
+ proc.wait()
+ output = b''.join(output).decode('utf-8', 'replace')
+ active = ('\n Class: %s\n' % self.cg_class) in output
+ del output
+ print(active)
+ print(repr(self.stop_command if active else self.start_command))
+ subprocess.Popen(self.stop_command if active else self.start_command).wait()
+
+ def function(self):
+ return self.title
+
+class MyCGNegative(MyCG):
+ def __init__(self, *args, title = 'Negative', rule = 'xpybar', priority = None, **kwargs):
+ MyCG.__init__(self, title, 'cg-negative', 'cg-tools::cg-negative::' + rule, *args, priority = priority, **kwargs)