-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
Add a shortkey for the keyboard layout manual switching #3859
Conversation
@@ -114,6 +114,10 @@ def parse_shortcuts(strs=(), shortcut_modifiers=(), modifier_names=()): | |||
args.append(None) | |||
elif x.find(".") != -1: | |||
args.append(float(x)) | |||
elif x in ("yes", "true", "on"): | |||
args.append(True) | |||
elif x in ("no", "false", "off"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
best to use x.lower() in TRUE_OPTIONS
/ x.lower() in FALSE_OPTIONS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good PR.
If you can address the minor points in this review, LGTM!
xpra/platform/win32/keyboard.py
Outdated
# https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-activatekeyboardlayout | ||
# KLF_SETFORPROCESS|KLF_REORDER = 0x108 | ||
old_hkl_or_zero_on_failure = ActivateKeyboardLayout(hkl, 0x108) | ||
return old_hkl_or_zero_on_failure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of the other set_platform_layout
functions return a value.
If anything, they should all return a boolean. (no point in exposing the "old hkl" to callers - they won't know what to do with it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the return value and just logged the failures because in the "gnome dbus request" scenario, successful/failed response will be determined by a callback and it does not seem good to block the shortkey processing until the callback is invoked.
xpra/platform/win32/keyboard.py
Outdated
return layout_to_hkl | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nitpick: one CR too many!
Thanks! |
@graph-inc FYI: a minor fix was needed. |
only the gnome input source bits do
Also got complaints that this broke the keyboard for users who don't have / want dbus installed, the commit above fixes that. |
only the gnome input source bits do
The usual way for switching the keyboard layouts is to ask the platform (i.e., Windows, POSIX) to perform the change and update the xpra keymap when the platform layout switching is detected. This merge request enables the opposite workflow by introducing the
next_keyboard_layout(self, update_platform_layout: bool)
method, so users can press a platform-independent shortkey and ask the xpra to update its keymap, and optionally inform the platform to switch its keyboard layout.This patch set requires three CLI options to work independent of the platform settings (of course, except the local support for the chosen keyboard layout). For example, to have "us" and "ir" keyboard layouts, starting by the "us" layout and switching to "ir" and back to the "us" again whenever the "Control+space" shortkey is pressed, following options may be passed:
Usage of the
false
boolean argument is to avoid race conditions when a shortkey is chosen which is monitored by the platform too. For example, ifAlt+Shift+Shift_L
is chosen in Windows platform,--key-shortcut=Alt+Shift+Shift_L:'next-keyboard-layout(false)'
is appropriate since Windows will switch the layout automatically.The platform layout switching is only supported in POSIX and Win32 platforms by this patch set.
A side-benefit of this opposite workflow (changing the xpra layout first and updating the platform layout later) is that it is more resilient against the platform layout switching detection bugs and complements the keyboard layout locking feature.