No effect from running the setxkbmap command

I’ve moved over to a new system, with Manjaro i3. In my well tested i3 config file I do have the following line:
exec_always --no-startup-id setxkbmap -layout us,no -option grp:caps_toggle,grp_led:scroll

This worked perfectly on my old system. However, on my new system it has no effect. Running the cli command setxkbmap -layout us,no -option grp:caps_toggle,grp_led:scroll has no immediate effect either.

One workaround is to open manjaro-settings-manager > Keyboard Settings > Switch from US to NO and Apply (without entering the password upon confirmation). Then, in my terminal execute setxkbmap -layout us,no -option grp:caps_toggle,grp_led:scroll. After doing this switching keyboard layout using the caps toggle button works fine.

Does anyone know why this is the case? Is the NO keyboard layout not initially activated? It’s clearly that I’m missing something here. I can’t figure out what. Any help is appreciated.

Related issue:

Not a fix but perhaps a workaround if you can adjust to your need…

To switch between bépo <–> azerty french keyboards, I’m using :

bindsym $mod+space exec ~/bin/i3-keyboard-layout cycle “fr azerty” “fr bepo_afnor”

1 Like

Sorry ! I forgot the script… :roll_eyes:

I found it on the internet but don’t remember where and from whom…

#!/bin/bash

set -e

get_kbdlayout() {
layout=$(setxkbmap -query | grep -oP ‘layout:\s*\K([\w,]+)’)
variant=$(setxkbmap -query | grep -oP ‘variant:\s*\K(\w+)’)
echo “$layout” “$variant”
}

set_kbdlayout() {
eval “array=($1)”
setxkbmap “${array[@]}”
pgrep i3status | xargs --no-run-if-empty kill -s USR1 # tell i3status to update
}

cycle() {
current_layout=$(get_kbdlayout | xargs)
layouts=("$@" “$1”) # add the first one at the end so that it cycles
index=0
while [ “${layouts[$index]}” != “$current_layout” ] && [ $index -lt “${#layouts[@]}” ]; do index=$[index +1]; done
next_index=$[index +1]
next_layout=${layouts[$next_index]}
set_kbdlayout “$next_layout”
}

i3status() {
while :
do
read line
block="{“full_text”:"$(get_kbdlayout)"}"
echo “${line/[{/[$block,{}”|| exit 1
done
}

subcommand="$1"
shift || (echo “Please specify one of: get, set , cycle … , i3status” && exit)

case $subcommand in
“get”)
echo -n $(get_kbdlayout)
;;
“set”)
set_kbdlayout “$1”
;;
“cycle”)
cycle “$@”
;;
“i3status”)
i3status
;;
esac

Thanks a lot, @Stephix. Nice having that as a backup. However, I would really like to know why I simply can’t run setxkbmap on this new system. Seems like the system has no clue of there being more than one keyboard layout available, before I’m changing settings in manjaro-settings-manager.

I have exactly the same problem.
@mzuniga, have you figured anything out?

Unfortunately, I have not found a solution to this issue, @Nerarith. I hoped someone here knew what was wrong and could guide me in the right direction.

I have found a workaround that at least works for me. In another thread on this forum (unfortunately I’m not allowed to link it) it was suggested that the problem is the missing -model option. So I tried adding -model pc105 when I ran setxkbmap (I have a 105-key keyboard), and everything worked like it should. And after I had specified the model once, I didn’t have to do it again (at least until I rebooted), and now something simple like setxkbmap us worked.

So the cause of our problem might be that initially setxkbmap doesn’t know which keyboard model to use, which is also hinted at by comparing the output of setxkbmap -v 10 before and after specifying the model
Before:

Setting verbose level to 10
locale is C
Trying to load rules file ./rules/evdev...
Trying to load rules file /usr/share/X11/xkb/rules/evdev...
Success.
Applied rules from evdev:
rules:      evdev
layout:     se
Trying to build keymap using the following components:

After:

Setting verbose level to 10
locale is C
Trying to load rules file ./rules/evdev...
Trying to load rules file /usr/share/X11/xkb/rules/evdev...
Success.
Applied rules from evdev:
rules:      evdev
model:      pc105
layout:     se
variant:    programmersDvorak
options:    compose:lctrl-altgr
Trying to build keymap using the following components:
keycodes:   evdev+aliases(qwerty)
types:      complete
compat:     complete
symbols:    pc+se(programmersDvorak)+inet(evdev)+compose(lctrl-altgr)
geometry:   pc(pc105)

But I don’t know why setxkbmap doesn’t initially know about the model. To fix it (if you have the same problem as I do), you can either specify the model of the keyboard the first time you run setxkbmap after a booting, or you can set XKBMODEL="pc105" (or whatever your model is) in the file /etc/default/keyboard.

Hope it helps!

1 Like

Wonderful, @Nerarith. Thanks for sharing. I will try this and report back.

You fixed my problem, @Nerarith. Thanks a lot. This did the trick:
exec_always --no-startup-id setxkbmap -model pc105 -layout us,no -option grp:caps_toggle,grp_led:scroll

Beats me as well why setxkbmap needs the model. I used the exact same keyboard on my previous PC, and then it worked fine without the model. Anyhow, glad it’s solved.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.