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 698652 - Aero-snapped windows in Win7 or 8 gets restored to previous size with gtk_window_present()
Aero-snapped windows in Win7 or 8 gets restored to previous size with gtk_win...
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Backend: Win32
2.24.x
Other Windows
: Normal normal
: ---
Assigned To: gtk-win32 maintainers
gtk-bugs
: 761387 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2013-04-23 12:16 UTC by Aleksander Morgado
Modified: 2016-02-15 08:02 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Tester to reproduce the issue. (2.61 KB, patch)
2013-04-23 12:16 UTC, Aleksander Morgado
none Details | Review
Patch. (2.06 KB, patch)
2013-04-23 12:18 UTC, Aleksander Morgado
none Details | Review
test-iconify (1.66 KB, text/x-c)
2016-02-08 11:53 UTC, Ignacio Casal Quinteiro (nacho)
  Details
win32: on focus restore the window if iconified (1.05 KB, patch)
2016-02-08 11:54 UTC, Ignacio Casal Quinteiro (nacho)
none Details | Review
win32: properly handle show and focus (2.10 KB, patch)
2016-02-08 12:26 UTC, Ignacio Casal Quinteiro (nacho)
committed Details | Review
win32: on focus restore the window if iconified (1.54 KB, patch)
2016-02-08 13:08 UTC, Ignacio Casal Quinteiro (nacho)
none Details | Review
gtk-2: Alexander's plus gdk_window_focus plus Nacho's (1.10 KB, patch)
2016-02-14 21:56 UTC, Yevgen Muntyan
none Details | Review

Description Aleksander Morgado 2013-04-23 12:16:38 UTC
Created attachment 242212 [details] [review]
Tester to reproduce the issue.

Windows 7 and newer come with the 'Aero Snap' feature, where if you open a window and use Windows+Left or Windows+Right (or if you just drag a window to the left or right side of the screen), the window will get docked-left or docked-right, filling in half of the screen. These windows behave like maximized windows, so that whenever you 'unsnap' them (e.g. double click on the title bar, or just again Windows+Left or Windows+Right), they recover the original size.
    
When a Gtk+ window is docked-left or docked-right using the Aero Snap feature, and we call gtk_window_present(), the window will get restored to the unsnapped state; i.e. to the size and position before the left or right docking. Instead, the window should retain its position and size (docked) when gtk_window_present() is called.

The attached tester creates a new tests/window-present-button program which just has a button. The button explicitly calls gtk_window_present() in the window. To reproduce the issue, just run the tester in either Win7 or Win8 (not reproducible with wine), then Win+Left to dock-left the window, and then click the button. The window is restored to its previous size, while it shouldn't.
Comment 1 Aleksander Morgado 2013-04-23 12:18:39 UTC
Created attachment 242214 [details] [review]
Patch.

Uses SW_SHOW and SW_SHOWNA (don't restore size) instead of SW_SHOWNORMAL and SW_SHOWNOACTIVATE (which do restore size).
Comment 2 Marc-Andre Lureau 2013-04-23 12:34:29 UTC
fwiw, virt-viewer suffered the same issue, and when I tried using SHOWNA that didn't help (but perhaps it was something else): https://git.fedorahosted.org/cgit/virt-viewer.git/commit/?id=081f2decbe026277548834fa7a9f421de8dec3af
Comment 3 Aleksander Morgado 2013-04-23 13:22:06 UTC
(In reply to comment #2)
> fwiw, virt-viewer suffered the same issue, and when I tried using SHOWNA that
> didn't help (but perhaps it was something else):
> https://git.fedorahosted.org/cgit/virt-viewer.git/commit/?id=081f2decbe026277548834fa7a9f421de8dec3af

Really? It works ok here.
Comment 4 Yevgen Muntyan 2016-02-04 07:44:46 UTC
This patch fixes gdk_window_show(), but gdk_window_focus() still calls ShowWindow (SW_SHOWNORMAL), so that needs to be patched as well.
Comment 5 Ignacio Casal Quinteiro (nacho) 2016-02-04 07:45:18 UTC
*** Bug 761387 has been marked as a duplicate of this bug. ***
Comment 6 LRN 2016-02-04 08:03:18 UTC
I did look into Aero Snap briefly, and it absolutely does not work for CSD windows (which i would like to see being eventually enabled by default in gtk-3). I'm also considering doing a custom resizing implementation for CSD windows, which might inevitably spill into non-CSD case, if i'm not careful.

Also, this bug is filed against gtk-2. I know that Aero Snap works for non-CSD windows in gtk-3, so it should probably apply there as well.

Just saying.
Comment 7 Ignacio Casal Quinteiro (nacho) 2016-02-08 11:53:19 UTC
Created attachment 320615 [details]
test-iconify

This is a new tester application based on the previous one but also adds a button that iconifies and calls gtk_window_present after 3 seconds.
Comment 8 Ignacio Casal Quinteiro (nacho) 2016-02-08 11:54:26 UTC
Created attachment 320616 [details] [review]
win32: on focus restore the window if iconified

If the window is iconified we want to restore the window
to get the proper size instead of showing it normal which
would change the size of the window.
Comment 9 Paolo Borelli 2016-02-08 11:59:30 UTC
Review of attachment 320616 [details] [review]:

Looks correct and it is the same we already do in focus
Comment 10 Ignacio Casal Quinteiro (nacho) 2016-02-08 12:01:09 UTC
Comment on attachment 320616 [details] [review]
win32: on focus restore the window if iconified

Attachment 320616 [details] pushed as 07a994c - win32: on focus restore the window if iconified
Comment 11 Ignacio Casal Quinteiro (nacho) 2016-02-08 12:26:33 UTC
Created attachment 320619 [details] [review]
win32: properly handle show and focus

The first time a window is shown we should always call SW_SHOWNORMAL.
Understand whether to call SW_SHOW or SW_SHOWNORMAL and the specific
ones for the temporary windows depending on IsWindowVisible.
This also fixes the problem when calling gtk_window_present and
the window is snapped to the left or right of the screen.

This patch is based on the patches provided by Yevgen Muntyan
and Aleksander Morgado.
Comment 12 Paolo Borelli 2016-02-08 13:00:16 UTC
Review of attachment 320619 [details] [review]:

This also look good to me.
Comment 13 Ignacio Casal Quinteiro (nacho) 2016-02-08 13:04:18 UTC
Comment on attachment 320619 [details] [review]
win32: properly handle show and focus

Attachment 320619 [details] pushed as eb55597 - win32: properly handle show and focus
Comment 14 Ignacio Casal Quinteiro (nacho) 2016-02-08 13:08:46 UTC
Created attachment 320622 [details] [review]
win32: on focus restore the window if iconified

If the window is iconified we want to restore the window
to get the proper size instead of showing it normal which
would change the size of the window.
Comment 15 Ignacio Casal Quinteiro (nacho) 2016-02-08 13:10:34 UTC
attached you can find the same patch but for the gtk-2-24 branch. Let me know if it builds and works fine and then i can push it. The other patch applies fine on the gtk-2-24 so you can apply it directly.
Comment 16 Yevgen Muntyan 2016-02-14 21:56:01 UTC
Created attachment 321161 [details] [review]
gtk-2: Alexander's plus gdk_window_focus plus Nacho's

I got confused by which patch is which, attached is what works for me in gtk-2: that's Alexander's patch, plus the corresponding change to gdk_window_focus, plus the gdk_window_focus() change to do SW_RESTORE for minimized windows from the last Nacho's comment.

Speaking of restore, gdk_window_show alone doesn't seem to show a minimized window, is that a bug? I don't have real application code which does gdk_window_show alone, so I can't verify that. (Nor do I want to fiddle with this code in the first place.)
Comment 17 Ignacio Casal Quinteiro (nacho) 2016-02-15 08:02:04 UTC
Thanks for the info. Pushed the same patches as in master to the gtk-2-24.