summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Byer <bbyer@bushing.apple.com>2008-03-28 20:47:44 -0700
committerJeremy Huddleston <jeremyhu@freedesktop.org>2008-03-31 16:44:23 -0700
commita4d034941100c6ca3b7cc4e59952c2745b9306cc (patch)
tree77b9ed20eab70690d5b523bf69e43f9187a67861
parent6648867d8bd1e86458d2ade77a3ee4567c3d6a97 (diff)
Add code to track 5 valuators for pointing device, in preparation
for supporting tablet input in Xquartz. (cherry picked from commit 22c8849ea819eb70a14b2e06330b11b22aa63ebc)
-rw-r--r--hw/xquartz/X11Application.m28
-rw-r--r--hw/xquartz/darwinEvents.c64
-rw-r--r--hw/xquartz/darwinEvents.h8
3 files changed, 80 insertions, 20 deletions
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 31c80dfa8..147b4b4c0 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -61,7 +61,7 @@ int X11EnableKeyEquivalents = TRUE;
int quartzHasRoot = FALSE, quartzEnableRootless = TRUE;
extern int darwinFakeButtons, input_check_flag;
-extern Bool enable_stereo;
+extern Bool enable_stereo;
extern xEvent *darwinEvents;
@@ -153,7 +153,7 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
tem = [infoDict objectForKey:@"CFBundleShortVersionString"];
- [dict setObject:[NSString stringWithFormat:@"Xquartz %@ - (xorg-server %s)", tem, XSERVER_VERSION]
+ [dict setObject:[NSString stringWithFormat:@"XQuartz %@ - (xorg-server %s)", tem, XSERVER_VERSION]
forKey:@"ApplicationVersion"];
[self orderFrontStandardAboutPanelWithOptions: dict];
@@ -501,7 +501,7 @@ static NSMutableArray * cfarray_to_nsarray (CFArrayRef in) {
if (value != NULL
&& CFGetTypeID (value) == CFNumberGetTypeID ()
- && CFNumberIsFloatType (value))
+ && CFNumberIsFloatType (value))
CFNumberGetValue (value, kCFNumberFloatType, &ret);
else if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ())
ret = CFStringGetDoubleValue (value);
@@ -862,7 +862,9 @@ static void send_nsevent (NSEventType type, NSEvent *e) {
NSRect screen;
NSPoint location;
NSWindow *window;
- int pointer_x, pointer_y, ev_button, ev_type;
+ int pointer_x, pointer_y, ev_button, ev_type;
+ float pressure, tilt_x, tilt_y;
+
// int num_events=0, i=0, state;
// xEvent xe;
@@ -884,6 +886,10 @@ static void send_nsevent (NSEventType type, NSEvent *e) {
pointer_y -= aquaMenuBarHeight;
// state = convert_flags ([e modifierFlags]);
+ pressure = 0; // for tablets
+ tilt_x = 0;
+ tilt_y = 0;
+
switch (type) {
case NSLeftMouseDown: ev_button=1; ev_type=ButtonPress; goto handle_mouse;
case NSOtherMouseDown: ev_button=2; ev_type=ButtonPress; goto handle_mouse;
@@ -894,6 +900,10 @@ static void send_nsevent (NSEventType type, NSEvent *e) {
case NSLeftMouseDragged: ev_button=1; ev_type=MotionNotify; goto handle_mouse;
case NSOtherMouseDragged: ev_button=2; ev_type=MotionNotify; goto handle_mouse;
case NSRightMouseDragged: ev_button=3; ev_type=MotionNotify; goto handle_mouse;
+ case NSTabletPoint:
+ pressure = [e pressure];
+ tilt_x = [e tilt].x;
+ tilt_y = [e tilt].y; // fall through
case NSMouseMoved: ev_button=0; ev_type=MotionNotify; goto handle_mouse;
handle_mouse:
@@ -907,10 +917,14 @@ static void send_nsevent (NSEventType type, NSEvent *e) {
DarwinSendPointerEvents(ev_type, ev_button, pointer_x, pointer_y);
} else if (ev_type==ButtonRelease && (button_state & (1 << ev_button)) == 0) break;
*/
- DarwinSendPointerEvents(ev_type, ev_button, pointer_x, pointer_y);
+
+ // if ([e subtype] == NSTabletPointEventSubtype) pressure = [e pressure];
+ DarwinSendPointerEvents(ev_type, ev_button, pointer_x, pointer_y,
+ pressure, tilt_x, tilt_y);
break;
- case NSScrollWheel:
- DarwinSendScrollEvents([e deltaY], pointer_x, pointer_y);
+ case NSScrollWheel:
+ DarwinSendScrollEvents([e deltaY], pointer_x, pointer_y,
+ pressure, tilt_x, tilt_y);
break;
case NSKeyDown: // do we need to translate these keyCodes?
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 113cfc109..2a28b1a31 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -173,6 +173,9 @@ static void DarwinReleaseModifiers(void) {
static void DarwinSimulateMouseClick(
int pointer_x,
int pointer_y,
+ float pressure,
+ float tilt_x,
+ float tilt_y,
int whichButton, // mouse button to be pressed
int modifierMask) // modifiers used for the fake click
{
@@ -183,8 +186,10 @@ static void DarwinSimulateMouseClick(
DarwinUpdateModifiers(KeyRelease, modifierMask);
// push the mouse button
- DarwinSendPointerEvents(ButtonPress, whichButton, pointer_x, pointer_y);
- DarwinSendPointerEvents(ButtonRelease, whichButton, pointer_x, pointer_y);
+ DarwinSendPointerEvents(ButtonPress, whichButton, pointer_x, pointer_y,
+ pressure, tilt_x, tilt_y);
+ DarwinSendPointerEvents(ButtonRelease, whichButton, pointer_x, pointer_y,
+ pressure, tilt_x, tilt_y);
// restore old modifiers
DarwinUpdateModifiers(KeyPress, modifierMask);
@@ -378,22 +383,39 @@ void DarwinPokeEQ(void) {
write(darwinEventWriteFD, &nullbyte, 1);
}
-void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int pointer_y) {
+void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int pointer_y,
+ float pressure, float tilt_x, float tilt_y) {
static int darwinFakeMouseButtonDown = 0;
static int darwinFakeMouseButtonMask = 0;
int i, num_events;
- int valuators[2] = {pointer_x, pointer_y};
+
+ /* I can't find a spec for this, but at least GTK expects that tablets are
+ just like mice, except they have either one or three extra valuators, in this
+ order:
+
+ X coord, Y coord, pressure, X tilt, Y tilt
+ Pressure and tilt should be represented natively as floats; unfortunately,
+ we can't do that. Again, GTK seems to record the min/max of each valuator,
+ and then perform scaling back to float itself using that info. Soo.... */
+
+ int valuators[5] = {pointer_x, pointer_y,
+ pressure * INT32_MAX * 1.0f,
+ tilt_x * INT32_MAX * 1.0f,
+ tilt_y * INT32_MAX * 1.0f};
+
if (ev_type == ButtonPress && darwinFakeButtons && ev_button == 1) {
// Mimic multi-button mouse with modifier-clicks
// If both sets of modifiers are pressed,
// button 2 is clicked.
if ((old_flags & darwinFakeMouse2Mask) == darwinFakeMouse2Mask) {
- DarwinSimulateMouseClick(pointer_x, pointer_y, 2, darwinFakeMouse2Mask);
+ DarwinSimulateMouseClick(pointer_x, pointer_y, pressure,
+ tilt_x, tilt_y, 2, darwinFakeMouse2Mask);
darwinFakeMouseButtonDown = 2;
darwinFakeMouseButtonMask = darwinFakeMouse2Mask;
return;
} else if ((old_flags & darwinFakeMouse3Mask) == darwinFakeMouse3Mask) {
- DarwinSimulateMouseClick(pointer_x, pointer_y, 3, darwinFakeMouse3Mask);
+ DarwinSimulateMouseClick(pointer_x, pointer_y, pressure,
+ tilt_x, tilt_y, 3, darwinFakeMouse3Mask);
darwinFakeMouseButtonDown = 3;
darwinFakeMouseButtonMask = darwinFakeMouse3Mask;
return;
@@ -412,7 +434,7 @@ void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int poin
}
num_events = GetPointerEvents(darwinEvents, darwinPointer, ev_type, ev_button,
- POINTER_ABSOLUTE, 0, 2, valuators);
+ POINTER_ABSOLUTE, 0, 5, valuators);
for(i=0; i<num_events; i++) mieqEnqueue (darwinPointer,&darwinEvents[i]);
DarwinPokeEQ();
@@ -438,18 +460,38 @@ void DarwinSendKeyboardEvents(int ev_type, int keycode) {
DarwinPokeEQ();
}
+void DarwinSendProximityEvents(int ev_type, int pointer_x, int pointer_y,
+ float pressure, float tilt_x, float tilt_y) {
+ int i, num_events;
+ int valuators[5] = {pointer_x, pointer_y,
+ pressure * INT32_MAX * 1.0f,
+ tilt_x * INT32_MAX * 1.0f,
+ tilt_y * INT32_MAX * 1.0f};
+
+ num_events = GetProximityEvents(darwinEvents, darwinPointer, ev_type,
+ 0, 5, valuators);
+
+ for(i=0; i<num_events; i++) mieqEnqueue (darwinPointer,&darwinEvents[i]);
+ DarwinPokeEQ();
+}
+
+
/* Send the appropriate number of button 4 / 5 clicks to emulate scroll wheel */
-void DarwinSendScrollEvents(float count, int pointer_x, int pointer_y) {
+void DarwinSendScrollEvents(float count, int pointer_x, int pointer_y,
+ float pressure, float tilt_x, float tilt_y) {
int i;
int ev_button = count > 0.0f ? 4 : 5;
- int valuators[2] = {pointer_x, pointer_y};
+ int valuators[5] = {pointer_x, pointer_y,
+ pressure * INT32_MAX * 1.0f,
+ tilt_x * INT32_MAX * 1.0f,
+ tilt_y * INT32_MAX * 1.0f};
for (count = fabs(count); count > 0.0; count = count - 1.0f) {
int num_events = GetPointerEvents(darwinEvents, darwinPointer, ButtonPress, ev_button,
- POINTER_ABSOLUTE, 0, 2, valuators);
+ POINTER_ABSOLUTE, 0, 5, valuators);
for(i=0; i<num_events; i++) mieqEnqueue(darwinPointer,&darwinEvents[i]);
num_events = GetPointerEvents(darwinEvents, darwinPointer, ButtonRelease, ev_button,
- POINTER_ABSOLUTE, 0, 2, valuators);
+ POINTER_ABSOLUTE, 0, 5, valuators);
for(i=0; i<num_events; i++) mieqEnqueue(darwinPointer,&darwinEvents[i]);
}
DarwinPokeEQ();
diff --git a/hw/xquartz/darwinEvents.h b/hw/xquartz/darwinEvents.h
index 82cc26bc0..496061420 100644
--- a/hw/xquartz/darwinEvents.h
+++ b/hw/xquartz/darwinEvents.h
@@ -32,9 +32,13 @@ void DarwinEQEnqueue(const xEventPtr e);
void DarwinEQPointerPost(DeviceIntPtr pDev, xEventPtr e);
void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX);
void DarwinPokeEQ(void);
-void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int pointer_y);
+void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int pointer_y,
+ float pressure, float tilt_x, float tilt_y);
+void DarwinSendProximityEvents(int ev_type, int pointer_x, int pointer_y,
+ float pressure, float tilt_x, float tilt_y);
void DarwinSendKeyboardEvents(int ev_type, int keycode);
-void DarwinSendScrollEvents(float count, int pointer_x, int pointer_y);
+void DarwinSendScrollEvents(float count, int pointer_x, int pointer_y,
+ float pressure, float tilt_x, float tilt_y);
void DarwinUpdateModKeys(int flags);
#endif /* _DARWIN_EVENTS_H */