summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-11-14 18:34:20 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-11-14 18:34:20 +0200
commitb55c5d8e93c5239d77e9afc1e15b2c7e9449d40e (patch)
tree33101f466bfe802bb03b5b9be9a6ed665523a87d
parentc11e09353ba7558f15958a01a0a4ac8f704d1ba5 (diff)
macOS: Disable menu shortcuts while binding keys
-rw-r--r--src/macos.h1
-rw-r--r--src/macos.m9
-rw-r--r--src/ui/bindingswidget.c10
3 files changed, 20 insertions, 0 deletions
diff --git a/src/macos.h b/src/macos.h
index ee06b69e..f948a0db 100644
--- a/src/macos.h
+++ b/src/macos.h
@@ -32,4 +32,5 @@ void enableMomentumScroll_MacOS (void);
32void registerURLHandler_MacOS (void); 32void registerURLHandler_MacOS (void);
33void setupApplication_MacOS (void); 33void setupApplication_MacOS (void);
34void insertMenuItems_MacOS (const char *menuLabel, int atIndex, const iMenuItem *items, size_t count); 34void insertMenuItems_MacOS (const char *menuLabel, int atIndex, const iMenuItem *items, size_t count);
35void enableMenu_MacOS (const char *menuLabel, iBool enable);
35void handleCommand_MacOS (const char *cmd); 36void handleCommand_MacOS (const char *cmd);
diff --git a/src/macos.m b/src/macos.m
index 28ebcc43..24a6fecb 100644
--- a/src/macos.m
+++ b/src/macos.m
@@ -491,6 +491,15 @@ void setupApplication_MacOS(void) {
491 windowCloseItem.action = @selector(closeTab); 491 windowCloseItem.action = @selector(closeTab);
492} 492}
493 493
494void enableMenu_MacOS(const char *menuLabel, iBool enable) {
495 NSApplication *app = [NSApplication sharedApplication];
496 NSMenu *appMenu = [app mainMenu];
497 NSString *label = [NSString stringWithUTF8String:menuLabel];
498 NSMenuItem *menuItem = [appMenu itemAtIndex:[appMenu indexOfItemWithTitle:label]];
499 [menuItem setEnabled:enable];
500 [label release];
501}
502
494void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *items, size_t count) { 503void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *items, size_t count) {
495 NSApplication *app = [NSApplication sharedApplication]; 504 NSApplication *app = [NSApplication sharedApplication];
496 MyDelegate *myDel = (MyDelegate *) app.delegate; 505 MyDelegate *myDel = (MyDelegate *) app.delegate;
diff --git a/src/ui/bindingswidget.c b/src/ui/bindingswidget.c
index 23fbbe88..a6e9f6a0 100644
--- a/src/ui/bindingswidget.c
+++ b/src/ui/bindingswidget.c
@@ -26,6 +26,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
26#include "command.h" 26#include "command.h"
27#include "util.h" 27#include "util.h"
28#include "app.h" 28#include "app.h"
29#if defined (iPlatformApple)
30# include "macos.h"
31#endif
29 32
30iDeclareType(BindingItem) 33iDeclareType(BindingItem)
31typedef iListItemClass iBindingItemClass; 34typedef iListItemClass iBindingItemClass;
@@ -129,6 +132,13 @@ static void setActiveItem_BindingsWidget_(iBindingsWidget *d, size_t pos) {
129 item->isWaitingForEvent = iTrue; 132 item->isWaitingForEvent = iTrue;
130 invalidateItem_ListWidget(d->list, d->activePos); 133 invalidateItem_ListWidget(d->list, d->activePos);
131 } 134 }
135#if defined (iPlatformApple)
136 /* Native menus must be disabled while grabbing keys so the shortcuts don't trigger. */
137 const iBool enableNativeMenus = (d->activePos == iInvalidPos);
138 enableMenu_MacOS("Edit", enableNativeMenus);
139 enableMenu_MacOS("View", enableNativeMenus);
140 enableMenu_MacOS("Identity", enableNativeMenus);
141#endif
132} 142}
133 143
134static iBool processEvent_BindingsWidget_(iBindingsWidget *d, const SDL_Event *ev) { 144static iBool processEvent_BindingsWidget_(iBindingsWidget *d, const SDL_Event *ev) {