From 0bf7fce688757a71e7581456273720477c9203eb Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Mon, 24 Nov 2025 19:47:07 +0100 Subject: [PATCH] Fixed display resolution getter on rotated displays --- sbapp/main.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/sbapp/main.py b/sbapp/main.py index 0b4c163..1e0b5cc 100644 --- a/sbapp/main.py +++ b/sbapp/main.py @@ -49,11 +49,26 @@ def get_display_res(): else: try: import subprocess - cmd_xrandr = subprocess.Popen(['xrandr'], stdout=subprocess.PIPE) - cmd_grep = subprocess.Popen(['grep', '*'], stdin=cmd_xrandr.stdout, stdout=subprocess.PIPE) + # Try to get connected and primary display + cmd_xrandr = subprocess.Popen(["xrandr"], stdout=subprocess.PIPE) + cmd_grep = subprocess.Popen(["grep", " connected primary"], stdin=cmd_xrandr.stdout, stdout=subprocess.PIPE) cmd_xrandr.stdout.close(); res_bytes, _ = cmd_grep.communicate() - resolution = res_bytes.split()[0] - width, height = resolution.split(b'x') + if not (len(res_bytes) > 25 and b"x" in res_bytes): + # Try to get connected display + cmd_xrandr = subprocess.Popen(["xrandr"], stdout=subprocess.PIPE) + cmd_grep = subprocess.Popen(["grep", " connected"], stdin=cmd_xrandr.stdout, stdout=subprocess.PIPE) + cmd_xrandr.stdout.close(); res_bytes, _ = cmd_grep.communicate() + + resolution_es = res_bytes.split() + for e in resolution_es: + if b"x" in e: + if b"+" in e: e = e.split(b"+")[0] + cs = e.split(b"x") + if len(cs) == 2: + resolution = e + break + + width, height = resolution.split(b"x") app_ui_dsp_width = int(width) app_ui_dsp_height = int(height) return app_ui_dsp_width, app_ui_dsp_height