Skip to content

Commit a1dc0a9

Browse files
committed
special key equivalents
1 parent de56538 commit a1dc0a9

File tree

10 files changed

+377
-258
lines changed

10 files changed

+377
-258
lines changed

Base.lproj/MainMenu.xib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<customObject id="770" userLabel="SquirrelPanel" customClass="SquirrelPanel"/>
2323
<menu id="773" userLabel="Menu">
2424
<items>
25-
<menuItem title="Squirrel Switcher" allowsKeyEquivalentWhenHidden="YES" id="780">
25+
<menuItem title="ㄓ⃣Squirrel Switcher" id="780">
2626
<modifierMask key="keyEquivalentModifierMask"/>
2727
<connections>
2828
<action selector="showSwitcher:" target="252" id="781"/>

SquirrelApplicationDelegate.mm

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ @implementation SquirrelApplicationDelegate {
1515

1616
- (IBAction)showSwitcher:(id)sender {
1717
NSLog(@"Show Switcher");
18-
RimeSessionId session = [sender unsignedLongValue];
19-
rime_get_api()->process_key(session, _switcherKeyEquivalent,
20-
_switcherKeyModifierMask);
18+
if (_switcherKeyEquivalent) {
19+
RimeSessionId session = [sender unsignedLongValue];
20+
rime_get_api()->process_key(session, _switcherKeyEquivalent,
21+
_switcherKeyModifierMask);
22+
}
2123
}
2224

2325
- (IBAction)deploy:(id)sender {
@@ -188,7 +190,7 @@ - (void)startRimeWithFullCheck:(BOOL)fullCheck {
188190
NSLog(@"Initializing la rime...");
189191
rime_get_api()->initialize(NULL);
190192
// check for configuration updates
191-
if (rime_get_api()->start_maintenance((Bool)fullCheck)) {
193+
if (rime_get_api()->start_maintenance(fullCheck)) {
192194
// update squirrel config
193195
rime_get_api()->deploy_config_file("squirrel.yaml", "config_version");
194196
}
@@ -200,32 +202,28 @@ - (void)shutdownRime {
200202
}
201203

202204
- (void)loadSettings {
205+
_switcherKeyModifierMask = 0;
206+
_switcherKeyEquivalent = 0;
203207
SquirrelConfig* defaultConfig = SquirrelConfig.alloc.init;
204208
if ([defaultConfig openWithConfigId:@"default"]) {
205-
NSString* hotKeys =
209+
NSString* hotkey =
206210
[defaultConfig getStringForOption:@"switcher/hotkeys/@0"];
207-
NSArray<NSString*>* keys = [hotKeys componentsSeparatedByString:@"+"];
208-
NSEventModifierFlags modifiers = 0;
209-
int rime_modifiers = 0;
210-
for (NSUInteger i = 0; i < keys.count - 1; ++i) {
211-
modifiers |= parse_macos_modifiers(keys[i].UTF8String);
212-
rime_modifiers |= parse_rime_modifiers(keys[i].UTF8String);
211+
if (hotkey) {
212+
NSArray<NSString*>* keys = [hotkey componentsSeparatedByString:@"+"];
213+
for (NSUInteger i = 0; i < keys.count - 1; ++i) {
214+
_switcherKeyModifierMask |=
215+
rime_modifiers_from_name(keys[i].UTF8String);
216+
}
217+
_switcherKeyEquivalent =
218+
rime_keycode_from_name(keys.lastObject.UTF8String);
213219
}
214-
int keycode = parse_keycode(keys.lastObject.UTF8String);
215-
unichar keychar = keycode <= 0xFFFF ? (unichar)keycode : 0;
216-
_menu.itemArray[0].keyEquivalent = [NSString stringWithCharacters:&keychar
217-
length:1];
218-
_menu.itemArray[0].keyEquivalentModifierMask = modifiers;
219-
_switcherKeyEquivalent = keycode;
220-
_switcherKeyModifierMask = rime_modifiers;
221220
}
222221
[defaultConfig close];
223222

224223
_config = SquirrelConfig.alloc.init;
225224
if (!_config.openBaseConfig) {
226225
return;
227226
}
228-
229227
NSString* showNotificationsWhen =
230228
[_config getStringForOption:@"show_notifications_when"];
231229
if ([@"never" caseInsensitiveCompare:showNotificationsWhen] ==

SquirrelConfig.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ typedef NSDictionary<NSString*, NSNumber*> SquirrelAppOptions;
6161
- (BOOL)setOption:(NSString* _Nonnull)option
6262
withString:(NSString* _Nonnull)value;
6363

64-
- (BOOL)getBoolForOption:(NSString* _Nonnull)option;
64+
- (bool)getBoolForOption:(NSString* _Nonnull)option;
6565
- (int)getIntForOption:(NSString* _Nonnull)option;
6666
- (double)getDoubleForOption:(NSString* _Nonnull)option;
6767
- (double)getDoubleForOption:(NSString* _Nonnull)option

SquirrelConfig.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,21 +247,21 @@ - (BOOL)setOption:(NSString*)option withString:(NSString*)value {
247247
value.UTF8String));
248248
}
249249

250-
- (BOOL)getBoolForOption:(NSString*)option {
251-
return [self getOptionalBoolForOption:option].boolValue;
250+
- (bool)getBoolForOption:(NSString*)option {
251+
return [self getOptionalBoolForOption:option alias:nil].boolValue;
252252
}
253253

254254
- (int)getIntForOption:(NSString*)option {
255-
return [self getOptionalIntForOption:option].intValue;
255+
return [self getOptionalIntForOption:option alias:nil].intValue;
256256
}
257257

258258
- (double)getDoubleForOption:(NSString*)option {
259-
return [self getOptionalDoubleForOption:option].doubleValue;
259+
return [self getOptionalDoubleForOption:option alias:nil].doubleValue;
260260
}
261261

262262
- (double)getDoubleForOption:(NSString*)option
263263
applyConstraint:(double (*)(double param))func {
264-
NSNumber* value = [self getOptionalDoubleForOption:option];
264+
NSNumber* value = [self getOptionalDoubleForOption:option alias:nil];
265265
return func(value.doubleValue);
266266
}
267267

0 commit comments

Comments
 (0)