XQuartz: Send tablet proximity events with tilt and pressure

<rdar://problem/6257569>

Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
This commit is contained in:
Jeremy Huddleston 2011-04-22 00:39:12 -07:00
parent 034538ea9b
commit 72bd232b11
5 changed files with 51 additions and 31 deletions

View File

@ -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:

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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);