Bug 412101

Summary: Wayland session does not remember the last used keyboard layout. The first keyboard layout listed in "layouts" tab of the "Keyboard" kcm is always used after login instead.
Product: [Plasma] kwin Reporter: Patrick Silva <bugseforuns>
Component: wayland-genericAssignee: Andrey <butirsky>
Status: REOPENED ---    
Severity: normal CC: arysin, aspotashev, butirsky, dev, kde, nate
Priority: NOR    
Version: 5.17.90   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
URL: https://invent.kde.org/plasma/kwin/-/merge_requests/38
See Also: https://bugs.kde.org/show_bug.cgi?id=425343
https://bugs.kde.org/show_bug.cgi?id=442804
Latest Commit: Version Fixed In: 5.20
Sentry Crash Report:
Bug Depends on: 420077    
Bug Blocks:    
Attachments: screenshot

Description Patrick Silva 2019-09-20 01:54:48 UTC
SUMMARY
I added pt-br and US keyboard layouts in Keyboard KCM.
If the active keyboad layout before logout is pt-br, Plasma
always changes it to US when I start a new Wayland session.

STEPS TO REPRODUCE
1. add US and pt-br keyboard layouts in Keyboard KCM
2. use the keyboard layout icon in systray to activate the pt-br layout
3. restart Wayland session

OBSERVED RESULT
after relogin, active keyboard layout is US


EXPECTED RESULT
active keyboard layout should be the same as before logout (pt-br in this case)

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 5.16.90
KDE Frameworks Version: 5.62.0
Qt Version: 5.13.1
Comment 1 Patrick Silva 2019-10-17 15:52:59 UTC
Wayland session always uses the first keyboard layout listed in "layouts" tab of the "Keyboard" kcm.

Operating System: Arch Linux 
KDE Plasma Version: 5.17.0
KDE Frameworks Version: 5.63.0
Qt Version: 5.13.1
Comment 2 Andrey 2020-05-22 18:22:47 UTC
KeyboardDaemon seems to be depended on X11 rather closely:
https://invent.kde.org/plasma/plasma-desktop/-/blob/master/kcms/keyboard/keyboard_daemon.cpp#L54
That is why layout saving doesn't work on Wayland, as well as country flag indicator, etc.

So we need either "untie" it from X11 somehow or re-implement/move parts of it in KWin.
Comment 4 Andrey 2020-07-01 21:49:42 UTC
The feature was not implemented so it's not related with 423039 bug. Removing.
Comment 5 Andrey 2020-07-20 11:05:26 UTC
Please test and report as it's still might be a problems
Comment 6 Patrick Silva 2020-07-22 12:17:03 UTC
This issue persists.

Operating System: KDE neon Unstable Edition
KDE Plasma Version: 5.19.80
KDE Frameworks Version: 5.73.0
Qt Version: 5.14.2
Comment 7 David Edmundson 2020-07-22 12:23:39 UTC
Note that for some reason (see the merge request) this only saves if session restore is on.

I would welcome feedback on that.
Comment 8 Patrick Silva 2020-07-22 13:09:36 UTC
I have enabled session restore, switched to the second keyboard layout listed in "Layouts" tab of Keyboard kcm, rebooted (currently logout fails because a supposedly fixed kwin_wayland crash - bug 420077 - that persists).
The kayboard layout activated before reboot was not remembered.
Comment 9 Andrey 2020-07-22 13:53:54 UTC
Hi Patrick, thanks for testing.
For now you probably need to compile Plasma yourself or try some sort of unstable Plasma distribution (for example, Neon).
Please note "Version Fixed In: 5.20" above.

If you already did it, let's try together to make it work for you.
Comment 10 Patrick Silva 2020-07-22 14:06:10 UTC
as you can read in comment 6, I'm using neon unstable.
Comment 11 Andrey 2020-07-22 15:17:53 UTC
Still, it has KDE Plasma Version:5.19.80 instead of needed 5.20, isn't it?
Comment 12 David Edmundson 2020-07-22 15:49:20 UTC
5.19.80 is git master
Comment 13 Andrey 2020-07-22 20:21:59 UTC
I'm not an expert in Neon but perhaps it doesn't build immediately on every commit.
What I can see is the current unstable version named neon-unstable-20200719-1102.iso and the patch was merged Jul 20'th https://invent.kde.org/plasma/kwin/-/merge_requests/38#note_76678, might it be the reason?
Comment 14 Patrick Silva 2020-07-27 11:37:58 UTC
(In reply to Andrey from comment #13)
> I'm not an expert in Neon but perhaps it doesn't build immediately on every
> commit.
> What I can see is the current unstable version named
> neon-unstable-20200719-1102.iso and the patch was merged Jul 20'th
> https://invent.kde.org/plasma/kwin/-/merge_requests/38#note_76678, might it
> be the reason?

kwin_wayland package was updated 3 times on my neon unstable installed on hard disk since my previous comment. This bug persists. :(
Comment 15 Andrey 2020-07-27 12:32:12 UTC
I think we still need to find a way to make sure the patch is there.
After that I'll try Neon myself, so let me know if you find it first.
Thanks for helping.
Comment 17 Andrey 2020-07-27 18:48:28 UTC
(In reply to Patrick Silva from comment #8)
> I have enabled session restore, switched to the second keyboard layout
> listed in "Layouts" tab of Keyboard kcm, rebooted (currently logout fails
> because a supposedly fixed kwin_wayland crash - bug 420077 - that persists).

Looking at the code seems like that crash might be the reason.
I could provide workaround, but proper fix would be eliminating the crash.
I suspect even when you reboot, that crash occurs, so kwin just can't be in time to save the layout.
Could we somehow terminate session without the crash?
Comment 18 Patrick Silva 2020-07-27 18:57:36 UTC
(In reply to Andrey from comment #17)
> (In reply to Patrick Silva from comment #8)
> > I have enabled session restore, switched to the second keyboard layout
> > listed in "Layouts" tab of Keyboard kcm, rebooted (currently logout fails
> > because a supposedly fixed kwin_wayland crash - bug 420077 - that persists).
> 
> Looking at the code seems like that crash might be the reason.
> I could provide workaround, but proper fix would be eliminating the crash.
> I suspect even when you reboot, that crash occurs, so kwin just can't be in
> time to save the layout.
> Could we somehow terminate session without the crash?

Can you reproduce the kwin_wayland crash on logout?
Comment 19 Andrey 2020-07-27 20:38:00 UTC
(In reply to Patrick Silva from comment #18)
> Can you reproduce the kwin_wayland crash on logout?
Yes, I reported it here: https://bugs.kde.org/show_bug.cgi?id=420077#c5
Comment 20 Andrey 2020-08-06 12:36:47 UTC
Since the crash bug  420077 we depend on is fixed now I'm closing this, feel free to reopen in case of any problems.
If testing on Neon, make sure the relevant commit is built in: https://build.neon.kde.org/view/3%20unstable%20%E2%98%A3%20git%20master/job/bionic_unstable_kde_kwin/changes
Comment 21 Andrey 2020-08-10 19:46:42 UTC
Hi Patrick, have you been able to test it since then?
Your feedback is welcomed :)
Comment 22 Patrick Silva 2020-08-11 13:36:47 UTC
Hi Andrey
Finally the annoying kwin_wayland crash on logout is fixed. \o/
Thank you.

However, the issue reported here is not completely fixed.
After I restart Wayland session, keyboard layout applet in system tray
indicates that the first keyboard layout listed in Keyboard kcm is in use.
Then I press any key and OSD appears on the screen to indicate that the keyboard layout changed to the one activated before logout.

Operating System: KDE neon Unstable Edition
KDE Plasma Version: 5.19.80
KDE Frameworks Version: 5.74.0
Qt Version: 5.14.2
Comment 23 Andrey 2020-08-11 15:23:28 UTC
Thanks for your feedback Patrick!
Could you clarify what keyboard layout applet you are talking about? It would be fine to take a screenshot, if possible.
The one showing layout in system tray on Wayland currently uses IBus and unrelated with the way layout handled in kwin (XKB).
So when you on X11 you probably see another layout applet in action.
That is the separate issue which needs to be dealing with.

PS: if possible, please also test the case with Application Policy for keyboard layouts - it might be some quirks there.
Comment 24 Patrick Silva 2020-08-11 15:45:59 UTC
Created attachment 130784 [details]
screenshot

I'm attaching a screenshot showing the keyboard layout applet.
Application policy is also not working. I activate the second layout and Plasma reverts to the first one when I press any key.
Comment 25 Andrey 2020-08-11 15:55:32 UTC
That applet should work, I'll see. Thanks.

About Application policy, isn't it the way it works? It remembers layouts for different windows separately, so it won't change in another window until you change it there.
Comment 26 Patrick Silva 2020-08-11 15:57:56 UTC
I open Kate and change the layout via systray applet.
When I start to type in Kate, Plasma reverts to the previous layout.
Comment 27 Andrey 2020-08-12 17:31:26 UTC
Hi Patrick,
I've checked and this actually is not a regression.
Actually it works, you just switched panel layout with the applet, instead of layout of the app.
To switch app's layout with the applet when Application policy is active, we need to prevent focus stealing by panel. It could be achieved by setting Keyboard Layout applet to "Always Shown" in Configure System Tray/Entires tab.
Please, try it yourself and report back :)

About the issue with first layout indication, would you like to file a separate bug? I'll try to fix it if possible.
Comment 28 Patrick Silva 2020-08-12 21:13:44 UTC
(In reply to Andrey from comment #27)
> Hi Patrick,
> I've checked and this actually is not a regression.
> Actually it works, you just switched panel layout with the applet, instead
> of layout of the app.
> To switch app's layout with the applet when Application policy is active, we
> need to prevent focus stealing by panel. It could be achieved by setting
> Keyboard Layout applet to "Always Shown" in Configure System Tray/Entires
> tab.
> Please, try it yourself and report back :)
you are right about yhat. Aplication policy works in the same way on X11.

> About the issue with first layout indication, would you like to file a
> separate bug? I'll try to fix it if possible.
I will open another report later.

Is intentional the fact that keyboard layout is only remembered on Wayland when session restore is enabled?
Comment 29 Andrey 2020-08-12 22:01:27 UTC
Thanks, please include me in CC then.

Yes, it was intentional. Some people agree with it and some not. See MR above for the details.
Comment 30 Andrey 2020-08-14 17:50:29 UTC
(In reply to Patrick Silva from comment #28)
> I will open another report later.
> 
https://bugs.kde.org/show_bug.cgi?id=425343
Feel free to amend or mark as duplicate, as you see appropriate.
Comment 31 Patrick Silva 2020-08-17 16:56:24 UTC
(In reply to Patrick Silva from comment #28)
> (In reply to Andrey from comment #27
> > About the issue with first layout indication, would you like to file a
> > separate bug? I'll try to fix it if possible.
> I will open another report later.

already reported by another user a fev months ago as bug 418699
Comment 32 Andrey 2020-08-17 21:29:41 UTC
(In reply to Patrick Silva from comment #31)
> already reported by another user a fev months ago as bug 418699

That seems another issue to me, but thanks.
Comment 33 Andrey 2020-08-20 16:19:35 UTC
(In reply to Patrick Silva from comment #22)
> However, the issue reported here is not completely fixed.
> After I restart Wayland session, keyboard layout applet in system tray
> indicates that the first keyboard layout listed in Keyboard kcm is in use.

Hi Patrick. It's fixed now in bug 425343. Please test and report back there!
Comment 34 Andrey 2024-04-16 15:12:03 UTC
*** Bug 485635 has been marked as a duplicate of this bug. ***
Comment 35 Andrey 2024-04-16 18:00:58 UTC
*** Bug 485635 has been marked as a duplicate of this bug. ***
Comment 36 Wismill 2024-04-16 18:50:13 UTC
It seems to have regressed. Tested on 6.0.3 and master (see Bug 485635).
Comment 37 Andrey 2024-04-16 19:01:56 UTC
In the ~/.config/kxkbrc file, there should be "LayoutDefault" entry.
Could you check if it's overwritten on the session logout?
Comment 38 Wismill 2024-04-16 19:11:03 UTC
I have a "LayoutDefaultGlobal" entry, but it is not overwritten at logout. It does work if I set it manually though.
Comment 39 Andrey 2024-04-16 19:38:06 UTC
Maybe we have stale KWin process?
Can you make sure there is no kwin and other Plasma processes in the system immediately after logout?

I also saw some bug reports about lost KConfig configuration recently, might be related.
Comment 40 Wismill 2024-04-16 20:43:22 UTC
(In reply to Andrey from comment #39)
> Maybe we have stale KWin process?
> Can you make sure there is no kwin and other Plasma processes in the system
> immediately after logout?
I tried to check this with htop in TTY and could not detect Plasma processes. But this method does not seem reliable if I am not fast enough.