[Xquartz-changes] xserver: Branch 'master' - 2 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Fri Apr 22 01:25:00 PDT 2011


 hw/xquartz/X11Application.m |   72 +++++++++++++++++++++++++++++++++-----------
 hw/xquartz/darwin.c         |    3 -
 hw/xquartz/darwin.h         |    1 
 hw/xquartz/darwinEvents.c   |   20 ++++++------
 hw/xquartz/darwinEvents.h   |    3 +
 5 files changed, 67 insertions(+), 32 deletions(-)

New commits:
commit b86ed868c82dad0422b1c1908ccf18d1febce0b2
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Apr 22 01:23:09 2011 -0700

    XQuartz: Do translation and handoff of NSEvent to X11 in a separate serial queue
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 1e36436..4131075 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -385,7 +385,22 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
     
     if (for_appkit) [super sendEvent:e];
     
-    if (for_x) [self sendX11NSEvent:e];
+    if (for_x) {
+#ifdef HAVE_LIBDISPATCH
+        static dispatch_queue_t eventTranslationQueue;
+        static dispatch_once_t pred;
+        dispatch_once(&pred, ^{
+            eventTranslationQueue = dispatch_queue_create(LAUNCHD_ID_PREFIX".X11.NSEventsToX11EventsQueue", NULL);
+            if(eventTranslationQueue == NULL)
+                FatalError("Error creating a dispatch queue\n");
+        });
+        dispatch_async(eventTranslationQueue, ^{
+#endif
+            [self sendX11NSEvent:e];
+#ifdef HAVE_LIBDISPATCH
+        });
+#endif
+    }
 }
 
 - (void) set_window_menu:(NSArray *)list {
commit 72bd232b117b2867282e0ae1855d779e126f912b
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Apr 22 00:39:12 2011 -0700

    XQuartz: Send tablet proximity events with tilt and pressure
    
    <rdar://problem/6257569>
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 988a86b..1e36436 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -1079,13 +1079,29 @@ static const char *untrusted_str(NSEvent *e) {
 #endif
 
 - (void) sendX11NSEvent:(NSEvent *)e {
-    NSPoint location = NSZeroPoint, tilt = NSZeroPoint;
+    NSPoint location = NSZeroPoint;
     int ev_button, ev_type;
-    float pressure = 0.0;
+    static float pressure = 0.0;       // static so ProximityOut will have the value from the previous tablet event
+    static NSPoint tilt;               // static so ProximityOut will have the value from the previous tablet event
+    static DeviceIntPtr darwinTabletCurrent = NULL;
+    static BOOL needsProximityIn = NO; // Do we do need to handle a pending ProximityIn once we have pressure/tilt?
     DeviceIntPtr pDev;
     int modifierFlags;
     BOOL isMouseOrTabletEvent, isTabletEvent;
 
+#ifdef HAVE_LIBDISPATCH
+    static dispatch_once_t once_pred;
+    dispatch_once(&once_pred, ^{
+        tilt = NSZeroPoint;
+        darwinTabletCurrent = darwinTabletStylus;
+    });
+#else
+    if(!darwinTabletCurrent) {
+        tilt = NSZeroPoint;
+        darwinTabletCurrent = darwinTabletStylus;
+    }
+#endif
+    
     isMouseOrTabletEvent =  [e type] == NSLeftMouseDown    ||  [e type] == NSOtherMouseDown    ||  [e type] == NSRightMouseDown    ||
                             [e type] == NSLeftMouseUp      ||  [e type] == NSOtherMouseUp      ||  [e type] == NSRightMouseUp      ||
                             [e type] == NSLeftMouseDragged ||  [e type] == NSOtherMouseDragged ||  [e type] == NSRightMouseDragged ||
@@ -1207,19 +1223,14 @@ static const char *untrusted_str(NSEvent *e) {
                         darwinTabletCurrent=darwinTabletCursor;
                         break;
                 }
-                
-                /* NSTabletProximityEventSubtype doesn't encode pressure ant tilt
-                 * So we just pretend the motion was caused by the mouse.  Hopefully
-                 * we'll have a better solution for this in the future (like maybe
-                 * NSTabletProximityEventSubtype will come from NSTabletPoint
-                 * rather than NSMouseMoved.
-                pressure = [e pressure];
-                tilt     = [e tilt];
-                pDev = darwinTabletCurrent;                
-                 */
 
-                DarwinSendProximityEvents([e isEnteringProximity] ? ProximityIn : ProximityOut,
-                                          location.x, location.y);
+                if([e isEnteringProximity])
+                    needsProximityIn = YES;
+                else
+                    DarwinSendProximityEvents(darwinTabletCurrent, ProximityOut,
+                                              location.x, location.y, pressure,
+                                              tilt.x, tilt.y);
+                return;
             }
 
 			if ([e type] == NSTabletPoint || [e subtype] == NSTabletPointEventSubtype) {
@@ -1227,6 +1238,14 @@ static const char *untrusted_str(NSEvent *e) {
                 tilt     = [e tilt];
                 
                 pDev = darwinTabletCurrent;
+                
+                if(needsProximityIn) {
+                    DarwinSendProximityEvents(darwinTabletCurrent, ProximityIn,
+                                              location.x, location.y, pressure,
+                                              tilt.x, tilt.y);
+
+                    needsProximityIn = NO;
+                }
             }
 
             if(!XQuartzServerVisible && noTestExtensions) {
@@ -1280,8 +1299,12 @@ static const char *untrusted_str(NSEvent *e) {
                     break;
             }
             
-			DarwinSendProximityEvents([e isEnteringProximity] ? ProximityIn : ProximityOut,
-                                      location.x, location.y);
+            if([e isEnteringProximity])
+                needsProximityIn = YES;
+            else
+                DarwinSendProximityEvents(darwinTabletCurrent, ProximityOut,
+                                          location.x, location.y, pressure,
+                                          tilt.x, tilt.y);
             break;
             
 		case NSScrollWheel:
diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index 3b6f0a2..00be74b 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -117,7 +117,6 @@ unsigned int            windowItemModMask = NX_COMMANDMASK;
 // devices
 DeviceIntPtr            darwinKeyboard = NULL;
 DeviceIntPtr            darwinPointer = NULL;
-DeviceIntPtr            darwinTabletCurrent = NULL;
 DeviceIntPtr            darwinTabletStylus = NULL;
 DeviceIntPtr            darwinTabletCursor = NULL;
 DeviceIntPtr            darwinTabletEraser = NULL;
@@ -492,8 +491,6 @@ void InitInput( int argc, char **argv )
     darwinTabletEraser = AddInputDevice(serverClient, DarwinTabletProc, TRUE);
     darwinTabletEraser->name = strdup("eraser");
 
-    darwinTabletCurrent = darwinTabletStylus;
-
     DarwinEQInit();
 
     QuartzInitInput(argc, argv);
diff --git a/hw/xquartz/darwin.h b/hw/xquartz/darwin.h
index e874af2..3602257 100644
--- a/hw/xquartz/darwin.h
+++ b/hw/xquartz/darwin.h
@@ -56,7 +56,6 @@ extern io_connect_t     darwinParamConnect;
 extern int              darwinEventReadFD;
 extern int              darwinEventWriteFD;
 extern DeviceIntPtr     darwinPointer;
-extern DeviceIntPtr     darwinTabletCurrent;
 extern DeviceIntPtr     darwinTabletCursor;
 extern DeviceIntPtr     darwinTabletStylus;
 extern DeviceIntPtr     darwinTabletEraser;
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index edf60c8..dc0b842 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -489,7 +489,7 @@ void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, floa
     DarwinPrepareValuators(pDev, valuators, screen, pointer_x, pointer_y, pressure, tilt_x, tilt_y);
     darwinEvents_lock(); {
         ValuatorMask mask;
-        valuator_mask_set_range(&mask, 0, (pDev == darwinTabletCurrent) ? 5 : 2, valuators);
+        valuator_mask_set_range(&mask, 0, (pDev == darwinPointer) ? 2 : 5, valuators);
         num_events = GetPointerEvents(darwinEvents, pDev, ev_type, ev_button, 
                                       POINTER_ABSOLUTE, &mask);
         for(i=0; i<num_events; i++) mieqEnqueue (pDev, (InternalEvent*)darwinEvents[i].event);
@@ -512,18 +512,18 @@ void DarwinSendKeyboardEvents(int ev_type, int keycode) {
     } darwinEvents_unlock();
 }
 
-void DarwinSendProximityEvents(int ev_type, float pointer_x, float pointer_y) {
-	int i, num_events;
+void DarwinSendProximityEvents(DeviceIntPtr pDev, int ev_type, float pointer_x, float pointer_y,  
+                               float pressure, float tilt_x, float tilt_y) {
+    int i, num_events;
     ScreenPtr screen;
-    DeviceIntPtr pDev = darwinTabletCurrent;
     int valuators[5];
 
-	DEBUG_LOG("DarwinSendProximityEvents(%d, %f, %f)\n", ev_type, pointer_x, pointer_y);
+    DEBUG_LOG("DarwinSendProximityEvents: %d l:%f,%f p:%f t:%f,%f\n", ev_type, pointer_x, pointer_y, pressure, tilt_x, tilt_y);
 
-	if(!darwinEvents) {
-		DEBUG_LOG("DarwinSendProximityEvents called before darwinEvents was initialized\n");
-		return;
-	}
+    if(!darwinEvents) {
+        DEBUG_LOG("DarwinSendProximityEvents called before darwinEvents was initialized\n");
+        return;
+    }
     
     screen = miPointerGetScreen(pDev);
     if(!screen) {
@@ -531,7 +531,7 @@ void DarwinSendProximityEvents(int ev_type, float pointer_x, float pointer_y) {
         return;
     }    
 
-    DarwinPrepareValuators(pDev, valuators, screen, pointer_x, pointer_y, 0.0f, 0.0f, 0.0f);
+    DarwinPrepareValuators(pDev, valuators, screen, pointer_x, pointer_y, pressure, tilt_x, tilt_y);
     darwinEvents_lock(); {
         ValuatorMask mask;
         valuator_mask_set_range(&mask, 0, 5, valuators);
diff --git a/hw/xquartz/darwinEvents.h b/hw/xquartz/darwinEvents.h
index 590305f..6769c8b 100644
--- a/hw/xquartz/darwinEvents.h
+++ b/hw/xquartz/darwinEvents.h
@@ -37,7 +37,8 @@ void DarwinEQPointerPost(DeviceIntPtr pDev, xEventPtr e);
 void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX);
 void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, float pointer_x, float pointer_y,
 			     float pressure, float tilt_x, float tilt_y);
-void DarwinSendProximityEvents(int ev_type, float pointer_x, float pointer_y);
+void DarwinSendProximityEvents(DeviceIntPtr pDev, int ev_type, float pointer_x, float pointer_y,
+                               float pressure, float tilt_x, float tilt_y);
 void DarwinSendKeyboardEvents(int ev_type, int keycode);
 void DarwinSendScrollEvents(float count_x, float count_y, float pointer_x, float pointer_y,
 			    float pressure, float tilt_x, float tilt_y);


More information about the Xquartz-changes mailing list