GNOME Bugzilla – Bug 761978
Several apps' saved window size getting messed up
Last modified: 2016-02-16 03:20:11 UTC
It seems to be a regression from 3.18, which I've noticed this with Chess, Dictionary, and Nibbles. Open the app, close it, and reopen. It will open with a noticeably bigger window than it had when it was closed. Rinse and repeat; the window size just keeps growing bigger. Seems like something that should be an application-specific bug rather than a toolkit bug, but none of the apps have this issue when using GTK+ 3.18. Curious.
308aec53c686eae69adbeaf5ca234a29cfd6eefa is the first bad commit commit 308aec53c686eae69adbeaf5ca234a29cfd6eefa Author: Christoph Reiter <creiter@src.gnome.org> Date: Wed Nov 18 19:17:01 2015 +0100 gtkwindow: apply CSD adjustments to the default size when used instead of when setting it Before the resulting window size would differ if the default size was set before adding a headerbar vs after. Now the saved state is again the actual requested size and it is adjusted at the time we request a window size. https://bugzilla.gnome.org/show_bug.cgi?id=756618
What are these applications doing with their size ?
Saving it in gsettings at shutdown, and reading it back at startup. Here's what Nibbles does (in src/gnome-nibbles.vala): protected override void shutdown () { settings.set_int ("window-width", window_width); settings.set_int ("window-height", window_height); settings.set_boolean ("window-is-maximized", is_maximized); // ... } private void size_allocate_cb (Gtk.Allocation allocation) { if (is_maximized || is_tiled) return; window_width = allocation.width; window_height = allocation.height; } protected override void startup () { // ... window.size_allocate.connect (size_allocate_cb); window.window_state_event.connect (window_state_event_cb); window.set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height")); if (settings.get_boolean ("window-is-maximized")) window.maximize (); // ... } Nibbles also responds to configure events on its game view, see configure_event_cb in that file, but that should never affect the size of the window, and Chess doesn't do that.
The 'best practice' for storing window state is documented in https://wiki.gnome.org/HowDoI/SaveWindowState I've just implemented this in the Application Class example of gtk3-demo to ensure that it works.
I just noticed Klotski and Robots are broken too; those are simply the two apps that I checked today.... From a quick glance over your best practices, the main difference I see is that these apps save window state in GtkApplication shutdown, not GtkApplicationWindow destroy. I doubt that matters, though.
The "best practice" is out of date. allocation_size != default_size when CSD is used (try running gtk3-demo with GTK_CSD=1). Using gtk_window_get_size() to get the state to save should fix it.
Could you update the wiki page with a working implementation ?
Created attachment 321117 [details] [review] gtk-demo: fix window size saving with CSD I can't edit that wiki page (says its immutable). Here is a gtk+ patch instead. (Also note that the bisected commit above by me is not the real cause but just a fix making default_size=content size work in all cases)
Sigh, this is an easy fix, but we're going to have to update dozens of apps.... Regarding the wiki, if you post your wiki account name, we can add it to https://wiki.gnome.org/TrustedEditorGroup
I've updated both gtk-demo and the wiki with a working implementation now.
So all apps that used to get the size from configure-event need to updated? Is the 'new way' also working on older gtk+, or do we need #ifdef:s with old code for older gtk, new code for new gtk?
Example fix for Vala applications: https://git.gnome.org/browse/gnome-klotski/commit/?id=a75cf8fd25a772c5013b3a0da64c099e1aec80e2
(In reply to Christian Persch from comment #11) > So all apps that used to get the size from configure-event need to updated? I hope it's OK to post this here, but there was a related discussion on IRC some time ago: https://bpaste.net/show/010a09cc9a84 > Is the 'new way' also working on older gtk+, or do we need #ifdef:s with old > code for older gtk, new code for new gtk? It should work with older gtk+
I've added a release note for this, since it may affect more than just a few applications. With the documentation now recommending to pair gtk_window_get_size with gtk_window_set_default_size, I think we can close this. Sorry for the inconvenience.