src/video/x11/SDL_x11window.c
changeset 2875 91a7e08cd238
parent 2859 99210400e8b9
child 2876 3fcb0d447bcd
     1.1 --- a/src/video/x11/SDL_x11window.c	Tue Dec 16 17:44:10 2008 +0000
     1.2 +++ b/src/video/x11/SDL_x11window.c	Wed Dec 17 07:17:54 2008 +0000
     1.3 @@ -287,7 +287,7 @@
     1.4                              visual, AllocNone);
     1.5      }
     1.6  
     1.7 -    if (window->x == SDL_WINDOWPOS_CENTERED) {
     1.8 +    if ((window->flags & SDL_WINDOW_FULLSCREEN) || window->x == SDL_WINDOWPOS_CENTERED) {
     1.9          x = (DisplayWidth(data->display, displaydata->screen) -
    1.10               window->w) / 2;
    1.11      } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
    1.12 @@ -295,7 +295,7 @@
    1.13      } else {
    1.14          x = window->x;
    1.15      }
    1.16 -    if (window->y == SDL_WINDOWPOS_CENTERED) {
    1.17 +    if ((window->flags & SDL_WINDOW_FULLSCREEN) || window->y == SDL_WINDOWPOS_CENTERED) {
    1.18          y = (DisplayHeight(data->display, displaydata->screen) -
    1.19               window->h) / 2;
    1.20      } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
    1.21 @@ -321,7 +321,7 @@
    1.22  
    1.23      sizehints = XAllocSizeHints();
    1.24      if (sizehints) {
    1.25 -        if (window->flags & SDL_WINDOW_RESIZABLE) {
    1.26 +        if ((window->flags & SDL_WINDOW_RESIZABLE) && !(window->flags & SDL_WINDOW_FULLSCREEN)) {
    1.27              sizehints->min_width = 32;
    1.28              sizehints->min_height = 32;
    1.29              sizehints->max_height = 4096;
    1.30 @@ -342,7 +342,7 @@
    1.31          XFree(sizehints);
    1.32      }
    1.33  
    1.34 -    if (window->flags & SDL_WINDOW_BORDERLESS) {
    1.35 +    if (window->flags & (SDL_WINDOW_BORDERLESS|SDL_WINDOW_FULLSCREEN)) {
    1.36          SDL_bool set;
    1.37          Atom WM_HINTS;
    1.38  
    1.39 @@ -601,8 +601,19 @@
    1.40      SDL_DisplayData *displaydata =
    1.41          (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
    1.42      Display *display = data->videodata->display;
    1.43 +    int x, y;
    1.44  
    1.45 -    XMoveWindow(display, data->window, window->x, window->y);
    1.46 +    if ((window->flags & SDL_WINDOW_FULLSCREEN) || window->x == SDL_WINDOWPOS_CENTERED) {
    1.47 +        x = (DisplayWidth(display, displaydata->screen) - window->w) / 2;
    1.48 +    } else {
    1.49 +        x = window->x;
    1.50 +    }
    1.51 +    if ((window->flags & SDL_WINDOW_FULLSCREEN) || window->y == SDL_WINDOWPOS_CENTERED) {
    1.52 +        y = (DisplayHeight(display, displaydata->screen) - window->h) / 2;
    1.53 +    } else {
    1.54 +        y = window->y;
    1.55 +    }
    1.56 +    XMoveWindow(display, data->window, x, y);
    1.57  }
    1.58  
    1.59  void
    1.60 @@ -662,7 +673,29 @@
    1.61  void
    1.62  X11_SetWindowGrab(_THIS, SDL_Window * window)
    1.63  {
    1.64 -    /* FIXME */
    1.65 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    1.66 +    Display *display = data->videodata->display;
    1.67 +
    1.68 +    if ((window->flags & (SDL_WINDOW_INPUT_GRABBED|SDL_WINDOW_FULLSCREEN)) &&
    1.69 +        (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
    1.70 +        /* Try to grab the mouse */
    1.71 +        for ( ; ; ) {
    1.72 +            int result = XGrabPointer(display, data->window, True, 0, GrabModeAsync, GrabModeAsync, data->window, None, CurrentTime);
    1.73 +            if ( result == GrabSuccess ) {
    1.74 +                break;
    1.75 +            }
    1.76 +            SDL_Delay(100);
    1.77 +        }
    1.78 +
    1.79 +        /* Raise the window if we grab the mouse */
    1.80 +        XRaiseWindow(display, data->window);
    1.81 +
    1.82 +        /* Now grab the keyboard */
    1.83 +        XGrabKeyboard(display, data->window, True, GrabModeAsync, GrabModeAsync, CurrentTime);
    1.84 +    } else {
    1.85 +        XUngrabPointer(display, CurrentTime);
    1.86 +        XUngrabKeyboard(display, CurrentTime);
    1.87 +    }
    1.88  }
    1.89  
    1.90  void