src/video/cocoa/SDL_cocoawindow.m
changeset 5398 83816c8a2b58
parent 5396 109b7c071f70
child 5399 1e2a82a66df8
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Thu Feb 24 23:42:58 2011 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sat Feb 26 10:11:09 2011 -0800
     1.3 @@ -22,6 +22,7 @@
     1.4  #include "SDL_config.h"
     1.5  
     1.6  #include "SDL_syswm.h"
     1.7 +#include "SDL_timer.h"  /* For SDL_GetTicks() */
     1.8  #include "../SDL_sysvideo.h"
     1.9  #include "../../events/SDL_keyboard_c.h"
    1.10  #include "../../events/SDL_mouse_c.h"
    1.11 @@ -31,6 +32,9 @@
    1.12  #include "SDL_cocoashape.h"
    1.13  #include "SDL_cocoamouse.h"
    1.14  
    1.15 +
    1.16 +static Uint32 s_moveHack;
    1.17 +
    1.18  static __inline__ void ConvertNSRect(NSRect *r)
    1.19  {
    1.20      r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
    1.21 @@ -115,11 +119,29 @@
    1.22  - (void)windowDidMove:(NSNotification *)aNotification
    1.23  {
    1.24      int x, y;
    1.25 -    NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
    1.26 +    SDL_Window *window = _data->window;
    1.27 +    NSWindow *nswindow = _data->nswindow;
    1.28 +    NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
    1.29      ConvertNSRect(&rect);
    1.30 +
    1.31 +    if (s_moveHack) {
    1.32 +        SDL_bool blockMove = ((SDL_GetTicks() - s_moveHack) < 500);
    1.33 +
    1.34 +        s_moveHack = 0;
    1.35 +
    1.36 +        if (blockMove) {
    1.37 +            /* Cocoa is adjusting the window in response to a mode change */
    1.38 +            rect.origin.x = window->x;
    1.39 +            rect.origin.y = window->y;
    1.40 +            ConvertNSRect(&rect);
    1.41 +            [nswindow setFrameOrigin:rect.origin];
    1.42 +            return;
    1.43 +        }
    1.44 +    }
    1.45 +
    1.46      x = (int)rect.origin.x;
    1.47      y = (int)rect.origin.y;
    1.48 -    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MOVED, x, y);
    1.49 +    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
    1.50  }
    1.51  
    1.52  - (void)windowDidResize:(NSNotification *)aNotification
    1.53 @@ -786,16 +808,22 @@
    1.54          if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
    1.55              [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
    1.56          }
    1.57 -        [nswindow setFrameOrigin:rect.origin];
    1.58 -        [nswindow setContentSize:rect.size];
    1.59      } else {
    1.60 +        rect.origin.x = window->windowed.x;
    1.61 +        rect.origin.y = window->windowed.y;
    1.62 +        rect.size.width = window->windowed.w;
    1.63 +        rect.size.height = window->windowed.h;
    1.64 +        ConvertNSRect(&rect);
    1.65 +
    1.66          if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
    1.67              [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
    1.68          }
    1.69 +    }
    1.70  
    1.71 -        // This doesn't seem to do anything...
    1.72 -        //[nswindow setFrameOrigin:origin];
    1.73 -    }
    1.74 +    s_moveHack = 0;
    1.75 +    [nswindow setFrameOrigin:rect.origin];
    1.76 +    [nswindow setContentSize:rect.size];
    1.77 +    s_moveHack = SDL_GetTicks();
    1.78  
    1.79  #ifdef FULLSCREEN_TOGGLEABLE
    1.80      if (fullscreen) {