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
#1141 rewrite fix for non-latin keyboard shortcuts #1142
base: master
Are you sure you want to change the base?
Conversation
gui/accelmap.py
Outdated
# So we get (<Shift>j, Shift+J) but just (plus, +). As I | ||
# understand it. | ||
|
||
keyval, keyval_lower, accel_label, mods = kb.translate_keyboard_state_improved( |
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.
line too long (87 > 79 characters)
gui/keyboard.py
Outdated
event.state | ||
& Gtk.accelerator_get_default_mod_mask() | ||
& ~consumed_modifiers | ||
keyval, keyval_lower, accel_label, modifiers = kb.translate_keyboard_state_improved( |
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.
line too long (92 > 79 characters)
lib/keyboard_util.py
Outdated
break | ||
|
||
if not ok_to_return: | ||
logger.warning('translate_keyboard_state() returned no valid response. ' |
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.
line too long (80 > 79 characters)
lib/keyboard_util.py
Outdated
def is_ascii(s): | ||
return s and all(ord(c) < 128 for c in s) | ||
|
||
def translate_keyboard_state_improved(hardware_keycode, state, group): |
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.
expected 2 blank lines, found 1
from lib.gibindings import Gtk | ||
|
||
import logging | ||
logger = logging.getLogger(__name__) |
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.
Black would make changes.
afa0e1b
to
2964f1a
Compare
2964f1a
to
f1edbfc
Compare
Thanks! You can ignore the "Black would make changes" warnings. I will test this tonight (CET) and I will try to do a better job than when I tested the last PR. On the other hand, merging the previous PR is what lead to getting feedback so swiftly, so not altogether a bad thing. |
This resolves the Shift-issues and other related issues that were identified in #1141, but there are a couple of issues left to tackle. For example, users of German and nordic layouts normally expect to be able to set and use shortcuts with characters like I will take a proper look at this issue tomorrow (Saturday), and dig into how applications like GIMP deal with this issue. |
Thanks, Gimp / Inkscape doesn't do anything special with the Shift key, and the display seems to be as it is without the Shift key (for special character like *, ~). At least that's the way it was in my environment. I wonder if it's a bug in GTK that the keymap is unstable when multiple IMEs are registered. |
Couldn't find anything about bugs with multiple input methods on the gtk tracker, but it's not impossible that it's a gtk issue (or something that simply isn't supported). I think it's more likely a problem with our implementation though. Based on how things work in GIMP and Krita, I think the behaviour we want is to prioritize the active/primary layout when setting and using shortcuts, and only fall back to other groups if no shortcut is found for the prioritized group. For example, in the Russian layout I'm testing with, the |
Thank you for the reponse. On a Japanese keyboard, we basically use Romaji to type hiragana, and no one sets up keyboard shortcuts using non-ascii characters.
In fact, that's what I was trying to do, but the code in the following part may have rejected it, causing it to fall back into a different group and not show the def is_ascii(s):
return s and all(ord(c) < 128 for c in s) Also I think the problem of garbled characters when setting key shortcuts can only be handled by input character / hardware keycode which is unstable. The problem would be solved if the behavior when setting key shortcuts were the same as in GIMP and Krita, but special character key shortcuts would not be displayed with "Shift+". If we make the display like GIMP, there is a possibility that the shortcuts currently set will not work. (idk for sure) If you use this code instead of #if is_ascii(lbl):
if keyval < 1000:
# dirty way of checking validity
# 1000 is probably beyond the upper limit of keyval?
ok_to_return = True
break I modified the test code I put in the first post to work in standalone as well. |
Ok, very good. Tomorrow evening I will take a more thorough look at the [relevant gdk documentation] (https://developer.gnome.org/gdk3/stable/gdk3-Keyboard-Handling.html) and build some minimal examples. Unfortunately I don't think the modified keyval check is enough, as for example the keyval of the We should remember that the original code was written nearly 11 years ago, and many things have changed or been added to the gdk/gtk APIs since then. There probably is a better way of handling the keyboard shortcuts in general. Of course, as you said, if we change the setup we'll have to make sure to avoid breaking compatibility with existing shortcuts stored in user settings. |
Thank you for all your research. I was not able to reproduce this garbled bug in 2.0.1, so it seems that this may be a bug that occurs only in the development environment. ( If there seems to be no good solution, it might be better to simply rewind my previous PR. #1139 I can manage to adjust it in my development environment. |
If a key binding contains non-ascii code, it will change the keyboard group and retry several times.
Here is SSCCE.
Test Code [Edited]
Test Code Output