-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreferences.m
executable file
·191 lines (158 loc) · 9.25 KB
/
Preferences.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
ShiftIt: Resize windows with Hotkeys
Copyright (C) 2010 Aravind
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#import "Preferences.h"
OSStatus winSizer(EventHandlerCallRef nextHandler,EventRef theEvent,void *userData){
//Do something once the key is pressed
EventHotKeyID hotKeyID;
GetEventParameter(theEvent,kEventParamDirectObject,typeEventHotKeyID,NULL,sizeof(hotKeyID),NULL,&hotKeyID);
int temphotKeyId = hotKeyID.id;
switch (temphotKeyId) {
case 1:
[(WindowSizer*)userData shiftToLeftHalf:NULL];
break;
case 2:
[(WindowSizer*)userData shiftToRightHalf:NULL];
break;
case 3:
[(WindowSizer*)userData shiftToTopHalf:NULL];
break;
case 4:
[(WindowSizer*)userData shiftToBottomHalf:NULL];
break;
case 5:
[(WindowSizer*)userData shiftToTopLeft:NULL];
break;
case 6:
[(WindowSizer*)userData shiftToTopRight:NULL];
break;
case 7:
[(WindowSizer*)userData shiftToBottomLeft:NULL];
break;
case 8:
[(WindowSizer*)userData shiftToBottomRight:NULL];
break;
case 9:
[(WindowSizer*)userData shiftToCenter:NULL];
break;
case 10:
[(WindowSizer*)userData fullScreen:NULL];
break;
case 11:
[(WindowSizer*)userData shiftToCursorLocation:NULL];
break;
default:
break;
}
return noErr;
}
@implementation Preferences
-(id)init{
if(self == [super init]){
_hKeyController = [hKController getInstance];
_winSizer = [[WindowSizer alloc] init];
_eventType.eventClass = kEventClassKeyboard;
_eventType.eventKind = kEventHotKeyPressed;
InstallApplicationEventHandler(&winSizer,1,&_eventType,_winSizer,NULL);
[self registerDefaults];
}
return self;
}
-(void)registerDefaults{
[NSUserDefaults resetStandardUserDefaults];
NSLog(@"Registering default");
_userDefaultsValuesDict = [NSMutableDictionary dictionary];
/*
NSDictionary * leftHalf = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask)],HotKeyModifers,
[NSNumber numberWithUnsignedInt:123],HotKeyCodes,
nil];
[_userDefaultsValuesDict setObject:leftHalf forKey:@"leftHalf"];
NSDictionary * rightHalf = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask)],HotKeyModifers,
[NSNumber numberWithUnsignedInt:124],HotKeyCodes,
nil];
[_userDefaultsValuesDict setObject:rightHalf forKey:@"rightHalf"];
NSDictionary * topHalf = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask)],HotKeyModifers,
[NSNumber numberWithUnsignedInt:126],HotKeyCodes,
nil];
[_userDefaultsValuesDict setObject:topHalf forKey:@"topHalf"];
NSDictionary * bottomhalf = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask)],HotKeyModifers,
[NSNumber numberWithUnsignedInt:125],HotKeyCodes,
nil];
[_userDefaultsValuesDict setObject:bottomhalf forKey:@"bottomHalf"];
NSDictionary * topLeft = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask+NSControlKeyMask)],HotKeyModifers,
[NSNumber numberWithUnsignedInt:123],HotKeyCodes,
nil];
[_userDefaultsValuesDict setObject:topLeft forKey:@"topLeft"];
NSDictionary * topRight = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask+NSControlKeyMask)],HotKeyModifers,
[NSNumber numberWithUnsignedInt:126],HotKeyCodes,
nil];
[_userDefaultsValuesDict setObject:topRight forKey:@"topRight"];
NSDictionary * bottomLeft = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask+NSControlKeyMask)],HotKeyModifers,
[NSNumber numberWithUnsignedInt:125],HotKeyCodes,
nil];
[_userDefaultsValuesDict setObject:bottomLeft forKey:@"bottomLeft"];
NSDictionary * bottomRight = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask+NSControlKeyMask)],HotKeyModifers,
[NSNumber numberWithUnsignedInt:124],HotKeyCodes,
nil];
[_userDefaultsValuesDict setObject:bottomRight forKey:@"bottomRight"];
NSDictionary * fullScreen = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask)],HotKeyModifers,
[NSNumber numberWithUnsignedInt:3],HotKeyCodes,
nil];
[_userDefaultsValuesDict setObject:fullScreen forKey:@"fullScreen"];
NSDictionary * center = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask)],HotKeyModifers,
[NSNumber numberWithUnsignedInt:8],HotKeyCodes,
nil];
[_userDefaultsValuesDict setObject:center forKey:@"center"];
*/
NSDictionary *cursor = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask+NSShiftKeyMask)], HotKeyModifers,
[NSNumber numberWithUnsignedInt:7], HotKeyCodes,
nil];
[_userDefaultsValuesDict setObject:cursor forKey:@"cursor"];
/*
[_hKeyController registerHotKey:[[SIHotKey alloc]initWithIdentifier:1 keyCode:123 modCombo:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask)]]];
[_hKeyController registerHotKey:[[SIHotKey alloc]initWithIdentifier:2 keyCode:124 modCombo:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask)]]];
[_hKeyController registerHotKey:[[SIHotKey alloc]initWithIdentifier:3 keyCode:126 modCombo:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask)]]];
[_hKeyController registerHotKey:[[SIHotKey alloc]initWithIdentifier:4 keyCode:125 modCombo:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask)]]];
[_hKeyController registerHotKey:[[SIHotKey alloc]initWithIdentifier:5 keyCode:123 modCombo:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask+NSControlKeyMask)]]];
[_hKeyController registerHotKey:[[SIHotKey alloc]initWithIdentifier:6 keyCode:126 modCombo:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask+NSControlKeyMask)]]];
[_hKeyController registerHotKey:[[SIHotKey alloc]initWithIdentifier:7 keyCode:125 modCombo:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask+NSControlKeyMask)]]];
[_hKeyController registerHotKey:[[SIHotKey alloc]initWithIdentifier:8 keyCode:124 modCombo:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask+NSControlKeyMask)]]];
[_hKeyController registerHotKey:[[SIHotKey alloc]initWithIdentifier:9 keyCode:8 modCombo:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask)]]];
[_hKeyController registerHotKey:[[SIHotKey alloc]initWithIdentifier:10 keyCode:3 modCombo:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask)]]];*/
[_hKeyController registerHotKey:[[SIHotKey alloc]initWithIdentifier:11 keyCode:7 modCombo:[NSNumber numberWithUnsignedInt:(NSCommandKeyMask+NSAlternateKeyMask+NSShiftKeyMask)]]];
[_userDefaultsValuesDict setObject:[NSNumber numberWithBool:YES] forKey:@"shiftItstartLogin"];
[_userDefaultsValuesDict setObject:[NSNumber numberWithBool:YES] forKey:@"shiftItshowMenu"];
[[NSUserDefaults standardUserDefaults] registerDefaults:_userDefaultsValuesDict];
[[NSUserDefaults standardUserDefaults] synchronize];
NSArray *resettableUserDefaultsKeys;
NSDictionary * initialValuesDict;
resettableUserDefaultsKeys=[NSArray arrayWithObjects:@"cursor",nil];//@"leftHalf",@"topHalf",@"bottomHalf",@"rightHalf",@"bottomLeft",@"bottomRight",@"topLeft",@"topRight",@"fullScreen",@"center",nil];
initialValuesDict=[[NSUserDefaults standardUserDefaults] dictionaryWithValuesForKeys:resettableUserDefaultsKeys];
// Set the initial values in the shared user defaults controller
[[NSUserDefaultsController sharedUserDefaultsController] setInitialValues:initialValuesDict];
}
-(void)modifyHotKey:(NSInteger)newKey modiferKeys:(NSInteger)modKeys key:(NSString*)keyCode{
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:newKey] forKey:[@"hkc" stringByAppendingString:keyCode]];
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:modKeys] forKey:[@"hkm" stringByAppendingString:keyCode]];
[_hKeyController modifyHotKey:[[SIHotKey alloc]initWithIdentifier:[[_userDefaultsValuesDict objectForKey:keyCode] intValue] keyCode:newKey modCombo:[NSNumber numberWithUnsignedInt:modKeys]]];
[[NSUserDefaults standardUserDefaults] synchronize];
}
-(void)dealloc{
[_winSizer release];
[_hKeyController release];
[_userDefaultsValuesDict release];
[super dealloc];
}
@end