This repository has been archived by the owner on Jul 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAcceleratorController.m
60 lines (58 loc) · 1.94 KB
/
AcceleratorController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#import "AcceleratorController.h"
#import "imousefix.h"
static BOOL isQuitting = NO;
@implementation AcceleratorController
- (id) init {
//NSLog(@"%s", __PRETTY_FUNCTION__);
if (self = [super init]) {
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
NSDictionary *defaults = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithDouble:3.0], @"MouseAcceleration",
[NSNumber numberWithBool:YES], @"EnableMouseAcceleration", nil];
[ud registerDefaults:defaults];
[ud addObserver:self forKeyPath:@"MouseAcceleration" options:nil context:nil];
[ud addObserver:self forKeyPath:@"EnableMouseAcceleration" options:nil context:nil];
[NSApp setDelegate:self];
}
return self;
}
- (IBAction)reset:(id)sender {
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
[ud setValue:[NSNumber numberWithDouble:3.0] forKey:@"MouseAcceleration"];
[ud setValue:[NSNumber numberWithBool:YES] forKey:@"EnableMouseAcceleration"];
[self runMousefix];
}
- (void) runMousefix {
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
BOOL enabled = [[ud objectForKey:@"EnableMouseAcceleration"] boolValue];
if (enabled==YES) {
double acceleration = [[ud objectForKey:@"MouseAcceleration"] doubleValue];
NSString *exestr = [NSString stringWithFormat:@"%f", acceleration];
const char *argv[2];
argv[0] = "imousefix";
argv[1] = [exestr UTF8String];
imousefix(2, argv);
} else {
const char *argv[1];
argv[0] = "imousefix";
imousefix(1, argv);
}
}
- (void) observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
[self runMousefix];
}
- (void)windowWillClose:(NSNotification *)aNotification {
if (isQuitting==NO) {
isQuitting = YES;
[NSApp terminate:self];
}
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
NSLog(@"%s", __PRETTY_FUNCTION__);
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
[ud synchronize];
}
@end