Fix X11_RestoreWindow() and X11_RaiseWindow() to properly do window activation.
authorSam Lantinga <slouken@libsdl.org>
Fri, 13 Sep 2013 17:42:38 -0700
changeset 7741 199d77d7bf1c
parent 7740 415bb39617a1
child 7742 84e32c3d415c
Fix X11_RestoreWindow() and X11_RaiseWindow() to properly do window activation. X11_RestoreWindow() had a call ordering problem that prevented activation, and X11_RaiseWindow() wasn't attempting activation. Windows and OS X both activate in these cases. CR: saml
src/video/x11/SDL_x11window.c
--- a/src/video/x11/SDL_x11window.c	Fri Sep 13 17:42:31 2013 -0700
+++ b/src/video/x11/SDL_x11window.c	Fri Sep 13 17:42:38 2013 -0700
@@ -935,6 +935,34 @@
     }
 }
 
+static void
+SetWindowActive(_THIS, SDL_Window * window)
+{
+    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+    SDL_DisplayData *displaydata =
+        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
+    Display *display = data->videodata->display;
+    Atom _NET_ACTIVE_WINDOW = data->videodata->_NET_ACTIVE_WINDOW;
+
+    if (X11_IsWindowMapped(_this, window)) {
+        XEvent e;
+
+        SDL_zero(e);
+        e.xany.type = ClientMessage;
+        e.xclient.message_type = _NET_ACTIVE_WINDOW;
+        e.xclient.format = 32;
+        e.xclient.window = data->xwindow;
+        e.xclient.data.l[0] = 1;  /* source indication. 1 = application */
+        e.xclient.data.l[1] = CurrentTime;
+        e.xclient.data.l[2] = 0;
+
+        XSendEvent(display, RootWindow(display, displaydata->screen), 0,
+                   SubstructureNotifyMask | SubstructureRedirectMask, &e);
+
+        XFlush(display);
+    }
+}
+
 void
 X11_RaiseWindow(_THIS, SDL_Window * window)
 {
@@ -942,6 +970,7 @@
     Display *display = data->videodata->display;
 
     XRaiseWindow(display, data->xwindow);
+    SetWindowActive(_this, window);
     XFlush(display);
 }
 
@@ -1002,40 +1031,12 @@
     XFlush(display);
 }
 
-static void
-SetWindowActive(_THIS, SDL_Window * window)
-{
-    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
-    SDL_DisplayData *displaydata =
-        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
-    Display *display = data->videodata->display;
-    Atom _NET_ACTIVE_WINDOW = data->videodata->_NET_ACTIVE_WINDOW;
-
-    if (X11_IsWindowMapped(_this, window)) {
-        XEvent e;
-
-        SDL_zero(e);
-        e.xany.type = ClientMessage;
-        e.xclient.message_type = _NET_ACTIVE_WINDOW;
-        e.xclient.format = 32;
-        e.xclient.window = data->xwindow;
-        e.xclient.data.l[0] = 1;  /* source indication. 1 = application */
-        e.xclient.data.l[1] = CurrentTime;
-        e.xclient.data.l[2] = 0;
-
-        XSendEvent(display, RootWindow(display, displaydata->screen), 0,
-                   SubstructureNotifyMask | SubstructureRedirectMask, &e);
-
-        XFlush(display);
-    }
-}
-
 void
 X11_RestoreWindow(_THIS, SDL_Window * window)
 {
     SetWindowMaximized(_this, window, SDL_FALSE);
+    X11_ShowWindow(_this, window);
     SetWindowActive(_this, window);
-    X11_ShowWindow(_this, window);
 }
 
 /* This asks the Window Manager to handle fullscreen for us. Most don't do it right, though. */