Skip to content

Commit a59f543

Browse files
committed
Fall back to defaults if user preference is set to incorrect type
1 parent 2b69abd commit a59f543

4 files changed

Lines changed: 19 additions & 13 deletions

File tree

DiscreteScroll.xcodeproj/project.pbxproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,14 @@
249249
buildSettings = {
250250
CODE_SIGN_STYLE = Automatic;
251251
COMBINE_HIDPI_IMAGES = YES;
252+
CURRENT_PROJECT_VERSION = 2;
252253
INFOPLIST_FILE = DiscreteScroll/Info.plist;
253254
LD_RUNPATH_SEARCH_PATHS = (
254255
"$(inherited)",
255256
"@executable_path/../Frameworks",
256257
);
257258
MACOSX_DEPLOYMENT_TARGET = 10.9;
258-
MARKETING_VERSION = 1.0.0;
259+
MARKETING_VERSION = 1.0.1;
259260
PRODUCT_BUNDLE_IDENTIFIER = com.emreyolcu.DiscreteScroll;
260261
PRODUCT_NAME = "$(TARGET_NAME)";
261262
};
@@ -266,13 +267,14 @@
266267
buildSettings = {
267268
CODE_SIGN_STYLE = Automatic;
268269
COMBINE_HIDPI_IMAGES = YES;
270+
CURRENT_PROJECT_VERSION = 2;
269271
INFOPLIST_FILE = DiscreteScroll/Info.plist;
270272
LD_RUNPATH_SEARCH_PATHS = (
271273
"$(inherited)",
272274
"@executable_path/../Frameworks",
273275
);
274276
MACOSX_DEPLOYMENT_TARGET = 10.9;
275-
MARKETING_VERSION = 1.0.0;
277+
MARKETING_VERSION = 1.0.1;
276278
PRODUCT_BUNDLE_IDENTIFIER = com.emreyolcu.DiscreteScroll;
277279
PRODUCT_NAME = "$(TARGET_NAME)";
278280
};

DiscreteScroll/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundleShortVersionString</key>
1818
<string>$(MARKETING_VERSION)</string>
1919
<key>CFBundleVersion</key>
20-
<string>1</string>
20+
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>LSApplicationCategoryType</key>
2222
<string>public.app-category.utilities</string>
2323
<key>LSMinimumSystemVersion</key>

DiscreteScroll/main.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#include <ApplicationServices/ApplicationServices.h>
22

3+
#define DEFAULT_LINES 3
34
#define SIGN(x) (((x) > 0) - ((x) < 0))
45

56
static int LINES;
67

78
CGEventRef 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,

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ As of May 2024, this application works on macOS versions 10.9–14.0.
1414

1515
### Installation
1616

17-
You may download the binary [here](https://github.com/emreyolcu/discrete-scroll/releases/download/v1.0.0/DiscreteScroll.zip).
17+
You may download the binary [here](https://github.com/emreyolcu/discrete-scroll/releases/download/v1.0.1/DiscreteScroll.zip).
1818

1919
It needs to be run each time you boot.
2020
If you want this to be automatic, do the following:
@@ -40,7 +40,10 @@ This number may even be negative, which inverts scrolling direction.
4040
defaults write com.emreyolcu.DiscreteScroll lines -int LINES
4141
```
4242

43-
You should restart the application for this setting to take effect.
43+
If you set the key `lines` to some value other than an integer,
44+
the default value of 3 is used as a fallback.
45+
46+
You should restart the application for the setting to take effect.
4447

4548
### Potential problems
4649

0 commit comments

Comments
 (0)