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 wrong menu title may be shown on macOS #101

Merged
merged 1 commit into from
Mar 18, 2024
Merged
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
39 changes: 28 additions & 11 deletions main_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ @implementation AppMenuDelegate {
None,
EnableMouse,
SelectScreen,
HideWindow,
};
-(instancetype)init {
self = [super init];
Expand Down Expand Up @@ -484,7 +485,7 @@ -(instancetype)init {
initWithTitle:@"Hide Window"
action:@selector(actionToggleHideWindow:)
keyEquivalent:@""];
[hideWindow setTag:Enum::underlyCast(MenuTag::None)];
[hideWindow setTag:Enum::underlyCast(MenuTag::HideWindow)];
[hideWindow setTarget:self];

NSMenuItem *quit = [[NSMenuItem alloc]
Expand Down Expand Up @@ -535,6 +536,30 @@ -(void)menuNeedsUpdate:(NSMenu *)menu {
[menu setItemArray:[[NSArray alloc] initWithArray:menuItems_ copyItems:YES]];
}

NSMenuItem *enableMouse = [menu itemWithTag:Enum::underlyCast(MenuTag::EnableMouse)];
if (!enableMouse) {
Err::Log("Internal error: \"Enable Mouse\" or \"Disable Mouse\" menu not found");
return;
}

if ([getAppMain() getIgnoreMouse]) {
[enableMouse setTitle:@"Enable Mouse"];
} else {
[enableMouse setTitle:@"Disable Mouse"];
}

NSMenuItem *hideWindow = [menu itemWithTag:Enum::underlyCast(MenuTag::HideWindow)];
if (!hideWindow) {
Err::Log("Internal error: \"Hide Window\" or \"Show Window\" menu not found");
return;
}

if (NSApp.hidden) {
[hideWindow setTitle:@"Show Window"];
} else {
[hideWindow setTitle:@"Hide Window"];
}

NSMenuItem *selectScreen = [menu itemWithTag:Enum::underlyCast(MenuTag::SelectScreen)];
if (!selectScreen) {
Err::Log("Internal error: \"Select screen\" menu not found");
Expand All @@ -551,9 +576,7 @@ -(void)actionQuit:(id)sender {
[NSApp terminate:sender];
}
-(void)actionToggleHandleMouse:(NSMenuItem *)sender {
constexpr NSString *titleEnable = @"Enable Mouse";
constexpr NSString *titleDisable = @"Disable Mouse";
if ([[sender title] compare:titleEnable] == NSOrderedSame) {
if ([[sender title] compare:@"Enable Mouse"] == NSOrderedSame) {
NSArray *appList = [[NSWorkspace sharedWorkspace] runningApplications];
for (NSRunningApplication *app in appList) {
if (app.active) {
Expand All @@ -563,7 +586,6 @@ -(void)actionToggleHandleMouse:(NSMenuItem *)sender {
}

[getAppMain() setIgnoreMouse:false];
[sender setTitle:titleDisable];

// Activate this app to enable touchpad gesture.
[NSApp activateIgnoringOtherApps:YES];
Expand All @@ -573,18 +595,13 @@ -(void)actionToggleHandleMouse:(NSMenuItem *)sender {
[alterApp_ activateWithOptions:NSApplicationActivateIgnoringOtherApps];
}
alterApp_ = NULL;
[sender setTitle:titleEnable];
}
}
-(void)actionToggleHideWindow:(NSMenuItem *)sender {
constexpr NSString *titleHide = @"Hide Window";
constexpr NSString *titleShow = @"Show Window";
if ([[sender title] compare:titleHide] == NSOrderedSame) {
if ([[sender title] compare:@"Hide Window"] == NSOrderedSame) {
[NSApp hide:self];
[sender setTitle:titleShow];
} else {
[NSApp unhide:self];
[sender setTitle:titleHide];
}
}
-(void)actionResetModelPosition:(NSMenuItem *)sender {
Expand Down
Loading