comparison src/video/quartz/SDL_QuartzWM.m @ 1629:ef4a796e7f24

Fixed bug #55 From Christian Walther: When writing my patch for #12, I ended up doing all sorts of changes to the way application/window activating/deactivating is handled in the Quartz backend, resulting in the attached patch. It does make the code a bit cleaner IMHO, but as it might be regarded as a case of "if it ain't broken, don't fix it" I'd like to hear other people's opinion about it. Please shout if some change strikes you as unnecessary or wrong, and I'll explain the reasons behind it. As far as I tested it, it does not introduce any new bugs, but I may well have missed some. - The most fundamental change (that triggered most of the others) is irrelevant for the usual single-window SDL applications, it only affects the people who are crazy enough to display other Cocoa windows alongside the SDL window (I'm actually doing this currently, although the additional window only displays debugging info and won't be present in the final product): Before, some things were done on the application becoming active, some on the window becoming key, and some on the window becoming main. Conceptually, all these actions belong to the window becoming key, so that's what I implemented. However, since in a single-window application these three events always happen together, the previous implementation "ain't broken". - This slightly changed the meaning of the SDL_APPMOUSEFOCUS flag from SDL_GetAppState(): Before, it meant "window is main and mouse is inside window (or mode is fullscreen)". Now, it means "window is key and mouse is inside window (or mode is fullscreen)". It makes more sense to me that way. (See http://developer.apple.com/documentation/Cocoa/Conceptual/WinPanel/Concepts/ChangingMainKeyWindow.html for a discussion of what key and main windows are.) The other two flags are unchanged: SDL_APPACTIVE = application is not hidden and window is not minimized, SDL_APPINPUTFOCUS = window is key (or mode is fullscreen). - As a side effect, the reorganization fixes the following two issues (and maybe others) (but they could also be fixed in less invasive ways): * A regression that was introduced in revision 1.42 of SDL_QuartzVideo.m (http://libsdl.org/cgi/cvsweb.cgi/SDL12/src/video/quartz/SDL_QuartzVideo.m.diff?r1=1.41&r2=1.42) (from half-desirable to undesirable behavior): Situation: While in windowed mode, hide the cursor using SDL_ShowCursor(SDL_DISABLE), move the mouse outside of the window so that the cursor becomes visible again, and SDL_SetVideoMode() to a fullscreen mode. What happened before revision 1.42: The cursor is visible, but becomes invisible as soon as the mouse is moved (half-desirable). What happens in revision 1.42 and after (including current CVS): The cursor is visible and stays visible (undesirable). What happens after my patch: The cursor is invisible from the beginning (desirable). * When the cursor is hidden and grabbed, switch away from the application using cmd-tab (which ungrabs and makes the cursor visible), move the cursor outside of the SDL window, then cmd-tab back to the application. In 1.2.8 and in the current CVS, the cursor is re-grabbed, but it stays visible (immovable in the middle of the window). With my patch, the cursor is correctly re-grabbed and hidden. (For some reason, it still doesn't work correctly if you switch back to the application using the dock instead of cmd-tab. I haven't been able to figure out why. I can step over [NSCursor hide] being called in the debugger, but it seems to have no effect.) - The patch includes my patch for #12 (it was easier to obtain using cvs diff that way). If you apply both of them, you will end up with 6 duplicate lines in SDL_QuartzEvents.m.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 13 Apr 2006 14:17:48 +0000
parents 376665398b25
children e49147870aac eed7a3f396ce
comparison
equal deleted inserted replaced
1628:10b4827452a8 1629:ef4a796e7f24
76 cursor_visible = YES; 76 cursor_visible = YES;
77 } 77 }
78 } 78 }
79 79
80 void QZ_HideMouse (_THIS) { 80 void QZ_HideMouse (_THIS) {
81 BOOL isInGameWin = QZ_IsMouseInWindow (this); 81 if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) && cursor_visible) {
82 if (isInGameWin && cursor_visible) {
83 [ NSCursor hide ]; 82 [ NSCursor hide ];
84 cursor_visible = NO; 83 cursor_visible = NO;
85 } 84 }
86 } 85 }
87 86
88 BOOL QZ_IsMouseInWindow (_THIS) { 87 BOOL QZ_IsMouseInWindow (_THIS) {
89 if (mode_flags & SDL_FULLSCREEN) return YES; 88 if (qz_window == nil) return YES; /*fullscreen*/
90 else { 89 else {
91 NSPoint p = [ qz_window mouseLocationOutsideOfEventStream ]; 90 NSPoint p = [ qz_window mouseLocationOutsideOfEventStream ];
92 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" */ 91 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" */
93 return NSPointInRect(p, [ window_view frame ]); 92 return NSPointInRect(p, [ window_view frame ]);
94 } 93 }
164 else { 163 else {
165 164
166 *p = [ window_view convertPoint:*p fromView: nil ]; 165 *p = [ window_view convertPoint:*p fromView: nil ];
167 166
168 /* We need a workaround in OpenGL mode */ 167 /* We need a workaround in OpenGL mode */
169 if ( SDL_VideoSurface->flags & SDL_OPENGL ) { 168 if ( SDL_VideoSurface != NULL && (SDL_VideoSurface->flags & SDL_OPENGL) ) {
170 p->y = [window_view frame].size.height - p->y; 169 p->y = [window_view frame].size.height - p->y;
171 } 170 }
172 } 171 }
173 } 172 }
174 173