diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m index 646b9ef12..691725df9 100644 --- a/hw/xquartz/X11Application.m +++ b/hw/xquartz/X11Application.m @@ -839,7 +839,7 @@ static void send_nsevent (NSEventType type, NSEvent *e) { int pointer_x, pointer_y, ev_button, ev_type; float pressure, tilt_x, tilt_y; - /* convert location to global top-left coordinates */ + /* convert location to be relative to top-left of primary display */ location = [e locationInWindow]; window = [e window]; screen = [[[NSScreen screens] objectAtIndex:0] frame]; diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c index 2c95ed7c3..154709448 100644 --- a/hw/xquartz/darwinEvents.c +++ b/hw/xquartz/darwinEvents.c @@ -359,6 +359,28 @@ static void DarwinPokeEQ(void) { write(darwinEventWriteFD, &nullbyte, 1); } +/* Convert from Appkit pointer input values to X input values: + * Note: pointer_x and pointer_y are relative to the upper-left of primary + * display. + */ +static void DarwinPrepareValuators(int *valuators, ScreenPtr screen, + int pointer_x, int 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; + + DEBUG_LOG("Valuators: {%d,%d,%d,%d,%d}\n", + valuators[0], valuators[1], valuators[2], valuators[3], valuators[4]); +} + 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; @@ -366,22 +388,26 @@ void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int poin int i, num_events; DeviceIntPtr dev; 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=%d, y=%d, p=%f, tx=%f, ty=%f\n", pointer_x, pointer_y, pressure, tilt_x, tilt_y); if(!darwinEvents) { - ErrorF("DarwinSendPointerEvents called before darwinEvents was initialized\n"); + DEBUG_LOG("DarwinSendPointerEvents called before darwinEvents was initialized\n"); return; } - int valuators[5] = {pointer_x, pointer_y, pressure * SCALEFACTOR_PRESSURE, - tilt_x * SCALEFACTOR_TILT, tilt_y * SCALEFACTOR_TILT}; - - if (pressure == 0 && tilt_x == 0 && tilt_y == 0) dev = darwinPointer; - else dev = darwinTablet; + if (pressure == 0 && tilt_x == 0 && tilt_y == 0) + dev = darwinPointer; + else + dev = darwinTablet; + + screen = miPointerGetScreen(dev); + if(!screen) { + DEBUG_LOG("DarwinSendPointerEvents called before screen was initialized\n"); + return; + } - DEBUG_LOG("Valuators: {%d,%d,%d,%d,%d}\n", - valuators[0], valuators[1], valuators[2], valuators[3], valuators[4]); if (ev_type == ButtonPress && darwinFakeButtons && ev_button == 1) { // Mimic multi-button mouse with modifier-clicks // If both sets of modifiers are pressed, @@ -411,19 +437,13 @@ void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int poin DarwinUpdateModifiers(KeyPress, darwinFakeMouseButtonMask & old_flags); darwinFakeMouseButtonMask = 0; return; - } + } + DarwinPrepareValuators(valuators, screen, pointer_x, pointer_y, pressure, tilt_x, tilt_y); darwinEvents_lock(); { num_events = GetPointerEvents(darwinEvents, dev, ev_type, ev_button, POINTER_ABSOLUTE, 0, dev==darwinTablet?5:2, valuators); - screen = miPointerGetScreen(dev); - for(i=0; imyNum].x; - darwinEvents[i].u.keyButtonPointer.rootY -= darwinMainScreenY + - dixScreenOrigins[screen->myNum].y; - mieqEnqueue (dev, &darwinEvents[i]); - } + for(i=0; i