XQuartz: Using absolute ranges for pointer location to increase resolution and better support tablets.

(cherry picked from commit d79ccb45f6)
This commit is contained in:
Jeremy Huddleston 2008-09-30 08:46:08 -07:00
parent 88bb8c6f48
commit 1657dfb843
4 changed files with 31 additions and 34 deletions

View File

@ -890,8 +890,8 @@ static void send_nsevent(NSEvent *e) {
NSRect screen;
NSPoint location;
NSWindow *window;
int pointer_x, pointer_y, ev_button, ev_type;
float pressure, tilt_x, tilt_y;
int ev_button, ev_type;
float pointer_x, pointer_y, pressure, tilt_x, tilt_y;
DeviceIntPtr pDev;
/* convert location to be relative to top-left of primary display */
@ -909,7 +909,8 @@ static void send_nsevent(NSEvent *e) {
pointer_y = (screen.origin.y + screen.size.height) - location.y;
}
pressure = 0; // for tablets
/* Setup our valuators. These will range from 0 to 1 */
pressure = 0;
tilt_x = 0;
tilt_y = 0;

View File

@ -341,6 +341,8 @@ static int DarwinMouseProc(DeviceIntPtr pPointer, int what) {
GetMotionHistorySize(), 2);
InitAbsoluteClassDeviceStruct(pPointer);
pPointer->valuator->mode = Absolute; // Relative
InitValuatorAxisStruct(pPointer, 0, 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
InitValuatorAxisStruct(pPointer, 1, 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
break;
case DEVICE_ON:
pPointer->public.on = TRUE;
@ -372,17 +374,12 @@ static int DarwinTabletProc(DeviceIntPtr pPointer, int what) {
InitProximityClassDeviceStruct(pPointer);
InitAbsoluteClassDeviceStruct(pPointer);
// InitValuatorAxisStruct(pPointer, 0, 0, 1440, 1, 0, 1);
// InitValuatorAxisStruct(pPointer, 1, 0, 900, 1, 0, 1);
InitValuatorAxisStruct(pPointer, 2, 0, 1023, 1, 0, 1);
InitValuatorAxisStruct(pPointer, 3, -64, 64, 1, 0, 1);
InitValuatorAxisStruct(pPointer, 4, -64, 64, 1, 0, 1);
// InitValuatorAxisStruct(pPointer, 2, 0, 240, 49999, 49999, 49999);
// InitValuatorAxisStruct(pPointer, 3, -64, 63, 128, 128, 128);
// InitValuatorAxisStruct(pPointer, 4, -64, 63, 128, 128, 128);
// InitValuatorAxisStruct(pPointer, 5, 0, 1023, 128, 128, 128);
// pPointer->use = IsXExtensionDevice;
InitValuatorAxisStruct(pPointer, 0, 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
InitValuatorAxisStruct(pPointer, 1, 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
InitValuatorAxisStruct(pPointer, 2, 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
InitValuatorAxisStruct(pPointer, 3, -XQUARTZ_VALUATOR_LIMIT, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
InitValuatorAxisStruct(pPointer, 4, -XQUARTZ_VALUATOR_LIMIT, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
// pPointer->use = IsXExtensionDevice;
break;
case DEVICE_ON:
pPointer->public.on = TRUE;

View File

@ -68,10 +68,6 @@ in this Software without prior written authorization from The Open Group.
#define SCROLLWHEELLEFTFAKE 6
#define SCROLLWHEELRIGHTFAKE 7
/* These values were chosen to match the output of xinput under Linux */
#define SCALEFACTOR_TILT 64.0
#define SCALEFACTOR_PRESSURE 1023.0
#define _APPLEWM_SERVER_
#include "applewmExt.h"
#include <X11/extensions/applewm.h>
@ -390,31 +386,31 @@ static void DarwinPokeEQ(void) {
* display.
*/
static void DarwinPrepareValuators(int *valuators, ScreenPtr screen,
int pointer_x, int pointer_y,
float pointer_x, float pointer_y,
float pressure, float tilt_x, float tilt_y) {
/* Fix offset between darwin and X screens */
pointer_x -= darwinMainScreenX + dixScreenOrigins[screen->myNum].x;
pointer_y -= darwinMainScreenY + dixScreenOrigins[screen->myNum].y;
/* Setup our array of values */
valuators[0] = pointer_x;
valuators[1] = pointer_y;
valuators[2] = pressure * SCALEFACTOR_PRESSURE;
valuators[3] = tilt_x * SCALEFACTOR_TILT;
valuators[4] = tilt_y * SCALEFACTOR_TILT;
valuators[0] = pointer_x * XQUARTZ_VALUATOR_LIMIT / (float)screenInfo.screens[0]->width;
valuators[1] = pointer_y * XQUARTZ_VALUATOR_LIMIT / (float)screenInfo.screens[0]->height;
valuators[2] = pressure * XQUARTZ_VALUATOR_LIMIT;
valuators[3] = tilt_x * XQUARTZ_VALUATOR_LIMIT;
valuators[4] = tilt_y * XQUARTZ_VALUATOR_LIMIT;
// DEBUG_LOG("Valuators: {%d,%d,%d,%d,%d}\n",
// valuators[0], valuators[1], valuators[2], valuators[3], valuators[4]);
DEBUG_LOG("Valuators: {%d,%d,%d,%d,%d}\n",
valuators[0], valuators[1], valuators[2], valuators[3], valuators[4]);
}
void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, int pointer_x, int pointer_y,
void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, float pointer_x, float pointer_y,
float pressure, float tilt_x, float tilt_y) {
static int darwinFakeMouseButtonDown = 0;
int i, num_events;
ScreenPtr screen;
int valuators[5];
// DEBUG_LOG("x=%d, y=%d, p=%f, tx=%f, ty=%f\n", pointer_x, pointer_y, pressure, tilt_x, tilt_y);
DEBUG_LOG("x=%f, y=%f, p=%f, tx=%f, ty=%f\n", pointer_x, pointer_y, pressure, tilt_x, tilt_y);
if(!darwinEvents) {
DEBUG_LOG("DarwinSendPointerEvents called before darwinEvents was initialized\n");
@ -483,13 +479,13 @@ void DarwinSendKeyboardEvents(int ev_type, int keycode) {
} darwinEvents_unlock();
}
void DarwinSendProximityEvents(int ev_type, int pointer_x, int pointer_y) {
void DarwinSendProximityEvents(int ev_type, float pointer_x, float pointer_y) {
int i, num_events;
ScreenPtr screen;
DeviceIntPtr dev = darwinTabletCurrent;
int valuators[5];
DEBUG_LOG("DarwinSendProximityEvents(%d, %d, %d)\n", ev_type, pointer_x, pointer_y);
DEBUG_LOG("DarwinSendProximityEvents(%d, %f, %f)\n", ev_type, pointer_x, pointer_y);
if(!darwinEvents) {
DEBUG_LOG("DarwinSendProximityEvents called before darwinEvents was initialized\n");
@ -514,7 +510,7 @@ void DarwinSendProximityEvents(int ev_type, int pointer_x, int pointer_y) {
/* Send the appropriate number of button clicks to emulate scroll wheel */
void DarwinSendScrollEvents(float count_x, float count_y,
int pointer_x, int pointer_y,
float pointer_x, float pointer_y,
float pressure, float tilt_x, float tilt_y) {
if(!darwinEvents) {
DEBUG_LOG("DarwinSendScrollEvents called before darwinEvents was initialized\n");

View File

@ -28,15 +28,18 @@
#ifndef _DARWIN_EVENTS_H
#define _DARWIN_EVENTS_H
/* For extra precision of our cursor and other valuators */
#define XQUARTZ_VALUATOR_LIMIT (1 << 16)
Bool DarwinEQInit(void);
void DarwinEQEnqueue(const xEventPtr e);
void DarwinEQPointerPost(DeviceIntPtr pDev, xEventPtr e);
void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX);
void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, int pointer_x, int pointer_y,
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, int pointer_x, int pointer_y);
void DarwinSendProximityEvents(int ev_type, float pointer_x, float pointer_y);
void DarwinSendKeyboardEvents(int ev_type, int keycode);
void DarwinSendScrollEvents(float count_x, float count_y, int pointer_x, int pointer_y,
void DarwinSendScrollEvents(float count_x, float count_y, float pointer_x, float pointer_y,
float pressure, float tilt_x, float tilt_y);
void DarwinUpdateModKeys(int flags);
void DarwinListenOnOpenFD(int fd);