Changing the TTY switch shortcut

Hello!

I want to change my TTY switch shortcut from Ctrl + Alt + Fx to Meta (Windows) + Alt + Fx, since i use Ctrl + Alt a lot in my IDE.

What should I do?

Welcome to the forum! :vulcan_salute:

Unfortunately, that is not possible. Those key sequences are hard-coded into the system console.

1 Like

I don’t think it is possible.

The shortcuts work even without a GUI so one is thinking they are defined at kernel level.

But as it software - everything is doable - it is just a matter of will and the means to do it - redefine a kernel header include somewhere and compile the kernel.

Just don’t use the function keys in your Ctrl + Alt shortcuts and it shouldn’t be a problem. You could reverse your idea and use Meta + Alt in the IDE instead, which is likely much better, though you may need to avoid meta (depending on what already uses it).


You might be able to do it…at least for X/Wayland…but if you can, then it might break other things. :man_shrugging:

On X you can use xkbcomp $DISPLAY ~/.xkbmap to dump the current config to ~/.xkbmap then edit the file and reapply it using xkbcomp ~/.xkbmap $DISPLAY.

This is some of the relevant config from mine:

type "CTRL+ALT" {
        modifiers= Shift+Control+Alt+LevelThree;
        map[Shift]= Level2;
        preserve[Shift]= Shift;
        map[LevelThree]= Level3;
        map[Shift+LevelThree]= Level4;
        preserve[Shift+LevelThree]= Shift;
        map[Control+Alt]= Level5;
        level_name[Level1]= "Base";
        level_name[Level2]= "Shift";
        level_name[Level3]= "AltGr";
        level_name[Level4]= "Shift AltGr";
        level_name[Level5]= "Ctrl+Alt";
    };

...

key <FK01> {
        type= "CTRL+ALT",
        symbols[Group1]= [              F1,              F1,              F1,              F1, XF86Switch_VT_1 ]
    };

You’d have to create a new type based on the CTRL+ALT type, which replaces level 5 with Meta + Alt, the former may be called Mod1. Of course you also need to apply that type to the definitions for the function keys. Not sure if your chosen modifier keys would work for this.

On wayland you’d have to do the same, but xkbcomp won’t work, you’d have to override the relevant files from /usr/share/X11/xkb, the overrides should be placed in either /etc/xkb or ~/.xkb (or it might be ~/.config/xkb).


Even if you do this, it may still be hard-coded in some places…if so there are no guarantees it would work.

X/wayland use different config to the linux console, not sure if you could change it for the latter…there’s a very good chance it’s hardcoded as @Aragorn said.

It’s better to just choose your shortcuts sensibly.

EDIT:

@Aragorn

Do you have any links to that information?

1 Like

This is a rather old, 'Buntu-centric, but related request, though it’s only for X11; it might (or might not) be inspirational:

Have at it. :person_fencing:


xremap key remapper for X11 and Wayland might potentially be useful, at a higher level; at least for fn keys.

I think I got it to work now.

I found the same when dumping my current config.

The type CTRL+ALT was defined in /usr/share/X11/xkb/types/pc.
I altered it from

type "CTRL+ALT" {
        modifiers= Shift+Control+Alt+LevelThree;
        map[Shift]= Level2;
        preserve[Shift]= Shift;
        map[LevelThree]= Level3;
        map[Shift+LevelThree]= Level4;
        preserve[Shift+LevelThree]= Shift;
        map[Control+Alt]= Level5;
        level_name[Level1]= "Base";
        level_name[Level2]= "Shift";
        level_name[Level3]= "AltGr";
        level_name[Level4]= "Shift AltGr";
        level_name[Level5]= "Ctrl+Alt";
};

to

type "META+ALT" {
        modifiers= Shift+Mod4+Alt+LevelThree;
        map[Shift]= Level2;
        preserve[Shift]= Shift;
        map[LevelThree]= Level3;
        map[Shift+LevelThree]= Level4;
        preserve[Shift+LevelThree]= Shift;
        map[Mod4+Alt]= Level5;
        level_name[Level1]= "Base";
        level_name[Level2]= "Shift";
        level_name[Level3]= "AltGr";
        level_name[Level4]= "Shift AltGr";
        level_name[Level5]= "Meta+Alt";
};

I also renamed the type for naming consistency, so i ended up greping and propagating the rename.

I finally restarted the X server and the changes were applied.

1 Like

That file is owned by a package, it will be overwritten next time xkeyboard-config is updated.

That’s why I said to use xkbcomp, it’s the only way to do it on X without it being overwritten by an update. For wayland you can take a copy of the file and put it in one of the locations I mentioned and modify that, but according to a blog by one of the maintainers of xkeyboard-config that functionality won’t be backported to X.

However xkbcomp is only temporary so you need to run it every time you log in and when the keyboard is reconnected (assuming it’s external). A systemd user service, and if necessary a udev rule, can used for that. Or you could make a pacman hook to redo your changes, not sure about pamac but it might use the same hook.

As for mod4, I forgot plasma switches meta compared to other DEs, mine is mod1 (which is also Alt :man_facepalming:).

Does it work on the ttys or do you need to use Ctrl + Alt? I would assume the latter.

Make sure it hasn’t broken anything.

2 Likes