# setxkbmap stop working randomly



## Nick-6 (Jan 13, 2022)

I'm using 13.0-RELEASE-p4 with x11-wm/openbox. I've set keyboard in ~/.config/openbox/autostart as:


```
setxkbmap -layout us,xx -option 'grp:win_space_toggle' &
```

I can't change the keyboard from time to time until I run that command in terminal again.

Do I need to set that in somewhere else? How can I fix that?


----------



## chrbr (Jan 13, 2022)

I am not sure but since there has been no reply so far...
Please try without the trailing `&` which will send the command in the background.
May be then it depends on the timings if it has effect on your openbox session or not.
I do not use x11-wm/openbox but have in my ~/.xinitrc

```
setxkbmap -layout de
```
.
Please give it a try without the trailing ampersand.


----------



## Nick-6 (Jan 14, 2022)

chrbr said:


> Please give it a try without the trailing ampersand.


Sorry, I didn't paste the whole content which actually is;

```
sakura &
compton &
setxkbmap -layout us,xx -option 'grp:win_space_toggle' &
gxkb &
volumeicon &
redshift &
plank &
tint2 &
xset -dpms
```
So, if I remove the ampersand, it won't work.



chrbr said:


> I do not use x11-wm/openbox but have in my ~/.xinitrc


Is it better or more proper to set it in ~/.xinitrc ? I have

```
exec openbox-session
```
in my ~/.xinitrc.

Btw, which DE or WM are you using? Thanks for your reply.


_Edited: Added  tint2 &_


----------



## eternal_noob (Jan 14, 2022)

I use Openbox too and if i `setxkbmap` in ~/.xinitrc all works like a charm.
Try something like

```
setxkbmap -layout us,xx -option 'grp:win_space_toggle'
exec openbox-session
```

(And don't forget to remove the entry from the autostart file)


----------



## Nick-6 (Jan 14, 2022)

eternal_noob said:


> Code:
> 
> ```
> setxkbmap -layout us,xx -option 'grp:win_space_toggle'
> ...


I'm testing it and will report back if the issue persists. One thing I don't understand is why don't we need an ampersand after `setxkbmap` command. I search for some sample ~/.xinitrc files online and found that if we have more than one command, we need to put trailing ampersands except the last one. Thanks.


----------



## hruodr (Jan 14, 2022)

I have it similar, but still using 11.4:


```
# cat .xinitrc 
setxkbmap de
xsetroot -solid black
twm&
xterm -geometry +1+1 -n login -display :0
```

I think, to run openbox or twm is in principle the same.


----------



## eternal_noob (Jan 14, 2022)

Nick-6 said:


> why don't we need an ampersand after `setxkbmap` command.


You only need an ampersand if you want to run the command in the background. This is only useful if the command doesn't exit but has a loop in it.
Since `setxkbmap` finishes after you run it, there is no need to run it in the background.


----------



## mer (Jan 14, 2022)

If you look at your autostart file, you do not have an ampersand after the xset command, simply because as eternal_noob points out "it runs and exits".  
I'm guessing the "gxkb" is something for the keyboard?  If so having that and the setxkbmap running in the background could be creating a race condition where gxkb actually wants the setxkbmap to do it's thing before it starts.

In general I've always set things in .xinitrc or .xsession if they are "global" for the X session, so things like the xset command, the setxkbmap, and environment variables and then the last line is usually an "exec" of the windowmanger or the desktop environment.


----------



## T-Daemon (Jan 14, 2022)

Alternatively you could create a Xorg configuration file instead:

/usr/local/etc/X11/xorg.conf.d/keyboard.conf

```
Section "InputClass"
        Identifier      "All Keyboards"
        MatchIsKeyboard "yes"
        Option          "XkbLayout" "us, xx"
        Option          "XkbOptions" "grp:win_space_toggle"
EndSection
```

I'm using such a configuration myself, never had a problem.

I can even assign (4) different keyboard layouts for each window separately without special configuration, with x11/sbxkb indicating with a flag the layout in the panel.

I'm running x11-wm/openbox and x11/tint as panel.


----------



## Nick-6 (Jan 14, 2022)

mer said:


> "gxkb" is something for the keyboard?


Yes, it is just a graphical indicator for current keyboard on panel.



T-Daemon said:


> Alternatively you could create a Xorg configuration file instead:
> 
> /usr/local/etc/X11/xorg.conf.d/keyboard.conf


After setting that, my keyboard setting survive even after waking up from `zzz`. But I still don't know it will randomly stop working later. I'll test and report back if the problem persists.



T-Daemon said:


> I'm running x11-wm/openbox and x11/tint as panel.


Me too. But x11/tint shows glitches sometimes. I don't know it is theme related or not. Have you experienced one?


----------



## T-Daemon (Jan 14, 2022)

Nick-6 said:


> Me too. But x11/tint shows glitches sometimes. I don't know it is theme related or not. Have you experienced one?


I haven't experienced any unusual behavior. The theme I use is horizontal-light-transparent.

How would you describe those glitches?


----------



## eternal_noob (Jan 14, 2022)

T-Daemon said:


> How would you describe those glitches?


I wanted to ask the same. I also use tint and for me it works like a charm.


----------



## chrbr (Jan 14, 2022)

Nick-6 said:


> Is it better or more proper to set it in ~/.xinitrc ?


I do now know. May be it makes sense to have it in ~/.xinitrc because `setxkbmap` should apply to any other window manager, too.


Nick-6 said:


> Btw, which DE or WM are you using?


I use x11-wm/awesome. Regarding the other items I am late and there are enough good answers. I hope this is fine with you.


----------



## Nick-6 (Jan 14, 2022)

T-Daemon said:


> How would you describe those glitches?





eternal_noob said:


> I wanted to ask the same. I also use tint and for me it works like a charm.


I disabled x11/tint and was using x11/rofi and x11/plank recently. I don't remember how to reproduce that glitch right now. It is something like the white grains on dark background panel. It was distorted and unusable. So, I had to kill and restart the process. Now I'm using x11/tint again. Since now I know it works flawlessly on others, I'll post a new thread and ask if it happens to me again.


T-Daemon said:


> The theme I use is horizontal-light-transparent.


I'm using repentance.


----------

