macOS keyboard shortcut handling: Qt problem? Or app problem?
-
I've read a bunch of stuff here about how the MVC approach of macOS Cocoa is somewhat at odds with Qt's architecture. I've noticed some strange behavior in a Qt app (OpenSCAD) on Mac, and I'm curious if this is a problem with Qt or with the app. Here's what I saw:
macOS has a feature where, even if the app you're using doesn't support custom key bindings, if something is in a menu, regardless of its preset keyboard shortcut, you can create alternate mappings, per application. It's wildly useful for crusty old farts like me who have 35 years of muscle memory to contend with.
This functionality can be found in System Preferences > Keyboard > Shortcuts > App Shortcuts. Once there, you can add shortcuts to (most) apps. For instance, I've been using other IDEs for years where the indent command is Cmd-Shift-Right, and dedent is Cmd-Shift-Left, this app uses different bindings for indent & dedent.
When I set up these overrides, I can even see the key combo change in the menu, and the menu gets activated when I press them, but the app doesn't indent/dedent, although weirdly, the initial key combos still do. This makes me suspect that keyboard commands are not using the standard macOS responder chain correctly, but are rather trying to manage keyboard input separately.
To Reproduce (in this case in OpenSCAD)
Steps to reproduce the behavior:
- Note the before state of the menu:
- Create a shortcut for Indent as described above in the system-native keyboard shortcuts.
- Note the after state of the menu:
- Enter 1 line of code
cube(10);
for instance - Try to indent and dedent that line of code, using the new key combos.
- Observe that the Edit menu flashed (meaning that the shortcut has sent that message up the responder chain through the macOS menu subsystem.)
- Observe that the indents and dedents don't happen in the editor.
Expected behavior:
I expect the new key combos to actually cause the desired indent and dedent operations in the editor, not just flash the menu.Code reproducing the issue
One line like:cube(10);
will allow you to repro this.
So that's the bullet. Is this a feature of macOS that Qt simply doesn't support? Or has OpenSCAD simply done something wrong?
Thanks,
Ian - Note the before state of the menu:
-
@ipmcc
Works for me with ⇧⌘I (shortcut not defined in my opensacd app version)
⇧⌘< seems to conflict with ⇧<About the responder chain, i'm talking about this HERE
As you can see in this screen shot of QtCReator, The main menu and the context menu are not synchronized (obviously there's nothing to copy), that what I 'm trying to implement in my link above.