Bug 452445 - per-application keyboard layout not persisting
Summary: per-application keyboard layout not persisting
Status: REPORTED
Alias: None
Product: systemsettings
Classification: Applications
Component: kcm_keyboard (show other bugs)
Version: 5.24.3
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-04-09 20:43 UTC by David
Modified: 2024-03-01 14:34 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
layout_config (96.67 KB, image/png)
2022-04-11 19:09 UTC, David
Details
Presentation of bug 452445 (923.54 KB, video/mp4)
2022-11-19 20:35 UTC, Andreas Korb
Details
Keyboard layout settings (99.24 KB, image/png)
2022-11-20 09:58 UTC, Andreas Korb
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David 2022-04-09 20:43:08 UTC
SUMMARY
Flatpak apps do not seem to remember their layout when using a per-application layout switch policy.

STEPS TO REPRODUCE
1. Go to System Settings -> Input Devices -> Layouts.
2. If there are no additional layouts added, add some layout there so that there would be at least 2 layouts in the system.
3. Set the switching policy to "Application".
4. Install some flatpak GUI app (such as "Tauon Music Box") and launch it.
5. Switch the layout in the flatpak application.
6. Close the application, restart the computer, launch the app again.

OBSERVED RESULT
Has the default layout instead of the layout that was being used for it the last time.

EXPECTED RESULT
Should remember the layout that it last had in the same way as non-flatpak apps do.

SOFTWARE/OS VERSIONS
Operating System: Debian GNU/Linux
KDE Plasma Version: 5.24.3
KDE Frameworks Version: 5.90.0
Qt Version: 5.15.2
Kernel Version: 5.16.0-5-amd64 (64-bit)
Graphics Platform: X11
Processors: 16 × AMD Ryzen 7 2700 Eight-Core Processor
Memory: 15.6 GiB of RAM
Graphics Processor: AMD VEGA10
Comment 1 Nate Graham 2022-04-11 18:26:46 UTC
> System Settings -> Input Devices -> Layouts
Can you attach a screenshots of the "Layouts" page? I don't have that on my system and I'm not familiar with what it is.
Comment 2 David 2022-04-11 19:09:37 UTC
Created attachment 148107 [details]
layout_config

Attached a screenshot of my layout config.
Comment 3 Nate Graham 2022-04-11 19:22:00 UTC
Aha, *keyboard* layouts. That was the missing part. :)
Comment 4 Aleix Pol 2022-04-11 20:00:46 UTC
I wouldn't say this is a bug in the portal, might be a feature entirely for xdg-desktop-portal, but I don't think there's much to do from the -kde side.

In order to address it, it would be useful to understand why an application would want to switch keyboard layouts.
Comment 5 David 2022-04-11 20:02:02 UTC
(In reply to Aleix Pol from comment #4)
> I wouldn't say this is a bug in the portal, might be a feature entirely for
> xdg-desktop-portal, but I don't think there's much to do from the -kde side.
> 
> In order to address it, it would be useful to understand why an application
> would want to switch keyboard layouts.

It's not the application that switches layout, it's me switching it manually.
Comment 6 Aleix Pol 2022-04-19 23:07:32 UTC
I probably am not understanding what the issue is then.

Does this mean it happens on every app?

> 5. Switch the layout in the flatpak application.

What does this mean exactly? That you change the layout only for the app specifically?
Comment 7 Harald Sitter 2022-04-20 12:14:28 UTC
Are you absolutely certain this works for non-flatpak apps? I can reproduce the problem but it affects all apps and indeed glancing at the code we don't understand why this would only affect flatpak apps.
Comment 8 David 2022-04-20 15:35:32 UTC
(In reply to Aleix Pol from comment #6)
> I probably am not understanding what the issue is then.
> 
> Does this mean it happens on every app?
> 
> > 5. Switch the layout in the flatpak application.
> 
> What does this mean exactly? That you change the layout only for the app
> specifically?

The issue happens only in flatpak apps.

What I mean by "switching layout for the app" is that I have the keyboard layout policy configured to be for each app (i.e. changing the layout in one app does not change the layout in other apps), and the way I change the keyboard layout for an app is either by pressing the assigned global keyboard shortcut, or by clicking on the language icon in the system tray.

And yes, it does work correctly for non-flatpak apps, both QT and GTK.
Comment 9 Harald Sitter 2022-04-20 19:43:11 UTC
Alright, we'll need a much more detailed guide to reproduce this.

I've just
- installed KDE neon user edition
- set the switching policy to application
- set up `us` and `at` layouts
- opened kwrite
- switched to `at` via the system tray icon
- opened gwenview and saw it switch back to `us`
- going back to kwrite automatically switched to `at`
- closed both kwrite and gwenview
- rebooted the system
- opened kwrite and found it using `us` rather than the expected `at` layout

For all intents and purposes this doesn't seem to be working regardless of sandboxing, and indeed the code supports this, flatpak or not makes no difference.
Comment 10 David 2022-04-23 15:03:12 UTC
(In reply to Harald Sitter from comment #9)
> Alright, we'll need a much more detailed guide to reproduce this.
> 
> I've just
> - installed KDE neon user edition
> - set the switching policy to application
> - set up `us` and `at` layouts
> - opened kwrite
> - switched to `at` via the system tray icon
> - opened gwenview and saw it switch back to `us`
> - going back to kwrite automatically switched to `at`
> - closed both kwrite and gwenview
> - rebooted the system
> - opened kwrite and found it using `us` rather than the expected `at` layout
> 
> For all intents and purposes this doesn't seem to be working regardless of
> sandboxing, and indeed the code supports this, flatpak or not makes no
> difference.

In my setup (debian testing), at that last point, the app would open with the last layout it had before closing it. Not sure which other setting I might have that could change such behavior.
Comment 11 Harald Sitter 2022-04-23 19:48:51 UTC
Please try to reproduce this in a clean environment. This will be impossible to debug if we can't reproduce it on a dev system.
Comment 12 David 2022-04-24 15:39:07 UTC
(In reply to Harald Sitter from comment #11)
> Please try to reproduce this in a clean environment. This will be impossible
> to debug if we can't reproduce it on a dev system.

Did some more testing and turns out the keyboard layout is actually not remembered for all native apps either - I tried kate and it always starts with the default layout for example, but it does work correctly (layout is remembered) for other apps, such as JuK.
Comment 13 Andrey 2022-04-25 18:59:23 UTC
I didn't try how it works on X11 but it also makes sense to check it for Wayland, maybe in separate report.
IIRC the layout is only saved there for apps instantiating itself (e.g opening a new window in Konsole).
So if Telegram is closed to tray, no layout restoration takes place on reopening.
That might be more attractive point to apply the efforts.
Comment 14 David 2022-05-20 18:23:03 UTC
Somehow, things are now working correctly in KDE 5.24.5 from debian sid. Layout is now remembered for flatpak-installed Tauon Music Box at least.
Comment 15 Andreas Korb 2022-11-19 20:35:48 UTC
Created attachment 153884 [details]
Presentation of bug 452445

This continues to happen for me for all applications under Wayland. I just tried it in a freshly installed KDE Neon VM (neon-user-20221117-0714.iso, KDE 5.26.3) and could reproduce it there as well.

On my host machine (manjaro, KDE 5.26.3) I recorded a video to show the problem. As you can see, the system does not remember that I previously set the keyboard layout to US and starts with the default DE layout.
Comment 16 Andrey 2022-11-19 20:47:08 UTC
Andreas, that's because if an application closed it won't be treated as the same application when it run again.
I don't know how to solve this.

If you open a new window from existing application, the layout will be preserved there.
Comment 17 Andreas Korb 2022-11-19 21:06:57 UTC
(In reply to Andrey from comment #16)
> Andreas, that's because if an application closed it won't be treated as the
> same application when it run again.
> I don't know how to solve this.
> 
> If you open a new window from existing application, the layout will be
> preserved there.

First of all, thank a lot for you blazingly fast response!
For X11 it works as I would expect. I guess the X11 subsystem handled this then separately somehow? (I don't know much about the inner systems here)

Maybe another point is interesting. In my attached video, if you look at the keyboard layout indicator when I open Konsole the second time and type the first 'z' (at around 00:11), the indicator jumps like it updates something, but stays at the default layout.
Comment 18 David 2022-11-20 09:34:22 UTC
(In reply to Andrey from comment #16)
> Andreas, that's because if an application closed it won't be treated as the
> same application when it run again.
> I don't know how to solve this.
> 
> If you open a new window from existing application, the layout will be
> preserved there.

For the most part, applications do remember the layout after closing them and launching them again.
Comment 19 Andreas Korb 2022-11-20 09:41:01 UTC
(In reply to David from comment #18)
> (In reply to Andrey from comment #16)
> > Andreas, that's because if an application closed it won't be treated as the
> > same application when it run again.
> > I don't know how to solve this.
> > 
> > If you open a new window from existing application, the layout will be
> > preserved there.
> 
> For the most part, applications do remember the layout after closing them
> and launching them again.

I didn't find one yet where it works. Could you give me a specific example of an application where it works?
Comment 20 David 2022-11-20 09:43:10 UTC
(In reply to Andreas Korb from comment #19)
> (In reply to David from comment #18)
> > (In reply to Andrey from comment #16)
> > > Andreas, that's because if an application closed it won't be treated as the
> > > same application when it run again.
> > > I don't know how to solve this.
> > > 
> > > If you open a new window from existing application, the layout will be
> > > preserved there.
> > 
> > For the most part, applications do remember the layout after closing them
> > and launching them again.
> 
> I didn't find one yet where it works. Could you give me a specific example
> of an application where it works?

Kate, notepadqq, gedit, JuK, among many others.
Comment 21 Andreas Korb 2022-11-20 09:53:37 UTC
(In reply to David from comment #20)
> (In reply to Andreas Korb from comment #19)
> > (In reply to David from comment #18)
> > > (In reply to Andrey from comment #16)
> > > > Andreas, that's because if an application closed it won't be treated as the
> > > > same application when it run again.
> > > > I don't know how to solve this.
> > > > 
> > > > If you open a new window from existing application, the layout will be
> > > > preserved there.
> > > 
> > > For the most part, applications do remember the layout after closing them
> > > and launching them again.
> > 
> > I didn't find one yet where it works. Could you give me a specific example
> > of an application where it works?
> 
> Kate, notepadqq, gedit, JuK, among many others.

I just tried Kate and notepadqq on the latest KDE Neon and both don't remember the keyboard layout after restarting the application. Not sure what I'm doing wrong.
Comment 22 David 2022-11-20 09:55:32 UTC
(In reply to Andreas Korb from comment #21)
> (In reply to David from comment #20)
> > (In reply to Andreas Korb from comment #19)
> > > (In reply to David from comment #18)
> > > > (In reply to Andrey from comment #16)
> > > > > Andreas, that's because if an application closed it won't be treated as the
> > > > > same application when it run again.
> > > > > I don't know how to solve this.
> > > > > 
> > > > > If you open a new window from existing application, the layout will be
> > > > > preserved there.
> > > > 
> > > > For the most part, applications do remember the layout after closing them
> > > > and launching them again.
> > > 
> > > I didn't find one yet where it works. Could you give me a specific example
> > > of an application where it works?
> > 
> > Kate, notepadqq, gedit, JuK, among many others.
> 
> I just tried Kate and notepadqq on the latest KDE Neon and both don't
> remember the keyboard layout after restarting the application. Not sure what
> I'm doing wrong.

Perhaps you haven't set the layout switching policy to "application"? (Settings -> Input devices -> Keyboard -> Layouts -> Switching policy).
Comment 23 Andreas Korb 2022-11-20 09:58:47 UTC
Created attachment 153898 [details]
Keyboard layout settings

(In reply to David from comment #22)
> (In reply to Andreas Korb from comment #21)
> 
> Perhaps you haven't set the layout switching policy to "application"?
> (Settings -> Input devices -> Keyboard -> Layouts -> Switching policy).

I think I have (see attachment)
Comment 24 Andreas Korb 2024-03-01 13:58:04 UTC
This appears to still be a issue in KDE 6, unfortunately. Is there any plan for this issue?
Otherwise, I'm actually willing to implement this myself, as it is the only thing that hinders me of fully switching to Wayland. Then, I'd appreciate some pointers, e.g., why it worked under X11 but doesn't under Wayland as of now, and which code areas are relevant. Thanks!
Comment 25 Andrey 2024-03-01 14:34:53 UTC
Andreas, X11 and Wayland have completely different codepaths there:
it's kded for X11 and kwin for Wayland.

You have to dig into how layout saving works for apps in kwin.
Ask if you need help, thanks.