Saturday, February 25, 2023

Another way of swapping alt and ctrl (using xkb)

EDIT: This might not be necessary. Refer to the original post and see updates.

I noitced that the method I described in a previous post does not work on Arch Linux. I came up with this quick (and probably dirty approach) to get the same effect.

First run this command:

xkbcomp $DISPLAY original.xkb

This will dump the current xkb config to a file named original.xkb. Make a copy of this file:

cp original.xkb swapped-alt-ctl.xkb

Edit the newly created swapped-alt-ctl.xkb file. Find the codes for LALT/LCTL and RALT/RCTL and swap them. For example, in my own file I found these for left alt/ctrl:

<LCTL> = 37;
<LALT> = 64;

I changed that to:

<LCTL> = 64;
<LALT> = 37;

Similarly for the right side I changed this:

<RCTL> = 105;
<RALT> = 108;

to:

<RCTL> = 108;
<RALT> = 105;

Then in order to reload the new config, run:

xkbcomp swapped-alt-ctl.xkb $DISPLAY

Put this in an appropriate place, like in your ~/.xinitrc file before the window manager is executed.

There might be a better way of doing this with xkb, but this works for me for now!

No comments:

Post a Comment