Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mac): move keyboard menu items to main Input Menu from submenu 🔥 🍒 🏠 #9810

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions mac/Keyman4MacIM/Keyman4MacIM/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="19529" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19529"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand All @@ -19,19 +19,16 @@
</customObject>
<menu id="Uod-T8-nBO">
<items>
<menuItem title="Keyboards" tag="1" id="bQa-j9-nHe">
<menuItem isSeparatorItem="YES" tag="-4" id="uqs-C7-aK3"/>
<menuItem title="Configuration..." tag="-3" id="P1b-lE-yFw"/>
<menuItem title="On-Screen Keyboard" tag="-2" id="s96-JI-YDh">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Keyboards" id="goP-aK-3WB"/>
</menuItem>
<menuItem title="Configuration..." tag="2" id="P1b-lE-yFw"/>
<menuItem title="On-Screen Keyboard" tag="3" id="s96-JI-YDh">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="About" tag="4" id="kb2-ww-RS3">
<menuItem title="About..." tag="-1" id="kb2-ww-RS3" userLabel="About">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
<point key="canvasLocation" x="57" y="152"/>
<point key="canvasLocation" x="56.5" y="151.5"/>
</menu>
</objects>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ - (void)checkBoxAction:(id)sender {
[self saveActiveKeyboards];
}
else if (checkBox.state == NSOffState) {
if ([self.AppDelegate debugMode])
NSLog(@"Disabling active keyboard: %@", kmxFilePath);
[self.activeKeyboards removeObject:kmxFilePath];
[self saveActiveKeyboards];
}
Expand Down
73 changes: 24 additions & 49 deletions mac/Keyman4MacIM/Keyman4MacIM/KMInputController.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,65 +183,40 @@ - (KMXFile *)kmx {
return self.AppDelegate.kmx;
}


- (void)menuAction:(id)sender {
NSMenuItem *mItem = [sender objectForKey:kIMKCommandMenuItemName];
NSInteger itag = mItem.tag;
if ([self.AppDelegate debugMode])
NSLog(@"Keyman menu clicked - tag: %lu", itag);
if (itag == 2) {
// Using `showConfigurationWindow` instead of `showPreferences:` because `showPreferences:` is missing in
// High Sierra (10.13.1 - 10.13.3). See: https://bugreport.apple.com/web/?problemID=35422518
// rrb: where Apple's API is broken (10.13.1-10.13.3) call our workaround, otherwise, call showPreferences
u_int16_t systemVersion = [KMOSVersion SystemVersion];
if ([KMOSVersion Version_10_13_1] <= systemVersion && systemVersion <= [KMOSVersion Version_10_13_3]) // between 10.13.1 and 10.13.3 inclusive
{
NSLog(@"Input Menu: calling workaround instead of showPreferences (sys ver %x)", systemVersion);
[self.AppDelegate showConfigurationWindow]; // call our workaround
}
else
{
NSLog(@"Input Menu: calling Apple's showPreferences (sys ver %x)", systemVersion);
[self showPreferences:sender]; // call Apple API
}
if (itag == CONFIG_MENUITEM_TAG) {
[self showConfigurationWindow:sender];
}
else if (itag == 3) {
else if (itag == OSK_MENUITEM_TAG) {
[self.AppDelegate showOSK];
}
else if (itag == 4) {
else if (itag == ABOUT_MENUITEM_TAG) {
[self.AppDelegate showAboutWindow];
}
else if (itag >= 1000) {
NSMenuItem *keyboards = [self.AppDelegate.menu itemWithTag:1];
for (NSMenuItem *item in keyboards.submenu.itemArray) {
if (item.tag == itag)
[item setState:NSOnState];
else
[item setState:NSOffState];
}

NSString *path = [self.AppDelegate.activeKeyboards objectAtIndex:itag%1000];
KMXFile *kmx = [[KMXFile alloc] initWithFilePath:path];
[self.AppDelegate setKmx:kmx];
KVKFile *kvk = nil;
NSDictionary *kmxInfo = [KMXFile keyboardInfoFromKmxFile:path];
NSString *kvkFilename = [kmxInfo objectForKey:kKMVisualKeyboardKey];
if (kvkFilename != nil) {
NSString *kvkFilePath = [self.AppDelegate kvkFilePathFromFilename:kvkFilename];
if (kvkFilePath != nil)
kvk = [[KVKFile alloc] initWithFilePath:kvkFilePath];
}
[self.AppDelegate setKvk:kvk];
NSString *keyboardName = [kmxInfo objectForKey:kKMKeyboardNameKey];
if ([self.AppDelegate debugMode])
NSLog(@"Selected keyboard from menu: %@", keyboardName);
[self.AppDelegate setKeyboardName:keyboardName];
[self.AppDelegate setKeyboardIcon:[kmxInfo objectForKey:kKMKeyboardIconKey]];
[self.AppDelegate setContextBuffer:nil];
[self.AppDelegate setSelectedKeyboard:path];
[self.AppDelegate loadSavedStores];
if (kvk != nil && self.AppDelegate.alwaysShowOSK)
[self.AppDelegate showOSK];
else if (itag >= KEYMAN_FIRST_KEYBOARD_MENUITEM_TAG) {
[self.AppDelegate selectKeyboardFromMenu:itag];
}
}

- (void)showConfigurationWindow:(id)sender {
// Using `showConfigurationWindow` instead of `showPreferences:` because `showPreferences:` is missing in
// High Sierra (10.13.1 - 10.13.3). See: https://bugreport.apple.com/web/?problemID=35422518
// rrb: where Apple's API is broken (10.13.1-10.13.3) call our workaround, otherwise, call showPreferences
u_int16_t systemVersion = [KMOSVersion SystemVersion];
if ([KMOSVersion Version_10_13_1] <= systemVersion && systemVersion <= [KMOSVersion Version_10_13_3]) // between 10.13.1 and 10.13.3 inclusive
{
NSLog(@"Input Menu: calling workaround instead of showPreferences (sys ver %x)", systemVersion);
[self.AppDelegate showConfigurationWindow]; // call our workaround
}
else
{
NSLog(@"Input Menu: calling Apple's showPreferences (sys ver %x)", systemVersion);
[self showPreferences:sender]; // call Apple API
}
}

@end
17 changes: 17 additions & 0 deletions mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ typedef struct {
NSString *apiKeymanCom;
} KeymanVersionInfo;

// tags for default menu items, displayed whether keyboards are active or not
static const int DIVIDER_MENUITEM_TAG = -4;
static const int CONFIG_MENUITEM_TAG = -3;
static const int OSK_MENUITEM_TAG = -2;
static const int ABOUT_MENUITEM_TAG = -1;

// the number of menu items that do not represent active keyboards
static const int DEFAULT_KEYMAN_MENU_ITEM_COUNT = 4;

// the tag for the first keyboard dynamically added to the menu
static const int KEYMAN_FIRST_KEYBOARD_MENUITEM_TAG = 0;

// the menu index for the first keyboard dynamically added to the menu
static const int KEYMAN_FIRST_KEYBOARD_MENUITEM_INDEX = 0;

@interface KMInputMethodAppDelegate : NSObject
#define USE_ALERT_SHOW_HELP_TO_FORCE_EASTER_EGG_CRASH_FROM_ENGINE 1
#ifdef USE_ALERT_SHOW_HELP_TO_FORCE_EASTER_EGG_CRASH_FROM_ENGINE
Expand All @@ -54,6 +69,7 @@ typedef struct {
@property (nonatomic, strong) NSMutableArray *kmxFileList;
@property (nonatomic, strong) NSString *selectedKeyboard;
@property (nonatomic, strong) NSMutableArray *activeKeyboards;
@property (assign) int numberOfKeyboardMenuItems;
@property (nonatomic, strong) NSMutableString *contextBuffer;
@property (nonatomic, assign) NSEventModifierFlags currentModifierFlags;
@property (nonatomic, assign) CFMachPortRef lowLevelEventTap;
Expand Down Expand Up @@ -87,6 +103,7 @@ typedef struct {
- (void)showAboutWindow;
- (void)showOSK;
- (void)showConfigurationWindow;
- (void)selectKeyboardFromMenu:(NSInteger)tag;
- (void)sleepFollowingDeactivationOfServer:(id)lastServer;
- (void)wakeUpWith:(id)newServer;
- (void)handleKeyEvent:(NSEvent *)event;
Expand Down
Loading