I'm a bit puzzled why this is not working as intended. My goal is to map the caps lock key to control. I'm using debian. For this I'm using the following command

/usr/bin/setxkbmap -layout "$(setxkbmap -print | awk -F + '/xkb_symbols/ {print $2}')" -option ctrl:nocaps

which works perfectly fine if I execute it via the terminal. However, I want this to be done at startup or login and always execute it manually. I've tried to add this command to the automatic startup session application in XFCE as well as putting the command in my ~/.profile. However, both options don't seem to work. I still have to execute it manually (which after it is correctly mapped). What am I doing wrong?

  • How are you starting XFCE? – muru Jun 28 at 9:35
  • @muru not sure if I fully understand your question. But I'm running it with lightdm – math Jun 28 at 10:10
  • 1
    try moving it to ~/.xprofile instead of /.profile. make sure any kbd-setup component of XFCE is disabled so that it's not overwriting your setxkbmap` call. make sure you really need the extra setxkbmap | awk interior call; in many cases a simple setxkbmap -opiton ctrl:nocaps would have the same effect. – quixotic Jun 29 at 12:38
  • @quixotic thx for the comment. I will try it. How can I check if any kdb-setup component of XFCE is disabled? – math Jun 29 at 12:42
  • @quixotic putting the command in .xprofile didn't work. – math Jun 30 at 13:15
up vote 6 down vote accepted
+50

The reason that setxkbmap command didn't after adding it to ~/.profile is that this file is read by your shell (which is probably bash) only when login shell is started. In X terminal emulators don't start login shells. You add setxkbmap to your ~/.bashrc if you use Bash but there is a better way available on debian systems - modify XKBOPTIONS section in your /etc/default/keyboard, for example:

root@debian:/home/ja# cat /etc/default/keyboard
# KEYBOARD CONFIGURATION FILE

# Consult the keyboard(5) manual page.

XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS="ctrl:nocaps"

BACKSPACE="guess"

Now run this command as described in man 7 keyboard:

udevadm trigger --subsystem-match=input --action=change

You don't even have to restart lightdm. Next time lightdm is started settings in /etc/default/keyboard will be applied automatically. I've just tested it on my Debian 9.4.

  • 1
    that works like a charm. many thx. I have to wait 24 hours to award the bounty, but I will give it to you. – math Jun 30 at 15:57

I think the better way is to create a file .xsessionrc in your home directory.

cat .xsessionrc 
setxkbmap -option ctrl:nocaps

This file is read at each start of your session.
This way, only your session is affected.
The others users don't get it.
It's ok on Debian and NetBSD.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.