diff --git a/src/video/quartz/SDL_QuartzEvents.m b/src/video/quartz/SDL_QuartzEvents.m index 64cefde53..1629a5650 100644 --- a/src/video/quartz/SDL_QuartzEvents.m +++ b/src/video/quartz/SDL_QuartzEvents.m @@ -614,8 +614,10 @@ static void QZ_GetMouseLocation (_THIS, NSPoint *p) { QZ_PrivateCocoaToSDL (this, p); } -static void QZ_DoActivate (_THIS) -{ +void QZ_DoActivate (_THIS) { + + SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS | (QZ_IsMouseInWindow (this) ? SDL_APPMOUSEFOCUS : 0)); + /* Hide the cursor if it was hidden by SDL_ShowCursor() */ if (!cursor_should_be_visible) QZ_HideMouse (this); @@ -635,7 +637,9 @@ static void QZ_DoActivate (_THIS) } } -static void QZ_DoDeactivate (_THIS) { +void QZ_DoDeactivate (_THIS) { + + SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS | SDL_APPMOUSEFOCUS); /* Get the current cursor location, for restore on activate */ QZ_GetMouseLocation (this, &cursor_loc); @@ -753,14 +757,9 @@ void QZ_PumpEvents (_THIS) BOOL isInGameWin; #define DO_MOUSE_DOWN(button) do { \ - if ( [ NSApp isActive ] ) { \ - if ( isInGameWin ) { \ - SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \ - expect_mouse_up |= 1<flags; - /* we're fullscreen, so flag all input states... */ - SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS | SDL_APPACTIVE); + /* Set app state, hide cursor if necessary, ... */ + QZ_DoActivate(this); return current; diff --git a/src/video/quartz/SDL_QuartzWM.m b/src/video/quartz/SDL_QuartzWM.m index 487e5323f..a3aa3ed23 100644 --- a/src/video/quartz/SDL_QuartzWM.m +++ b/src/video/quartz/SDL_QuartzWM.m @@ -78,15 +78,14 @@ void QZ_ShowMouse (_THIS) { } void QZ_HideMouse (_THIS) { - BOOL isInGameWin = QZ_IsMouseInWindow (this); - if (isInGameWin && cursor_visible) { + if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) && cursor_visible) { [ NSCursor hide ]; cursor_visible = NO; } } BOOL QZ_IsMouseInWindow (_THIS) { - if (mode_flags & SDL_FULLSCREEN) return YES; + if (qz_window == nil) return YES; /*fullscreen*/ else { NSPoint p = [ qz_window mouseLocationOutsideOfEventStream ]; p.y -= 1.0f; /* Apparently y goes from 1 to h, not from 0 to h-1 (i.e. the "location of the mouse" seems to be defined as "the location of the top left corner of the mouse pointer's hot pixel" */ @@ -166,7 +165,7 @@ void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p) { *p = [ window_view convertPoint:*p fromView: nil ]; /* We need a workaround in OpenGL mode */ - if ( SDL_VideoSurface->flags & SDL_OPENGL ) { + if ( SDL_VideoSurface != NULL && (SDL_VideoSurface->flags & SDL_OPENGL) ) { p->y = [window_view frame].size.height - p->y; } } diff --git a/src/video/quartz/SDL_QuartzWindow.m b/src/video/quartz/SDL_QuartzWindow.m index 5b29f1ce8..ffbf1eadf 100644 --- a/src/video/quartz/SDL_QuartzWindow.m +++ b/src/video/quartz/SDL_QuartzWindow.m @@ -208,24 +208,12 @@ static void QZ_SetPortAlphaOpaque () { - (void)windowDidBecomeKey:(NSNotification *)aNotification { - SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS); + QZ_DoActivate (current_video); } - (void)windowDidResignKey:(NSNotification *)aNotification { - SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS); -} - -- (void)windowDidBecomeMain:(NSNotification *)aNotification -{ - SDL_VideoDevice *this = (SDL_VideoDevice*)current_video; - if (this && QZ_IsMouseInWindow (this)) - SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); -} - -- (void)windowDidResignMain:(NSNotification *)aNotification -{ - SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS); + QZ_DoDeactivate (current_video); } @end