How to Remap Caps Lock to Control Key in XFCE4: Permanent XKB Configuration


1 views

When migrating from GNOME to XFCE, many users find their existing keyboard customizations don't carry over. The ctrl:nocaps option in xorg.conf often gets ignored by XFCE's lightweight architecture. Here's how to properly implement this remapping.

For a quick temporary solution:

setxkbmap -option "ctrl:nocaps"

To make this persistent, add it to your XFCE autostart:

echo 'setxkbmap -option "ctrl:nocaps"' >> ~/.config/xfce4/xinitrc

Create a ~/.Xmodmap file with:

remove Lock = Caps_Lock
keysym Caps_Lock = Control_L
add Control = Control_L

Then load it with:

xmodmap ~/.Xmodmap

For a more permanent solution, edit/create /etc/X11/xorg.conf.d/00-keyboard.conf:

Section "InputClass"
    Identifier "system-keyboard"
    MatchIsKeyboard "on"
    Option "XkbOptions" "ctrl:nocaps"
EndSection

Check active XKB options with:

setxkbmap -query | grep options

Test key functionality with:

xev | grep -A2 --line-buffered '^KeyRelease' | sed -n '/keycode /s/^.*keycode $[0-9]*$.* (.*, $.*$).*$/\1 \2/p'

If changes don't persist:

  1. Check for competing settings in ~/.xprofile or ~/.xsession
  2. Ensure no other desktop managers are overriding settings
  3. Verify XFCE isn't resetting keyboard layouts on login

For modern systems using systemd, you might need to create a service:

[Unit]
Description=Load keyboard mapping

[Service]
Type=oneshot
ExecStart=/usr/bin/setxkbmap -option "ctrl:nocaps"

[Install]
WantedBy=multi-user.target

Many developers migrating from GNOME to XFCE encounter this remapping issue. While GNOME provides GUI tools for key remapping, XFCE requires more manual configuration. The ctrl:nocaps option in xorg.conf often doesn't propagate properly to XFCE's session.

Here are three reliable methods to achieve the Caps Lock to Control remapping in XFCE:

Method 1: Using setxkbmap

The most straightforward solution is to run this command in your XFCE session:

setxkbmap -option ctrl:nocaps

To make it persistent, add it to your XFCE autostart:

echo 'setxkbmap -option ctrl:nocaps' >> ~/.config/xfce4/xinitrc

Method 2: Xmodmap Configuration

Create a ~/.Xmodmap file with:

remove Lock = Caps_Lock
keysym Caps_Lock = Control_L
add Control = Control_L

Then load it with:

xmodmap ~/.Xmodmap

Method 3: Creating a Custom XKB Layout

For advanced users who need system-wide changes:

sudo nano /usr/share/X11/xkb/symbols/ctrl

Add or modify the following section:

partial modifier_keys
xkb_symbols "nocaps" {
    replace key  { [ Control_L, Control_L ] };
    modifier_map Control { ,  };
};

If changes don't persist after reboot:

  • Check if other applications (like input method frameworks) are overriding your settings
  • Verify that no conflicting settings exist in ~/.config/xfce4/xfconf/xfce-perchannel-xml/keyboard-layout.xml
  • Test with xev to see actual keycodes being sent

For keyboard firmware that supports QMK or similar:

/* In your keymap.c */
case KC_CAPS:
    return KC_LCTL;