11#include <ApplicationServices/ApplicationServices.h>
22
3+ #define DEFAULT_LINES 3
34#define SIGN (x ) (((x) > 0) - ((x) < 0))
45
56static int LINES ;
67
78CGEventRef callback (CGEventTapProxy proxy , CGEventType type , CGEventRef event , void * userInfo )
89{
9- if (! CGEventGetIntegerValueField (event , kCGScrollWheelEventIsContinuous )) {
10- int64_t delta = CGEventGetIntegerValueField (event , kCGScrollWheelEventPointDeltaAxis1 );
10+ if (CGEventGetIntegerValueField (event , kCGScrollWheelEventIsContinuous ) == 0 ) {
11+ int delta = ( int ) CGEventGetIntegerValueField (event , kCGScrollWheelEventPointDeltaAxis1 );
1112 CGEventSetIntegerValueField (event , kCGScrollWheelEventDeltaAxis1 , SIGN (delta ) * LINES );
1213 }
1314
@@ -32,24 +33,24 @@ int main(void)
3233 (const void * * )& kAXTrustedCheckOptionPrompt , (const void * * )& kCFBooleanTrue , 1 ,
3334 & kCFTypeDictionaryKeyCallBacks , & kCFTypeDictionaryValueCallBacks
3435 );
35- Boolean trusted = AXIsProcessTrustedWithOptions (options );
36+ bool trusted = AXIsProcessTrustedWithOptions (options );
3637 CFRelease (options );
3738 if (!trusted )
3839 displayNoticeAndExit (
3940 CFSTR ("Restart DiscreteScroll after granting it access to accessibility features." )
4041 );
4142
42- CFStringRef key = CFSTR ("lines" );
4343 CFNumberRef value = (CFNumberRef )CFPreferencesCopyAppValue (
44- key , kCFPreferencesCurrentApplication
44+ CFSTR ( "lines" ) , kCFPreferencesCurrentApplication
4545 );
46- Boolean got = false;
46+ bool got = false;
4747 if (value ) {
48- got = CFNumberGetValue (value , kCFNumberIntType , & LINES );
48+ if (CFGetTypeID (value ) == CFNumberGetTypeID ())
49+ got = CFNumberGetValue (value , kCFNumberIntType , & LINES );
4950 CFRelease (value );
5051 }
5152 if (!got )
52- LINES = 3 ;
53+ LINES = DEFAULT_LINES ;
5354
5455 CFMachPortRef tap = CGEventTapCreate (
5556 kCGSessionEventTap , kCGHeadInsertEventTap , kCGEventTapOptionDefault ,
0 commit comments