src/video/SDL_video.c
changeset 1956 ba0d62354872
parent 1952 420716272158
child 1963 2590b68531ef
     1.1 --- a/src/video/SDL_video.c	Sat Jul 29 03:57:55 2006 +0000
     1.2 +++ b/src/video/SDL_video.c	Sat Jul 29 21:51:00 2006 +0000
     1.3 @@ -614,9 +614,8 @@
     1.4      for (i = 0; i < display->num_windows; ++i) {
     1.5          SDL_Window *window = &display->windows[i];
     1.6          if (FULLSCREEN_VISIBLE(window)) {
     1.7 -            SDL_SetWindowPosition(window->id,
     1.8 -                                  ((display_mode.w - window->w) / 2),
     1.9 -                                  ((display_mode.h - window->h) / 2));
    1.10 +            SDL_SetWindowPosition(window->id, SDL_WINDOWPOS_CENTERED,
    1.11 +                                  SDL_WINDOWPOS_CENTERED);
    1.12          }
    1.13      }
    1.14  
    1.15 @@ -718,12 +717,8 @@
    1.16  {
    1.17      const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN |
    1.18                                    SDL_WINDOW_OPENGL |
    1.19 -                                  SDL_WINDOW_SHOWN |
    1.20                                    SDL_WINDOW_BORDERLESS |
    1.21 -                                  SDL_WINDOW_RESIZABLE |
    1.22 -                                  SDL_WINDOW_MAXIMIZED |
    1.23 -                                  SDL_WINDOW_MINIMIZED |
    1.24 -                                  SDL_WINDOW_INPUT_GRABBED);
    1.25 +                                  SDL_WINDOW_RESIZABLE);
    1.26      SDL_VideoDisplay *display;
    1.27      SDL_Window window;
    1.28      int num_windows;
    1.29 @@ -739,9 +734,14 @@
    1.30          return 0;
    1.31      }
    1.32  
    1.33 +    /* Fullscreen windows don't have any window decorations */
    1.34 +    if (flags & SDL_WINDOW_FULLSCREEN) {
    1.35 +        flags |= SDL_WINDOW_BORDERLESS;
    1.36 +        flags &= ~SDL_WINDOW_RESIZABLE;
    1.37 +    }
    1.38 +
    1.39      SDL_zero(window);
    1.40      window.id = _this->next_object_id++;
    1.41 -    window.title = title ? SDL_strdup(title) : NULL;
    1.42      window.x = x;
    1.43      window.y = y;
    1.44      window.w = w;
    1.45 @@ -750,9 +750,6 @@
    1.46      window.display = _this->current_display;
    1.47  
    1.48      if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) {
    1.49 -        if (window.title) {
    1.50 -            SDL_free(window.title);
    1.51 -        }
    1.52          return 0;
    1.53      }
    1.54  
    1.55 @@ -764,27 +761,27 @@
    1.56          if (_this->DestroyWindow) {
    1.57              _this->DestroyWindow(_this, &window);
    1.58          }
    1.59 -        if (window.title) {
    1.60 -            SDL_free(window.title);
    1.61 -        }
    1.62          return 0;
    1.63      }
    1.64      windows[num_windows] = window;
    1.65      display->windows = windows;
    1.66      display->num_windows++;
    1.67  
    1.68 -    if (FULLSCREEN_VISIBLE(&window)) {
    1.69 -        /* Hide any other fullscreen windows */
    1.70 -        int i;
    1.71 -        for (i = 0; i < display->num_windows; ++i) {
    1.72 -            SDL_Window *other = &display->windows[i];
    1.73 -            if (other->id != window.id && FULLSCREEN_VISIBLE(other)) {
    1.74 -                SDL_MinimizeWindow(other->id);
    1.75 -            }
    1.76 -        }
    1.77 -        SDL_SetDisplayMode(display->fullscreen_mode);
    1.78 +    if (title) {
    1.79 +        SDL_SetWindowTitle(window.id, title);
    1.80      }
    1.81 -
    1.82 +    if (flags & SDL_WINDOW_MAXIMIZED) {
    1.83 +        SDL_MaximizeWindow(window.id);
    1.84 +    }
    1.85 +    if (flags & SDL_WINDOW_MINIMIZED) {
    1.86 +        SDL_MinimizeWindow(window.id);
    1.87 +    }
    1.88 +    if (flags & SDL_WINDOW_SHOWN) {
    1.89 +        SDL_ShowWindow(window.id);
    1.90 +    }
    1.91 +    if (flags & SDL_WINDOW_INPUT_GRABBED) {
    1.92 +        SDL_SetWindowGrab(window.id, 1);
    1.93 +    }
    1.94      return window.id;
    1.95  }
    1.96  
    1.97 @@ -833,15 +830,44 @@
    1.98  int
    1.99  SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
   1.100  {
   1.101 +    char *title = window->title;
   1.102 +
   1.103      if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
   1.104          SDL_SetError("No OpenGL support in video driver");
   1.105          return -1;
   1.106      }
   1.107 +
   1.108      if (_this->DestroyWindow) {
   1.109          _this->DestroyWindow(_this, window);
   1.110      }
   1.111 -    window->flags = flags;
   1.112 -    return _this->CreateWindow(_this, window);
   1.113 +
   1.114 +    window->title = NULL;
   1.115 +    window->flags =
   1.116 +        (flags &
   1.117 +         ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED | SDL_WINDOW_SHOWN |
   1.118 +           SDL_WINDOW_INPUT_GRABBED));
   1.119 +
   1.120 +    if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) {
   1.121 +        return -1;
   1.122 +    }
   1.123 +
   1.124 +    if (title) {
   1.125 +        SDL_SetWindowTitle(window->id, title);
   1.126 +        SDL_free(title);
   1.127 +    }
   1.128 +    if (flags & SDL_WINDOW_MAXIMIZED) {
   1.129 +        SDL_MaximizeWindow(window->id);
   1.130 +    }
   1.131 +    if (flags & SDL_WINDOW_MINIMIZED) {
   1.132 +        SDL_MinimizeWindow(window->id);
   1.133 +    }
   1.134 +    if (flags & SDL_WINDOW_SHOWN) {
   1.135 +        SDL_ShowWindow(window->id);
   1.136 +    }
   1.137 +    if (flags & SDL_WINDOW_INPUT_GRABBED) {
   1.138 +        SDL_SetWindowGrab(window->id, 1);
   1.139 +    }
   1.140 +    return 0;
   1.141  }
   1.142  
   1.143  SDL_Window *
   1.144 @@ -873,6 +899,9 @@
   1.145          SDL_UninitializedVideo();
   1.146          return NULL;
   1.147      }
   1.148 +    if (!window) {
   1.149 +        return NULL;
   1.150 +    }
   1.151      return &_this->displays[window->display];
   1.152  }
   1.153  
   1.154 @@ -891,14 +920,20 @@
   1.155  SDL_SetWindowTitle(SDL_WindowID windowID, const char *title)
   1.156  {
   1.157      SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.158 +    const char *last_title;
   1.159  
   1.160 -    if (!window) {
   1.161 +    if (!window || title == window->title) {
   1.162          return;
   1.163      }
   1.164 +
   1.165      if (window->title) {
   1.166          SDL_free(window->title);
   1.167      }
   1.168 -    window->title = SDL_strdup(title);
   1.169 +    if (title) {
   1.170 +        window->title = SDL_strdup(title);
   1.171 +    } else {
   1.172 +        window->title = NULL;
   1.173 +    }
   1.174  
   1.175      if (_this->SetWindowTitle) {
   1.176          _this->SetWindowTitle(_this, window);
   1.177 @@ -942,15 +977,20 @@
   1.178  SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y)
   1.179  {
   1.180      SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.181 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   1.182  
   1.183      if (!window) {
   1.184          return;
   1.185      }
   1.186  
   1.187 -    if (x != SDL_WINDOWPOS_UNDEFINED) {
   1.188 +    if (x == SDL_WINDOWPOS_CENTERED) {
   1.189 +        window->x = (display->current_mode.w - window->w) / 2;
   1.190 +    } else if (x != SDL_WINDOWPOS_UNDEFINED) {
   1.191          window->x = x;
   1.192      }
   1.193 -    if (y != SDL_WINDOWPOS_UNDEFINED) {
   1.194 +    if (y == SDL_WINDOWPOS_CENTERED) {
   1.195 +        window->y = (display->current_mode.h - window->h) / 2;
   1.196 +    } else if (y != SDL_WINDOWPOS_UNDEFINED) {
   1.197          window->y = y;
   1.198      }
   1.199  
   1.200 @@ -1045,7 +1085,7 @@
   1.201  {
   1.202      SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.203  
   1.204 -    if (!window) {
   1.205 +    if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
   1.206          return;
   1.207      }
   1.208