GNOME Bugzilla – Bug 698652
Aero-snapped windows in Win7 or 8 gets restored to previous size with gtk_window_present()
Last modified: 2016-02-15 08:02:04 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.
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).
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
(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.
This patch fixes gdk_window_show(), but gdk_window_focus() still calls ShowWindow (SW_SHOWNORMAL), so that needs to be patched as well.
*** Bug 761387 has been marked as a duplicate of this bug. ***
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.
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.
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.
Review of attachment 320616 [details] [review]: Looks correct and it is the same we already do in focus
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
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.
Review of attachment 320619 [details] [review]: This also look good to me.
Comment on attachment 320619 [details] [review] win32: properly handle show and focus Attachment 320619 [details] pushed as eb55597 - win32: properly handle show and focus
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.
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.
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.)
Thanks for the info. Pushed the same patches as in master to the gtk-2-24.