From 5f3827a2cbc2ba1808ad92700b45c6a7cc8281db Mon Sep 17 00:00:00 2001 From: Jookia Date: Sat, 18 Mar 2023 00:49:28 +1100 Subject: [PATCH] screen: Only switch layouts if the window has been majorly resized (#913) * screen: Only switch layouts if the window has been majorly resized Changing the layout can cause the window to resize on some systems. This can create a feedback loop on systems with square displays. Keep track of the vertical aspect ratio associated with the current mode and only switch between vertical and horizontal mode when a significant aspect ratio change has been detected. * fixup --------- Co-authored-by: alfrix --- screen.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/screen.py b/screen.py index 8e9b4089..4fd75cd5 100755 --- a/screen.py +++ b/screen.py @@ -122,7 +122,8 @@ class KlipperScreen(Gtk.Window): self.set_resizable(True) if not (self._config.get_main_config().get("width") or self._config.get_main_config().get("height")): self.fullscreen() - self.vertical_mode = self.width < self.height + self.aspect_ratio = self.width / self.height + self.vertical_mode = self.aspect_ratio < 1.0 logging.info(f"Screen resolution: {self.width}x{self.height}") self.theme = self._config.get_main_config().get('theme') self.show_cursor = self._config.get_main_config().getboolean("show_cursor", fallback=False) @@ -962,9 +963,13 @@ class KlipperScreen(Gtk.Window): def update_size(self, *args): self.width, self.height = self.get_size() - if self.vertical_mode != (self.width < self.height): + new_ratio = self.width / self.height + new_mode = new_ratio < 1.0 + ratio_delta = abs(self.aspect_ratio - new_ratio) + if ratio_delta > 0.1 and self.vertical_mode != new_mode: self.reload_panels() - self.vertical_mode = self.width < self.height + self.vertical_mode = new_mode + self.aspect_ratio = new_ratio def main():