[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25042] trunk/blender/intern/ghost/intern/ GHOST_SystemCocoa.mm: Cocoa: implement Cmd+W to close window, workaround for wrong modifiers key status upon focus retrieval

Damien Plisson damien.plisson at yahoo.fr
Tue Dec 1 11:23:30 CET 2009


Revision: 25042
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25042
Author:   damien78
Date:     2009-12-01 11:23:27 +0100 (Tue, 01 Dec 2009)

Log Message:
-----------
Cocoa: implement Cmd+W to close window, workaround for wrong modifiers key status upon focus retrieval
The carbon GetModifierFlag function (to get the current modifier keys status) is reimplemented in cocoa only from 10.6.
So we need to use a workaround to get the correct modifiers when blender application gets focus back. Current one is to assume no modifiers.
This at least fixes the issue when blender has been hidden using Cmd+H. The Cmd modifier was still seen as ON until the user pressed again on it.

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

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2009-12-01 09:21:15 UTC (rev 25041)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2009-12-01 10:23:27 UTC (rev 25042)
@@ -392,6 +392,8 @@
 
 #pragma mark Cocoa objects
 
+static bool justGotFocus = false;
+
 /**
  * CocoaAppDelegate
  * ObjC object to capture applicationShouldTerminate, and send quit event
@@ -403,6 +405,7 @@
 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
 - (void)applicationWillTerminate:(NSNotification *)aNotification;
+- (void)applicationWillBecomeActive:(NSNotification *)aNotification;
 @end
 
 @implementation CocoaAppDelegate : NSObject
@@ -436,6 +439,11 @@
 	/*G.afbreek = 0; //Let Cocoa perform the termination at the end
 	WM_exit(C);*/
 }
+
+- (void)applicationWillBecomeActive:(NSNotification *)aNotification
+{
+	justGotFocus = true;
+}
 @end
 
 
@@ -530,6 +538,9 @@
 				
 				[windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
 				
+				menuItem = [windowMenu addItemWithTitle:@"Close" action:@selector(performClose:) keyEquivalent:@"w"];
+				[menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];
+				
 				menuItem = [[NSMenuItem	alloc] init];
 				[menuItem setSubmenu:windowMenu];
 				
@@ -706,14 +717,33 @@
 
 GHOST_TSuccess GHOST_SystemCocoa::getModifierKeys(GHOST_ModifierKeys& keys) const
 {
-	unsigned int modifiers = [[NSApp currentEvent] modifierFlags];
-	//Direct query to modifierFlags can be used in 10.6
+#ifdef MAC_OS_X_VERSION_10_6
+	unsigned int modifiers = [NSEvent modifierFlags];
 
     keys.set(GHOST_kModifierKeyCommand, (modifiers & NSCommandKeyMask) ? true : false);
     keys.set(GHOST_kModifierKeyLeftAlt, (modifiers & NSAlternateKeyMask) ? true : false);
     keys.set(GHOST_kModifierKeyLeftShift, (modifiers & NSShiftKeyMask) ? true : false);
     keys.set(GHOST_kModifierKeyLeftControl, (modifiers & NSControlKeyMask) ? true : false);
-	
+
+#else
+	if (justGotFocus) {
+			//TODO: need to find a better workaround for the missing cocoa "getModifierFlag" function in 10.4/10.5
+		justGotFocus = false;
+		keys.set(GHOST_kModifierKeyCommand, false);
+		keys.set(GHOST_kModifierKeyLeftAlt, false);
+		keys.set(GHOST_kModifierKeyLeftShift, false);
+		keys.set(GHOST_kModifierKeyLeftControl, false);
+	}
+	else {
+		unsigned int modifiers = [[NSApp currentEvent] modifierFlags];
+		
+		keys.set(GHOST_kModifierKeyCommand, (modifiers & NSCommandKeyMask) ? true : false);
+		keys.set(GHOST_kModifierKeyLeftAlt, (modifiers & NSAlternateKeyMask) ? true : false);
+		keys.set(GHOST_kModifierKeyLeftShift, (modifiers & NSShiftKeyMask) ? true : false);
+		keys.set(GHOST_kModifierKeyLeftControl, (modifiers & NSControlKeyMask) ? true : false);
+	}
+
+#endif
     return GHOST_kSuccess;
 }
 





More information about the Bf-blender-cvs mailing list