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

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

Closed
viennaa opened this issue Oct 17, 2018 · 22 comments
Closed

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

viennaa opened this issue Oct 17, 2018 · 22 comments

Comments

@viennaa
Copy link

viennaa commented Oct 17, 2018

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
Copy link
Owner

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
Copy link

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

@flowchartsman
Copy link

flowchartsman commented Aug 15, 2019

@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. a076d0c

@kovidgoyal
Copy link
Owner

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

@sergei-dyshel
Copy link

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
Copy link

flowchartsman commented Aug 15, 2019

@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:

  • Reason 1
    • It's a relatively common thing to want do since they keys are in the same position and serve a similar function to Ctrl on other keyboards and in other operating systems.
  • Reason 2
    • Different people prefer different hands to hit the modifier key. I (and probably many others) prefer the right hand due to years of muscle memory, and there is no corresponding Ctrl key on that side
  • Reason 3
    • Ctrl is very awkward to hit on Apple keyboards; it is not the same priority as cmd for reasons @sergei-dyshel mentioned. It requires you to curl your thumb and lift your hand, and is very inconvenient, especially to people with years of experience hitting Ctrl on standard keyboards. And I use it a lot as a heavy tmux / vim user

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
Copy link

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
Copy link
Owner

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
Copy link

aste4 commented Aug 22, 2019

@kovidgoyal, thank you for directing me to this issue

+1 to everything in this issue

@flowchartsman
Copy link

@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
Copy link
Owner

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
Copy link

ultrox commented Jul 23, 2020

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
Copy link

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

@ultrox
Copy link

ultrox commented Jul 24, 2020

@sergei-dyshel will try that, thank you!

@aliher1911
Copy link

aliher1911 commented Mar 10, 2022

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
Copy link

vaskozl commented Jun 29, 2023

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
Copy link
Contributor

ppwwyyxx commented Nov 3, 2023

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
Copy link

espenaf commented Jan 12, 2024

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

@inv2004
Copy link

inv2004 commented Apr 3, 2024

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
Copy link

@inv2004
This commit bde8691 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
Copy link

inv2004 commented Apr 25, 2024

sorry, still not clear. The comment mentioned swap ctrl<=>cmd #1077 (comment) - is it some global change outside kitty?

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

@necauqua
Copy link

necauqua commented Jan 2, 2025

hey here's an updated version of that patch to swap ctrl and super that works as of now:

diff --git a/gen/key_constants.py b/gen/key_constants.py
index 7bf9a90d8..119eac65b 100755
--- a/gen/key_constants.py
+++ b/gen/key_constants.py
@@ -113,15 +113,15 @@
 raise_volume                XF86AudioRaiseVolume        -      -
 mute_volume                 XF86AudioMute               -      -
 left_shift                  Shift_L                     0x38   -
-left_control                Control_L                   0x3B   -
+left_control                Super_L                     0x3B   -
 left_alt                    Alt_L                       0x3A   -
-left_super                  Super_L                     0x37   -
+left_super                  Control_L                   0x37   -
 left_hyper                  Hyper_L                     -      -
 left_meta                   Meta_L                      -      -
 right_shift                 Shift_R                     0x3C   -
-right_control               Control_R                   0x3E   -
+right_control               Super_R                     0x3E   -
 right_alt                   Alt_R                       0x3D   -
-right_super                 Super_R                     0x36   -
+right_super                 Control_R                   0x36   -
 right_hyper                 Hyper_R                     -      -
 right_meta                  Meta_R                      -      -
 iso_level3_shift            ISO_Level3_Shift            -      -
diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m
index 79e4104a1..16b50dd54 100644
--- a/glfw/cocoa_window.m
+++ b/glfw/cocoa_window.m
@@ -108,13 +108,13 @@
         case 0x4c: return GLFW_FKEY_KP_ENTER;
         case 0x51: return GLFW_FKEY_KP_EQUAL;
         case 0x38: return GLFW_FKEY_LEFT_SHIFT;
-        case 0x3b: return GLFW_FKEY_LEFT_CONTROL;
+        case 0x37: return GLFW_FKEY_LEFT_CONTROL;
         case 0x3a: return GLFW_FKEY_LEFT_ALT;
-        case 0x37: return GLFW_FKEY_LEFT_SUPER;
+        case 0x3b: return GLFW_FKEY_LEFT_SUPER;
         case 0x3c: return GLFW_FKEY_RIGHT_SHIFT;
-        case 0x3e: return GLFW_FKEY_RIGHT_CONTROL;
+        case 0x36: return GLFW_FKEY_RIGHT_CONTROL;
         case 0x3d: return GLFW_FKEY_RIGHT_ALT;
-        case 0x36: return GLFW_FKEY_RIGHT_SUPER;
+        case 0x3e: return GLFW_FKEY_RIGHT_SUPER;
 /* end vk to functional */
         default:
             return 0;
@@ -438,11 +438,11 @@ static void releaseMonitor(_GLFWwindow* window)
     if (flags & NSEventModifierFlagShift)
         mods |= GLFW_MOD_SHIFT;
     if (flags & NSEventModifierFlagControl)
-        mods |= GLFW_MOD_CONTROL;
+        mods |= GLFW_MOD_SUPER;
     if (flags & NSEventModifierFlagOption)
         mods |= GLFW_MOD_ALT;
     if (flags & NSEventModifierFlagCommand)
-        mods |= GLFW_MOD_SUPER;
+        mods |= GLFW_MOD_CONTROL;
     if (flags & NSEventModifierFlagCapsLock)
         mods |= GLFW_MOD_CAPS_LOCK;
 
@@ -1033,11 +1033,11 @@ - (NSTextInputContext *)inputContext
     if (flags & NSEventModifierFlagShift)
         mods |= shiftKey;
     if (flags & NSEventModifierFlagControl)
-        mods |= controlKey;
+        mods |= cmdKey;
     if (flags & NSEventModifierFlagOption)
         mods |= optionKey;
     if (flags & NSEventModifierFlagCommand)
-        mods |= cmdKey;
+        mods |= controlKey;
     if (flags & NSEventModifierFlagCapsLock)
         mods |= alphaLock;
 
@@ -1223,10 +1223,10 @@ - (void)flagsChanged:(NSEvent *)event
         case GLFW_FKEY_CAPS_LOCK:
             mod_name = "capslock";
             action = modifierFlags & NSEventModifierFlagCapsLock ? GLFW_PRESS : GLFW_RELEASE; break;
-        case GLFW_FKEY_LEFT_SUPER: action_for(super, NX_DEVICELCMDKEYMASK, NX_DEVICERCMDKEYMASK, NX_COMMANDMASK);
-        case GLFW_FKEY_RIGHT_SUPER: action_for(super, NX_DEVICERCMDKEYMASK, NX_DEVICELCMDKEYMASK, NX_COMMANDMASK);
-        case GLFW_FKEY_LEFT_CONTROL: action_for(ctrl, NX_DEVICELCTLKEYMASK, NX_DEVICERCTLKEYMASK, NX_CONTROLMASK);
-        case GLFW_FKEY_RIGHT_CONTROL: action_for(ctrl, NX_DEVICERCTLKEYMASK, NX_DEVICELCTLKEYMASK, NX_CONTROLMASK);
+        case GLFW_FKEY_LEFT_CONTROL: action_for(super, NX_DEVICELCMDKEYMASK, NX_DEVICERCMDKEYMASK, NX_COMMANDMASK);
+        case GLFW_FKEY_RIGHT_CONTROL: action_for(super, NX_DEVICERCMDKEYMASK, NX_DEVICELCMDKEYMASK, NX_COMMANDMASK);
+        case GLFW_FKEY_LEFT_SUPER: action_for(ctrl, NX_DEVICELCTLKEYMASK, NX_DEVICERCTLKEYMASK, NX_CONTROLMASK);
+        case GLFW_FKEY_RIGHT_SUPER: action_for(ctrl, NX_DEVICERCTLKEYMASK, NX_DEVICELCTLKEYMASK, NX_CONTROLMASK);
         case GLFW_FKEY_LEFT_ALT: action_for(alt, NX_DEVICELALTKEYMASK, NX_DEVICERALTKEYMASK, NX_ALTERNATEMASK);
         case GLFW_FKEY_RIGHT_ALT: action_for(alt, NX_DEVICERALTKEYMASK, NX_DEVICELALTKEYMASK, NX_ALTERNATEMASK);
         case GLFW_FKEY_LEFT_SHIFT: action_for(shift, NX_DEVICELSHIFTKEYMASK, NX_DEVICERSHIFTKEYMASK, NX_SHIFTMASK);
@@ -3113,11 +3113,11 @@ GLFWAPI GLFWColorScheme glfwGetCurrentSystemColorTheme(bool query_if_unintialize
     if (glfw_mods & GLFW_MOD_SHIFT)
         *cocoa_mods |= NSEventModifierFlagShift;
     if (glfw_mods & GLFW_MOD_CONTROL)
-        *cocoa_mods |= NSEventModifierFlagControl;
+        *cocoa_mods |= NSEventModifierFlagCommand;
     if (glfw_mods & GLFW_MOD_ALT)
         *cocoa_mods |= NSEventModifierFlagOption;
     if (glfw_mods & GLFW_MOD_SUPER)
-        *cocoa_mods |= NSEventModifierFlagCommand;
+        *cocoa_mods |= NSEventModifierFlagControl;
     if (glfw_mods & GLFW_MOD_CAPS_LOCK)
         *cocoa_mods |= NSEventModifierFlagCapsLock;
     return _glfwPlatformGetNativeKeyForKey(glfw_key);

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

No branches or pull requests