X11: Force the window focus during ShowWindow if there's no window manager.
authorRyan C. Gordon
Fri, 29 May 2015 15:21:47 -0400
changeset 9683aa4e4768c6c1
parent 9682 0265666d0238
child 9684 c7db25205399
X11: Force the window focus during ShowWindow if there's no window manager.

Fixes Bugzilla #2997.
src/video/x11/SDL_x11window.c
     1.1 --- a/src/video/x11/SDL_x11window.c	Thu May 28 19:06:07 2015 -0700
     1.2 +++ b/src/video/x11/SDL_x11window.c	Fri May 29 15:21:47 2015 -0400
     1.3 @@ -884,6 +884,24 @@
     1.4      X11_XCheckIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
     1.5  }
     1.6  
     1.7 +static SDL_bool
     1.8 +X11_HasWindowManager(const SDL_WindowData *data)
     1.9 +{
    1.10 +    const SDL_DisplayData *displaydata =
    1.11 +        (SDL_DisplayData *) SDL_GetDisplayForWindow(data->window)->driverdata;
    1.12 +    Display *display = data->videodata->display;
    1.13 +    const int screen  = displaydata->screen;
    1.14 +    char atomname[16];
    1.15 +    Atom atom;
    1.16 +
    1.17 +    /* Compliments to Chromium for this technique.
    1.18 +        Window Managers are supposed to own "WM_Sx" selections, where
    1.19 +        "x" is the screen number (ICCCM 2.8). */
    1.20 +    SDL_snprintf(atomname, sizeof (atomname), "WM_S%d", screen);
    1.21 +    atom = X11_XInternAtom(display, atomname, True);
    1.22 +    return ((atom != None) && (X11_XGetSelectionOwner(display, atom) != None));
    1.23 +}
    1.24 +
    1.25  void
    1.26  X11_ShowWindow(_THIS, SDL_Window * window)
    1.27  {
    1.28 @@ -899,6 +917,12 @@
    1.29          X11_XIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
    1.30          X11_XFlush(display);
    1.31      }
    1.32 +
    1.33 +    if (!X11_HasWindowManager(data)) {
    1.34 +        /* no WM means no FocusIn event, which confuses us. Force it. */
    1.35 +        X11_XSetInputFocus(display, data->xwindow, RevertToNone, CurrentTime);
    1.36 +        X11_XFlush(display);
    1.37 +    }
    1.38  }
    1.39  
    1.40  void