/* Send the appropriate number of button clicks to emulate scroll wheel */ void DarwinSendScrollEvents(double scroll_x, double scroll_y) { ScreenPtr screen; ValuatorMask valuators; if (!darwinEvents) { DEBUG_LOG( "DarwinSendScrollEvents called before darwinEvents was initialized\n"); return; } screen = miPointerGetScreen(darwinPointer); if (!screen) { DEBUG_LOG( "DarwinSendScrollEvents called before screen was initialized\n"); return; } valuator_mask_zero(&valuators); valuator_mask_set_double(&valuators, 4, scroll_y); valuator_mask_set_double(&valuators, 5, scroll_x); darwinEvents_lock(); { QueuePointerEvents(darwinPointer, MotionNotify, 0, POINTER_RELATIVE, &valuators); DarwinPokeEQ(); } darwinEvents_unlock(); }
/** * Modifies valuators in-place. * This version employs a velocity approximation algorithm to * enable fine-grained predictable acceleration profiles. */ void acceleratePointerPredictable( DeviceIntPtr dev, ValuatorMask* val, CARD32 evtime) { double dx = 0, dy = 0; DeviceVelocityPtr velocitydata = GetDevicePredictableAccelData(dev); Bool soften = TRUE; if (valuator_mask_num_valuators(val) == 0 || !velocitydata) return; if (velocitydata->statistics.profile_number == AccelProfileNone && velocitydata->const_acceleration == 1.0f) { return; /*we're inactive anyway, so skip the whole thing.*/ } if (valuator_mask_isset(val, 0)) { dx = valuator_mask_get_double(val, 0); } if (valuator_mask_isset(val, 1)) { dy = valuator_mask_get_double(val, 1); } if (dx != 0.0 || dy != 0.0) { /* reset non-visible state? */ if (ProcessVelocityData2D(velocitydata, dx , dy, evtime)) { soften = FALSE; } if (dev->ptrfeed && dev->ptrfeed->ctrl.num) { double mult; /* invoke acceleration profile to determine acceleration */ mult = ComputeAcceleration (dev, velocitydata, dev->ptrfeed->ctrl.threshold, (double)dev->ptrfeed->ctrl.num / (double)dev->ptrfeed->ctrl.den); if(mult != 1.0f || velocitydata->const_acceleration != 1.0f) { if (mult > 1.0f && soften) ApplySoftening(velocitydata, &dx, &dy); ApplyConstantDeceleration(velocitydata, &dx, &dy); if (dx != 0.0) valuator_mask_set_double(val, 0, mult * dx); if (dy != 0.0) valuator_mask_set_double(val, 1, mult * dy); DebugAccelF("pos (%i | %i) delta x:%.3f y:%.3f\n", mult * dx, mult * dy); } } } /* remember last motion delta (for softening/slow movement treatment) */ velocitydata->last_dx = dx; velocitydata->last_dy = dy; }
/** * Originally a part of xf86PostMotionEvent; modifies valuators * in-place. Retained mostly for embedded scenarios. */ void acceleratePointerLightweight( DeviceIntPtr dev, ValuatorMask* val, CARD32 ignored) { double mult = 0.0, tmpf; double dx = 0.0, dy = 0.0; if (valuator_mask_isset(val, 0)) { dx = valuator_mask_get(val, 0); } if (valuator_mask_isset(val, 1)) { dy = valuator_mask_get(val, 1); } if (valuator_mask_num_valuators(val) == 0) return; if (dev->ptrfeed && dev->ptrfeed->ctrl.num) { /* modeled from xf86Events.c */ if (dev->ptrfeed->ctrl.threshold) { if ((fabs(dx) + fabs(dy)) >= dev->ptrfeed->ctrl.threshold) { if (dx != 0.0) { tmpf = (dx * (double)(dev->ptrfeed->ctrl.num)) / (double)(dev->ptrfeed->ctrl.den); valuator_mask_set_double(val, 0, tmpf); } if (dy != 0.0) { tmpf = (dy * (double)(dev->ptrfeed->ctrl.num)) / (double)(dev->ptrfeed->ctrl.den); valuator_mask_set_double(val, 1, tmpf); } } } else { mult = pow(dx * dx + dy * dy, ((double)(dev->ptrfeed->ctrl.num) / (double)(dev->ptrfeed->ctrl.den) - 1.0) / 2.0) / 2.0; if (dx != 0.0) valuator_mask_set_double(val, 0, mult * dx); if (dy != 0.0) valuator_mask_set_double(val, 1, mult * dy); } } }
void DarwinSendTabletEvents(DeviceIntPtr pDev, int ev_type, int ev_button, double pointer_x, double pointer_y, double pressure, double tilt_x, double tilt_y) { ScreenPtr screen; ValuatorMask valuators; if (!darwinEvents) { DEBUG_LOG("%s called before darwinEvents was initialized\n", __FUNCTION__); return; } screen = miPointerGetScreen(pDev); if (!screen) { DEBUG_LOG("%s called before screen was initialized\n", __FUNCTION__); return; } /* Fix offset between darwin and X screens */ pointer_x -= darwinMainScreenX + screen->x; pointer_y -= darwinMainScreenY + screen->y; /* Adjust our pointer location to the [0,1] range */ pointer_x = pointer_x / (double)screenInfo.width; pointer_y = pointer_y / (double)screenInfo.height; valuator_mask_zero(&valuators); valuator_mask_set_double(&valuators, 0, XQUARTZ_VALUATOR_LIMIT * pointer_x); valuator_mask_set_double(&valuators, 1, XQUARTZ_VALUATOR_LIMIT * pointer_y); valuator_mask_set_double(&valuators, 2, XQUARTZ_VALUATOR_LIMIT * pressure); valuator_mask_set_double(&valuators, 3, XQUARTZ_VALUATOR_LIMIT * tilt_x); valuator_mask_set_double(&valuators, 4, XQUARTZ_VALUATOR_LIMIT * tilt_y); darwinEvents_lock(); { if (ev_type == ProximityIn || ev_type == ProximityOut) { QueueProximityEvents(pDev, ev_type, &valuators); } else { QueuePointerEvents(pDev, ev_type, ev_button, POINTER_ABSOLUTE, &valuators); } DarwinPokeEQ(); } darwinEvents_unlock(); }
static void set_and_post_mask(struct MTouch *mt, DeviceIntPtr dev, mstime_t delta_t){ struct Gestures* gs; ValuatorMask* mask; float speed_factor; gs = &mt->gs; mask = mt->vm; valuator_mask_zero(mask); if (gs->move_dx) valuator_mask_set_double(mask, 0, gs->move_dx); if (gs->move_dy) valuator_mask_set_double(mask, 1, gs->move_dy); switch (gs->move_type){ case GS_SCROLL: case GS_SWIPE3: case GS_SWIPE4: //case GS_MOVE: case GS_NONE: /* Only scroll, or swipe or move can trigger coasting right now */ /* Continue coasting if enabled */ speed_factor = (mt->cfg.scroll_coast.num_of_ticks - gs->scroll_coast_tick_no) / (float)(mt->cfg.scroll_coast.num_of_ticks); if (ABSVAL(gs->scroll_speed_x) > mt->cfg.scroll_coast.min_speed) valuator_mask_set_double(mask, 2, gs->scroll_speed_x * delta_t * speed_factor); if (ABSVAL(gs->scroll_speed_y) > mt->cfg.scroll_coast.min_speed) valuator_mask_set_double(mask, 3, gs->scroll_speed_y * delta_t * speed_factor); break; default: /* Any other movement/gesture type will break coasting. */ mt->gs.scroll_speed_y = mt->gs.scroll_speed_x = 0.0f; break; } xf86PostMotionEventM(dev, Relative, mask); /* Once posted, we can clear the move variables */ gs->move_dx = gs->move_dy = 0; }
void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, double pointer_x, double pointer_y, double pointer_dx, double pointer_dy) { static int darwinFakeMouseButtonDown = 0; ScreenPtr screen; ValuatorMask valuators; if (!darwinEvents) { DEBUG_LOG("%s called before darwinEvents was initialized\n", __FUNCTION__); return; } screen = miPointerGetScreen(pDev); if (!screen) { DEBUG_LOG("%s called before screen was initialized\n", __FUNCTION__); return; } /* Handle fake click */ if (ev_type == ButtonPress && darwinFakeButtons && ev_button == 1) { if (darwinFakeMouseButtonDown != 0) { /* We're currently "down" with another button, so release it first */ DarwinSendPointerEvents(pDev, ButtonRelease, darwinFakeMouseButtonDown, pointer_x, pointer_y, 0.0, 0.0); darwinFakeMouseButtonDown = 0; } if (darwin_all_modifier_flags & darwinFakeMouse2Mask) { ev_button = 2; darwinFakeMouseButtonDown = 2; DarwinUpdateModKeys( darwin_all_modifier_flags & ~darwinFakeMouse2Mask); } else if (darwin_all_modifier_flags & darwinFakeMouse3Mask) { ev_button = 3; darwinFakeMouseButtonDown = 3; DarwinUpdateModKeys( darwin_all_modifier_flags & ~darwinFakeMouse3Mask); } } if (ev_type == ButtonRelease && ev_button == 1) { if (darwinFakeMouseButtonDown) { ev_button = darwinFakeMouseButtonDown; } if (darwinFakeMouseButtonDown == 2) { DarwinUpdateModKeys( darwin_all_modifier_flags & ~darwinFakeMouse2Mask); } else if (darwinFakeMouseButtonDown == 3) { DarwinUpdateModKeys( darwin_all_modifier_flags & ~darwinFakeMouse3Mask); } darwinFakeMouseButtonDown = 0; } /* Fix offset between darwin and X screens */ pointer_x -= darwinMainScreenX + screen->x; pointer_y -= darwinMainScreenY + screen->y; valuator_mask_zero(&valuators); valuator_mask_set_double(&valuators, 0, pointer_x); valuator_mask_set_double(&valuators, 1, pointer_y); if (ev_type == MotionNotify) { if (pointer_dx != 0.0) valuator_mask_set_double(&valuators, 2, pointer_dx); if (pointer_dy != 0.0) valuator_mask_set_double(&valuators, 3, pointer_dy); } darwinEvents_lock(); { QueuePointerEvents(pDev, ev_type, ev_button, POINTER_ABSOLUTE, &valuators); DarwinPokeEQ(); } darwinEvents_unlock(); }