Bug 476831 - Per application Keyboard Layout not remembered under Wayland
Summary: Per application Keyboard Layout not remembered under Wayland
Status: RESOLVED FIXED
Alias: None
Product: systemsettings
Classification: Applications
Component: kcm_keyboard (other bugs)
Version First Reported In: 5.27.9
Platform: Manjaro Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords: wayland-only
Depends on:
Blocks:
 
Reported: 2023-11-11 09:49 UTC by Silver Salonen
Modified: 2026-10-27 14:43 UTC (History)
11 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 6.8.2
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Silver Salonen 2023-11-11 09:49:03 UTC
SUMMARY
I use "Application" Switching Policy for keyboard layouts. When used under X11, layout mappings for applications were always remembered, even across sessions. Under Wayland they are not remembered, even within the same session.


STEPS TO REPRODUCE
1. Use Wayland session
2. Configure multiple (I use 2) keyboard layouts

OBSERVED RESULT
I always switch to US layout when using Konsole. When closing Konsole and starting it again, it uses my first layout instead.

EXPECTED RESULT
After switching layout for an application and closing the application, re-opening the application should also switch to the layout used last with this application.

SOFTWARE/OS VERSIONS
KDE Plasma Version: 5.27.9
KDE Frameworks Version: 5.111.0
Qt Version: 5.15.11
Comment 1 Andrey 2024-01-12 16:12:32 UTC
This bug might be related with Session management on Wayland which is not quite implemented yet.

*** This bug has been marked as a duplicate of bug 436318 ***
Comment 2 Andrey 2024-01-12 16:15:00 UTC
If it's doubtful this should be handled with the session management, we can reopen the bug.
Comment 3 Silver Salonen 2024-01-13 07:14:30 UTC
I'm not sure what component handles this, but it does not seem to me it's related to session. The use-case I described is done during the same session, not over several sessions.
Although previously, I think per application keyboard layouts indeed were remembered across sessions too.
Comment 4 Tomáš Myšík 2026-07-25 07:02:25 UTC
Seems to be still valid. My versions:

$ pacman -Q plasma-workspace kwayland kwin
plasma-workspace 6.7.3-1
kwayland 6.7.3-1.1
kwin 6.7.3-1.1
Comment 5 Bug Janitor Service 2026-10-18 18:51:38 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/10142
Comment 6 Vlad Zahorodnii 2026-10-27 07:46:14 UTC
Git commit a9b33800ebe5dbd191292addeb87a92772a1e9ae by Vlad Zahorodnii, on behalf of Marián Kadaňka.
Committed on 27/10/2026 at 07:46.
Pushed by vladz into branch 'master'.

keyboard_layout: Keep an application's layout after its last window closes

In System Settings -\> Keyboard -\> Keyboard -\> Configure Switching, "Switching layout affects" is set to "All windows of current application". It works for regular applications, and yet in Yakuake (terminal emulator), every time I switch the layout to English while the Yakuake window is open, then switch to some other application and back to Yakuake, Yakuake gets the system default (Slovak) layout back. It works as expected on X11.

The cause is that ApplicationPolicy keeps layouts by window and drops the entry when the window closes. Yakuake (with "Keep window open when it loses focus" setting off) hides its window when it lose focus, which on Wayland destroys it so every time it is shown again it is a new window and nothing is there to inherit the layout from. The same happens to any application after its last window is closed. On X11 it was handled by kded keyboard module that kept layouts by window class, so it worked.

This change keeps the layout of an application's last window under its desktop file name when the window closes (in m_layoutsRestored) which is already used when an application's first window is activated. Those entries are also saved with the session so the layout also survives logout when the session is restored.

How to test it:

- added integration test testApplicationPolicyLastWindowClosed (closes an application's last window, opens a new one, and checks the layout comes back, also across a session save and restore), it fails on un-patched KWin and pass with this patch
- have at least 2 keyboard layouts set in System Settings, non-English with higher priority, then launch Yakuake, switch to keyboard layout to English, focus another application so Yakuake hides, show Yakuake again - layout stays English
- close some application on English layout, log out and back in, open it again - layout would be English
- running it on Plasma 6.8.0 (KDE Neon)
Related: bug 452445

M  +39   -0    autotests/integration/keyboard_layout_test.cpp
M  +28   -1    src/keyboard_layout_switching.cpp
M  +1    -0    src/keyboard_layout_switching.h

https://invent.kde.org/plasma/kwin/-/commit/a9b33800ebe5dbd191292addeb87a92772a1e9ae
Comment 7 Vlad Zahorodnii 2026-10-27 08:43:22 UTC
Git commit 07db8db46db5a51e8b987a04d416596b548556ec by Vlad Zahorodnii.
Committed on 27/10/2026 at 08:43.
Pushed by vladz into branch 'Plasma/6.8'.

keyboard_layout: Keep an application's layout after its last window closes

In System Settings -\> Keyboard -\> Keyboard -\> Configure Switching, "Switching layout affects" is set to "All windows of current application". It works for regular applications, and yet in Yakuake (terminal emulator), every time I switch the layout to English while the Yakuake window is open, then switch to some other application and back to Yakuake, Yakuake gets the system default (Slovak) layout back. It works as expected on X11.

The cause is that ApplicationPolicy keeps layouts by window and drops the entry when the window closes. Yakuake (with "Keep window open when it loses focus" setting off) hides its window when it lose focus, which on Wayland destroys it so every time it is shown again it is a new window and nothing is there to inherit the layout from. The same happens to any application after its last window is closed. On X11 it was handled by kded keyboard module that kept layouts by window class, so it worked.

This change keeps the layout of an application's last window under its desktop file name when the window closes (in m_layoutsRestored) which is already used when an application's first window is activated. Those entries are also saved with the session so the layout also survives logout when the session is restored.

How to test it:

- added integration test testApplicationPolicyLastWindowClosed (closes an application's last window, opens a new one, and checks the layout comes back, also across a session save and restore), it fails on un-patched KWin and pass with this patch
- have at least 2 keyboard layouts set in System Settings, non-English with higher priority, then launch Yakuake, switch to keyboard layout to English, focus another application so Yakuake hides, show Yakuake again - layout stays English
- close some application on English layout, log out and back in, open it again - layout would be English
- running it on Plasma 6.8.0 (KDE Neon)
Related: bug 452445


(cherry picked from commit a9b33800ebe5dbd191292addeb87a92772a1e9ae)

Co-authored-by: Marián Kadaňka <marian@kadanka.net>

M  +39   -0    autotests/integration/keyboard_layout_test.cpp
M  +28   -1    src/keyboard_layout_switching.cpp
M  +1    -0    src/keyboard_layout_switching.h

https://invent.kde.org/plasma/kwin/-/commit/07db8db46db5a51e8b987a04d416596b548556ec