src/video/x11/SDL_x11window.c
changeset 6662 698c2e533a7e
parent 6638 3d221da309d3
child 6885 700f1b25f77f
     1.1 --- a/src/video/x11/SDL_x11window.c	Wed Nov 07 11:13:28 2012 -0800
     1.2 +++ b/src/video/x11/SDL_x11window.c	Wed Nov 07 15:55:43 2012 -0800
     1.3 @@ -22,6 +22,7 @@
     1.4  
     1.5  #if SDL_VIDEO_DRIVER_X11
     1.6  
     1.7 +#include "SDL_hints.h"
     1.8  #include "../SDL_sysvideo.h"
     1.9  #include "../SDL_pixels_c.h"
    1.10  #include "../../events/SDL_keyboard_c.h"
    1.11 @@ -1089,7 +1090,7 @@
    1.12      XIfEvent(display, &ev, &isMapNotify, (XPointer)&data->xwindow);
    1.13      XCheckIfEvent(display, &ev, &isUnmapNotify, (XPointer)&data->xwindow);
    1.14  
    1.15 -    X11_SetWindowGrab(_this, window);
    1.16 +    SDL_UpdateWindowGrab(window);
    1.17  }
    1.18  
    1.19  static void
    1.20 @@ -1115,7 +1116,7 @@
    1.21      }
    1.22  #endif
    1.23  
    1.24 -    X11_SetWindowGrab(_this, window);
    1.25 +    SDL_UpdateWindowGrab(window);
    1.26  
    1.27      XReparentWindow(display, data->xwindow, root, window->x, window->y);
    1.28  
    1.29 @@ -1238,19 +1239,21 @@
    1.30  }
    1.31  
    1.32  void
    1.33 -X11_SetWindowGrab(_THIS, SDL_Window * window)
    1.34 +X11_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
    1.35  {
    1.36      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    1.37      Display *display = data->videodata->display;
    1.38      SDL_bool oldstyle_fullscreen;
    1.39 +    SDL_bool grab_keyboard;
    1.40 +    const char *hint;
    1.41  
    1.42 -    /* ICCCM2.0-compliant window managers can handle fullscreen windows */
    1.43 +    /* ICCCM2.0-compliant window managers can handle fullscreen windows
    1.44 +       If we're using XVidMode to change resolution we need to confine
    1.45 +       the cursor so we don't pan around the virtual desktop.
    1.46 +     */
    1.47      oldstyle_fullscreen = X11_IsWindowLegacyFullscreen(_this, window);
    1.48  
    1.49 -    if (oldstyle_fullscreen ||
    1.50 -        ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
    1.51 -         (window->flags & SDL_WINDOW_INPUT_FOCUS))) {
    1.52 -
    1.53 +    if (oldstyle_fullscreen || grabbed) {
    1.54          /* Try to grab the mouse */
    1.55          for (;;) {
    1.56              int result =
    1.57 @@ -1259,15 +1262,26 @@
    1.58              if (result == GrabSuccess) {
    1.59                  break;
    1.60              }
    1.61 -            SDL_Delay(100);
    1.62 +            SDL_Delay(50);
    1.63          }
    1.64  
    1.65          /* Raise the window if we grab the mouse */
    1.66          XRaiseWindow(display, data->xwindow);
    1.67  
    1.68          /* Now grab the keyboard */
    1.69 -        XGrabKeyboard(display, data->xwindow, True, GrabModeAsync,
    1.70 -                      GrabModeAsync, CurrentTime);
    1.71 +        hint = SDL_GetHint(SDL_HINT_GRAB_KEYBOARD);
    1.72 +        if (hint && SDL_atoi(hint)) {
    1.73 +            grab_keyboard = SDL_TRUE;
    1.74 +        } else {
    1.75 +            /* We need to do this with the old style override_redirect
    1.76 +               fullscreen window otherwise we won't get keyboard focus.
    1.77 +            */
    1.78 +            grab_keyboard = oldstyle_fullscreen;
    1.79 +        }
    1.80 +        if (grab_keyboard) {
    1.81 +            XGrabKeyboard(display, data->xwindow, True, GrabModeAsync,
    1.82 +                          GrabModeAsync, CurrentTime);
    1.83 +        }
    1.84      } else {
    1.85          XUngrabPointer(display, CurrentTime);
    1.86          XUngrabKeyboard(display, CurrentTime);