[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56683] trunk/blender/intern/ghost/intern: Fix #35265: on OS X, pressing system shortcuts such as cmd+M or cmd+` would both

Brecht Van Lommel brechtvanlommel at pandora.be
Sat May 11 12:15:28 CEST 2013


Revision: 56683
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56683
Author:   blendix
Date:     2013-05-11 10:15:27 +0000 (Sat, 11 May 2013)
Log Message:
-----------
Fix #35265: on OS X, pressing system shortcuts such as cmd+M or cmd+` would both
insert text in the text editor and do the associated operation like minimizing the
window or switching windows.

The code was always doing both without trying to ensure only one is done. Now we
integrate a bit better with the event handling and pass the event to NSApp, which
then decides to handle the event itself or pass it on to the window, from where
we then send it back to be handled.

Modified Paths:
--------------
    trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h
    trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
    trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h	2013-05-11 09:31:58 UTC (rev 56682)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h	2013-05-11 10:15:27 UTC (rev 56683)
@@ -237,16 +237,7 @@
 		return 0;
 	}
 	
-	
-protected:
 	/**
-	 * Initializes the system.
-	 * For now, it justs registers the window class (WNDCLASS).
-	 * \return A success value.
-	 */
-	virtual GHOST_TSuccess init();
-
-	/**
 	 * Handles a tablet event.
 	 * \param eventPtr	An NSEvent pointer (casted to void* to enable compilation in standard C++)
 	 * \param eventType The type of the event.
@@ -270,6 +261,14 @@
 	 * \return Indication whether the event was handled.
 	 */
 	GHOST_TSuccess handleKeyEvent(void *eventPtr);
+	
+protected:
+	/**
+	 * Initializes the system.
+	 * For now, it justs registers the window class (WNDCLASS).
+	 * \return A success value.
+	 */
+	virtual GHOST_TSuccess init();
 
 	/**
 	 * Performs the actual cursor position update (location in screen coordinates).

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2013-05-11 09:31:58 UTC (rev 56682)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2013-05-11 10:15:27 UTC (rev 56683)
@@ -931,59 +931,9 @@
 			
 			anyProcessed = true;
 			
-			switch ([event type]) {
-				case NSKeyDown:
-				case NSKeyUp:
-				case NSFlagsChanged:
-					handleKeyEvent(event);
-					
-					/* Support system-wide keyboard shortcuts, like Exposé, ...) =>included in always NSApp sendEvent */
-					/*		if (([event modifierFlags] & NSCommandKeyMask) || [event type] == NSFlagsChanged) {
-					 [NSApp sendEvent:event];
-					 }*/
-					break;
-					
-				case NSLeftMouseDown:
-				case NSLeftMouseUp:
-				case NSRightMouseDown:
-				case NSRightMouseUp:
-				case NSMouseMoved:
-				case NSLeftMouseDragged:
-				case NSRightMouseDragged:
-				case NSScrollWheel:
-				case NSOtherMouseDown:
-				case NSOtherMouseUp:
-				case NSOtherMouseDragged:
-				case NSEventTypeMagnify:
-				case NSEventTypeRotate:
-				case NSEventTypeBeginGesture:
-				case NSEventTypeEndGesture:
-					handleMouseEvent(event);
-					break;
-					
-				case NSTabletPoint:
-				case NSTabletProximity:
-					handleTabletEvent(event,[event type]);
-					break;
-					
-					/* Trackpad features, fired only from OS X 10.5.2
-					 case NSEventTypeGesture:
-					 case NSEventTypeSwipe:
-					 break; */
-					
-					/*Unused events
-					 NSMouseEntered       = 8,
-					 NSMouseExited        = 9,
-					 NSAppKitDefined      = 13,
-					 NSSystemDefined      = 14,
-					 NSApplicationDefined = 15,
-					 NSPeriodic           = 16,
-					 NSCursorUpdate       = 17,*/
-					
-				default:
-					break;
-			}
-			//Resend event to NSApp to ensure Mac wide events are handled
+			// Send event to NSApp to ensure Mac wide events are handled,
+			// this will send events to CocoaWindow which will call back
+			// to handleKeyEvent, handleMouseEvent and handleTabletEvent
 			[NSApp sendEvent:event];
 			[pool drain];
 		} while (event != nil);

Modified: trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm	2013-05-11 09:31:58 UTC (rev 56682)
+++ trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm	2013-05-11 10:15:27 UTC (rev 56683)
@@ -297,37 +297,106 @@
 		[self interpretKeyEvents:events]; // calls insertText
 		[events removeObject:event];
 		[events release];
+	}
 
-		return;
-	}
+	systemCocoa->handleKeyEvent(event);
 }
 
-#if MAC_OS_X_VERSION_MIN_REQUIRED <= 1040
-//Cmd+key are handled differently before 10.5
-- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
+- (void)keyUp:(NSEvent *)event
 {
-	NSString *chars = [theEvent charactersIgnoringModifiers];
-	
-	if ([chars length] <1) 
-		return NO;
-	
-	//Let cocoa handle menu shortcuts
-	switch ([chars characterAtIndex:0]) {
-		case 'q':
-		case 'w':
-		case 'h':
-		case 'm':
-		case '<':
-		case '>':
-		case '~':
-		case '`':
-			return NO;
-		default:
-			return YES;
-	}
+	systemCocoa->handleKeyEvent(event);
 }
-#endif
 
+- (void)flagsChanged:(NSEvent *)event
+{
+	systemCocoa->handleKeyEvent(event);
+}
+
+- (void)mouseDown:(NSEvent *)event
+{
+	systemCocoa->handleMouseEvent(event);
+}
+
+- (void)mouseUp:(NSEvent *)event
+{
+	systemCocoa->handleMouseEvent(event);
+}
+
+- (void)rightMouseDown:(NSEvent *)event
+{
+	systemCocoa->handleMouseEvent(event);
+}
+
+- (void)rightMouseUp:(NSEvent *)event
+{
+	systemCocoa->handleMouseEvent(event);
+}
+
+- (void)mouseMoved:(NSEvent *)event
+{
+	systemCocoa->handleMouseEvent(event);
+}
+
+- (void)mouseDragged:(NSEvent *)event
+{
+	systemCocoa->handleMouseEvent(event);
+}
+
+- (void)rightMouseDragged:(NSEvent *)event
+{
+	systemCocoa->handleMouseEvent(event);
+}
+
+- (void)scrollWheel:(NSEvent *)event
+{
+	systemCocoa->handleMouseEvent(event);
+}
+
+- (void)otherMouseDown:(NSEvent *)event
+{
+	systemCocoa->handleMouseEvent(event);
+}
+
+- (void)otherMouseUp:(NSEvent *)event
+{
+	systemCocoa->handleMouseEvent(event);
+}
+
+- (void)otherMouseDragged:(NSEvent *)event
+{
+	systemCocoa->handleMouseEvent(event);
+}
+
+- (void)magnifyWithEvent:(NSEvent *)event
+{
+	systemCocoa->handleMouseEvent(event);
+}
+
+- (void)rotateWithEvent:(NSEvent *)event
+{
+	systemCocoa->handleMouseEvent(event);
+}
+
+- (void)beginGestureWithEvent:(NSEvent *)event
+{
+	systemCocoa->handleMouseEvent(event);
+}
+
+- (void)endGestureWithEvent:(NSEvent *)event
+{
+	systemCocoa->handleMouseEvent(event);
+}
+
+- (void)tabletPoint:(NSEvent *)event
+{
+	systemCocoa->handleTabletEvent(event,[event type]);
+}
+
+- (void)tabletProximity:(NSEvent *)event
+{
+	systemCocoa->handleTabletEvent(event,[event type]);
+}
+
 - (BOOL)isOpaque
 {
 	return YES;




More information about the Bf-blender-cvs mailing list