From 79b3111fb0bde3c938cf1ff2d37f6e3e6abb52db Mon Sep 17 00:00:00 2001 From: coderkun Date: Sun, 6 Apr 2025 16:03:39 +0200 Subject: [PATCH] Fix reacting to window resizing (close #107) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the handlers for the “default-width” and “default-height” with an override to the virtual “size_allocate” method to reliably react to Window resizing. --- src/window.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/window.py b/src/window.py index 648853d..db10c23 100644 --- a/src/window.py +++ b/src/window.py @@ -75,6 +75,8 @@ class Window(Adw.ApplicationWindow): self._setting_volume = False self._headerbar_connection_button_active = True self._headerbar_playpause_button_active = True + self._width = 0 + self._height = 0 # Help/Shortcuts dialog self.set_help_overlay(ShortcutsDialog()) @@ -144,8 +146,6 @@ class Window(Adw.ApplicationWindow): self._settings.get_boolean(Window.SETTING_SORT_TYPE)) # Signals - self.connect("notify::default-width", self.on_resize) - self.connect("notify::default-height", self.on_resize) self.connect("notify::maximized", self.on_maximized) self.connect("notify::fullscreened", self.on_fullscreened) self._connection_panel.connect( @@ -258,6 +258,22 @@ class Window(Adw.ApplicationWindow): self.on_menu_search_library) self.add_action(self._search_library_action) + def do_size_allocate(self, width, height, baseline): + Gtk.ApplicationWindow().do_size_allocate(self, width, height, baseline) + + if self._width == width and self._height == height: + return + self._width = width + self._height = height + + if width > 0: + self._cover_panel.set_width(width) + if not self._state.get_property(WindowState.PROP_MAXIMIZED): + self._state.set_property(WindowState.PROP_WIDTH, width) + self._state.set_property(WindowState.PROP_HEIGHT, height) + GObject.idle_add(self._playlist_panel.set_size, width, height) + GObject.idle_add(self._library_panel.set_size, width, height) + # Menu callbacks def on_menu_connect(self, action, value): @@ -287,17 +303,6 @@ class Window(Adw.ApplicationWindow): # Window callbacks - def on_resize(self, widget, event): - width = self.get_size(Gtk.Orientation.HORIZONTAL) - height = self.get_size(Gtk.Orientation.VERTICAL) - if width > 0: - self._cover_panel.set_width(width) - if not self._state.get_property(WindowState.PROP_MAXIMIZED): - self._state.set_property(WindowState.PROP_WIDTH, width) - self._state.set_property(WindowState.PROP_HEIGHT, height) - GObject.idle_add(self._playlist_panel.set_size, width, height) - GObject.idle_add(self._library_panel.set_size, width, height) - def on_maximized(self, widget, maximized): self._state.set_property(WindowState.PROP_MAXIMIZED, maximized is True)