From f67a4fe683e9e7f697f383b2379e70ee9c27d6d0 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Fri, 31 Jan 2020 16:16:02 -0300 Subject: [PATCH] Basic replica detection --- main.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.py b/main.py index 35832bd..40ebaf7 100644 --- a/main.py +++ b/main.py @@ -34,6 +34,19 @@ def parse_monitor(line): ) +def is_replica_of(a, b): + """Return True if monitor a is a replica of b. + + Replica means same resolution and position. + """ + return ( + a["pos_x"] == b["pos_x"] + and a["pos_y"] == b["pos_y"] + and a["res_x"] == b["res_x"] + and a["res_y"] == b["res_y"] + ) + + class Window(QObject): def __init__(self, ui): super().__init__() @@ -132,6 +145,8 @@ class Window(QObject): for mon in self.xrandr_info: if mon != name: self.ui.replicaOf.addItem(mon) + if is_replica_of(self.xrandr_info[mon], self.xrandr_info[name]): + self.ui.replicaOf.setCurrentText(mon) def updateScaleLabels(self): self.ui.horizontalScaleLabel.setText(f"{self.ui.horizontalScale.value()}%")