Skip to content
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

Keybindings does not work with not English layout. #1946

Closed
vantu5z opened this issue Oct 22, 2021 · 1 comment · Fixed by #1953
Closed

Keybindings does not work with not English layout. #1946

vantu5z opened this issue Oct 22, 2021 · 1 comment · Fixed by #1953

Comments

@vantu5z
Copy link
Contributor

vantu5z commented Oct 22, 2021

Keybinds with layout sensitive keys (letters and other) doesn't work.
Test on Arch Linux.

In Guake 3.7.0 keybindings works on both layouts, I think because there used Gtk.AccelGroup.
This was changed in commit 6af0a95 and now keyval is used.
Maybe we should back to Accel realisation with build-in magic.

For example copy keys (Ctrl+Shift+C)
For US layout

keyval:  67
mod:  <flags GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD2_MASK of type Gdk.ModifierType>
scancode/keycode:  54

For RU layout

keyval:  1779
mod:  <flags GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD2_MASK | GDK_MODIFIER_RESERVED_13_MASK of type Gdk.ModifierType>
scancode/keycode:  54

As workaround convert keycode to english keyval, for me it look like this:

keybindings.py

def activate(self, window, event):
        key = event.keyval
        mod = event.state
        keycode = event.get_keycode()
        if keycode[0]:
            ent = Gdk.Keymap.get_for_display(window.get_display()).get_entries_for_keycode(keycode[1])
            if ent[0]:
                key = ent[2][0]
        ...

This code does not full tested so it can crash in some case.

@vantu5z
Copy link
Contributor Author

vantu5z commented Oct 25, 2021

Another workaround - using keycodes:

keybindings.py

    def activate(self, window, event):
        """If keystroke matches a key binding, activate keybinding. Otherwise, allow
        keystroke to pass through."""
        key = event.keyval
        mod = event.state
        keycode = event.hardware_keycode            # get keycode from event

        if mod & Gdk.ModifierType.SHIFT_MASK:
            if key == Gdk.KEY_ISO_Left_Tab:
                key = Gdk.KEY_Tab
            else:
                key = Gdk.keyval_to_lower(key)
        else:
            keys = Gdk.keyval_convert_case(key)
            if keys[0] != keys[1]:
                key = keys[1]
                mod &= ~Gdk.ModifierType.SHIFT_MASK

        mask = mod & self._masks

        #func = self._lookup[mask].get(key, None)
        func = self._lookup[mask].get(keycode, None)          # use keycode insted of keyval
        if func:
            func()
            return True

        return False


    def load_accelerators(self):
        """Reads all gconf paths under /apps/guake/keybindings/local
        and adds to the _lookup.
        """
        for binding, action in self.keys:
            #key, mask = Gtk.accelerator_parse( 
            key, codes, mask = Gtk.accelerator_parse_with_keycode(             # get keycode for accel
                self.guake.settings.keybindingsLocal.get_string(binding)
            )
            #if key > 0:
            if codes and codes[0]:                                        # check keycode
                #self._lookup[mask][key] = action
                self._lookup[mask][codes[0]] = action            # use keycode for accel
                self._masks |= mask

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant