Fixed bug #719 SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Wed, 23 Sep 2009 07:18:02 +0000
branchSDL-1.2
changeset 4240 cb44bf8f8a0f
parent 4239 3d467ee2af5e
child 4241 d3a210342761
Fixed bug #719 Mike Blaguszewski 2009-03-23 13:32:22 PDT Patch to 1.2 HEAD that fixes the issue Fixes bug in SDL 1.2.13 where clicking on an app's title bar to activate the app, when cursor capturing is enabled, will cause the window to jump. This is because SDL's handler for activate events calls a low-level Quartz function to move the cursor. Calling this when the mouse is down in the title bar confuses the WindowServer into thinking the title bar has been dragged. The patch defers processing of activate events in this case. The bottom line is that CGWarpMouseCursorPosition() is not safe to call when the mouse in down in a window's title bar.
src/video/quartz/SDL_QuartzWindow.h
src/video/quartz/SDL_QuartzWindow.m
--- a/src/video/quartz/SDL_QuartzWindow.h	Wed Sep 23 07:07:44 2009 +0000
+++ b/src/video/quartz/SDL_QuartzWindow.h	Wed Sep 23 07:18:02 2009 +0000
@@ -27,6 +27,10 @@
 
 /* Subclass of NSWindow to fix genie effect and support resize events  */
 @interface SDL_QuartzWindow : NSWindow
+{
+	BOOL watchForMouseUp;
+}
+
 - (void)miniaturize:(id)sender;
 - (void)display;
 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
--- a/src/video/quartz/SDL_QuartzWindow.m	Wed Sep 23 07:07:44 2009 +0000
+++ b/src/video/quartz/SDL_QuartzWindow.m	Wed Sep 23 07:18:02 2009 +0000
@@ -128,6 +128,30 @@
     }
 }
 
+/* QZ_DoActivate() calls a low-level CoreGraphics routine to adjust
+   the cursor position, if input is being grabbed. If app activation is
+   triggered by a mouse click in the title bar, then the window manager
+   gets confused and thinks we're dragging the window. The solution
+   below postpones the activate event to avoid this scenario. */
+- (void)becomeKeyWindow
+{
+	NSEvent *event = [self currentEvent];
+	if ([event type] == NSLeftMouseDown && [event window] == self)
+		watchForMouseUp = YES;
+	else
+		[super becomeKeyWindow];
+}
+
+- (void)sendEvent:(NSEvent *)event
+{
+	[super sendEvent:event];
+	if (watchForMouseUp && [event type] == NSLeftMouseUp)
+	{
+		watchForMouseUp = NO;
+		[super becomeKeyWindow];
+	}
+}
+
 - (void)appDidHide:(NSNotification*)note
 {
     SDL_PrivateAppActive (0, SDL_APPACTIVE);