Fixed bug #719 SDL-1.2
authorSam Lantinga
Wed, 23 Sep 2009 07:18:02 +0000
branchSDL-1.2
changeset 4240cb44bf8f8a0f
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
     1.1 --- a/src/video/quartz/SDL_QuartzWindow.h	Wed Sep 23 07:07:44 2009 +0000
     1.2 +++ b/src/video/quartz/SDL_QuartzWindow.h	Wed Sep 23 07:18:02 2009 +0000
     1.3 @@ -27,6 +27,10 @@
     1.4  
     1.5  /* Subclass of NSWindow to fix genie effect and support resize events  */
     1.6  @interface SDL_QuartzWindow : NSWindow
     1.7 +{
     1.8 +	BOOL watchForMouseUp;
     1.9 +}
    1.10 +
    1.11  - (void)miniaturize:(id)sender;
    1.12  - (void)display;
    1.13  - (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
     2.1 --- a/src/video/quartz/SDL_QuartzWindow.m	Wed Sep 23 07:07:44 2009 +0000
     2.2 +++ b/src/video/quartz/SDL_QuartzWindow.m	Wed Sep 23 07:18:02 2009 +0000
     2.3 @@ -128,6 +128,30 @@
     2.4      }
     2.5  }
     2.6  
     2.7 +/* QZ_DoActivate() calls a low-level CoreGraphics routine to adjust
     2.8 +   the cursor position, if input is being grabbed. If app activation is
     2.9 +   triggered by a mouse click in the title bar, then the window manager
    2.10 +   gets confused and thinks we're dragging the window. The solution
    2.11 +   below postpones the activate event to avoid this scenario. */
    2.12 +- (void)becomeKeyWindow
    2.13 +{
    2.14 +	NSEvent *event = [self currentEvent];
    2.15 +	if ([event type] == NSLeftMouseDown && [event window] == self)
    2.16 +		watchForMouseUp = YES;
    2.17 +	else
    2.18 +		[super becomeKeyWindow];
    2.19 +}
    2.20 +
    2.21 +- (void)sendEvent:(NSEvent *)event
    2.22 +{
    2.23 +	[super sendEvent:event];
    2.24 +	if (watchForMouseUp && [event type] == NSLeftMouseUp)
    2.25 +	{
    2.26 +		watchForMouseUp = NO;
    2.27 +		[super becomeKeyWindow];
    2.28 +	}
    2.29 +}
    2.30 +
    2.31  - (void)appDidHide:(NSNotification*)note
    2.32  {
    2.33      SDL_PrivateAppActive (0, SDL_APPACTIVE);