diff options
author | Jeremy Huddleston <jeremyhu@apple.com> | 2011-04-22 00:39:12 -0700 |
---|---|---|
committer | Jeremy Huddleston <jeremyhu@apple.com> | 2011-04-22 01:24:44 -0700 |
commit | 72bd232b117b2867282e0ae1855d779e126f912b (patch) | |
tree | d2adc7b4653c2076c0719a2858818e6e3dbeba0f | |
parent | 034538ea9b4770025e3573bc708039cabbe1e10d (diff) |
XQuartz: Send tablet proximity events with tilt and pressure
<rdar://problem/6257569>
Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
-rw-r--r-- | hw/xquartz/X11Application.m | 55 | ||||
-rw-r--r-- | hw/xquartz/darwin.c | 3 | ||||
-rw-r--r-- | hw/xquartz/darwin.h | 1 | ||||
-rw-r--r-- | hw/xquartz/darwinEvents.c | 20 | ||||
-rw-r--r-- | hw/xquartz/darwinEvents.h | 3 |
5 files changed, 51 insertions, 31 deletions
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m index 988a86bae..1e3643670 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 3b6f0a29e..00be74ba0 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 e874af24c..360225742 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 edf60c89c..dc0b84270 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 590305f3e..6769c8bd8 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); |