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

Improve menu title to enable/disable mouse #100

Merged
merged 2 commits into from
Mar 18, 2024
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
18 changes: 5 additions & 13 deletions main_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ -(instancetype)init {
keyEquivalent:@""];
[enableMouse setTag:Enum::underlyCast(MenuTag::EnableMouse)];
[enableMouse setTarget:self];
[enableMouse setState:NSControlStateValueOff];


NSMenuItem *resetModelPosition = [[NSMenuItem alloc]
Expand Down Expand Up @@ -536,17 +535,6 @@ -(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\" menu not found");
return;
}

if ([getAppMain() getIgnoreMouse])
[enableMouse setState:NSControlStateValueOff];
else
[enableMouse setState:NSControlStateValueOn];

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

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

// Activate this app to enable touchpad gesture.
[NSApp activateIgnoringOtherApps:YES];
Expand All @@ -582,6 +573,7 @@ -(void)actionToggleHandleMouse:(NSMenuItem *)sender {
[alterApp_ activateWithOptions:NSApplicationActivateIgnoringOtherApps];
}
alterApp_ = NULL;
[sender setTitle:titleEnable];
}
}
-(void)actionToggleHideWindow:(NSMenuItem *)sender {
Expand Down
12 changes: 7 additions & 5 deletions main_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,13 @@ DWORD WINAPI AppMenu::showMenu(LPVOID param) {
}

UniqueHMENU hmenu = CreatePopupMenu();
AppendMenuW(hmenu, MF_STRING, Enum::underlyCast(Cmd::EnableMouse), L"&Enable Mouse");
if (parentWinExStyle & WS_EX_TRANSPARENT) {
AppendMenuW(hmenu, MF_STRING,
Enum::underlyCast(Cmd::EnableMouse), L"&Enable Mouse");
} else {
AppendMenuW(hmenu, MF_STRING,
Enum::underlyCast(Cmd::EnableMouse), L"&Disable Mouse");
}
AppendMenuW(hmenu, MF_STRING, Enum::underlyCast(Cmd::ResetPosition), L"&Reset Position");
AppendMenuW(hmenu, MF_SEPARATOR, Enum::underlyCast(Cmd::None), L"");
AppendMenuW(hmenu, MF_POPUP, reinterpret_cast<UINT_PTR>(hScreensMenu.GetRawHandler()), L"&Select screen");
Expand All @@ -663,10 +669,6 @@ DWORD WINAPI AppMenu::showMenu(LPVOID param) {

if (parentWinExStyle == 0) {
EnableMenuItem(hmenu, Enum::underlyCast(Cmd::EnableMouse), MF_DISABLED);
} else if (parentWinExStyle & WS_EX_TRANSPARENT) {
CheckMenuItem(hmenu, Enum::underlyCast(Cmd::EnableMouse), MF_UNCHECKED);
} else {
CheckMenuItem(hmenu, Enum::underlyCast(Cmd::EnableMouse), MF_CHECKED);
}

if (monitorHandles.size() <= 1)
Expand Down
Loading