summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-11-14 15:06:07 +0100
committerAnton Khirnov <anton@khirnov.net>2021-11-14 15:06:52 +0100
commit9f0a029edae359c2b42cfc4ffa0bb476c5782246 (patch)
treed67cb2fbdf33ee4003cbe18bdae5fec893b169dc
parent00d2b1dd2f4cb2c815f4eb748746cdce49875ae5 (diff)
desktop: add a script for toggling the brightness on individual outputs
Allows to software-disable a single output, useful e.g. when watching movies.
-rwxr-xr-xbin/randr_output_toggle57
-rw-r--r--desktop.conf.yaml1
2 files changed, 58 insertions, 0 deletions
diff --git a/bin/randr_output_toggle b/bin/randr_output_toggle
new file mode 100755
index 0000000..3906655
--- /dev/null
+++ b/bin/randr_output_toggle
@@ -0,0 +1,57 @@
+#!/usr/bin/python3
+# Toggle the brightness on the given randr output
+
+import subprocess
+import os
+import os.path
+import re
+import random
+import sys
+import tempfile
+
+class Display:
+ index = None
+ name = None
+ offset = None
+ size = None
+
+ wall_filename = None
+
+ def __cmp__(self, other):
+ if self.offset[1] != other.offset[1]:
+ return cmp(self.offset[1], other.offset[1])
+ return cmp(self.offset[0], other.offset[0])
+
+def parse_outputs():
+ outputs = {}
+
+ p = subprocess.run(['xrandr', '--verbose'], check = True, capture_output = True,
+ encoding = 'utf-8')
+ cur_output = None
+ for line in p.stdout.splitlines():
+ m = re.match(r'(\S*) connected.*', line)
+ if m:
+ cur_output = m.group(1)
+ continue
+
+ if 'Brightness:' in line:
+ _, val = line.strip().split()
+ outputs[cur_output] = float(val)
+ cur_output = None
+
+ return outputs
+
+if len(sys.argv) < 2:
+ sys.stderr.write('Usage: %s <output name>\n'%(sys.argv[0]))
+ sys.exit(1)
+
+output = sys.argv[1]
+outputs = parse_outputs()
+
+if not output in outputs:
+ sys.stderr.write('No such output: %s\n' % output)
+ sys.exit(1)
+
+val = 0.0 if outputs[output] == 1.0 else 1.0
+subprocess.run(['xrandr', '--output', output, '--brightness', str(val)],
+ check = True)
diff --git a/desktop.conf.yaml b/desktop.conf.yaml
index 81ade61..292e8c6 100644
--- a/desktop.conf.yaml
+++ b/desktop.conf.yaml
@@ -5,6 +5,7 @@
- link:
~/.config/mpv/config: dotfiles/mpv
~/.local/bin/brightness_monitor: bin/brightness_monitor
+ ~/.local/bin/randr_output_toggle: bin/randr_output_toggle
~/.local/bin/ssh_sk_clean: bin/ssh_sk_clean
~/.local/bin/udev_match: bin/udev_match
~/.urxvt/ext/reselect: urxvt/reselect/reselect