src/video/SDL_video.c
changeset 2875 91a7e08cd238
parent 2869 2fe507a2ef7d
child 2876 3fcb0d447bcd
     1.1 --- a/src/video/SDL_video.c	Tue Dec 16 17:44:10 2008 +0000
     1.2 +++ b/src/video/SDL_video.c	Wed Dec 17 07:17:54 2008 +0000
     1.3 @@ -123,8 +123,7 @@
     1.4  static SDL_VideoDevice *_this = NULL;
     1.5  
     1.6  /* Various local functions */
     1.7 -int SDL_VideoInit(const char *driver_name, Uint32 flags);
     1.8 -void SDL_VideoQuit(void);
     1.9 +static void SDL_UpdateWindowGrab(SDL_Window *window);
    1.10  
    1.11  static int
    1.12  cmpmodes(const void *A, const void *B)
    1.13 @@ -635,8 +634,7 @@
    1.14      for (i = 0; i < display->num_windows; ++i) {
    1.15          SDL_Window *window = &display->windows[i];
    1.16          if (FULLSCREEN_VISIBLE(window)) {
    1.17 -            SDL_SetWindowPosition(window->id, SDL_WINDOWPOS_CENTERED,
    1.18 -                                  SDL_WINDOWPOS_CENTERED);
    1.19 +            SDL_SetWindowPosition(window->id, window->x, window->y);
    1.20          }
    1.21      }
    1.22  
    1.23 @@ -752,7 +750,8 @@
    1.24      const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN |
    1.25                                    SDL_WINDOW_OPENGL |
    1.26                                    SDL_WINDOW_BORDERLESS |
    1.27 -                                  SDL_WINDOW_RESIZABLE);
    1.28 +                                  SDL_WINDOW_RESIZABLE |
    1.29 +                                  SDL_WINDOW_INPUT_GRABBED);
    1.30      SDL_VideoDisplay *display;
    1.31      SDL_Window window;
    1.32      int num_windows;
    1.33 @@ -766,11 +765,6 @@
    1.34          SDL_SetError("No OpenGL support in video driver");
    1.35          return 0;
    1.36      }
    1.37 -    /* Fullscreen windows don't have any window decorations */
    1.38 -    if (flags & SDL_WINDOW_FULLSCREEN) {
    1.39 -        flags |= SDL_WINDOW_BORDERLESS;
    1.40 -        flags &= ~SDL_WINDOW_RESIZABLE;
    1.41 -    }
    1.42      SDL_zero(window);
    1.43      window.id = _this->next_object_id++;
    1.44      window.x = x;
    1.45 @@ -809,9 +803,8 @@
    1.46      if (flags & SDL_WINDOW_SHOWN) {
    1.47          SDL_ShowWindow(window.id);
    1.48      }
    1.49 -    if (flags & SDL_WINDOW_INPUT_GRABBED) {
    1.50 -        SDL_SetWindowGrab(window.id, 1);
    1.51 -    }
    1.52 +    SDL_UpdateWindowGrab(&window);
    1.53 +
    1.54      return window.id;
    1.55  }
    1.56  
    1.57 @@ -889,9 +882,8 @@
    1.58      if (flags & SDL_WINDOW_SHOWN) {
    1.59          SDL_ShowWindow(window->id);
    1.60      }
    1.61 -    if (flags & SDL_WINDOW_INPUT_GRABBED) {
    1.62 -        SDL_SetWindowGrab(window->id, 1);
    1.63 -    }
    1.64 +    SDL_UpdateWindowGrab(window);
    1.65 +
    1.66      return 0;
    1.67  }
    1.68  
    1.69 @@ -1004,19 +996,16 @@
    1.70      if (!window) {
    1.71          return;
    1.72      }
    1.73 -    if (x == SDL_WINDOWPOS_CENTERED) {
    1.74 -        window->x = (display->current_mode.w - window->w) / 2;
    1.75 -    } else if (x != SDL_WINDOWPOS_UNDEFINED) {
    1.76 +    if (x != SDL_WINDOWPOS_UNDEFINED) {
    1.77          window->x = x;
    1.78      }
    1.79 -    if (y == SDL_WINDOWPOS_CENTERED) {
    1.80 -        window->y = (display->current_mode.h - window->h) / 2;
    1.81 -    } else if (y != SDL_WINDOWPOS_UNDEFINED) {
    1.82 +    if (y != SDL_WINDOWPOS_UNDEFINED) {
    1.83          window->y = y;
    1.84      }
    1.85      if (_this->SetWindowPosition) {
    1.86          _this->SetWindowPosition(_this, window);
    1.87      }
    1.88 +    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, x, y);
    1.89  }
    1.90  
    1.91  void
    1.92 @@ -1082,11 +1071,11 @@
    1.93      if (!window || (window->flags & SDL_WINDOW_SHOWN)) {
    1.94          return;
    1.95      }
    1.96 -    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0);
    1.97  
    1.98      if (_this->ShowWindow) {
    1.99          _this->ShowWindow(_this, window);
   1.100      }
   1.101 +    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0);
   1.102  }
   1.103  
   1.104  void
   1.105 @@ -1097,11 +1086,11 @@
   1.106      if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
   1.107          return;
   1.108      }
   1.109 -    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0);
   1.110  
   1.111      if (_this->HideWindow) {
   1.112          _this->HideWindow(_this, window);
   1.113      }
   1.114 +    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0);
   1.115  }
   1.116  
   1.117  void
   1.118 @@ -1125,11 +1114,11 @@
   1.119      if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) {
   1.120          return;
   1.121      }
   1.122 -    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
   1.123  
   1.124      if (_this->MaximizeWindow) {
   1.125          _this->MaximizeWindow(_this, window);
   1.126      }
   1.127 +    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
   1.128  }
   1.129  
   1.130  void
   1.131 @@ -1140,11 +1129,11 @@
   1.132      if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) {
   1.133          return;
   1.134      }
   1.135 -    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
   1.136  
   1.137      if (_this->MinimizeWindow) {
   1.138          _this->MinimizeWindow(_this, window);
   1.139      }
   1.140 +    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
   1.141  }
   1.142  
   1.143  void
   1.144 @@ -1156,11 +1145,11 @@
   1.145          || (window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
   1.146          return;
   1.147      }
   1.148 -    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0);
   1.149  
   1.150      if (_this->RestoreWindow) {
   1.151          _this->RestoreWindow(_this, window);
   1.152      }
   1.153 +    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0);
   1.154  }
   1.155  
   1.156  int
   1.157 @@ -1217,7 +1206,12 @@
   1.158      } else {
   1.159          window->flags &= ~SDL_WINDOW_INPUT_GRABBED;
   1.160      }
   1.161 +    SDL_UpdateWindowGrab(window);
   1.162 +}
   1.163  
   1.164 +static void
   1.165 +SDL_UpdateWindowGrab(SDL_Window *window)
   1.166 +{
   1.167      if ((window->flags & SDL_WINDOW_INPUT_FOCUS) && _this->SetWindowGrab) {
   1.168          _this->SetWindowGrab(_this, window);
   1.169      }
   1.170 @@ -1237,11 +1231,17 @@
   1.171  void
   1.172  SDL_OnWindowShown(SDL_Window * window)
   1.173  {
   1.174 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   1.175 +        SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
   1.176 +    }
   1.177  }
   1.178  
   1.179  void
   1.180  SDL_OnWindowHidden(SDL_Window * window)
   1.181  {
   1.182 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   1.183 +        SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
   1.184 +    }
   1.185  }
   1.186  
   1.187  void
   1.188 @@ -1265,7 +1265,7 @@
   1.189      if (display->gamma && _this->SetDisplayGammaRamp) {
   1.190          _this->SetDisplayGammaRamp(_this, display->gamma);
   1.191      }
   1.192 -    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) && _this->SetWindowGrab) {
   1.193 +    if ((window->flags & (SDL_WINDOW_INPUT_GRABBED|SDL_WINDOW_FULLSCREEN)) && _this->SetWindowGrab) {
   1.194          _this->SetWindowGrab(_this, window);
   1.195      }
   1.196  }
   1.197 @@ -1282,7 +1282,7 @@
   1.198      if (display->gamma && _this->SetDisplayGammaRamp) {
   1.199          _this->SetDisplayGammaRamp(_this, display->saved_gamma);
   1.200      }
   1.201 -    if ((window->flags & SDL_WINDOW_INPUT_GRABBED) && _this->SetWindowGrab) {
   1.202 +    if ((window->flags & (SDL_WINDOW_INPUT_GRABBED|SDL_WINDOW_FULLSCREEN)) && _this->SetWindowGrab) {
   1.203          _this->SetWindowGrab(_this, window);
   1.204      }
   1.205  }