Fix "make not-a-replica"

This commit is contained in:
Roberto Alsina 2022-06-08 13:15:22 -03:00
parent 6c8ff840d0
commit 05bf2b963e

View File

@ -127,33 +127,34 @@ class Window(QObject):
def replica_changed(self): def replica_changed(self):
mon_name = self.ui.screenCombo.currentText() mon_name = self.ui.screenCombo.currentText()
replicate = self.ui.replicaOf.currentText() replicate = self.ui.replicaOf.currentText()
print(f"Making {mon_name} a replica of {replicate}")
if replicate in ("None", "", None):
print("TODO: make things non-replicas")
return
mon = self.screen.monitors[mon_name] mon = self.screen.monitors[mon_name]
replicate = self.screen.monitors[replicate] if replicate in ("None", "", None):
print(f"Making {mon_name} NOT a replica")
# Making a replica implies: mon.pos_x += 300
# Set the same position
mon.pos_x = replicate.pos_x
mon.pos_y = replicate.pos_y
# Set the same mode if possible
matching_mode = mon.get_matching_mode(replicate.get_current_mode())
if matching_mode:
mon.set_current_mode(matching_mode.name)
else: else:
# Keep the current mode, and change scaling so it replicate = self.screen.monitors[replicate]
# has the same effective size as the desired mode print(f"Making {mon_name} a replica of {replicate}")
c_mode = mon.get_current_mode()
mod_x, mod_y = c_mode.res_x, c_mode.res_y # Making a replica implies:
r_mode = replicate.get_current_mode # Set the same position
target_x, target_y = r_mode.res_x, r_mode.res_y mon.pos_x = replicate.pos_x
scale_x = 1000 * target_x / mod_x mon.pos_y = replicate.pos_y
scale_y = 1000 * target_y / mod_y
self.ui.horizontalScale.setValue(scale_x) # Set the same mode if possible
self.ui.verticalScale.setValue(scale_y) matching_mode = mon.get_matching_mode(replicate.get_current_mode())
if matching_mode:
mon.set_current_mode(matching_mode.name)
else:
# Keep the current mode, and change scaling so it
# has the same effective size as the desired mode
c_mode = mon.get_current_mode()
mod_x, mod_y = c_mode.res_x, c_mode.res_y
r_mode = replicate.get_current_mode
target_x, target_y = r_mode.res_x, r_mode.res_y
scale_x = 1000 * target_x / mod_x
scale_y = 1000 * target_y / mod_y
self.ui.horizontalScale.setValue(scale_x)
self.ui.verticalScale.setValue(scale_y)
self.screen.update_replica_of() self.screen.update_replica_of()
for mon in self.screen.monitors.values(): for mon in self.screen.monitors.values():