rbreaves / kinto

Mac-style shortcut keys for Linux & Windows.
http://kinto.sh
GNU General Public License v2.0
4.25k stars 213 forks source link

Some shortcuts not working in Kitty terminal #760

Closed seanbanko closed 1 year ago

seanbanko commented 1 year ago

Describe the bug Kinto key remaps are not recognized in Kitty terminal but seem to work everywhere else (Firefox, default terminal application, etc.)

Expected behavior Kinto key remaps should work with Kitty.

Install Type: Bare Metal Distro: Zorin OS 16 DE: Gnome Branch: master Commit:

rbreaves commented 1 year ago

Use xprop to get your wm_class name and share it please. I believe kitty is in the list but it sometimes varies still or app names could potentially change if a developer does so later on.

Kitty is on line 20 fyi. https://github.com/rbreaves/kinto/blob/master/linux/kinto.py#L20

seanbanko commented 1 year ago

The output says WM_CLASS(STRING) = "kitty", "kitty"

RedBearAK commented 1 year ago

@seanbanko

The WM_CLASS is good, so what keyboard specific shortcuts don't seem to be working as expected in Kitty?

seanbanko commented 1 year ago

With "cmd' referring to what is actually the alt key to the left of the spacebar on my pc, here are some examples:

shortcuts that do not work:

shortcuts that do work:

For reference, all of the ones that do not work in Kitty do work in GNOME Terminal.

RedBearAK commented 1 year ago

@seanbanko

shortcuts that do work:

This part proves that:

So that's all good, as far as that goes.

shortcuts that do not work:

This part shows that Kitty either:

Verbose explanation (suggested complete solution below):

The way the Kinto config works is that there are layers of keymaps starting from "General GUI" that will apply to most applications. Linux terminals generally want the basis of the keyboard shortcuts to be Shift+Ctrl instead of Ctrl, so there is a "terminals" keymap that mainly just remaps a bunch of combos from Ctrl+Key to Shift+Ctrl+Key when you are in a "terminal" application like Kitty.

So the question becomes, why aren't those specific shortcuts working in Kitty. Looking at the shortcut reference for Kitty (https://sw.kovidgoyal.net/kitty/overview/), it doesn't appear that there is a special shortcut for "last command". Which kind of makes sense, since the standard "Up" arrow key works for that in most terminal emulators. It should be a simple matter of remapping Cmd+P to "Up" to fix that.

K("RC-P"):  K("Up"),

You may notice if you examine the key.py file that there is no mention of the "capital" characters found on any keyboard key. That's because evdev only cares about the "base" key function. So the tab nav shortcuts are just Shift+Ctrl+Left_Brace/Right_Brace, not curly braces. That's just something to understand how evdev works. To get a double quote character you have to have it type "Shift-Apostrophe", for instance.

Kitty is one of several known applications that uses Shift+Ctrl+Tab/Ctrl+Tab for tab navigation, instead of the more common Ctrl+PgUp/PgDn. (Actually it looks like it also works with Shift+Ctrl+Left/Right.) So to make the braces shortcuts work, we would need something like this:

K("Shift-RC-Left_Brace"):   K("Shift-C-Tab"),
K("Shift-RC-Right_Brace"):  K("C-Tab"),

Now for the clear terminal/log shortcut, looks like Kitty accepts Ctrl+L for that, but the general "terminals" keymap in the Kinto config just changes Cmd+L (RC-L) to Shift+Ctrl+L, which works for most terminals. So that interferes with it working in Kitty. To make it work in Kitty, we would just override that (and Cmd+K does the same thing in macOS, so might as well add that):

K("RC-L"):  K("C-L"),
K("RC-K"):  K("C-L"),

Complete Solution:

For this to all work, a specific "Kitty" keymap like this must be inserted in the config file before the general "terminals" keymap, and also before the "General GUI" keymap, since it needs to override the general tab nav shortcuts.

define_keymap(re.compile("^kitty$", re.IGNORECASE),{
    K("Shift-RC-Left_Brace"):   K("Shift-C-Tab"),               # Tab nav: Go to prior tab (left)
    K("Shift-RC-Right_Brace"):  K("C-Tab"),                     # Tab nav: Go to next tab (right)
    K("RC-L"):                  K("C-L"),                       # Clear log
    K("RC-K"):                  K("C-L"),                       # Clear log (macOS)
    K("RC-P"):                  K("Up"),                        # Previous command
}, "Kitty terminal")

This should all be cleared up even more cleanly than this in a future version of the config file.

If you happen to run into any other specific shortcuts that don't work, try to find the correct shortcut to remap to and make a note of it here.

You may want to change the title of this issue to something like "Some shortcuts not working in Kitty terminal", since this is just about fixing some specific shortcuts.

seanbanko commented 1 year ago

Thank you for both the solution and for providing such a thorough explanation so I could understand it. Adding the following to my kinto.py achieved the desired behavior, and I suspect I could have also tinkered with kitty.conf to the achieve the same effect.

# Special overrides for Kitty
define_keymap(re.compile("^kitty$", re.IGNORECASE),{
    K("RC-Shift-Left_Brace"):   K("C-Shift-Left"),             # Tab nav: Go to prior tab (left)
    K("RC-Shift-Right_Brace"):  K("C-Shift-Right"),         # Tab nav: Go to next tab (right)
    K("RC-L"):                  K("C-L"),                                  # Clear log
    K("RC-K"):                  K("C-L"),                                  # Clear log (macOS)
}, "Kitty terminal")

As for Ctrl-P, I realized my Cmd-P habit was in fact not something I should have expected to be emulated by Kinto, just a remnant of having remapped that Cmd key to be a second Ctrl key in the past. Ctrl-P does in fact have the desired previous command behavior with no additional configuration required (and Ctrl-N for the inverse). Closing this here. Thanks again.

RedBearAK commented 1 year ago

@seanbanko

could have also tinkered with kitty.conf to the achieve the same effect

There are many cases where that would be true. But that's generally not advisable in the context of Kinto. The object of Kinto is to overlay Mac-like shortcuts onto Linux apps. In order for that to work for as many apps as possible without the user wasting a lot of time and effort, the Kinto config needs to map onto the default shortcuts of particular apps like Kitty, if they are different from other similar apps. So the goal would be to leave each app set to use its default set of shortcuts.

As for Ctrl-P, I realized my Cmd-P habit was in fact not something I should have expected to be emulated by Kinto, just a remnant of having remapped that Cmd key to be a second Ctrl key in the past. Ctrl-P does in fact have the desired previous command behavior with no additional configuration required (and Ctrl-N for the inverse).

I see. It did work in GNOME Terminal, but it looks like that was just because of the generic terminals remap from Cmd+P to Shift+Ctrl+P, which GNOME Terminal responds to in the same way as Ctrl+P. That's an odd one, since Shift+Ctrl+N opens a new window. Doesn't make much sense.

Talking about Ctrl can get a bit confusing with Kinto, since the "Cmd" key location is actually Control_R (right Ctrl) on a PC keyboard, while the physical Ctrl keys both become Control_L (left Ctrl) in terminals. I actually forgot to try the real Ctrl keys. Physical Ctrl+P/N works in macOS and GNOME Terminal the same way as in Kitty. So it looks like it doesn't need to be there as a special remap. Good catch.

Thanks for making a note of that.

rbreaves commented 1 year ago

Guess this is the first instance of anyone using kitty enough to discover this & in reality other terminals may need some custom work done as well.

I do realize too that trying to reach 100% remap coverage is like saying you’re trying to go at the speed of light 😂.. you’ll never actually reach it but the closer you get to complete the coverage the more surprising & frustrating the gaps may become.

I mostly just use xfce4-terminal & gauke. Rarely gnome-terminal. I used to like & test on konsole as well - but it’s a lot when you don’t dog food on KDE already.