Skip to content

Commit

Permalink
Adding missing amount to OSX.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhat committed Apr 19, 2024
1 parent dbb8ba3 commit ec2cd86
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
35 changes: 23 additions & 12 deletions src/darwin/dispatch_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,32 +623,46 @@ bool dispatch_mouse_wheel(uint64_t timestamp, CGEventRef event_ref) {
CGEventSourceRef source = CGEventCreateSourceFromEvent(event_ref);
double ppl = CGEventSourceGetPixelsPerLine(source);

unsigned int wheel_amount = 10;
if (CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventIsContinuous) != 0) {
// continuous device (trackpad)
ppl *= 1;
wheel_amount = 1;

ppl *= wheel_amount;
uio_event.data.wheel.type = WHEEL_BLOCK_SCROLL;

if (CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventDeltaAxis1) != 0) {
uio_event.data.wheel.direction = WHEEL_VERTICAL_DIRECTION;
uio_event.data.wheel.rotation = (int16_t) (CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventPointDeltaAxis1) * ppl * 1);
uio_event.data.wheel.rotation = (int16_t) (
CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventPointDeltaAxis1) * ppl * wheel_amount
);
} else if (CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventDeltaAxis2) != 0) {
uio_event.data.wheel.direction = WHEEL_HORIZONTAL_DIRECTION;
uio_event.data.wheel.rotation = (int16_t) (CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventPointDeltaAxis2) * ppl * 1);
uio_event.data.wheel.rotation = (int16_t) (
CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventPointDeltaAxis2) * ppl * wheel_amount
);
}
} else {
// non-continuous device (wheel mice)
ppl *= 10;
wheel_amount = 10;

ppl *= wheel_amount;
uio_event.data.wheel.type = WHEEL_UNIT_SCROLL;

if (CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventDeltaAxis1) != 0) {
uio_event.data.wheel.direction = WHEEL_VERTICAL_DIRECTION;
uio_event.data.wheel.rotation = (int16_t) (CGEventGetDoubleValueField(event_ref, kCGScrollWheelEventFixedPtDeltaAxis1) * ppl * 10);
uio_event.data.wheel.rotation = (int16_t) (
CGEventGetDoubleValueField(event_ref, kCGScrollWheelEventFixedPtDeltaAxis1) * ppl * wheel_amount
);
} else if (CGEventGetIntegerValueField(event_ref, kCGScrollWheelEventDeltaAxis2) != 0) {
uio_event.data.wheel.direction = WHEEL_HORIZONTAL_DIRECTION;
uio_event.data.wheel.rotation = (int16_t) (CGEventGetDoubleValueField(event_ref, kCGScrollWheelEventFixedPtDeltaAxis2) * ppl * 10);
uio_event.data.wheel.rotation = (int16_t) (
CGEventGetDoubleValueField(event_ref, kCGScrollWheelEventFixedPtDeltaAxis2) * ppl * wheel_amount
);
}
}

uio_event.data.wheel.amount = (uint8_t) wheel_amount;
uio_event.data.wheel.delta = (uint16_t) ppl;

if (source) {
Expand All @@ -657,12 +671,9 @@ bool dispatch_mouse_wheel(uint64_t timestamp, CGEventRef event_ref) {

logger(LOG_LEVEL_DEBUG, "%s [%u]: Mouse wheel %i / %u of type %u in the %u direction at %u, %u.\n",
__FUNCTION__, __LINE__,
uio_event.data.wheel.rotation,
uio_event.data.wheel.delta,
uio_event.data.wheel.type,
uio_event.data.wheel.direction,
uio_event.data.wheel.x,
uio_event.data.wheel.y);
uio_event.data.wheel.rotation, uio_event.data.wheel.delta,
uio_event.data.wheel.type, uio_event.data.wheel.direction,
uio_event.data.wheel.x, uio_event.data.wheel.y);

// Fire mouse wheel event.
dispatch_event(&uio_event);
Expand Down
10 changes: 5 additions & 5 deletions src/windows/dispatch_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,11 @@ bool dispatch_mouse_wheel(uint64_t timestamp, MSLLHOOKSTRUCT *mshook, uint8_t di
uio_event.data.wheel.x = (int16_t) mshook->pt.x;
uio_event.data.wheel.y = (int16_t) mshook->pt.y;

/* Delta GET_WHEEL_DELTA_WPARAM(mshook->mouseData)
* A positive value indicates that the wheel was rotated
* forward, away from the user; a negative value indicates that
* the wheel was rotated backward, toward the user. One wheel
* click is defined as WHEEL_DELTA, which is 120. */
/* The GET_WHEEL_DELTA_WPARAM(mshook->mouseData) macro returns the high-order word of mouseData which represents
* the wheel delta.
* A positive value indicates that the wheel was rotated forward, away from the user.
* A negative value indicates that the wheel was rotated backward, toward the user.
* One wheel click is defined as WHEEL_DELTA, which is 120. */
uio_event.data.wheel.rotation = (int16_t) GET_WHEEL_DELTA_WPARAM(mshook->mouseData);
uio_event.data.wheel.delta = WHEEL_DELTA;

Expand Down

0 comments on commit ec2cd86

Please sign in to comment.