From 2a5b5725bf9a50f36a50e105b1bfa5b1b686a1b8 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 30 Apr 2024 22:29:21 -0700 Subject: [PATCH] Added videocommon to set screens to largest common mode. --- quol/bin/videocommon | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 quol/bin/videocommon diff --git a/quol/bin/videocommon b/quol/bin/videocommon new file mode 100644 index 0000000..b3a8650 --- /dev/null +++ b/quol/bin/videocommon @@ -0,0 +1,54 @@ +#!/usr/bin/python3 + +import re +import sys +import subprocess + +conn_re = re.compile(r'(\w+) connected') +mode_re = re.compile(r'\s+([0-9]+x[0-9]+)') + +cmd = ['xrandr', '-q'] +cp = subprocess.run(cmd, capture_output=True, check=True, text=True) +lines = cp.stdout.split('\n') + +devs = [] +modes = {} +for line in lines: + mat = conn_re.match(line) + if mat: + dev = mat.group(1) + devs.append(dev) + mat = mode_re.match(line) + if mat: + mode = mat.group(1) + ary = modes.get(dev) + if ary is None: + ary = [] + modes[dev] = ary + ary.append(mode) + +saw_data = True +while saw_data: + mode = min([ary[0] for ary in modes.values()]) + saw_data = False + agree = True + for dev in devs: + ary = modes[dev] + if ary: + saw_data = True + if ary[0] > mode: + agree = False + ary.pop(0) + else: + argree = False + if agree: + break + +if not agree: + sys.exit(1) + +cmd = ['xrandr'] +for dev in devs: + cmd.extend(['--output', dev, '--mode', mode, '--scale', '1']) +cp = subprocess.run(cmd, check=True) +sys.exit(cp.returncode)