| Summary: | Cleaning up application activation/deactivation code on Mac OS X (Quartz) | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Christian Walther <cwalther> |
| Component: | events | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | max, terence1819 |
| Version: | HG 1.2 | ||
| Hardware: | PowerPC | ||
| OS: | Mac OS X (All) | ||
| Attachments: |
proposed patch
Proposed patch (Updated to apply to latest CVS) |
||
|
Description
Christian Walther
2006-01-19 12:28:27 UTC
Created attachment 26 [details]
proposed patch
Setting Sam as "QA Contact" on all bugs (even resolved ones) so he'll definitely be in the loop to any further discussion here about SDL. --ryan. Created attachment 92 [details]
Proposed patch (Updated to apply to latest CVS)
The patch seems sane to me. I just recompiled SDL CVS with the patch applied. That way, both I and everybody using builds made by me will give it some testing :-). I'll return here when I either think it works fine, or find a problem.
So far the patch worked flawlessly for me. I think it could safely be accepted, and would benefit SDL, as it both simplifies and fixes the activation handling. This patch is in CVS, thanks! Thanks, and thanks for testing, Max. Comment on attachment 92 [details] Proposed patch (Updated to apply to latest CVS) >Index: src/video/quartz/SDL_QuartzEvents.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzEvents.m,v >retrieving revision 1.41 >diff -u -d -r1.41 SDL_QuartzEvents.m >--- src/video/quartz/SDL_QuartzEvents.m 21 Mar 2006 00:35:22 -0000 1.41 >+++ src/video/quartz/SDL_QuartzEvents.m 22 Mar 2006 18:44:15 -0000 >@@ -614,8 +614,10 @@ > 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_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 @@ > BOOL isInGameWin; > > #define DO_MOUSE_DOWN(button) do { \ >- if ( [ NSApp isActive ] ) { \ >- if ( isInGameWin ) { \ >- SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \ >- expect_mouse_up |= 1<<button; \ >- } \ >- } \ >- else { \ >- QZ_DoActivate (this); \ >+ if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) { \ >+ SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \ >+ expect_mouse_up |= 1<<button; \ > } \ > [ NSApp sendEvent:event ]; \ > } while(0) >@@ -916,7 +915,7 @@ > QZ_ShowMouse (this); > } > else >- if ( isInGameWin && !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) { >+ if ( isInGameWin && (SDL_GetAppState() & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) == SDL_APPINPUTFOCUS ) { > > SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); > if (!cursor_should_be_visible) >@@ -950,17 +949,7 @@ > break; > case NSFlagsChanged: > break; >- case NSAppKitDefined: >- switch ( [ event subtype ] ) { >- case NSApplicationActivatedEventType: >- QZ_DoActivate (this); >- break; >- case NSApplicationDeactivatedEventType: >- QZ_DoDeactivate (this); >- break; >- } >- [ NSApp sendEvent:event ]; >- break; >+ /* case NSAppKitDefined: break; */ > /* case NSApplicationDefined: break; */ > /* case NSPeriodic: break; */ > /* case NSCursorUpdate: break; */ >Index: src/video/quartz/SDL_QuartzVideo.h >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzVideo.h,v >retrieving revision 1.30 >diff -u -d -r1.30 SDL_QuartzVideo.h >--- src/video/quartz/SDL_QuartzVideo.h 8 Mar 2006 06:21:04 -0000 1.30 >+++ src/video/quartz/SDL_QuartzVideo.h 22 Mar 2006 18:44:16 -0000 >@@ -224,3 +224,5 @@ > void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p); > void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p); > BOOL QZ_IsMouseInWindow (_THIS); >+void QZ_DoActivate (_THIS); >+void QZ_DoDeactivate (_THIS); >Index: src/video/quartz/SDL_QuartzVideo.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzVideo.m,v >retrieving revision 1.57 >diff -u -d -r1.57 SDL_QuartzVideo.m >--- src/video/quartz/SDL_QuartzVideo.m 15 Mar 2006 17:46:40 -0000 1.57 >+++ src/video/quartz/SDL_QuartzVideo.m 22 Mar 2006 18:44:16 -0000 >@@ -560,8 +560,8 @@ > /* Save the flags to ensure correct tear-down */ > mode_flags = current->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; > >Index: src/video/quartz/SDL_QuartzWM.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzWM.m,v >retrieving revision 1.27 >diff -u -d -r1.27 SDL_QuartzWM.m >--- src/video/quartz/SDL_QuartzWM.m 21 Feb 2006 08:47:46 -0000 1.27 >+++ src/video/quartz/SDL_QuartzWM.m 22 Mar 2006 18:44:17 -0000 >@@ -78,15 +78,14 @@ > } > > 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 @@ > *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; > } > } >Index: src/video/quartz/SDL_QuartzWindow.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzWindow.m,v >retrieving revision 1.11 >diff -u -d -r1.11 SDL_QuartzWindow.m >--- src/video/quartz/SDL_QuartzWindow.m 9 Mar 2006 06:33:21 -0000 1.11 >+++ src/video/quartz/SDL_QuartzWindow.m 22 Mar 2006 18:44:17 -0000 >@@ -208,24 +208,12 @@ > > - (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 Comment on attachment 92 [details] Proposed patch (Updated to apply to latest CVS) >Index: src/video/quartz/SDL_QuartzEvents.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzEvents.m,v >retrieving revision 1.41 >diff -u -d -r1.41 SDL_QuartzEvents.m >--- src/video/quartz/SDL_QuartzEvents.m 21 Mar 2006 00:35:22 -0000 1.41 >+++ src/video/quartz/SDL_QuartzEvents.m 22 Mar 2006 18:44:15 -0000 >@@ -614,8 +614,10 @@ > 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_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 @@ > BOOL isInGameWin; > > #define DO_MOUSE_DOWN(button) do { \ >- if ( [ NSApp isActive ] ) { \ >- if ( isInGameWin ) { \ >- SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \ >- expect_mouse_up |= 1<<button; \ >- } \ >- } \ >- else { \ >- QZ_DoActivate (this); \ >+ if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) { \ >+ SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \ >+ expect_mouse_up |= 1<<button; \ > } \ > [ NSApp sendEvent:event ]; \ > } while(0) >@@ -916,7 +915,7 @@ > QZ_ShowMouse (this); > } > else >- if ( isInGameWin && !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) { >+ if ( isInGameWin && (SDL_GetAppState() & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) == SDL_APPINPUTFOCUS ) { > > SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); > if (!cursor_should_be_visible) >@@ -950,17 +949,7 @@ > break; > case NSFlagsChanged: > break; >- case NSAppKitDefined: >- switch ( [ event subtype ] ) { >- case NSApplicationActivatedEventType: >- QZ_DoActivate (this); >- break; >- case NSApplicationDeactivatedEventType: >- QZ_DoDeactivate (this); >- break; >- } >- [ NSApp sendEvent:event ]; >- break; >+ /* case NSAppKitDefined: break; */ > /* case NSApplicationDefined: break; */ > /* case NSPeriodic: break; */ > /* case NSCursorUpdate: break; */ >Index: src/video/quartz/SDL_QuartzVideo.h >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzVideo.h,v >retrieving revision 1.30 >diff -u -d -r1.30 SDL_QuartzVideo.h >--- src/video/quartz/SDL_QuartzVideo.h 8 Mar 2006 06:21:04 -0000 1.30 >+++ src/video/quartz/SDL_QuartzVideo.h 22 Mar 2006 18:44:16 -0000 >@@ -224,3 +224,5 @@ > void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p); > void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p); > BOOL QZ_IsMouseInWindow (_THIS); >+void QZ_DoActivate (_THIS); >+void QZ_DoDeactivate (_THIS); >Index: src/video/quartz/SDL_QuartzVideo.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzVideo.m,v >retrieving revision 1.57 >diff -u -d -r1.57 SDL_QuartzVideo.m >--- src/video/quartz/SDL_QuartzVideo.m 15 Mar 2006 17:46:40 -0000 1.57 >+++ src/video/quartz/SDL_QuartzVideo.m 22 Mar 2006 18:44:16 -0000 >@@ -560,8 +560,8 @@ > /* Save the flags to ensure correct tear-down */ > mode_flags = current->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; > >Index: src/video/quartz/SDL_QuartzWM.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzWM.m,v >retrieving revision 1.27 >diff -u -d -r1.27 SDL_QuartzWM.m >--- src/video/quartz/SDL_QuartzWM.m 21 Feb 2006 08:47:46 -0000 1.27 >+++ src/video/quartz/SDL_QuartzWM.m 22 Mar 2006 18:44:17 -0000 >@@ -78,15 +78,14 @@ > } > > 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 @@ > *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; > } > } >Index: src/video/quartz/SDL_QuartzWindow.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzWindow.m,v >retrieving revision 1.11 >diff -u -d -r1.11 SDL_QuartzWindow.m >--- src/video/quartz/SDL_QuartzWindow.m 9 Mar 2006 06:33:21 -0000 1.11 >+++ src/video/quartz/SDL_QuartzWindow.m 22 Mar 2006 18:44:17 -0000 >@@ -208,24 +208,12 @@ > > - (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 Comment on attachment 92 [details] Proposed patch (Updated to apply to latest CVS) >Index: src/video/quartz/SDL_QuartzEvents.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzEvents.m,v >retrieving revision 1.41 >diff -u -d -r1.41 SDL_QuartzEvents.m >--- src/video/quartz/SDL_QuartzEvents.m 21 Mar 2006 00:35:22 -0000 1.41 >+++ src/video/quartz/SDL_QuartzEvents.m 22 Mar 2006 18:44:15 -0000 >@@ -614,8 +614,10 @@ > 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_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 @@ > BOOL isInGameWin; > > #define DO_MOUSE_DOWN(button) do { \ >- if ( [ NSApp isActive ] ) { \ >- if ( isInGameWin ) { \ >- SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \ >- expect_mouse_up |= 1<<button; \ >- } \ >- } \ >- else { \ >- QZ_DoActivate (this); \ >+ if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) { \ >+ SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \ >+ expect_mouse_up |= 1<<button; \ > } \ > [ NSApp sendEvent:event ]; \ > } while(0) >@@ -916,7 +915,7 @@ > QZ_ShowMouse (this); > } > else >- if ( isInGameWin && !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) { >+ if ( isInGameWin && (SDL_GetAppState() & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) == SDL_APPINPUTFOCUS ) { > > SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); > if (!cursor_should_be_visible) >@@ -950,17 +949,7 @@ > break; > case NSFlagsChanged: > break; >- case NSAppKitDefined: >- switch ( [ event subtype ] ) { >- case NSApplicationActivatedEventType: >- QZ_DoActivate (this); >- break; >- case NSApplicationDeactivatedEventType: >- QZ_DoDeactivate (this); >- break; >- } >- [ NSApp sendEvent:event ]; >- break; >+ /* case NSAppKitDefined: break; */ > /* case NSApplicationDefined: break; */ > /* case NSPeriodic: break; */ > /* case NSCursorUpdate: break; */ >Index: src/video/quartz/SDL_QuartzVideo.h >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzVideo.h,v >retrieving revision 1.30 >diff -u -d -r1.30 SDL_QuartzVideo.h >--- src/video/quartz/SDL_QuartzVideo.h 8 Mar 2006 06:21:04 -0000 1.30 >+++ src/video/quartz/SDL_QuartzVideo.h 22 Mar 2006 18:44:16 -0000 >@@ -224,3 +224,5 @@ > void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p); > void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p); > BOOL QZ_IsMouseInWindow (_THIS); >+void QZ_DoActivate (_THIS); >+void QZ_DoDeactivate (_THIS); >Index: src/video/quartz/SDL_QuartzVideo.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzVideo.m,v >retrieving revision 1.57 >diff -u -d -r1.57 SDL_QuartzVideo.m >--- src/video/quartz/SDL_QuartzVideo.m 15 Mar 2006 17:46:40 -0000 1.57 >+++ src/video/quartz/SDL_QuartzVideo.m 22 Mar 2006 18:44:16 -0000 >@@ -560,8 +560,8 @@ > /* Save the flags to ensure correct tear-down */ > mode_flags = current->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; > >Index: src/video/quartz/SDL_QuartzWM.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzWM.m,v >retrieving revision 1.27 >diff -u -d -r1.27 SDL_QuartzWM.m >--- src/video/quartz/SDL_QuartzWM.m 21 Feb 2006 08:47:46 -0000 1.27 >+++ src/video/quartz/SDL_QuartzWM.m 22 Mar 2006 18:44:17 -0000 >@@ -78,15 +78,14 @@ > } > > 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 @@ > *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; > } > } >Index: src/video/quartz/SDL_QuartzWindow.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzWindow.m,v >retrieving revision 1.11 >diff -u -d -r1.11 SDL_QuartzWindow.m >--- src/video/quartz/SDL_QuartzWindow.m 9 Mar 2006 06:33:21 -0000 1.11 >+++ src/video/quartz/SDL_QuartzWindow.m 22 Mar 2006 18:44:17 -0000 >@@ -208,24 +208,12 @@ > > - (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 Comment on attachment 92 [details] Proposed patch (Updated to apply to latest CVS) >Index: src/video/quartz/SDL_QuartzEvents.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzEvents.m,v >retrieving revision 1.41 >diff -u -d -r1.41 SDL_QuartzEvents.m >--- src/video/quartz/SDL_QuartzEvents.m 21 Mar 2006 00:35:22 -0000 1.41 >+++ src/video/quartz/SDL_QuartzEvents.m 22 Mar 2006 18:44:15 -0000 >@@ -614,8 +614,10 @@ > 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_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 @@ > BOOL isInGameWin; > > #define DO_MOUSE_DOWN(button) do { \ >- if ( [ NSApp isActive ] ) { \ >- if ( isInGameWin ) { \ >- SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \ >- expect_mouse_up |= 1<<button; \ >- } \ >- } \ >- else { \ >- QZ_DoActivate (this); \ >+ if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) { \ >+ SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \ >+ expect_mouse_up |= 1<<button; \ > } \ > [ NSApp sendEvent:event ]; \ > } while(0) >@@ -916,7 +915,7 @@ > QZ_ShowMouse (this); > } > else >- if ( isInGameWin && !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) { >+ if ( isInGameWin && (SDL_GetAppState() & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) == SDL_APPINPUTFOCUS ) { > > SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); > if (!cursor_should_be_visible) >@@ -950,17 +949,7 @@ > break; > case NSFlagsChanged: > break; >- case NSAppKitDefined: >- switch ( [ event subtype ] ) { >- case NSApplicationActivatedEventType: >- QZ_DoActivate (this); >- break; >- case NSApplicationDeactivatedEventType: >- QZ_DoDeactivate (this); >- break; >- } >- [ NSApp sendEvent:event ]; >- break; >+ /* case NSAppKitDefined: break; */ > /* case NSApplicationDefined: break; */ > /* case NSPeriodic: break; */ > /* case NSCursorUpdate: break; */ >Index: src/video/quartz/SDL_QuartzVideo.h >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzVideo.h,v >retrieving revision 1.30 >diff -u -d -r1.30 SDL_QuartzVideo.h >--- src/video/quartz/SDL_QuartzVideo.h 8 Mar 2006 06:21:04 -0000 1.30 >+++ src/video/quartz/SDL_QuartzVideo.h 22 Mar 2006 18:44:16 -0000 >@@ -224,3 +224,5 @@ > void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p); > void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p); > BOOL QZ_IsMouseInWindow (_THIS); >+void QZ_DoActivate (_THIS); >+void QZ_DoDeactivate (_THIS); >Index: src/video/quartz/SDL_QuartzVideo.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzVideo.m,v >retrieving revision 1.57 >diff -u -d -r1.57 SDL_QuartzVideo.m >--- src/video/quartz/SDL_QuartzVideo.m 15 Mar 2006 17:46:40 -0000 1.57 >+++ src/video/quartz/SDL_QuartzVideo.m 22 Mar 2006 18:44:16 -0000 >@@ -560,8 +560,8 @@ > /* Save the flags to ensure correct tear-down */ > mode_flags = current->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; > >Index: src/video/quartz/SDL_QuartzWM.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzWM.m,v >retrieving revision 1.27 >diff -u -d -r1.27 SDL_QuartzWM.m >--- src/video/quartz/SDL_QuartzWM.m 21 Feb 2006 08:47:46 -0000 1.27 >+++ src/video/quartz/SDL_QuartzWM.m 22 Mar 2006 18:44:17 -0000 >@@ -78,15 +78,14 @@ > } > > 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 @@ > *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; > } > } >Index: src/video/quartz/SDL_QuartzWindow.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzWindow.m,v >retrieving revision 1.11 >diff -u -d -r1.11 SDL_QuartzWindow.m >--- src/video/quartz/SDL_QuartzWindow.m 9 Mar 2006 06:33:21 -0000 1.11 >+++ src/video/quartz/SDL_QuartzWindow.m 22 Mar 2006 18:44:17 -0000 >@@ -208,24 +208,12 @@ > > - (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 Comment on attachment 92 [details] Proposed patch (Updated to apply to latest CVS) >Index: src/video/quartz/SDL_QuartzEvents.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzEvents.m,v >retrieving revision 1.41 >diff -u -d -r1.41 SDL_QuartzEvents.m >--- src/video/quartz/SDL_QuartzEvents.m 21 Mar 2006 00:35:22 -0000 1.41 >+++ src/video/quartz/SDL_QuartzEvents.m 22 Mar 2006 18:44:15 -0000 >@@ -614,8 +614,10 @@ > 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_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 @@ > BOOL isInGameWin; > > #define DO_MOUSE_DOWN(button) do { \ >- if ( [ NSApp isActive ] ) { \ >- if ( isInGameWin ) { \ >- SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \ >- expect_mouse_up |= 1<<button; \ >- } \ >- } \ >- else { \ >- QZ_DoActivate (this); \ >+ if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) { \ >+ SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \ >+ expect_mouse_up |= 1<<button; \ > } \ > [ NSApp sendEvent:event ]; \ > } while(0) >@@ -916,7 +915,7 @@ > QZ_ShowMouse (this); > } > else >- if ( isInGameWin && !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) { >+ if ( isInGameWin && (SDL_GetAppState() & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) == SDL_APPINPUTFOCUS ) { > > SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); > if (!cursor_should_be_visible) >@@ -950,17 +949,7 @@ > break; > case NSFlagsChanged: > break; >- case NSAppKitDefined: >- switch ( [ event subtype ] ) { >- case NSApplicationActivatedEventType: >- QZ_DoActivate (this); >- break; >- case NSApplicationDeactivatedEventType: >- QZ_DoDeactivate (this); >- break; >- } >- [ NSApp sendEvent:event ]; >- break; >+ /* case NSAppKitDefined: break; */ > /* case NSApplicationDefined: break; */ > /* case NSPeriodic: break; */ > /* case NSCursorUpdate: break; */ >Index: src/video/quartz/SDL_QuartzVideo.h >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzVideo.h,v >retrieving revision 1.30 >diff -u -d -r1.30 SDL_QuartzVideo.h >--- src/video/quartz/SDL_QuartzVideo.h 8 Mar 2006 06:21:04 -0000 1.30 >+++ src/video/quartz/SDL_QuartzVideo.h 22 Mar 2006 18:44:16 -0000 >@@ -224,3 +224,5 @@ > void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p); > void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p); > BOOL QZ_IsMouseInWindow (_THIS); >+void QZ_DoActivate (_THIS); >+void QZ_DoDeactivate (_THIS); >Index: src/video/quartz/SDL_QuartzVideo.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzVideo.m,v >retrieving revision 1.57 >diff -u -d -r1.57 SDL_QuartzVideo.m >--- src/video/quartz/SDL_QuartzVideo.m 15 Mar 2006 17:46:40 -0000 1.57 >+++ src/video/quartz/SDL_QuartzVideo.m 22 Mar 2006 18:44:16 -0000 >@@ -560,8 +560,8 @@ > /* Save the flags to ensure correct tear-down */ > mode_flags = current->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; > >Index: src/video/quartz/SDL_QuartzWM.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzWM.m,v >retrieving revision 1.27 >diff -u -d -r1.27 SDL_QuartzWM.m >--- src/video/quartz/SDL_QuartzWM.m 21 Feb 2006 08:47:46 -0000 1.27 >+++ src/video/quartz/SDL_QuartzWM.m 22 Mar 2006 18:44:17 -0000 >@@ -78,15 +78,14 @@ > } > > 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 @@ > *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; > } > } >Index: src/video/quartz/SDL_QuartzWindow.m >=================================================================== >RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL_QuartzWindow.m,v >retrieving revision 1.11 >diff -u -d -r1.11 SDL_QuartzWindow.m >--- src/video/quartz/SDL_QuartzWindow.m 9 Mar 2006 06:33:21 -0000 1.11 >+++ src/video/quartz/SDL_QuartzWindow.m 22 Mar 2006 18:44:17 -0000 >@@ -208,24 +208,12 @@ > > - (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 |