Artix Linux Forum

Artix Linux => Installation / Migration / Configuration => Topic started by: shako on 26 October 2021, 10:21:25

Title: [SOLVED] Switching between multible keyboard layouts
Post by: shako on 26 October 2021, 10:21:25
Dear all,

I recently set up a base install of Artix Linux with a minimalistic set of programs and dwm as its window manager. I am using an italian keyboard but would like to being able to switch to the us layout with a key binding. I followed the instructions in this (https://forum.artixlinux.org/index.php/topic,1664.0.html) topic. Namely:

1) uncommenting the desired locales in /etc/locale.gen (in my case, it_IT.UTF-8 and en_US.UTF-8),

2) run sudo locale-gen to generate the desired locales (with the expected output), and

3) created a 00-keyboard.conf file in /etc/X11/xorg.conf.d with:

Code: [Select]
Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbLayout" "it,us"
        Option "XkbModel" "thinkpad"
        Option "XkbVariant" "qwerty"
        Option "XkbOptions" "grp:alt_shift_toggle"
EndSection

However, after a reboot, pressing alt+shift doesn't switch between the two layouts. In my .xinitrc file I have this line:

Code: [Select]
setxkbmap it &

because I want the default layout to be italian. However maybe this is the issue, or i didn't install some packages. Do any of you have some suggestions?
Title: Re: Switching between multible keyboard layouts
Post by: strajder on 26 October 2021, 12:16:59
https://git.sr.ht/~strahinja/dwm/tree/master/item/config.h#L48
Title: Re: Switching between multible keyboard layouts
Post by: shako on 26 October 2021, 13:11:10
Thank you @strajder. So basically all the previous steps I did are useless in dwm? May I delete the 00-keyboard.conf file?
Title: Re: Switching between multible keyboard layouts
Post by: strajder on 26 October 2021, 13:53:48
That topic is related to setting XKB on Thinkpad. You can also set it up using a .conf file, but it needs to match your keyboard model. See the official documentation (https://www.x.org/wiki/XKB/).

In my dwm setup, I'm not using any special X.Org configuration files, which fits the theme of my "portable" fork of dwm. For example, when I install different guests in QEMU, I just pick up my fork of dwm to have a lot of the settings, like my dwm keyboard shortcuts, starting st + tmux window, etc, and XKB layouts, working "out of the box".

Edit: Just tested in a XFCE OpenRC guest, this should work after X.Org restart or reboot if using DM:
Code: [Select]
# Read and parsed by systemd-localed. It's probably wise not to edit this file
# manually too freely.
Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbLayout" "us,rs"
        Option "XkbOptions" "grp:alt_shift_toggle"
EndSection
 
If not, check your X.Org log.
Title: Re: Switching between multible keyboard layouts
Post by: calvinh on 26 October 2021, 17:01:31
1. Use

Code: [Select]
$setxkbmap -print -verbose 10

to find out your keyboard model and configure  /etc/X11/xorg.conf.d /00-keyboard.conf accordingly

2. Remove this line in your .xinitrc

Code: [Select]
setxkbmap it &

X picks the first value in XkbLayout as default.

3. You may have missed step 04 and 05 in his summary section.
Title: Re: Switching between multible keyboard layouts
Post by: shako on 26 October 2021, 17:21:05
Quote
2. Remove this line in your .xinitrc

Code: [Select]
setxkbmap it &

X picks the first value in XkbLayout as default.

@calvinh yes, that was it! Thanks a lot! I marked this as "solved".