[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26767] trunk/blender: Cocoa : use Cocoa NSWindow tag for identifying the window where a mouse/tablet/ key event happened => enables some actions in inactive windows as per OSX standard

Damien Plisson damien.plisson at yahoo.fr
Wed Feb 10 15:16:02 CET 2010


Revision: 26767
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26767
Author:   damien78
Date:     2010-02-10 15:16:02 +0100 (Wed, 10 Feb 2010)

Log Message:
-----------
Cocoa : use Cocoa NSWindow tag for identifying the window where a mouse/tablet/key event happened => enables some actions in inactive windows as per OSX standard

Previous code was assuming an event can only be sent from the active window.
On OSX, Right, Middle mouse buttons, mouse wheel and trackpad events are sent to inactive windows too.

For example, this allows to zoom, pan the view without changing the window order.

Modified Paths:
--------------
    trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
    trunk/blender/source/blender/windowmanager/intern/wm_event_system.c

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2010-02-10 13:25:50 UTC (rev 26766)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2010-02-10 14:16:02 UTC (rev 26767)
@@ -1322,16 +1322,12 @@
 GHOST_TSuccess GHOST_SystemCocoa::handleTabletEvent(void *eventPtr, short eventType)
 {
 	NSEvent *event = (NSEvent *)eventPtr;
-	GHOST_IWindow* window = m_windowManager->getActiveWindow();
+	GHOST_IWindow* window;
 	
+	window = m_windowManager->getWindowAssociatedWithOSWindow((void*)[event window]);
 	if (!window) {
-		/* If no active window found, still tries to find the window associated with the event
-		 This may happen when Cocoa continues to send some events after the window deactivate one */
-		window = m_windowManager->getWindowAssociatedWithOSWindow((void*)[event window]);
-		if (!window) {
-			//printf("\nW failure for event 0x%x",[event type]);
-			return GHOST_kFailure;
-		}
+		//printf("\nW failure for event 0x%x",[event type]);
+		return GHOST_kFailure;
 	}
 	
 	GHOST_TabletData& ct=((GHOST_WindowCocoa*)window)->GetCocoaTabletData();
@@ -1381,16 +1377,12 @@
 GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
 {
 	NSEvent *event = (NSEvent *)eventPtr;
-    GHOST_Window* window = (GHOST_Window*)m_windowManager->getActiveWindow();
+    GHOST_Window* window;
 	
+	window = (GHOST_Window*)m_windowManager->getWindowAssociatedWithOSWindow((void*)[event window]);
 	if (!window) {
-		/* If no active window found, still tries to find the window associated with the event
-		 This may happen when Cocoa continues to send some events after the window deactivate one */
-		window = (GHOST_Window*)m_windowManager->getWindowAssociatedWithOSWindow((void*)[event window]);
-		if (!window) {
-			//printf("\nW failure for event 0x%x",[event type]);
-			return GHOST_kFailure;
-		}
+		//printf("\nW failure for event 0x%x",[event type]);
+		return GHOST_kFailure;
 	}
 	
 	switch ([event type])
@@ -1586,7 +1578,7 @@
 GHOST_TSuccess GHOST_SystemCocoa::handleKeyEvent(void *eventPtr)
 {
 	NSEvent *event = (NSEvent *)eventPtr;
-	GHOST_IWindow* window = m_windowManager->getActiveWindow();
+	GHOST_IWindow* window;
 	unsigned int modifiers;
 	NSString *characters;
 	NSData *convertedCharacters;
@@ -1594,14 +1586,10 @@
 	unsigned char ascii;
 	NSString* charsIgnoringModifiers;
 
+	window = m_windowManager->getWindowAssociatedWithOSWindow((void*)[event window]);
 	if (!window) {
-		/* If no active window found, still tries to find the window associated with the event
-		 This may happen when Cocoa continues to send some events after the window deactivate one */
-		window = m_windowManager->getWindowAssociatedWithOSWindow((void*)[event window]);
-		if (!window) {
-			//printf("\nW failure for event 0x%x",[event type]);
-			return GHOST_kFailure;
-		}
+		//printf("\nW failure for event 0x%x",[event type]);
+		return GHOST_kFailure;
 	}
 	
 	switch ([event type]) {

Modified: trunk/blender/source/blender/windowmanager/intern/wm_event_system.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_event_system.c	2010-02-10 13:25:50 UTC (rev 26766)
+++ trunk/blender/source/blender/windowmanager/intern/wm_event_system.c	2010-02-10 14:16:02 UTC (rev 26767)
@@ -2090,39 +2090,37 @@
 			break;
 		}
 		case GHOST_kEventTrackpad: {
-			if (win->active) {
-				GHOST_TEventTrackpadData * pd = customdata;
-				switch (pd->subtype) {
-					case GHOST_kTrackpadEventMagnify:
-						event.type = MOUSEZOOM;
-						break;
-					case GHOST_kTrackpadEventRotate:
-						event.type = MOUSEROTATE;
-						break;
-					case GHOST_kTrackpadEventScroll:
-					default:
-						event.type= MOUSEPAN;
-						break;
-				}
+			GHOST_TEventTrackpadData * pd = customdata;
+			switch (pd->subtype) {
+				case GHOST_kTrackpadEventMagnify:
+					event.type = MOUSEZOOM;
+					break;
+				case GHOST_kTrackpadEventRotate:
+					event.type = MOUSEROTATE;
+					break;
+				case GHOST_kTrackpadEventScroll:
+				default:
+					event.type= MOUSEPAN;
+					break;
+			}
 #if defined(__APPLE__) && defined(GHOST_COCOA)
-				//Cocoa already uses coordinates with y=0 at bottom, and returns inwindow coordinates on mouse moved event
-				event.x= evt->x = pd->x;
-				event.y = evt->y = pd->y;
+			//Cocoa already uses coordinates with y=0 at bottom, and returns inwindow coordinates on mouse moved event
+			event.x= evt->x = pd->x;
+			event.y = evt->y = pd->y;
 #else
-                {
-				int cx, cy;
-				GHOST_ScreenToClient(win->ghostwin, pd->x, pd->y, &cx, &cy);
-				event.x= evt->x= cx;
-				event.y= evt->y= (win->sizey-1) - cy;
-                }
+			{
+			int cx, cy;
+			GHOST_ScreenToClient(win->ghostwin, pd->x, pd->y, &cx, &cy);
+			event.x= evt->x= cx;
+			event.y= evt->y= (win->sizey-1) - cy;
+			}
 #endif
-				// Use prevx/prevy so we can calculate the delta later
-				event.prevx= event.x - pd->deltaX;
-				event.prevy= event.y - pd->deltaY;
-				
-				update_tablet_data(win, &event);
-				wm_event_add(win, &event);
-			}			
+			// Use prevx/prevy so we can calculate the delta later
+			event.prevx= event.x - pd->deltaX;
+			event.prevy= event.y - pd->deltaY;
+			
+			update_tablet_data(win, &event);
+			wm_event_add(win, &event);
 			break;
 		}
 		/* mouse button */





More information about the Bf-blender-cvs mailing list