Bug 466252

Summary: Kirigami.Settings.tabletMode & Kirigami.InputMethod not working in Flatpak
Product: [Plasma] xdg-desktop-portal-kde Reporter: Plata <plata.hill>
Component: generalAssignee: Plasma Bugs List <plasma-bugs>
Status: CONFIRMED ---    
Severity: normal CC: aleixpol, jgrulich, kde, nate, notmart, sitter, tim
Priority: NOR    
Version: 5.27.0   
Target Milestone: ---   
Platform: Other   
OS: Other   
Latest Commit: Version Fixed In:

Description Plata 2023-02-22 17:47:21 UTC
For example, QMLKonsole uses Settings.tabletMode to determine if the key toolbar is shown. This doesn't work in Flatpak which makes the application unusable.
Comment 1 Nate Graham 2023-02-24 19:18:14 UTC
Probably need to export it in the portal settings.
Comment 2 Plata 2023-02-26 11:01:43 UTC
Makes sense. What's the way forward to trigger this? I guess it should be aligned with Gnome etc as well?
Comment 3 Harald Sitter 2023-02-28 11:59:03 UTC
Huh. This is a bit complicated.

So tablet mode (or as we call it in the GUI: touch mode) is ultimately controlled by kwin and currently kirigami talks directly to kwin. The easy fix is to have relevant apps talk-name=org.kde.KWin but that is a bit questionable from a security POV what with kwin being the wayland compositor.

The reasonable, albeit more invasive, fix is to restructure how things work. The settings portal should talk to Kwin and abstract the tabletmode setting. Kirigami should then talk to the portal rather than kwin. Flatpak apps equally talk to the portal. IOW: everything needs to talk to the portal and the portal talks to kwin.
Comment 4 Harald Sitter 2023-02-28 13:47:44 UTC
As it turns out this also affects Kirigami.InputMethod which is backed by kwin also. Both those interfaces need exposing through the settings portal.
Comment 5 Harald Sitter 2023-03-01 13:15:39 UTC
*Sigh* this looked easy but alas, it's not.

TabletMode we could make work through the settings portal.

InputMethod on the other hand needs to write to properties, to activate a virtual keyboard for example, and the settings portal doesn't support writing settings.

That leaves us with a bunch of not so lovely options:

a) make a virtualkeyboard portal (that may be the smartest thing long term?)
b) let apps talk to kwin (seems silly from a security POV)
c) add a supplemental portal that proxies between kwin and the flatpak so as to reduce exposure of kwin interfaces (i.e. talk=org.kde.VirtualKeyboard rather than talk=org.kde.KWin -- with the former playing proxy to kwin)
d) add a proprietary write function to our settings portal (kinda crap because then the flatpak needs to talk to our portal impl directly, again raising concerns over security and breaking abstraction)
Comment 6 Timothée Ravier 2023-03-01 13:19:57 UTC
Agree that A & C look like a better design but require more work.
Comment 7 Timothée Ravier 2023-03-01 13:21:10 UTC
If `talk-name=org.kde.KWin` works as a workaround right now then it's not ideal (Kwin/KDE session only) but could be a temporary workaround.

Which apps are impacted?
Comment 8 Harald Sitter 2023-03-01 13:27:12 UTC
TabletMode impacts all kirigami apps (it adjusts the UI to be more friendly for touch inputs)

VirtualKeyboard appears only used in plasma-* right now.
Comment 9 David Edmundson 2023-03-01 13:57:04 UTC
>InputMethod on the other hand needs to write to properties, to activate a virtual keyboard for example, and the settings portal doesn't support writing settings.

It's exposed, but is it used?

I know Inputmethod.willShowOnActive is used but that is read only. Worth checking if this is a non-issue before starting too much.
Comment 10 Harald Sitter 2023-03-01 14:41:23 UTC
Not used from what I can find. But we do expose the API in Kirigami, so...

option e) retract mutability of InputMethod.enabled and InputMethod.active in Kirigami for KF6 and use Settings portal for reading all settings
Comment 11 Bug Janitor Service 2023-03-01 14:58:24 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kirigami/-/merge_requests/982
Comment 12 Bug Janitor Service 2023-03-01 15:29:40 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kirigami/-/merge_requests/983
Comment 14 Harald Sitter 2023-03-06 11:45:18 UTC
Git commit 27da4afe3488a222a6e4a56787abb440515d081b by Harald Sitter.
Committed on 06/03/2023 at 09:44.
Pushed by sitter into branch 'master'.

make InputMethod immutable

previously enabled and active were writable properties which complicated
abstraction inside application sandboxes. to solve this problem we no
longer consider them writable in KF6 and consider their writability
deprecated in KF5.

active is controllable through Qt's IM API and enabled shouldn't really
be touched by random applications anyway

this then allows us to eventually back them using the XDG Settings
portal instead of talking to KWin directly.

M  +0    -20   src/inputmethod.cpp
M  +2    -4    src/inputmethod.h
M  +0    -30   src/libkirigami/virtualkeyboardwatcher.cpp
M  +2    -4    src/libkirigami/virtualkeyboardwatcher.h

Comment 15 Aleix Pol 2023-03-08 16:32:01 UTC
Git commit 5d9499250a2c8bc9b716efdbd7c956f5043e45ca by Aleix Pol Gonzalez, on behalf of Harald Sitter.
Committed on 08/03/2023 at 16:07.
Pushed by sitter into branch 'master'.

implement settings for org.kde.TabletMode and .VirtualKeyboard

they each reflect a part of settings that reside in kwin

M  +3    -0    src/CMakeLists.txt
A  +18   -0    src/org.kde.KWin.TabletModeManager.xml
A  +30   -0    src/org.kde.KWin.VirtualKeyboard.xml
M  +128  -0    src/settings.cpp

Comment 16 Harald Sitter 2023-03-17 13:24:12 UTC
Git commit 560d71422bbe563454859895c42e5090c7d5bd23 by Harald Sitter.
Committed on 17/03/2023 at 12:58.
Pushed by sitter into branch 'master'.

move from kwin API to portal API

instead of directly talking to org.kde.KWin talk to
org.freedesktop.portal.Desktop's Settings interface. This allows us to
abstract the actual implementation of those interfaces, and more
importantly allows us to not have all kirigami apps talk to our wayland
compositor and get access to literally all its dbus functionality

M  +2    -2    src/libkirigami/CMakeLists.txt
A  +18   -0    src/libkirigami/dbustypes.h     [License: LGPL(v2.0+)]
A  +27   -0    src/libkirigami/org.freedesktop.portal.Settings.xml
D  +0    -13   src/libkirigami/org.kde.KWin.TabletModeManager.xml
D  +0    -45   src/libkirigami/org.kde.KWin.VirtualKeyboard.xml
M  +25   -24   src/libkirigami/tabletmodewatcher.cpp
M  +55   -66   src/libkirigami/virtualkeyboardwatcher.cpp