Lagrange [work/v1.6]

macOS: Disable menu shortcuts while binding keys

=> b55c5d8e93c5239d77e9afc1e15b2c7e9449d40e

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);
 void    registerURLHandler_MacOS    (void);
 void    setupApplication_MacOS      (void);
 void    insertMenuItems_MacOS       (const char *menuLabel, int atIndex, const iMenuItem *items, size_t count);
+void    enableMenu_MacOS            (const char *menuLabel, iBool enable);
 void    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) {
     windowCloseItem.action = @selector(closeTab);
 }
 
+void enableMenu_MacOS(const char *menuLabel, iBool enable) {
+    NSApplication *app = [NSApplication sharedApplication];
+    NSMenu *appMenu = [app mainMenu];
+    NSString *label = [NSString stringWithUTF8String:menuLabel];
+    NSMenuItem *menuItem = [appMenu itemAtIndex:[appMenu indexOfItemWithTitle:label]];
+    [menuItem setEnabled:enable];
+    [label release];
+}
+
 void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *items, size_t count) {
     NSApplication *app = [NSApplication sharedApplication];
     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. */
 #include "command.h"
 #include "util.h"
 #include "app.h"
+#if defined (iPlatformApple)
+#   include "macos.h"
+#endif
 
 iDeclareType(BindingItem)
 typedef iListItemClass iBindingItemClass;
@@ -129,6 +132,13 @@ static void setActiveItem_BindingsWidget_(iBindingsWidget *d, size_t pos) {
         item->isWaitingForEvent = iTrue;
         invalidateItem_ListWidget(d->list, d->activePos);
     }
+#if defined (iPlatformApple)
+    /* Native menus must be disabled while grabbing keys so the shortcuts don't trigger. */
+    const iBool enableNativeMenus = (d->activePos == iInvalidPos);
+    enableMenu_MacOS("Edit", enableNativeMenus);
+    enableMenu_MacOS("View", enableNativeMenus);
+    enableMenu_MacOS("Identity", enableNativeMenus);
+#endif
 }
 
 static iBool processEvent_BindingsWidget_(iBindingsWidget *d, const SDL_Event *ev) {
Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.6/cdiff/b55c5d8e93c5239d77e9afc1e15b2c7e9449d40e
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
50.534258 milliseconds
Gemini-to-HTML Time
0.145519 milliseconds

This content has been proxied by September (ba2dc).