GNOME Bugzilla – Bug 665760
gtk_window_present no longer raises Window above of other applications' windows
Last modified: 2012-01-25 19:34:21 UTC
Some time between GTK+ 2.16.6 and GTK+ 2.24.8 (I believe that this change probably happened quite a while ago), the behavior of gtk_window_present changed such that it will no longer raise a window to the top of the stack of desktop windows (including other applications); instead it only raises to the top of the windows of the current application. Perhaps the following example will make it more clear: Pidgin has a system tray icon which, when double-clicked, will show and hide the Buddy List (using gtk_window_present()). With GTK+ 2.16.6, double-clicking on the icon will raise the Buddy List above all other windows and give it focus regardless of which application currently has focus. With GTK+ 2.24.8, double-clicking on the icon will raise the Buddy List only above other Pidgin Windows, so if, e.g. a Firefox is obscuring it, it will remain behind the Firefox window.
Turns out that obscuring a test app's window with the console window that started said test app does not reproduce this bug, but obscuring the test app's window with for example windows explorer does. Then traced this to the BringWindowToTop() call in gdk/win32/gdkwindow-win32.c:1838. Replacing that with a SetForegroundWindow() as suggested by datallah on #win32 seems to be doing the "right thing (tm)". During testing, we also discovered that sometimes SetForeGroundWindow() will (correctly) refuse to raise the window and fail(for example: sometimes when dragging a different application at the time of a gtk_window_present() call). To prevent a GdkWarning from being produced, usage of the API_CALL macro has been removed for this case. Behaviour of SetForegroundWindow(): - it brings the window to the front when the process is the foreground process (for example when gtk_window_present is called from a GtkStatusIcon's activate signal handler) - it limits itself to flashing the task bar button associated with the window if not (for example when gtk_window_present is called from a g_timeout_add callback function) All this simply didn't work with BringWindowToTop(). I'll attach 2 test programs illustrating this and off course, the patch (tested on windows XP an 7).
Created attachment 203987 [details] [review] (gtk-2-24) win32: fix gdk_win32_window_raise
Created attachment 203988 [details] GtkStatusIcon test
Created attachment 203989 [details] g_timeout_add test
Looks good to me. We should fix it in master too.
I've been able to validate that the patch fixes the issue I was experiencing.
Committed as fb87d9c90153dcfd2e126c5bca9ad2d4ffbdfdff on gtk-2-24 branch and fe1907708c4edb5a97184a2e027b7a028a7b5554 on master