11

Before Fedora switched to Wayland I used this .Xmodmap file to use my CapsLock Key to reach German Umlauts:

keycode 66 = Mode_switch Multi_key
keycode 20 = minus underscore ssharp
keycode 34 = bracketleft braceleft udiaeresis Udiaeresis
keycode 47 = semicolon colon odiaeresis Odiaeresis
keycode 48 = apostrophe quotedbl adiaeresis Adiaeresis

On Wayland this does not work any more - CapsLock would just work as before.

Is there a way to achieve the same result in Wayland, too?

frans
  • 1,057
  • 2
  • 14
  • 27

4 Answers4

12

For gnome you can use

gsettings set org.gnome.desktop.input-sources xkb-options "['caps:ctrl_modifier']"

While the preferred way for X is now

setxkbmap -option caps:ctrl_modifier

instead of xmodmap i believe. See this bugreport

anon
  • 121
  • 3
  • 10
    Where do you find the list of codes? ie How did you know the code was ctrl_modifier? – Aaron Skomra Jun 27 '17 at 22:26
  • 4
    This doesn't seem to work on Wayland/Sway – djsumdog Feb 19 '18 at 05:45
  • 1
    @djsumdog, the trick anon gave for wayland is gnome-shell specific. sway would have to implement their own version of this setting. alot of features that were handled by X11 will have to be handled by the window manager from now on. – thebunnyrules Feb 22 '18 at 06:30
  • gsettings worked for my Arch Linux 2019.02.01, but, setxkbmap solution not working. – zw963 Feb 26 '19 at 14:17
  • 1
    `gsettings` work for me on Ubuntu on Wayland 20.04 and persisted after reboot. – Boris Verkhovskiy Oct 07 '20 at 03:16
  • 2
    @AaronSkomra `localectl list-x11-keymap-options | cat`. [Source](https://gist.github.com/lboulard/335822a9355f3d122191c2a99e516855#list-all-xlb-options) – Rafael Eyng Dec 26 '22 at 15:29
  • 1
    @Aaron Skomra `cat /usr/share/X11/xkb/rules/base.lst` – robertspierre Dec 31 '22 at 03:34
  • This disabled the Caps Lock key, but I want to use a key combination for toggling Caps Lock mode. Can I do that? In the Settings -> Keyboard -> View and Customise Shortcuts -> Custom Shortcuts -> Add Shortcut, what "Command" should I use to toggle Caps Lock mode? – Damn Vegetables Feb 06 '23 at 09:08
3

For completeness: Under KWin/KDE you can remap Caps-Lock (and a few other control keys) quite flexibly using System settingsInput DevicesKeyboardAdvanced.

In particular you can set the Key to choose the 3rd level to Caps Lock to achieve your particular configuration.

– Much better than using Alt Gr when programming and losing Caps Lock in return is not really a loss at all.

Destroy666
  • 5,299
  • 7
  • 16
  • 35
ntninja
  • 348
  • 3
  • 6
1

For sway you can use:

export XKB_DEFAULT_OPTIONS=caps:escape

before running:

sway

reference https://github.com/swaywm/sway/wiki

0

Here is a script which change Capslock to Ctrl, and change rightAlt to Capslock for GNOME + Wayland for Arch linux.

https://gist.github.com/zw963/e8156358b2029c4f5a6f0d57fb9f6143

Script contents is:


#! /bin/bash

if ! fgrep -qs 'ctrl:new_ctrl  =   +new_ctrl(new_ctrl)' /usr/share/X11/xkb/rules/evdev; then
    sudo sed -i.bak '/ctrl:nocaps[[:blank:]]*=[[:blank:]]*+ctrl(nocaps)/a\
  ctrl:new_ctrl  =   +new_ctrl(new_ctrl)
' /usr/share/X11/xkb/rules/evdev
fi

cat <<'HEREDOC' |sudo tee /usr/share/X11/xkb/symbols/new_ctrl
partial modifier_keys
xkb_symbols "new_ctrl" {
    replace key <CAPS> { [ Control_L ] };
    modifier_map Control { <CAPS>, <LCTL> };
    replace key <RALT> { [ Caps_Lock ] };
    modifier_map Lock { <RALT> };
};
HEREDOC

gsettings set org.gnome.desktop.input-sources xkb-options "['ctrl:new_ctrl']"

# for to disable this run
# gsettings reset org.gnome.desktop.input-sources xkb-options
Rohit Gupta
  • 2,721
  • 18
  • 27
  • 35
zw963
  • 101
  • 3