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 7741199d77d7bf1c
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
     1.1 --- a/src/video/x11/SDL_x11window.c	Fri Sep 13 17:42:31 2013 -0700
     1.2 +++ b/src/video/x11/SDL_x11window.c	Fri Sep 13 17:42:38 2013 -0700
     1.3 @@ -935,6 +935,34 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +static void
     1.8 +SetWindowActive(_THIS, SDL_Window * window)
     1.9 +{
    1.10 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    1.11 +    SDL_DisplayData *displaydata =
    1.12 +        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
    1.13 +    Display *display = data->videodata->display;
    1.14 +    Atom _NET_ACTIVE_WINDOW = data->videodata->_NET_ACTIVE_WINDOW;
    1.15 +
    1.16 +    if (X11_IsWindowMapped(_this, window)) {
    1.17 +        XEvent e;
    1.18 +
    1.19 +        SDL_zero(e);
    1.20 +        e.xany.type = ClientMessage;
    1.21 +        e.xclient.message_type = _NET_ACTIVE_WINDOW;
    1.22 +        e.xclient.format = 32;
    1.23 +        e.xclient.window = data->xwindow;
    1.24 +        e.xclient.data.l[0] = 1;  /* source indication. 1 = application */
    1.25 +        e.xclient.data.l[1] = CurrentTime;
    1.26 +        e.xclient.data.l[2] = 0;
    1.27 +
    1.28 +        XSendEvent(display, RootWindow(display, displaydata->screen), 0,
    1.29 +                   SubstructureNotifyMask | SubstructureRedirectMask, &e);
    1.30 +
    1.31 +        XFlush(display);
    1.32 +    }
    1.33 +}
    1.34 +
    1.35  void
    1.36  X11_RaiseWindow(_THIS, SDL_Window * window)
    1.37  {
    1.38 @@ -942,6 +970,7 @@
    1.39      Display *display = data->videodata->display;
    1.40  
    1.41      XRaiseWindow(display, data->xwindow);
    1.42 +    SetWindowActive(_this, window);
    1.43      XFlush(display);
    1.44  }
    1.45  
    1.46 @@ -1002,40 +1031,12 @@
    1.47      XFlush(display);
    1.48  }
    1.49  
    1.50 -static void
    1.51 -SetWindowActive(_THIS, SDL_Window * window)
    1.52 -{
    1.53 -    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    1.54 -    SDL_DisplayData *displaydata =
    1.55 -        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
    1.56 -    Display *display = data->videodata->display;
    1.57 -    Atom _NET_ACTIVE_WINDOW = data->videodata->_NET_ACTIVE_WINDOW;
    1.58 -
    1.59 -    if (X11_IsWindowMapped(_this, window)) {
    1.60 -        XEvent e;
    1.61 -
    1.62 -        SDL_zero(e);
    1.63 -        e.xany.type = ClientMessage;
    1.64 -        e.xclient.message_type = _NET_ACTIVE_WINDOW;
    1.65 -        e.xclient.format = 32;
    1.66 -        e.xclient.window = data->xwindow;
    1.67 -        e.xclient.data.l[0] = 1;  /* source indication. 1 = application */
    1.68 -        e.xclient.data.l[1] = CurrentTime;
    1.69 -        e.xclient.data.l[2] = 0;
    1.70 -
    1.71 -        XSendEvent(display, RootWindow(display, displaydata->screen), 0,
    1.72 -                   SubstructureNotifyMask | SubstructureRedirectMask, &e);
    1.73 -
    1.74 -        XFlush(display);
    1.75 -    }
    1.76 -}
    1.77 -
    1.78  void
    1.79  X11_RestoreWindow(_THIS, SDL_Window * window)
    1.80  {
    1.81      SetWindowMaximized(_this, window, SDL_FALSE);
    1.82 +    X11_ShowWindow(_this, window);
    1.83      SetWindowActive(_this, window);
    1.84 -    X11_ShowWindow(_this, window);
    1.85  }
    1.86  
    1.87  /* This asks the Window Manager to handle fullscreen for us. Most don't do it right, though. */