Bug 447206

Summary: kwin_wayland ignores $XDG_CONFIG_HOME/xkb
Product: [Plasma] kwin Reporter: Marc Mezzarobba <marc+bugs>
Component: inputAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: butirsky, nate
Priority: NOR Keywords: wayland
Version: 5.23.4   
Target Milestone: ---   
Platform: Debian unstable   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=432818
Latest Commit: Version Fixed In: 5.27
Sentry Crash Report:

Description Marc Mezzarobba 2021-12-18 20:25:55 UTC
SUMMARY

kwin_wayland supports getting its xkb configuration from the environment variables XKB_DEFAULT_LAYOUT, and libxkbcommon's default include paths include $XDG_CONFIG_HOME/xkb. This should make it possible to load a custom keymap from ~/.config/xkb when launching kwin as a wayland compositor, even though kcm_keyboard only supports keymaps from the system-wide xkb library.

However, on my system, kwin only looks in /usr/share/X11/xkb/ and /etc/xkb when loading the keymap, not in the other standard locations $HOME/.xkb and $XDG_CONFIG_HOME/xkb.

STEPS TO REPRODUCE
1. put a custom keymap "mylayout" in $HOME/.config/xkb
2. create .config/plasma-workspace/env/setkeymap.sh containing
export QT_LOGGING_RULES="kwin_*.debug=true"
export XKB_LOG_VERBOSITY=10
export KWIN_XKB_DEFAULT_KEYMAP=yes
export XKB_DEFAULT_LAYOUT=mylayout
3. launch plasma session

OBSERVED RESULT

The custom keymap is not used. The logs in .local/share/sddm/wayland-session.log confirm that libxkbcommon only searched /usr/share/X11/xkb/ and /etc/xkb.

ADDITIONAL INFORMATION

Possibly related to #388249?

On a single-user machine, a possible workaround is to put one's custom keymaps in /etc/xkb.
Comment 1 Vlad Zahorodnii 2022-01-10 12:00:55 UTC
libxkbcommon doesn't search for keymaps in .config/xkb because it uses secure_getenv. Since kwin_wayland plays with its nice capability, it has its effective capability set, so secure_getenv() won't work.
Comment 2 Bug Janitor Service 2023-01-07 00:56:38 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/3402
Comment 3 Vlad Zahorodnii 2023-01-07 12:26:19 UTC
Git commit 6e87fae7f72416e1108b00c7abdfd438dc713706 by Vlad Zahorodnii, on behalf of Weng Xuetian.
Committed on 07/01/2023 at 11:35.
Pushed by vladz into branch 'master'.

Support XKB_CONTEXT_NO_SECURE_GETENV flag

Since kwin play with CAP_SYS_NICE, secure_getenv will fail for xkbcommon
to load user level xkbmap. This allows kwin to load config under
~/.config/xkb

M  +5    -0    CMakeLists.txt
M  +1    -0    src/config-kwin.h.cmake
M  +7    -1    src/xkb.cpp

https://invent.kde.org/plasma/kwin/commit/6e87fae7f72416e1108b00c7abdfd438dc713706