setxkbmap command doesn't work from .i3/config

Hi all,

I am a recent user of manjaro i3 and ran into a weird problem. I have the following command that work just fine from the terminal:

setxkbmap -model pc105 -layout us,tr -option grp:lalt_lshift_toggle

Interestingly the following code in .i3/config does not work:

exec --no-startup-id setxkbmap -model pc105 -layout us,tr -option grp:lalt_lshift_toggle

What am I missing? Any input will be greatly appreciated.

This might be happening before something else does keyboard mapping after the exec in i3, causing it to be overwritten.

If you really wanna experiment, try this. (I have not tried it)
try `(sleep 5; setxkbmap -model pc105 -layout us,tr -option grp:lalt_lshift_toggle) &` 

set the seconds to something like 10 if that does not work, see what happens.

If it breaks X or I3, just remove the line from tty2 and restart X.

So here is an actual posible fix

exec_always "setxkbmap -model pc104 -layout us,ru,ua -variant ,, -option grp:alt_shift_toggle"

And if you want to do it for X - change it in your xinitrc (source slackware)

i3 does not come with any built-in keyboard setting mechanism. The setxkbmap command, however, does the job well. If you've set the keyboard layout system-wide and do not need to switch between layouts, you do not need to do anything. If you'd like to set the layout just for i3, you can edit its .xinitrc file. If you change a graphical environment often and you do not want the keymap to be overwritten, you need to modify /etc/X11/xinit/xinitrc.i3 .

# nano /etc/X11/xinit/xinitrc.i3

Just before the Start i3 section you can specify the desired keymap (eg. gb):

setxkbmap gb

Save the file and run (as a standard user) xwmconfig and choose i3 to copy the xinitrc file to your home directory. If you are in X, you might need to restart it.

I dont know which - if any - of the sollutions are prefered, someone else might be able to wheigh in on that.

Agreed, but what could that be? setxkmap command is already the last line in my .i3/config and sleep 5 trick breaks the config file syntax; at least that is what I get as a red bar on top of the display as an error message and it does not fix the problem.

exec_always "setxkbmap -model pc104 -layout us,ru,ua -variant ,, -option grp:alt_shift_toggle"

fixes the problem if one restarts i3 in place (mod+shift+r). However, it does not stick after logging off and logging back in.

# nano /etc/X11/xinit/xinitrc.i3

I don't have such file. I only have xinitrc there which does not have an i3 section. I tried editing ~/.xinitrc and putting my setxkbmap command there with no change in behavior.

Thank you for the brainstorming...

Try putting the setxkbmap in ~/.xinitrc (create the file if it does not exists)

Also - the output of setxkbmap -print -verbose 10 might help.

Ok, so it seems like the keyboard layout is set /etc/X11/xorg.conf.d in the 00-keyboard.conf. You can set the options there to be persistent

Sorry - I only now have access to my manjaro computer, was at work.

This can be done using the localectl

$ localectl [--no-convert] set-x11-keymap layout [model [variant [options]]]

I did it (see above my previous comment) and nothing changed.

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...
Applied rules from evdev:
rules:      evdev
model:      pc105
layout:     us
Trying to build keymap using the following components:
keycodes:   evdev+aliases(qwerty)
types:      complete
compat:     complete
symbols:    pc+us+inet(evdev)
geometry:   pc(pc105)
xkb_keymap {
	xkb_keycodes  { include "evdev+aliases(qwerty)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete"	};
	xkb_symbols   { include "pc+us+inet(evdev)"	};
	xkb_geometry  { include "pc(pc105)"	};

Curiously, this output implies the setxkbmap command, which is now everywhere, including .i3/config, ~/.xinitrc was not executed. The only layout listed here is us...

I also tried the following:

$ localectl set-x11-keymap us,tr pc105 , grp:lalt_lshift_toggle

Then I got this:

$ localectl 
   System Locale: LANG=en_US.UTF-8
       VC Keymap: us-acentos
      X11 Layout: us,tr
       X11 Model: pc105
     X11 Variant: ,
     X11 Options: grp:lalt_lshift_toggle

Still no joy.

The thing that works for me, although ugly, is putting the setxkbmap command in ~/.bashrc. Then, only after opening a terminal I can switch keyboard layouts as intended.

Try setting the settings there manually. I am in i3 and setting my capslock to ctrl worked when I put it there.

I am sorry to be too difficult but this did not work for me either. I appreciate your patience.

Don't worry - you are not being difficult. :slight_smile: (maybe your computer, but definitely not you).

Do you have any DEs (Gnome, KDE etc.) installed alongside i3?

1 Like

Thank you :slight_smile:.
No, I just installed this from the Manjaro i3 community edition image. It's my rather old laptop, I wanted to keep it simple.

Ok, I just remembered that manjaro ships with a settings gui, and it has keyboard settings... manjaro-settings-manager

Will that work for your purposes?


Yes, I confirm that it works. Unfortunately, it is not as easy as using alt-shift combination on the keyboard. Convenience of manjaro comes with a price on this one I guess :slight_smile:.

Thank you!

You can set your default there, and then use setxkbmap in i3 to a different layout if you want?

It only works by issuing that command from a terminal, ~/.i3/config setting doesn't work to set the toggle key and the alternative keymap :slightly_smiling_face:.

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

Forum kindly sponsored by