kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.36k stars 979 forks source link

OSX ctrl cmd swapped - way to swap in kitty too? #1077

Closed viennaa closed 6 years ago

viennaa commented 6 years ago

Hi,

since I have ctrl and cmd swapped in the whole system I wonder, if there is the possibility to swap them in the kitty config as well (since I would need to use CMD+C in order to issue a Ctrl+C console behaviour). Haven't found anything so far.

I tried remapping them directly with the glfw keys (swapped 0x2 and 0x8 here) without success. on_key_input: glfw key: 347 native_code: 0x36 action: PRESS mods: 0x2 text: '' on_key_input: glfw key: 341 native_code: 0x3b action: PRESS mods: 0x8 text: ''

Is this somehow possible viennaa

kovidgoyal commented 6 years ago

You cannot remap modifiers in kitty, I'm afraid. The closest you can come is mapping entire keypresses, which you will have to do for all keypresses to have that affect. It should also be a fairly simple thing to atch kitty to do what you need, see keys.c in the kitty source code

sergei-dyshel commented 5 years ago

FYI, I've made a simple patch to address this problem, see 056c124f

flowchartsman commented 5 years ago

@kovidgoyal, is there any way you would be able to take a look at the latest patch from @sergei-dyshel and see if there's a way to make this configurable? It does exactly what I want, and it would be amazing to offer it to everyone. https://github.com/kovidgoyal/kitty/commit/a076d0cd8cae0f1a177fc93bd53e0d19bf1f67a9

kovidgoyal commented 5 years ago

Not something I am interested in personally, sorry. It might help if you explained the need for it.

sergei-dyshel commented 5 years ago

Here's my vision of why one would like to swap Cmd and Ctrl on Mac:

On Linux (and Window) Ctrl and to lesser extent Alt are used as application modifiers (i.e. most application keybindings use combination of Ctrl and Alt), so one could call Ctrl the primary modifier and Alt a secondary one. On the other side Windows(aka Super) is mostly used as global modifier, i.e. for OS-level tasks, window management, global shortcuts.

On MacOS the situation is more complex, since Ctrl is also used for application-level bindings but there still seem to be a concept of Cmd being the primary modifier, Option (aka Alt) being the secondary modifier and Ctrl is used for global tasks but also for application.

So according to my "classification" ctrl and cmd already have swapped roles for one comming from Linux/Windows world and it might make sense to use Cmd as main modifier in terminal too, i.e. for the Ctrl key.

But this is only my personal option and I understand that my patch is just a dirty hack and implementing this feature properly would require much more dev effort so I fully agree with @kovidgoyal's stance.

@flowchartsman There is an app called Karabiner which allows to remap any keys on per-app basis so you might try this instead of patching Kitty's code. I would do that too but I just have this fetish of patching open-source software 😄

flowchartsman commented 5 years ago

@kovidgoyal Of course! I'm happy to explain. I feel the same way as @sergei-dyshel, but would like to give a few reasons of my own:

I hope that explains my rationale. iterm2 provides this ability for probably similar reasons, but I really like Kitty, and would like this option there. I think it would make a very useful configuration option. Of course I don't believe it should be on by default! :)

@sergei-dyshel: I'm aware of Karabiner, but that is way too heavy of a tool for this use, and I've had trouble getting it to work.

As for Kitty, I don't know the codebase well enough to know how much work it would be to make it a configuration option. That's why I mentioned @kovidgoyal. I was hoping to at least get some guidance on doing this the right way. I understand if it's not something he uses or wants to take the time to do, but at least some kind of guidance would be helpful so we can give back instead of just maintaining personal hacks.

sergei-dyshel commented 5 years ago

BTW, I'd like to add that Karabiner rule would swap modifiers for system keybindings too, i.e. if you have cmd+space binding for Spotlight and you swap ctrl and cmd in Karabiner for kitty/iterm2, than you will have to press ctrl+space in those apps for Spotlight. Unfortunately iterm2 built-in modifier remapping works in the same manner (probably utilising same low-level mechanism). This behaviour is very annoying.... So I would say that the remapping I did in kitty's code is the only proper solution existing on Mac terminals 😄

kovidgoyal commented 5 years ago

I'm fine with a patch adding such an (off-by-default) option, I'm just not motivated enough to come up with one myself.

aste4 commented 5 years ago

@kovidgoyal, thank you for directing me to this issue

+1 to everything in this issue

flowchartsman commented 5 years ago

@kovidgoyal Understood. Would you be willing to provide a little direction on me or @sergei-dyshel integrating this the proper way? Anything we should be aware of? I'll take a crack at it.

kovidgoyal commented 5 years ago

Feel free to ask if you have questions, in general, this will need to be done at the level of glfw, not kitty, since you will also have to remap the cocoa global menu shortcuts. You define options in config_data.py and state.[ch] and you will need to create a glfwinithint which the kitty code in create_os_window() will need to set based onthe option when creating the first window.

ultrox commented 4 years ago

I'm a very big fan of kitty, but unfortunately, lack of this feature on mac is preventing me to use it, I see a lot of people on blogs are struggling with this. I hope you change your mind @kovidgoyal.

sergei-dyshel commented 4 years ago

@ultrox You can use the patch I posted here earlier. It does the job pretty well.

ultrox commented 4 years ago

@sergei-dyshel will try that, thank you!

aliher1911 commented 2 years ago

Can the same be applied to x11 version? Should the swapping be done inside x11_window.c? Found it. It seem enough to just swap modifiers and relevant key definitions like this: https://github.com/aliher1911/kitty/tree/remap-ctrl-super Then it would be possible to swap ctrl-super-alt in layout and use macos modifiers layout in linux.

vaskozl commented 1 year ago

After getting a Mac in addition to a Linux workstation the difference was driving me crazy. On the OS/QMK side I put "Control" on the same key as Mac "Command" as muscle memory is very strong. This makes pretty much all GUI apps equivalent. But terminals is the one place it's different due to the dedicated control key in Macs.

Since on Linux I don't use a DE that uses the super key, I'm now using @aliher1911 fork to remap Super and Control on linux kitty such that things match. The advantage of making Super the Control key in kitty, is that the real control can still be used for the normal shortcuts, just like MacOS.

E.g. once swapped, to make simple Control+C and Control+V do copy and paste:

kitty_mod super

Now we can have total parity between mac and linux from terminal to browser!

ppwwyyxx commented 11 months ago

I would hope to see an option to swap option and command key on mac.

AFAIK, option and command key are interpreted by kitty as "alt" and "super". However, on mac, option is on the left of command, but on a standard keyboard, alt is on the right of super. The only way to address this inconsistencies so far seems to be to do a system-wide modifier swap on mac. But I hope to apply this swap only to kitty without affecting other apps.

UPDATE: I use this patch to swap command and option.

espenaf commented 9 months ago

Created a new patch for command <-> control swap with the latest HEAD.

inv2004 commented 6 months ago

Could someone provide an instruction how to achieve it on mac? Because some forks and paches as mentioned and it is still not very clear if it is possible in the last kitty release and how to configure it.

Thank you,

sergei-dyshel commented 6 months ago

@inv2004 This commit https://github.com/kovidgoyal/kitty/commit/bde8691ea724be2ad9153616222a28e087e216e3 worked for me. It's based on fairly recent version of kitty. I assume it should work for latest version too, though I haven't checked that explicitly since I've moved to another terminal already.

inv2004 commented 6 months ago

sorry, still not clear. The comment mentioned swap ctrl<=>cmd https://github.com/kovidgoyal/kitty/issues/1077#issuecomment-1793153216 - is it some global change outside kitty?

Should I add something into kitty after the change or it is just kitty config?