After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 761978 - Several apps' saved window size getting messed up
Several apps' saved window size getting messed up
Status: RESOLVED WONTFIX
Product: gtk+
Classification: Platform
Component: .General
3.19.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2016-02-13 00:55 UTC by Michael Catanzaro
Modified: 2016-02-16 03:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gtk-demo: fix window size saving with CSD (975 bytes, patch)
2016-02-14 14:48 UTC, Christoph Reiter (lazka)
none Details | Review

Description Michael Catanzaro 2016-02-13 00:55:30 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.
Comment 1 Michael Catanzaro 2016-02-13 01:36:40 UTC
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
Comment 2 Matthias Clasen 2016-02-13 11:13:25 UTC
What are these applications doing with their size ?
Comment 3 Michael Catanzaro 2016-02-13 18:43:29 UTC
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.
Comment 4 Matthias Clasen 2016-02-14 03:57:42 UTC
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.
Comment 5 Michael Catanzaro 2016-02-14 04:11:06 UTC
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.
Comment 6 Christoph Reiter (lazka) 2016-02-14 11:03:24 UTC
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.
Comment 7 Matthias Clasen 2016-02-14 14:20:57 UTC
Could you update the wiki page with a working implementation ?
Comment 8 Christoph Reiter (lazka) 2016-02-14 14:48:09 UTC
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)
Comment 9 Michael Catanzaro 2016-02-14 15:06:49 UTC
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
Comment 10 Matthias Clasen 2016-02-14 16:21:12 UTC
I've updated both gtk-demo and the wiki with a working implementation now.
Comment 11 Christian Persch 2016-02-14 16:53:25 UTC
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?
Comment 12 Michael Catanzaro 2016-02-14 17:15:30 UTC
Example fix for Vala applications: https://git.gnome.org/browse/gnome-klotski/commit/?id=a75cf8fd25a772c5013b3a0da64c099e1aec80e2
Comment 13 Christoph Reiter (lazka) 2016-02-14 17:22:00 UTC
(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+
Comment 14 Matthias Clasen 2016-02-16 03:20:11 UTC
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.