From 9f0a029edae359c2b42cfc4ffa0bb476c5782246 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 14 Nov 2021 15:06:07 +0100 Subject: desktop: add a script for toggling the brightness on individual outputs Allows to software-disable a single output, useful e.g. when watching movies. --- bin/randr_output_toggle | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ desktop.conf.yaml | 1 + 2 files changed, 58 insertions(+) create mode 100755 bin/randr_output_toggle 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 \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 -- cgit v1.2.3