changeset 5251:58265e606e4e

Window coordinates are in the global space and windows are not tied to a particular display. Also added Ctrl-Enter keybinding to the test code to toggle fullscreen mode for testing.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 10 Feb 2011 14:44:25 -0800
parents 329d435f97f4
children d844537c42fd
files include/SDL_video.h src/video/SDL_shape.c src/video/SDL_sysvideo.h src/video/SDL_video.c src/video/cocoa/SDL_cocoaopengl.m src/video/cocoa/SDL_cocoawindow.h src/video/cocoa/SDL_cocoawindow.m src/video/directfb/SDL_DirectFB_modes.c src/video/directfb/SDL_DirectFB_mouse.c src/video/directfb/SDL_DirectFB_render.c src/video/directfb/SDL_DirectFB_window.c src/video/nds/SDL_ndsrender.c src/video/pandora/SDL_pandora.c src/video/uikit/SDL_uikitopengles.m src/video/uikit/SDL_uikitwindow.m src/video/windows/SDL_windowswindow.c src/video/x11/SDL_x11clipboard.c src/video/x11/SDL_x11opengl.c src/video/x11/SDL_x11window.c test/common.c test/testwm2.c
diffstat 21 files changed, 300 insertions(+), 190 deletions(-) [+]
line wrap: on
line diff
--- a/include/SDL_video.h	Thu Feb 10 14:36:09 2011 -0800
+++ b/include/SDL_video.h	Thu Feb 10 14:44:25 2011 -0800
@@ -113,12 +113,20 @@
 /**
  *  \brief Used to indicate that you don't care what the window position is.
  */
-#define SDL_WINDOWPOS_UNDEFINED 0x7FFFFFF
+#define SDL_WINDOWPOS_UNDEFINED_MASK    0x1FFF0000
+#define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X)  (SDL_WINDOWPOS_UNDEFINED_MASK|(X))
+#define SDL_WINDOWPOS_UNDEFINED         SDL_WINDOWPOS_UNDEFINED_DISPLAY(0)
+#define SDL_WINDOWPOS_ISUNDEFINED(X)    \
+            (((X)&0xFFFF0000) == SDL_WINDOWPOS_UNDEFINED_MASK)
 
 /**
  *  \brief Used to indicate that the window position should be centered.
  */
-#define SDL_WINDOWPOS_CENTERED  0x7FFFFFE
+#define SDL_WINDOWPOS_CENTERED_MASK    0x2FFF0000
+#define SDL_WINDOWPOS_CENTERED_DISPLAY(X)  (SDL_WINDOWPOS_CENTERED_MASK|(X))
+#define SDL_WINDOWPOS_CENTERED         SDL_WINDOWPOS_CENTERED_DISPLAY(0)
+#define SDL_WINDOWPOS_ISCENTERED(X)    \
+            (((X)&0xFFFF0000) == SDL_WINDOWPOS_CENTERED_MASK)
 
 /**
  *  \brief Event subtype for window events
@@ -304,6 +312,14 @@
 extern DECLSPEC SDL_DisplayMode * SDLCALL SDL_GetClosestDisplayMode(int displayIndex, const SDL_DisplayMode * mode, SDL_DisplayMode * closest);
 
 /**
+ *  \brief Get the display index associated with a window.
+ *  
+ *  \return the display index of the display containing the center of the
+ *          window, or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_GetWindowDisplay(SDL_Window * window);
+
+/**
  *  \brief Set the display mode used when a fullscreen window is visible.
  *
  *  By default the window's dimensions and the desktop format and refresh rate
@@ -531,7 +547,7 @@
  *  \sa SDL_GetWindowDisplayMode()
  */
 extern DECLSPEC int SDLCALL SDL_SetWindowFullscreen(SDL_Window * window,
-                                                    int fullscreen);
+                                                    SDL_bool fullscreen);
 
 /**
  *  \brief Get an SDL surface associated with the window.
--- a/src/video/SDL_shape.c	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/SDL_shape.c	Thu Feb 10 14:44:25 2011 -0800
@@ -35,7 +35,7 @@
     SDL_Window *result = NULL;
     result = SDL_CreateWindow(title,-1000,-1000,w,h,(flags | SDL_WINDOW_BORDERLESS) & (~SDL_WINDOW_FULLSCREEN) & (~SDL_WINDOW_RESIZABLE) /*& (~SDL_WINDOW_SHOWN)*/);
     if(result != NULL) {
-        result->shaper = result->display->device->shape_driver.CreateShaper(result);
+        result->shaper = SDL_GetVideoDevice()->shape_driver.CreateShaper(result);
         if(result->shaper != NULL) {
             result->shaper->userx = x;
             result->shaper->usery = y;
@@ -240,7 +240,7 @@
     
     if(shape_mode != NULL)
         window->shaper->mode = *shape_mode;
-    result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shape_mode);
+    result = SDL_GetVideoDevice()->shape_driver.SetWindowShape(window->shaper,shape,shape_mode);
     window->shaper->hasshape = SDL_TRUE;
     if(window->shaper->userx != 0 && window->shaper->usery != 0) {
         SDL_SetWindowPosition(window,window->shaper->userx,window->shaper->usery);
--- a/src/video/SDL_sysvideo.h	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/SDL_sysvideo.h	Thu Feb 10 14:44:25 2011 -0800
@@ -76,8 +76,6 @@
     int w, h;
     Uint32 flags;
 
-    SDL_VideoDisplay *display;
-
     SDL_DisplayMode fullscreen_mode;
     
     SDL_Surface *surface;
@@ -110,7 +108,6 @@
     SDL_DisplayMode current_mode;
     SDL_bool updating_fullscreen;
 
-    SDL_Window *windows;
     SDL_Window *fullscreen_window;
 
     SDL_VideoDevice *device;
@@ -153,8 +150,7 @@
     int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
 
     /*
-     * Get a list of the available display modes. e.g.
-     * SDL_AddDisplayMode(_this->current_display, mode)
+     * Get a list of the available display modes for a display.
      */
     void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
 
@@ -236,7 +232,7 @@
     SDL_bool suspend_screensaver;
     int num_displays;
     SDL_VideoDisplay *displays;
-    int current_display;
+    SDL_Window *windows;
     Uint8 window_magic;
     Uint32 next_object_id;
     char * clipboard_text;
@@ -326,6 +322,7 @@
 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
 extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
+extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
 
 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
 
--- a/src/video/SDL_video.c	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/SDL_video.c	Thu Feb 10 14:44:25 2011 -0800
@@ -655,6 +655,12 @@
     return SDL_TRUE;
 }
 
+SDL_VideoDisplay *
+SDL_GetFirstDisplay(void)
+{
+    return &_this->displays[0];
+}
+
 static int
 SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display)
 {
@@ -893,6 +899,67 @@
 }
 
 int
+SDLCALL SDL_GetWindowDisplay(SDL_Window * window)
+{
+    int displayIndex;
+    int i, dist;
+    int closest = -1;
+    int closest_dist = 0x7FFFFFFF;
+    SDL_Point center;
+    SDL_Point delta;
+    SDL_Rect rect;
+
+    CHECK_WINDOW_MAGIC(window, -1);
+
+    if (SDL_WINDOWPOS_ISUNDEFINED(window->x) ||
+        SDL_WINDOWPOS_ISCENTERED(window->x)) {
+        displayIndex = (window->x & 0xFFFF);
+        if (displayIndex >= _this->num_displays) {
+            displayIndex = 0;
+        }
+        return displayIndex;
+    }
+    if (SDL_WINDOWPOS_ISUNDEFINED(window->y) ||
+        SDL_WINDOWPOS_ISCENTERED(window->y)) {
+        displayIndex = (window->y & 0xFFFF);
+        if (displayIndex >= _this->num_displays) {
+            displayIndex = 0;
+        }
+        return displayIndex;
+    }
+
+    /* Find the display containing the window */
+    center.x = window->x + window->w / 2;
+    center.y = window->y + window->h / 2;
+    for (i = 0; i < _this->num_displays; ++i) {
+        SDL_VideoDisplay *display = &_this->displays[i];
+
+        SDL_GetDisplayBounds(i, &rect);
+        if (display->fullscreen_window == window || SDL_EnclosePoints(&center, 1, &rect, NULL)) {
+            return i;
+        }
+
+        delta.x = center.x - (rect.x + rect.w / 2);
+        delta.y = center.y - (rect.y + rect.h / 2);
+        dist = (delta.x*delta.x + delta.y*delta.y);
+        if (dist < closest_dist) {
+            closest = i;
+            closest_dist = dist;
+        }
+    }
+    if (closest < 0) {
+        SDL_SetError("Couldn't find any displays");
+    }
+    return closest;
+}
+
+SDL_VideoDisplay *
+SDL_GetDisplayForWindow(SDL_Window *window)
+{
+    return &_this->displays[SDL_GetWindowDisplay(window)];
+}
+
+int
 SDL_SetWindowDisplayMode(SDL_Window * window, const SDL_DisplayMode * mode)
 {
     CHECK_WINDOW_MAGIC(window, -1);
@@ -920,7 +987,7 @@
         fullscreen_mode.h = window->h;
     }
 
-    if (!SDL_GetClosestDisplayModeForDisplay(window->display,
+    if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window),
                                              &fullscreen_mode,
                                              &fullscreen_mode)) {
         SDL_SetError("Couldn't find display mode match");
@@ -936,15 +1003,19 @@
 Uint32
 SDL_GetWindowPixelFormat(SDL_Window * window)
 {
-    SDL_VideoDisplay *display = window->display;
-    SDL_DisplayMode *displayMode = &display->current_mode;
-    return displayMode->format;
+    SDL_VideoDisplay *display;
+    SDL_DisplayMode *displayMode;
+
+    CHECK_WINDOW_MAGIC(window, SDL_PIXELFORMAT_UNKNOWN);
+
+    display = SDL_GetDisplayForWindow(window);
+    return display->current_mode.format;
 }
 
 static void
 SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt)
 {
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
 
     /* See if we're already processing a window */
     if (display->updating_fullscreen) {
@@ -971,19 +1042,17 @@
 
     if (FULLSCREEN_VISIBLE(window)) {
         /* Hide any other fullscreen windows */
-        SDL_Window *other;
-        for (other = display->windows; other; other = other->next) {
-            if (other != window && FULLSCREEN_VISIBLE(other)) {
-                SDL_MinimizeWindow(other);
-            }
+        if (display->fullscreen_window != window) {
+            SDL_MinimizeWindow(display->fullscreen_window);
         }
     }
 
     display->updating_fullscreen = SDL_FALSE;
 
     /* See if there are any fullscreen windows */
-    for (window = display->windows; window; window = window->next) {
-        if (FULLSCREEN_VISIBLE(window)) {
+    for (window = _this->windows; window; window = window->next) {
+        if (FULLSCREEN_VISIBLE(window) &&
+            SDL_GetDisplayForWindow(window) == display) {
             SDL_DisplayMode fullscreen_mode;
             if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
                 SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
@@ -1022,7 +1091,6 @@
         }
         SDL_GL_LoadLibrary(NULL);
     }
-    display = &_this->displays[0]; /* FIXME */
     window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
     window->magic = &_this->window_magic;
     window->id = _this->next_object_id++;
@@ -1031,12 +1099,11 @@
     window->w = w;
     window->h = h;
     window->flags = (flags & allowed_flags);
-    window->display = display;
-    window->next = display->windows;
-    if (display->windows) {
-        display->windows->prev = window;
+    window->next = _this->windows;
+    if (_this->windows) {
+        _this->windows->prev = window;
     }
-    display->windows = window;
+    _this->windows = window;
 
     if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) {
         SDL_DestroyWindow(window);
@@ -1063,24 +1130,21 @@
 SDL_Window *
 SDL_CreateWindowFrom(const void *data)
 {
-    SDL_VideoDisplay *display;
     SDL_Window *window;
 
     if (!_this) {
         SDL_UninitializedVideo();
         return NULL;
     }
-    display = &_this->displays[0]; /* FIXME */
     window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
     window->magic = &_this->window_magic;
     window->id = _this->next_object_id++;
     window->flags = SDL_WINDOW_FOREIGN;
-    window->display = display;
-    window->next = display->windows;
-    if (display->windows) {
-        display->windows->prev = window;
+    window->next = _this->windows;
+    if (_this->windows) {
+        _this->windows->prev = window;
     }
-    display->windows = window;
+    _this->windows = window;
 
     if (!_this->CreateWindowFrom ||
         _this->CreateWindowFrom(_this, window, data) < 0) {
@@ -1171,13 +1235,9 @@
     if (!_this) {
         return NULL;
     }
-    /* FIXME: Should we keep a separate hash table for these? */
-    for (i = _this->num_displays; i--;) {
-        SDL_VideoDisplay *display = &_this->displays[i];
-        for (window = display->windows; window; window = window->next) {
-            if (window->id == id) {
-                return window;
-            }
+    for (window = _this->windows; window; window = window->next) {
+        if (window->id == id) {
+            return window;
         }
     }
     return NULL;
@@ -1298,29 +1358,36 @@
     if (y != SDL_WINDOWPOS_UNDEFINED) {
         window->y = y;
     }
-    if (_this->SetWindowPosition) {
-        _this->SetWindowPosition(_this, window);
+    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+        if (_this->SetWindowPosition) {
+            _this->SetWindowPosition(_this, window);
+        }
+        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
     }
-    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
 }
 
 void
 SDL_GetWindowPosition(SDL_Window * window, int *x, int *y)
 {
-    if (_this && window && window->magic == &_this->window_magic) {
+    /* Clear the values */
+    if (x) {
+        *x = 0;
+    }
+    if (y) {
+        *y = 0;
+    }
+
+    CHECK_WINDOW_MAGIC(window, );
+
+    /* Fullscreen windows are always at their display's origin */
+    if (window->flags & SDL_WINDOW_FULLSCREEN) {
+    } else {
         if (x) {
             *x = window->x;
         }
         if (y) {
             *y = window->y;
         }
-    } else {
-        if (x) {
-            *x = 0;
-        }
-        if (y) {
-            *y = 0;
-        }
     }
 }
 
@@ -1341,6 +1408,20 @@
 void
 SDL_GetWindowSize(SDL_Window * window, int *w, int *h)
 {
+    int dummy;
+
+    if (!w) {
+        w = &dummy;
+    }
+    if (!h) {
+        h = &dummy;
+    }
+
+    *w = 0;
+    *h = 0;
+
+    CHECK_WINDOW_MAGIC(window, );
+
     if (_this && window && window->magic == &_this->window_magic) {
         if (w) {
             *w = window->w;
@@ -1450,7 +1531,7 @@
 }
 
 int
-SDL_SetWindowFullscreen(SDL_Window * window, int fullscreen)
+SDL_SetWindowFullscreen(SDL_Window * window, SDL_bool fullscreen)
 {
     CHECK_WINDOW_MAGIC(window, -1);
 
@@ -1610,8 +1691,6 @@
 void
 SDL_OnWindowFocusGained(SDL_Window * window)
 {
-    SDL_VideoDisplay *display = window->display;
-
     if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
         && _this->SetWindowGrab) {
         _this->SetWindowGrab(_this, window);
@@ -1621,8 +1700,6 @@
 void
 SDL_OnWindowFocusLost(SDL_Window * window)
 {
-    SDL_VideoDisplay *display = window->display;
-
     /* If we're fullscreen on a single-head system and lose focus, minimize */
     if ((window->flags & SDL_WINDOW_FULLSCREEN) &&
         _this->num_displays == 1) {
@@ -1638,14 +1715,12 @@
 SDL_Window *
 SDL_GetFocusWindow(void)
 {
-    SDL_VideoDisplay *display;
     SDL_Window *window;
 
     if (!_this) {
         return NULL;
     }
-    display = &_this->displays[0]; /* FIXME */
-    for (window = display->windows; window; window = window->next) {
+    for (window = _this->windows; window; window = window->next) {
         if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
             return window;
         }
@@ -1677,6 +1752,11 @@
         SDL_GL_UnloadLibrary();
     }
 
+    display = SDL_GetDisplayForWindow(window);
+    if (display->fullscreen_window == window) {
+        display->fullscreen_window = NULL;
+    }
+
     /* Now invalidate magic */
     window->magic = NULL;
 
@@ -1693,14 +1773,13 @@
     }
 
     /* Unlink the window from the list */
-    display = window->display;
     if (window->next) {
         window->next->prev = window->prev;
     }
     if (window->prev) {
         window->prev->next = window->next;
     } else {
-        display->windows = window->next;
+        _this->windows = window->next;
     }
 
     SDL_free(window);
@@ -1763,11 +1842,8 @@
     SDL_EnableScreenSaver();
 
     /* Clean up the system video */
-    for (i = _this->num_displays; i--;) {
-        SDL_VideoDisplay *display = &_this->displays[i];
-        while (display->windows) {
-            SDL_DestroyWindow(display->windows);
-        }
+    while (_this->windows) {
+        SDL_DestroyWindow(_this->windows);
     }
     _this->VideoQuit(_this);
 
--- a/src/video/cocoa/SDL_cocoaopengl.m	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/cocoa/SDL_cocoaopengl.m	Thu Feb 10 14:44:25 2011 -0800
@@ -72,7 +72,7 @@
 Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
 {
     NSAutoreleasePool *pool;
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
     NSOpenGLPixelFormatAttribute attr[32];
     NSOpenGLPixelFormat *fmt;
--- a/src/video/cocoa/SDL_cocoawindow.h	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/cocoa/SDL_cocoawindow.h	Thu Feb 10 14:44:25 2011 -0800
@@ -86,7 +86,6 @@
     SDL_Window *window;
     NSWindow *nswindow;
     SDL_bool created;
-    CGDirectDisplayID display;
     Cocoa_WindowListener *listener;
     struct SDL_VideoData *videodata;
 };
--- a/src/video/cocoa/SDL_cocoawindow.m	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/cocoa/SDL_cocoawindow.m	Thu Feb 10 14:44:25 2011 -0800
@@ -403,8 +403,6 @@
 {
     NSAutoreleasePool *pool;
     SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
-    SDL_VideoDisplay *display = window->display;
-    SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
     SDL_WindowData *data;
 
     /* Allocate the window data */
@@ -416,7 +414,6 @@
     data->window = window;
     data->nswindow = nswindow;
     data->created = created;
-    data->display = displaydata->display;
     data->videodata = videodata;
 
     pool = [[NSAutoreleasePool alloc] init];
@@ -438,9 +435,8 @@
         [contentView release];
 
         ConvertNSRect(&rect);
-        Cocoa_GetDisplayBounds(_this, display, &bounds);
-        window->x = (int)rect.origin.x - bounds.x;
-        window->y = (int)rect.origin.y - bounds.y;
+        window->x = (int)rect.origin.x;
+        window->y = (int)rect.origin.y;
         window->w = (int)rect.size.width;
         window->h = (int)rect.size.height;
     }
@@ -493,27 +489,27 @@
 {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     NSWindow *nswindow;
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     NSRect rect;
     SDL_Rect bounds;
     unsigned int style;
 
     Cocoa_GetDisplayBounds(_this, display, &bounds);
     if ((window->flags & SDL_WINDOW_FULLSCREEN)
-        || window->x == SDL_WINDOWPOS_CENTERED) {
+        || SDL_WINDOWPOS_ISCENTERED(window->x)) {
         rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
-    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
+    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
         rect.origin.x = bounds.x;
     } else {
-        rect.origin.x = bounds.x + window->x;
+        rect.origin.x = window->x;
     }
     if ((window->flags & SDL_WINDOW_FULLSCREEN)
-        || window->y == SDL_WINDOWPOS_CENTERED) {
+        || SDL_WINDOWPOS_ISCENTERED(window->y)) {
         rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
-    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
+    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
         rect.origin.y = bounds.y;
     } else {
-        rect.origin.y = bounds.y + window->y;
+        rect.origin.y = window->y;
     }
     rect.size.width = window->w;
     rect.size.height = window->h;
@@ -599,22 +595,22 @@
 {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     NSRect rect;
     SDL_Rect bounds;
 
     Cocoa_GetDisplayBounds(_this, display, &bounds);
     if ((window->flags & SDL_WINDOW_FULLSCREEN)
-        || window->x == SDL_WINDOWPOS_CENTERED) {
+        || SDL_WINDOWPOS_ISCENTERED(window->x)) {
         rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
     } else {
-        rect.origin.x = bounds.x + window->x;
+        rect.origin.x = window->x;
     }
     if ((window->flags & SDL_WINDOW_FULLSCREEN)
-        || window->y == SDL_WINDOWPOS_CENTERED) {
+        || SDL_WINDOWPOS_ISCENTERED(window->y)) {
         rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
     } else {
-        rect.origin.y = bounds.y + window->y;
+        rect.origin.y = window->y;
     }
     rect.size.width = window->w;
     rect.size.height = window->h;
--- a/src/video/directfb/SDL_DirectFB_modes.c	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/directfb/SDL_DirectFB_modes.c	Thu Feb 10 14:44:25 2011 -0800
@@ -135,7 +135,7 @@
      *        This has simply no effect.
      */
 
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
 
 	/* FIXME: should we handle the error */
--- a/src/video/directfb/SDL_DirectFB_mouse.c	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/directfb/SDL_DirectFB_mouse.c	Thu Feb 10 14:44:25 2011 -0800
@@ -170,7 +170,7 @@
     if (!window)
         return -1;
     else {
-        SDL_VideoDisplay *display = window->display;
+        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
 
         if (display) {
             DFB_DisplayData *dispdata =
@@ -222,7 +222,7 @@
 static void
 DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_Window * window, int x, int y)
 {
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
     DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
     DFBResult ret;
--- a/src/video/directfb/SDL_DirectFB_render.c	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/directfb/SDL_DirectFB_render.c	Thu Feb 10 14:44:25 2011 -0800
@@ -301,7 +301,7 @@
 DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags)
 {
     SDL_DFB_WINDOWDATA(window);
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_Renderer *renderer = NULL;
     DirectFB_RenderData *data = NULL;
     DFBSurfaceCapabilities scaps;
@@ -409,7 +409,7 @@
 {
     //SDL_DFB_RENDERERDATA(renderer);
     SDL_Window *window = renderer->window;
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_DFB_DEVICEDATA(display->device);
     DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
     DirectFB_TextureData *data = texture->driverdata;
@@ -465,7 +465,7 @@
 DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
 {
     SDL_Window *window = renderer->window;
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_DFB_DEVICEDATA(display->device);
     DirectFB_TextureData *data;
     DFBSurfaceDescription dsc;
@@ -1129,7 +1129,7 @@
 DirectFB_DestroyRenderer(SDL_Renderer * renderer)
 {
     DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
-    SDL_VideoDisplay *display = renderer->window->display;
+    SDL_VideoDisplay *display = renderer->SDL_GetDisplayForWindow(window);
 
 #if 0
     if (display->palette) {
--- a/src/video/directfb/SDL_DirectFB_window.c	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/directfb/SDL_DirectFB_window.c	Thu Feb 10 14:44:25 2011 -0800
@@ -62,17 +62,17 @@
 		bshaped = 1;
 	
     /* Fill the window description. */
-    if (window->x == SDL_WINDOWPOS_CENTERED) {
+    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
         x = (dispdata->cw - window->w) / 2;
-    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
+    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
         x = 0;
     } else {
         x = window->x;
     }
     
-    if (window->y == SDL_WINDOWPOS_CENTERED) {
+    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
         y = (dispdata->ch - window->h) / 2;
-    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
+    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
         y = 0;
     } else {
         y = window->y;
@@ -264,17 +264,17 @@
     SDL_DFB_DISPLAYDATA(window);
     int x, y;
 
-    if (window->x == SDL_WINDOWPOS_CENTERED) {
+    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
         x = (dispdata->cw - window->w) / 2;
-    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
+    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
         x = 0;
     } else {
         x = window->x;
     }
     
-    if (window->y == SDL_WINDOWPOS_CENTERED) {
+    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
         y = (dispdata->ch - window->h) / 2;
-    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
+    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
         y = 0;
     } else {
         y = window->y;
@@ -358,7 +358,7 @@
 DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
 {
     SDL_DFB_WINDOWDATA(window);
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     DFBWindowOptions wopts;
 
     SDL_DFB_CHECK(windata->dfbwin->GetPosition(windata->dfbwin,
@@ -526,7 +526,7 @@
 
     if (adjust) {
 #if SDL_DIRECTFB_OPENGL
-		DirectFB_GL_FreeWindowContexts(window->display->device, window);
+		DirectFB_GL_FreeWindowContexts(SDL_GetVideoDevice(), window);
 #endif
 
 #if (DFB_VERSION_ATLEAST(1,2,1))
@@ -552,10 +552,10 @@
                          GetSubSurface(windata->window_surface,
                                        &windata->client, &windata->surface));
 #endif
-        DirectFB_WM_RedrawLayout(window->display->device, window);
+        DirectFB_WM_RedrawLayout(SDL_GetVideoDevice(), window);
         
 #if SDL_DIRECTFB_OPENGL
-		DirectFB_GL_ReAllocWindowContexts(window->display->device, window);
+		DirectFB_GL_ReAllocWindowContexts(SDL_GetVideoDevice(), window);
 #endif
    }
   error:
--- a/src/video/nds/SDL_ndsrender.c	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/nds/SDL_ndsrender.c	Thu Feb 10 14:44:25 2011 -0800
@@ -107,7 +107,7 @@
 SDL_Renderer *
 NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
 {
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_DisplayMode *displayMode = &display->current_mode;
     SDL_Renderer *renderer;
     NDS_RenderData *data;
@@ -462,7 +462,7 @@
     NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
     NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
     SDL_Window *window = renderer->window;
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     int Bpp = SDL_BYTESPERPIXEL(texture->format);
 
     if (txdat->type == NDSTX_BG) {
@@ -487,7 +487,7 @@
 {
     NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
     SDL_Window *window = renderer->window;
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
 
     /* update sprites */
 //    NDS_OAM_Update(&(data->oam_copy), data->sub);
--- a/src/video/pandora/SDL_pandora.c	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/pandora/SDL_pandora.c	Thu Feb 10 14:44:25 2011 -0800
@@ -417,7 +417,7 @@
     SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
     SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
     SDL_DisplayData *didata =
-        (SDL_DisplayData *) window->display->driverdata;
+        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
     EGLBoolean status;
     int32_t gfstatus;
     EGLint configs;
@@ -816,7 +816,7 @@
     SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
     SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
     SDL_DisplayData *didata =
-        (SDL_DisplayData *) window->display->driverdata;
+        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
 
 
     if (phdata->egl_initialized != SDL_TRUE) {
--- a/src/video/uikit/SDL_uikitopengles.m	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/uikit/SDL_uikitopengles.m	Thu Feb 10 14:44:25 2011 -0800
@@ -103,7 +103,7 @@
 {
     SDL_uikitopenglview *view;
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
-    UIScreen *uiscreen = (UIScreen *) window->display->driverdata;
+    UIScreen *uiscreen = (UIScreen *) SDL_GetDisplayForWindow(window)->driverdata;
     UIWindow *uiwindow = data->uiwindow;
 
     /* construct our view, passing in SDL's OpenGL configuration data */
--- a/src/video/uikit/SDL_uikitwindow.m	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/uikit/SDL_uikitwindow.m	Thu Feb 10 14:44:25 2011 -0800
@@ -40,7 +40,7 @@
 
 static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created)
 {
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     UIScreen *uiscreen = (UIScreen *) display->driverdata;
     SDL_WindowData *data;
         
@@ -85,9 +85,9 @@
 }
 
 int
-UIKit_CreateWindow(_THIS, SDL_Window *window) {
-        
-    SDL_VideoDisplay *display = window->display;
+UIKit_CreateWindow(_THIS, SDL_Window *window)
+{
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     UIScreen *uiscreen = (UIScreen *) display->driverdata;
 
     // SDL currently puts this window at the start of display's linked list. We rely on this.
--- a/src/video/windows/SDL_windowswindow.c	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/windows/SDL_windowswindow.c	Thu Feb 10 14:44:25 2011 -0800
@@ -46,7 +46,7 @@
 SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
 {
     SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_WindowData *data;
 
     /* Allocate the window data */
@@ -93,10 +93,8 @@
         point.x = 0;
         point.y = 0;
         if (ClientToScreen(hwnd, &point)) {
-            SDL_Rect bounds;
-            WIN_GetDisplayBounds(_this, display, &bounds);
-            window->x = point.x - bounds.x;
-            window->y = point.y - bounds.y;
+            window->x = point.x;
+            window->y = point.y;
         }
     }
     {
@@ -166,7 +164,7 @@
 int
 WIN_CreateWindow(_THIS, SDL_Window * window)
 {
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     HWND hwnd;
     RECT rect;
     SDL_Rect bounds;
@@ -203,28 +201,28 @@
         }
     }
     if ((window->flags & SDL_WINDOW_FULLSCREEN)
-        || window->x == SDL_WINDOWPOS_CENTERED) {
+        || SDL_WINDOWPOS_ISCENTERED(window->x)) {
         x = bounds.x + (bounds.w - w) / 2;
-    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
+    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
         if (bounds.x == 0) {
             x = CW_USEDEFAULT;
         } else {
             x = bounds.x;
         }
     } else {
-        x = bounds.x + window->x + rect.left;
+        x = window->x + rect.left;
     }
     if ((window->flags & SDL_WINDOW_FULLSCREEN)
-        || window->y == SDL_WINDOWPOS_CENTERED) {
+        || SDL_WINDOWPOS_ISCENTERED(window->y)) {
         y = bounds.y + (bounds.h - h) / 2;
-    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
+    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
         if (bounds.x == 0) {
             y = CW_USEDEFAULT;
         } else {
             y = bounds.y;
         }
     } else {
-        y = bounds.y + window->y + rect.top;
+        y = window->y + rect.top;
     }
 
     hwnd =
@@ -366,7 +364,7 @@
 void
 WIN_SetWindowPosition(_THIS, SDL_Window * window)
 {
-    SDL_VideoDisplay *display = window->display;
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
     RECT rect;
     SDL_Rect bounds;
@@ -406,16 +404,16 @@
         }
     }
     if ((window->flags & SDL_WINDOW_FULLSCREEN)
-        || window->x == SDL_WINDOWPOS_CENTERED) {
+        || SDL_WINDOWPOS_ISCENTERED(window->x)) {
         x = bounds.x + (bounds.w - w) / 2;
     } else {
-        x = bounds.x + window->x + rect.left;
+        x = window->x + rect.left;
     }
     if ((window->flags & SDL_WINDOW_FULLSCREEN)
-        || window->y == SDL_WINDOWPOS_CENTERED) {
+        || SDL_WINDOWPOS_ISCENTERED(window->y)) {
         y = bounds.y + (bounds.h - h) / 2;
     } else {
-        y = bounds.y + window->y + rect.top;
+        y = window->y + rect.top;
     }
 
     SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));
@@ -452,35 +450,35 @@
     h = (rect.bottom - rect.top);
 
     SetWindowPos(hwnd, top, 0, 0, w, h, (SWP_NOCOPYBITS | SWP_NOMOVE));
-}
+}
+
+#ifdef _WIN32_WCE
+void WINCE_ShowWindow(_THIS, SDL_Window* window, int visible)
+{
+    SDL_WindowData* windowdata = (SDL_WindowData*) window->driverdata;
+    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
+
+    if(visible) {
+        if(window->flags & SDL_WINDOW_FULLSCREEN) {
+            if(videodata->SHFullScreen)
+                videodata->SHFullScreen(windowdata->hwnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON);
 
-#ifdef _WIN32_WCE
-void WINCE_ShowWindow(_THIS, SDL_Window* window, int visible)
-{
-    SDL_WindowData* windowdata = (SDL_WindowData*) window->driverdata;
-    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
-
-    if(visible) {
-        if(window->flags & SDL_WINDOW_FULLSCREEN) {
-            if(videodata->SHFullScreen)
-                videodata->SHFullScreen(windowdata->hwnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON);
-
-            ShowWindow(FindWindow(TEXT("HHTaskBar"), NULL), SW_HIDE);
-        }
-
-        ShowWindow(windowdata->hwnd, SW_SHOW);
-        SetForegroundWindow(windowdata->hwnd);
-    } else {
-        ShowWindow(windowdata->hwnd, SW_HIDE);
-
-        if(window->flags & SDL_WINDOW_FULLSCREEN) {
-            if(videodata->SHFullScreen)
-                videodata->SHFullScreen(windowdata->hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON);
-
-            ShowWindow(FindWindow(TEXT("HHTaskBar"), NULL), SW_SHOW);
-
-        }
-    }
+            ShowWindow(FindWindow(TEXT("HHTaskBar"), NULL), SW_HIDE);
+        }
+
+        ShowWindow(windowdata->hwnd, SW_SHOW);
+        SetForegroundWindow(windowdata->hwnd);
+    } else {
+        ShowWindow(windowdata->hwnd, SW_HIDE);
+
+        if(window->flags & SDL_WINDOW_FULLSCREEN) {
+            if(videodata->SHFullScreen)
+                videodata->SHFullScreen(windowdata->hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON);
+
+            ShowWindow(FindWindow(TEXT("HHTaskBar"), NULL), SW_SHOW);
+
+        }
+    }
 }
 #endif /* _WIN32_WCE */
 
--- a/src/video/x11/SDL_x11clipboard.c	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/x11/SDL_x11clipboard.c	Thu Feb 10 14:44:25 2011 -0800
@@ -38,15 +38,11 @@
 static Window
 GetWindow(_THIS)
 {
-    SDL_VideoDisplay *display;
     SDL_Window *window;
 
-    display = _this->displays;
-    if (display) {
-        window = display->windows;
-        if (window) {
-            return ((SDL_WindowData *) window->driverdata)->xwindow;
-        }
+    window = _this->windows;
+    if (window) {
+        return ((SDL_WindowData *) window->driverdata)->xwindow;
     }
     return None;
 }
--- a/src/video/x11/SDL_x11opengl.c	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/x11/SDL_x11opengl.c	Thu Feb 10 14:44:25 2011 -0800
@@ -380,7 +380,7 @@
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     Display *display = data->videodata->display;
     int screen =
-        ((SDL_DisplayData *) window->display->driverdata)->screen;
+        ((SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata)->screen;
     XWindowAttributes xattr;
     XVisualInfo v, *vinfo;
     int n;
--- a/src/video/x11/SDL_x11window.c	Thu Feb 10 14:36:09 2011 -0800
+++ b/src/video/x11/SDL_x11window.c	Thu Feb 10 14:44:25 2011 -0800
@@ -90,7 +90,7 @@
 {
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     SDL_DisplayData *displaydata =
-        (SDL_DisplayData *) window->display->driverdata;
+        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
     XWindowAttributes attr;
 
     XGetWindowAttributes(data->display, RootWindow(data->display, displaydata->screen), &attr);
@@ -259,7 +259,7 @@
 {
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     SDL_DisplayData *displaydata =
-        (SDL_DisplayData *) window->display->driverdata;
+        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
     Display *display = data->display;
     int screen = displaydata->screen;
     Visual *visual;
@@ -328,19 +328,19 @@
     xattr.colormap = XCreateColormap(display, RootWindow(display, screen), visual, AllocNone);
 
     if (oldstyle_fullscreen
-        || window->x == SDL_WINDOWPOS_CENTERED) {
+        || SDL_WINDOWPOS_ISCENTERED(window->x)) {
         X11_GetDisplaySize(_this, window, &x, NULL);
         x = (x - window->w) / 2;
-    } else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
+    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
         x = 0;
     } else {
         x = window->x;
     }
     if (oldstyle_fullscreen
-        || window->y == SDL_WINDOWPOS_CENTERED) {
+        || SDL_WINDOWPOS_ISCENTERED(window->y)) {
         X11_GetDisplaySize(_this, window, NULL, &y);
         y = (y - window->h) / 2;
-    } else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
+    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
         y = 0;
     } else {
         y = window->y;
@@ -377,8 +377,8 @@
             sizehints->flags = PMaxSize | PMinSize;
         }
         if (!oldstyle_fullscreen
-            && window->x != SDL_WINDOWPOS_UNDEFINED
-            && window->y != SDL_WINDOWPOS_UNDEFINED) {
+            && !SDL_WINDOWPOS_ISUNDEFINED(window->x)
+            && !SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
             sizehints->x = x;
             sizehints->y = y;
             sizehints->flags |= USPosition;
@@ -713,14 +713,14 @@
     oldstyle_fullscreen = X11_IsWindowOldFullscreen(_this, window);
 
     if (oldstyle_fullscreen
-        || window->x == SDL_WINDOWPOS_CENTERED) {
+        || SDL_WINDOWPOS_ISCENTERED(window->x)) {
         X11_GetDisplaySize(_this, window, &x, NULL);
         x = (x - window->w) / 2;
     } else {
         x = window->x;
     }
     if (oldstyle_fullscreen
-        || window->y == SDL_WINDOWPOS_CENTERED) {
+        || SDL_WINDOWPOS_ISCENTERED(window->y)) {
         X11_GetDisplaySize(_this, window, NULL, &y);
         y = (y - window->h) / 2;
     } else {
@@ -777,7 +777,7 @@
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     SDL_DisplayData *displaydata =
-        (SDL_DisplayData *) window->display->driverdata;
+        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
     Display *display = data->videodata->display;
     Atom _NET_WM_STATE = data->videodata->_NET_WM_STATE;
     Atom _NET_WM_STATE_MAXIMIZED_VERT = data->videodata->_NET_WM_STATE_MAXIMIZED_VERT;
@@ -832,7 +832,7 @@
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     SDL_DisplayData *displaydata =
-        (SDL_DisplayData *) window->display->driverdata;
+        (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
     Display *display = data->videodata->display;
  
     XIconifyWindow(display, data->xwindow, displaydata->screen);
--- a/test/common.c	Thu Feb 10 14:36:09 2011 -0800
+++ b/test/common.c	Thu Feb 10 14:44:25 2011 -0800
@@ -1015,12 +1015,14 @@
         case SDLK_m:
             if (event->key.keysym.mod & KMOD_CTRL) {
                 /* Ctrl-M maximize */
-                /* FIXME: Which window has focus for this keyboard? */
                 for (i = 0; i < state->num_windows; ++i) {
-                    if (SDL_GetWindowFlags(state->windows[i]) & SDL_WINDOW_MAXIMIZED) {
-                        SDL_RestoreWindow(state->windows[i]);
-                    } else {
-                        SDL_MaximizeWindow(state->windows[i]);
+                    Uint32 flags = SDL_GetWindowFlags(state->windows[i]);
+                    if (flags & SDL_WINDOW_INPUT_FOCUS) {
+                        if (flags & SDL_WINDOW_MAXIMIZED) {
+                            SDL_RestoreWindow(state->windows[i]);
+                        } else {
+                            SDL_MaximizeWindow(state->windows[i]);
+                        }
                     }
                 }
             }
@@ -1028,9 +1030,26 @@
         case SDLK_z:
             if (event->key.keysym.mod & KMOD_CTRL) {
                 /* Ctrl-Z minimize */
-                /* FIXME: Which window has focus for this keyboard? */
                 for (i = 0; i < state->num_windows; ++i) {
-                    SDL_MinimizeWindow(state->windows[i]);
+                    Uint32 flags = SDL_GetWindowFlags(state->windows[i]);
+                    if (flags & SDL_WINDOW_INPUT_FOCUS) {
+                        SDL_MinimizeWindow(state->windows[i]);
+                    }
+                }
+            }
+            break;
+        case SDLK_RETURN:
+            if (event->key.keysym.mod & KMOD_CTRL) {
+                /* Ctrl-Enter toggle fullscreen */
+                for (i = 0; i < state->num_windows; ++i) {
+                    Uint32 flags = SDL_GetWindowFlags(state->windows[i]);
+                    if (flags & SDL_WINDOW_INPUT_FOCUS) {
+                        if (flags & SDL_WINDOW_FULLSCREEN) {
+                            SDL_SetWindowFullscreen(state->windows[i], SDL_FALSE);
+                        } else {
+                            SDL_SetWindowFullscreen(state->windows[i], SDL_TRUE);
+                        }
+                    }
                 }
             }
             break;
--- a/test/testwm2.c	Thu Feb 10 14:36:09 2011 -0800
+++ b/test/testwm2.c	Thu Feb 10 14:44:25 2011 -0800
@@ -49,6 +49,19 @@
         /* Check for events */
         while (SDL_PollEvent(&event)) {
             CommonEvent(state, &event, &done);
+
+            if (event.type == SDL_WINDOWEVENT) {
+                if (event.window.event == SDL_WINDOWEVENT_MOVED) {
+                    SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
+                    if (window) {
+                        printf("Window %d moved to %d,%d (display %d)\n",
+                            event.window.windowID,
+                            event.window.data1,
+                            event.window.data2,
+                            SDL_GetWindowDisplay(window));
+                    }
+                }
+            }
         }
     }
     quit(0);