Fixed bug 1372 - OSX Window Maximize/Resize Doesn't Update Window Position
authorSam Lantinga <slouken@libsdl.org>
Wed, 18 Jan 2012 22:22:54 -0500
changeset 6231 5eecf59b698f
parent 6223 af89a3a770e7
child 6232 37e8d0736366
Fixed bug 1372 - OSX Window Maximize/Resize Doesn't Update Window Position Alex Nankervis 2012-01-15 14:20:01 PST SDL_cocoawindow.m, windowDidResize needs to also send a window move event. Depending on the corner you resize a window from, or when maximizing a window, the window position will change. Discovered this when creating a maximized window and found that the window position was stuck at the un-maximized window's value. Diff with fix attached.
src/video/cocoa/SDL_cocoawindow.m
--- a/src/video/cocoa/SDL_cocoawindow.m	Mon Jan 16 20:40:10 2012 -0500
+++ b/src/video/cocoa/SDL_cocoawindow.m	Wed Jan 18 22:22:54 2012 -0500
@@ -153,8 +153,11 @@
 - (void)windowDidResize:(NSNotification *)aNotification
 {
     SDL_VideoDevice *device = SDL_GetVideoDevice();
-    int w, h;
+    int x, y, w, h;
     NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
+    ConvertNSRect(&rect);
+    x = (int)rect.origin.x;
+    y = (int)rect.origin.y;
     w = (int)rect.size.width;
     h = (int)rect.size.height;
     if (SDL_IsShapedWindow(_data->window))
@@ -164,6 +167,9 @@
         [((NSOpenGLContext *) device->current_glctx) update];
     }
 
+    /* The window can move during a resize event, such as when maximizing
+       or resizing from a corner */
+    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MOVED, x, y);
     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
 }