Skip to content

Commit

Permalink
Clean up source
Browse files Browse the repository at this point in the history
  • Loading branch information
emreyolcu committed Apr 4, 2024
1 parent d3bf7db commit 5ff0212
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions DiscreteScroll/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,31 @@
#define SIGN(x) (((x) > 0) - ((x) < 0))
#define LINES 3

CGEventRef cgEventCallback(CGEventTapProxy proxy, CGEventType type,
CGEventRef event, void *refcon)
CGEventRef cgEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
{
if (!CGEventGetIntegerValueField(event, kCGScrollWheelEventIsContinuous)) {
int64_t delta = CGEventGetIntegerValueField(event, kCGScrollWheelEventPointDeltaAxis1);

CGEventSetIntegerValueField(event, kCGScrollWheelEventDeltaAxis1, SIGN(delta) * LINES);
}

return event;
}

int main(void)
{
CFMachPortRef eventTap;
CFRunLoopSourceRef runLoopSource;

eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0,
1 << kCGEventScrollWheel, cgEventCallback, NULL);

eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0, 1 << kCGEventScrollWheel, cgEventCallback, NULL);
runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);

CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
CGEventTapEnable(eventTap, true);
CFRunLoopRun();

CFRelease(eventTap);
CFRelease(runLoopSource);

return 0;
}

0 comments on commit 5ff0212

Please sign in to comment.