XQuartz: Use doubles for input valuators

Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
This commit is contained in:
Jeremy Huddleston 2012-03-17 00:04:27 -07:00
parent cd84c0949a
commit 5ff46d651a
2 changed files with 59 additions and 72 deletions

View File

@ -430,10 +430,12 @@ DarwinPokeEQ(void)
* display. * display.
*/ */
static void static void
DarwinPrepareValuators(DeviceIntPtr pDev, int *valuators, ScreenPtr screen, DarwinPrepareValuators(DeviceIntPtr pDev, ValuatorMask *pmask, ScreenPtr screen,
float pointer_x, float pointer_y, double pointer_x, double pointer_y,
float pressure, float tilt_x, float tilt_y) double pressure, double tilt_x, double tilt_y)
{ {
valuator_mask_zero(pmask);
/* Fix offset between darwin and X screens */ /* Fix offset between darwin and X screens */
pointer_x -= darwinMainScreenX + screen->x; pointer_x -= darwinMainScreenX + screen->x;
pointer_y -= darwinMainScreenY + screen->y; pointer_y -= darwinMainScreenY + screen->y;
@ -445,26 +447,19 @@ DarwinPrepareValuators(DeviceIntPtr pDev, int *valuators, ScreenPtr screen,
pointer_y = 0.0; pointer_y = 0.0;
if (pDev == darwinPointer) { if (pDev == darwinPointer) {
valuators[0] = pointer_x; valuator_mask_set_double(pmask, 0, pointer_x);
valuators[1] = pointer_y; valuator_mask_set_double(pmask, 1, pointer_y);
valuators[2] = 0; } else {
valuators[3] = 0; valuator_mask_set_double(pmask, 0, XQUARTZ_VALUATOR_LIMIT * (pointer_x / (double)screenInfo.screens[0]->width));
valuators[4] = 0; valuator_mask_set_double(pmask, 1, XQUARTZ_VALUATOR_LIMIT * (pointer_y / (double)screenInfo.screens[0]->height));
valuator_mask_set_double(pmask, 2, XQUARTZ_VALUATOR_LIMIT * pressure);
valuator_mask_set_double(pmask, 3, XQUARTZ_VALUATOR_LIMIT * tilt_x);
valuator_mask_set_double(pmask, 4, XQUARTZ_VALUATOR_LIMIT * tilt_y);
} }
else { //DEBUG_LOG("Pointer (%lf, %lf), Valuators: {%lf,%lf,%lf,%lf,%lf}\n", pointer_x, pointer_y,
/* Setup our array of values */ // valuator_mask_get_double(pmask, 0), valuator_mask_get_double(pmask, 1),
valuators[0] = // valuator_mask_get_double(pmask, 2), valuator_mask_get_double(pmask, 3),
XQUARTZ_VALUATOR_LIMIT * (pointer_x / // valuator_mask_get_double(pmask, 4));
(float) screenInfo.screens[0]->width);
valuators[1] =
XQUARTZ_VALUATOR_LIMIT * (pointer_y /
(float) screenInfo.screens[0]->height);
valuators[2] = XQUARTZ_VALUATOR_LIMIT * pressure;
valuators[3] = XQUARTZ_VALUATOR_LIMIT * tilt_x;
valuators[4] = XQUARTZ_VALUATOR_LIMIT * tilt_y;
}
//DEBUG_LOG("Pointer (%f, %f), Valuators: {%d,%d,%d,%d,%d}\n", pointer_x, pointer_y,
// valuators[0], valuators[1], valuators[2], valuators[3], valuators[4]);
} }
void void
@ -497,12 +492,12 @@ DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev)
void void
DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button,
float pointer_x, float pointer_y, float pressure, double pointer_x, double pointer_y, double pressure,
float tilt_x, float tilt_y) double tilt_x, double tilt_y)
{ {
static int darwinFakeMouseButtonDown = 0; static int darwinFakeMouseButtonDown = 0;
ScreenPtr screen; ScreenPtr screen;
int valuators[5]; ValuatorMask valuators;
//DEBUG_LOG("x=%f, y=%f, 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);
@ -559,14 +554,10 @@ DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button,
darwinFakeMouseButtonDown = 0; darwinFakeMouseButtonDown = 0;
} }
DarwinPrepareValuators(pDev, valuators, screen, pointer_x, pointer_y, DarwinPrepareValuators(pDev, &valuators, screen, pointer_x, pointer_y,
pressure, tilt_x, tilt_y); pressure, tilt_x, tilt_y);
darwinEvents_lock(); { darwinEvents_lock(); {
ValuatorMask mask; QueuePointerEvents(pDev, ev_type, ev_button, POINTER_ABSOLUTE, &valuators);
valuator_mask_set_range(&mask, 0, (pDev == darwinPointer) ? 2 : 5,
valuators);
QueuePointerEvents(pDev, ev_type, ev_button, POINTER_ABSOLUTE, &mask);
DarwinPokeEQ(); DarwinPokeEQ();
} darwinEvents_unlock(); } darwinEvents_unlock();
} }
@ -590,12 +581,12 @@ DarwinSendKeyboardEvents(int ev_type, int keycode)
} }
void void
DarwinSendProximityEvents(DeviceIntPtr pDev, int ev_type, float pointer_x, DarwinSendProximityEvents(DeviceIntPtr pDev, int ev_type, double pointer_x,
float pointer_y, float pressure, float tilt_x, double pointer_y, double pressure, double tilt_x,
float tilt_y) double tilt_y)
{ {
ScreenPtr screen; ScreenPtr screen;
int valuators[5]; ValuatorMask valuators;
DEBUG_LOG("DarwinSendProximityEvents: %d l:%f,%f p:%f t:%f,%f\n", ev_type, DEBUG_LOG("DarwinSendProximityEvents: %d l:%f,%f p:%f t:%f,%f\n", ev_type,
pointer_x, pointer_y, pressure, tilt_x, tilt_y); pointer_x, pointer_y, pressure, tilt_x, tilt_y);
@ -613,54 +604,50 @@ DarwinSendProximityEvents(DeviceIntPtr pDev, int ev_type, float pointer_x,
return; return;
} }
DarwinPrepareValuators(pDev, valuators, screen, pointer_x, pointer_y, DarwinPrepareValuators(pDev, &valuators, screen, pointer_x, pointer_y,
pressure, tilt_x, tilt_y); pressure, tilt_x, tilt_y);
darwinEvents_lock(); { darwinEvents_lock(); {
ValuatorMask mask; QueueProximityEvents(pDev, ev_type, &valuators);
valuator_mask_set_range(&mask, 0, 5, valuators);
QueueProximityEvents(pDev, ev_type, &mask);
DarwinPokeEQ(); DarwinPokeEQ();
} darwinEvents_unlock(); } darwinEvents_unlock();
} }
/* Send the appropriate number of button clicks to emulate scroll wheel */ /* Send the appropriate number of button clicks to emulate scroll wheel */
void void
DarwinSendScrollEvents(float count_x, float count_y, DarwinSendScrollEvents(double scroll_x, double scroll_y, double pointer_x,
float pointer_x, float pointer_y, double pointer_y, double pressure, double tilt_x,
float pressure, float tilt_x, float tilt_y) double tilt_y)
{ {
int sign_x, sign_y; int sign_x, sign_y;
if (!darwinEvents) { if (!darwinEvents) {
DEBUG_LOG DEBUG_LOG("DarwinSendScrollEvents called before darwinEvents was initialized\n");
("DarwinSendScrollEvents called before darwinEvents was initialized\n");
return; return;
} }
sign_x = count_x > 0.0f ? SCROLLWHEELLEFTFAKE : SCROLLWHEELRIGHTFAKE; sign_x = scroll_x > 0.0f ? SCROLLWHEELLEFTFAKE : SCROLLWHEELRIGHTFAKE;
sign_y = count_y > 0.0f ? SCROLLWHEELUPFAKE : SCROLLWHEELDOWNFAKE; sign_y = scroll_y > 0.0f ? SCROLLWHEELUPFAKE : SCROLLWHEELDOWNFAKE;
count_x = fabs(count_x); scroll_x = fabs(scroll_x);
count_y = fabs(count_y); scroll_y = fabs(scroll_y);
while ((count_x > 0.0f) || (count_y > 0.0f)) { while ((scroll_x > 0.0f) || (scroll_y > 0.0f)) {
if (count_x > 0.0f) { if (scroll_x > 0.0f) {
DarwinSendPointerEvents(darwinPointer, ButtonPress, sign_x, DarwinSendPointerEvents(darwinPointer, ButtonPress, sign_x,
pointer_x, pointer_y, pressure, tilt_x, pointer_x, pointer_y, pressure,
tilt_y); tilt_x, tilt_y);
DarwinSendPointerEvents(darwinPointer, ButtonRelease, sign_x, DarwinSendPointerEvents(darwinPointer, ButtonRelease, sign_x,
pointer_x, pointer_y, pressure, tilt_x, pointer_x, pointer_y, pressure,
tilt_y); tilt_x, tilt_y);
count_x = count_x - 1.0f; scroll_x = scroll_x - 1.0f;
} }
if (count_y > 0.0f) {
if (scroll_y > 0.0f) {
DarwinSendPointerEvents(darwinPointer, ButtonPress, sign_y, DarwinSendPointerEvents(darwinPointer, ButtonPress, sign_y,
pointer_x, pointer_y, pressure, tilt_x, pointer_x, pointer_y, pressure,
tilt_y); tilt_x, tilt_y);
DarwinSendPointerEvents(darwinPointer, ButtonRelease, sign_y, DarwinSendPointerEvents(darwinPointer, ButtonRelease, sign_y,
pointer_x, pointer_y, pressure, tilt_x, pointer_x, pointer_y, pressure,
tilt_y); tilt_x, tilt_y);
count_y = count_y - 1.0f; scroll_y = scroll_y - 1.0f;
} }
} }
} }

View File

@ -38,15 +38,15 @@ void DarwinEQPointerPost(DeviceIntPtr pDev, xEventPtr e);
void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX); void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX);
void DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev); void DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev);
void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button,
float pointer_x, float pointer_y, float pressure, double pointer_x, double pointer_y, double pressure,
float tilt_x, float tilt_y); double tilt_x, double tilt_y);
void DarwinSendProximityEvents(DeviceIntPtr pDev, int ev_type, float pointer_x, void DarwinSendProximityEvents(DeviceIntPtr pDev, int ev_type, double pointer_x,
float pointer_y, float pressure, float tilt_x, double pointer_y, double pressure, double tilt_x,
float tilt_y); double tilt_y);
void DarwinSendKeyboardEvents(int ev_type, int keycode); void DarwinSendKeyboardEvents(int ev_type, int keycode);
void DarwinSendScrollEvents(float count_x, float count_y, float pointer_x, void DarwinSendScrollEvents(double scroll_x, double scroll_y, double pointer_x,
float pointer_y, float pressure, float tilt_x, double pointer_y, double pressure, double tilt_x,
float tilt_y); double tilt_y);
void DarwinUpdateModKeys(int flags); void DarwinUpdateModKeys(int flags);
void DarwinListenOnOpenFD(int fd); void DarwinListenOnOpenFD(int fd);