helloSystem / QtPlugin

Qt platform plugin and style, required for Qt applications to export their menus over D-Bus in the required format
5 stars 4 forks source link

Enable MacKeyboardScheme, make QKeySequence::StandardKey behave like on the Mac #12

Open probonopd opened 2 years ago

probonopd commented 2 years ago

Currently we have the clearly Windows-inspired "F3" for Find Again, whereas we want Command-G.

Supposedly we can get this for all Qt applications by setting QPlatformTheme::MacKeyboardScheme. How?

Command-G is mentioned in the early Macintosh Human Interface Guidelines:

image

Source: Apple Computer, Inc. 1992. Macintosh human interface guidelines. Addison-Wesley Publishing Company, USA. https://dl.acm.org/doi/book/10.5555/573097

probonopd commented 2 years ago

Need to find a way to get QKeySequence::StandardKey to behave like on the Mac.

https://doc.qt.io/qt-5/qkeysequence.html#StandardKey-enum

Note that the key bindings are platform dependent. The currently bound shortcuts can be queried using keyBindings().

How can we change it so that it behaves like on the Mac?

probonopd commented 2 years ago

If we can't find another way to implement this, then maybe go the LD_PRELOAD route like in https://github.com/helloSystem/QKeySequenceOverride/ for QList<QKeySequence> QKeySequence::keyBindings(QKeySequence::StandardKey key) too.

NorwegianRockCat commented 2 years ago

The keyboard scheme is set by the platform theme. Which is defined is sort of documented.

You can force a theme by setting the QT_QPA_PLATFORMTHEME environment variable or explicitly setting it for each Qt application invocation, but it looks like you would need a platformtheme plugin that would return the correct ThemeHint.

The only themes that return MacKeyboardScheme are the Cocoa and iOS themes, but I doubt those are built on X11. I suspect that otherwise it uses the qgenericunixthemes.cpp unless a platformtheme plugin intercepts it.

You could consider creating a helloSystem platformtheme plugin that simply reimplements themeHint() to do the right thing. There is something like this done for GTK3 or QXdgDesktopPortal, so it might be a starting point there.

This is at least a basic map of what you would need to do, hope this helps.

probonopd commented 2 years ago

Thanks @NorwegianRockCat.

We are exporting QT_QPA_PLATFORMTHEME=panda and are loading our own platformtheme plugin but the following does not seem to have an effect:

https://github.com/helloSystem/QtPlugin/blob/c973e717c0282b2a92c4c867714b57ba8d1729fc/platformthemeplugin/hintsettings.cpp#L44

In any case, will follow your hint to check out what GTK3 and QXdgDesktopPortal are doing.