-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMouseMemoryAppDelegate.m
133 lines (98 loc) · 3.56 KB
/
MouseMemoryAppDelegate.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// MouseMemoryAppDelegate.m
// MouseMemory
//
// Created by Adam Tomeček on 7/3/11.
// Copyright 2011 OwnSoft. All rights reserved.
//
#import "MouseMemoryAppDelegate.h"
#import "HIDSystem.h"
#import "Defaults.h"
#include <IOKit/IOKitLib.h>
#include <IOKit/hidsystem/IOHIDLib.h>
#include <IOKit/hidsystem/IOHIDParameter.h>
#include <IOKit/hidsystem/event_status_driver.h>
@implementation MouseMemoryAppDelegate
@synthesize window;
@synthesize about;
@synthesize slider;
@synthesize text;
@synthesize menuProfiles;
@synthesize menuProfilesDelete;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
openConnectionToHIDSystem(&HIDSystem);
NSString *path = [[NSBundle mainBundle] pathForResource:@"profiles" ofType:@"plist"];
profiles = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
[self createMenu];
}
- (void)awakeFromNib{
[window setReleasedWhenClosed:NO];
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
[statusItem setMenu:statusMenu];
[statusItem setImage:[NSImage imageNamed:@"m.png"]];
[statusItem setAlternateImage:[NSImage imageNamed:@"ma.png"]];
[statusItem setHighlightMode:YES];
}
- (void)createMenu{
NSArray *names = [profiles allKeys];
int numberOfProfiles = [names count];
if (numberOfProfiles > 0) {
[menuProfiles removeAllItems];
[menuProfilesDelete removeAllItems];
for(int i = 0; i < numberOfProfiles; i++){
NSDictionary *array = [profiles objectForKey:[names objectAtIndex:i]];
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[array objectForKey:[NSString stringWithFormat:@"name"]] action:@selector(setMouseSpeed:) keyEquivalent:@""];
NSMenuItem *item2 = [[NSMenuItem alloc] initWithTitle:[array objectForKey:[NSString stringWithFormat:@"name"]] action:@selector(deleteProfile:) keyEquivalent:@""];
[menuProfiles insertItem:item atIndex:i];
[menuProfilesDelete insertItem:item2 atIndex:i];
}
}
}
- (void)testMouseSpeed:(id)sender{
[self mouseSpeed:[slider floatValue]];
}
- (void)deleteProfile:(id)sender{
NSMenuItem *item = (NSMenuItem *)sender;
[profiles removeObjectForKey:[item title]];
[self createMenu];
}
- (void)setMouseSpeed:(id)sender{
NSMenuItem *item = (NSMenuItem *)sender;
NSDictionary *dictionary = [profiles objectForKey:[item title]];
[self mouseSpeed:[[dictionary objectForKey:@"sensitivity"] floatValue]];
}
- (void)mouseSpeed:(float)value{
IOHIDSetAccelerationWithKey(HIDSystem, CFSTR(kIOHIDMouseAccelerationType), value);
}
- (void)createProfile:(id)sender{
[window close];
NSString *name = [text stringValue];
text.stringValue = @"";
NSDictionary *array = [[NSDictionary alloc] initWithObjectsAndKeys:
name,@"name",
[NSNumber numberWithFloat:[slider floatValue]], @"sensitivity",
nil];
[profiles setValue:array forKey:name];
NSString *path = [[NSBundle mainBundle] pathForResource:@"profiles" ofType:@"plist"];
[profiles writeToFile:path atomically:YES];
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:name action:@selector(setMouseSpeed:) keyEquivalent:@""];
[menuProfiles addItem:item];
}
- (void)openWindow:(id)sender{
[window orderFrontRegardless];
}
- (void)openAbout:(id)sender{
[about orderFrontRegardless];
}
- (void)quit:(id)sender{
[NSApp terminate:sender];
}
- (void)dealloc{
[slider release];
[text release];
[profiles release];
[menuProfiles release];
[about release];
[super dealloc];
}
@end