Bug 450342

Summary: Launching some gtk3 apps on wayland causes error
Product: [Plasma] kwin Reporter: Marko Gobin <gobonja>
Component: effects-overviewAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: kde, nate, nicolas.fella
Priority: NOR    
Version: 5.24.1   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 5.92
Attachments: error

Description Marko Gobin 2022-02-15 20:40:22 UTC
Created attachment 146792 [details]
error

SUMMARY
When launching some gtk3 apps on wayland error pops out. When launching with overview X11 or when launching with krunner on wayland there is no error.

STEPS TO REPRODUCE
1. Login with Wayland session
2. Launch app using overview effect (gnome calendar, gnome disks, tilix, pamac, cockpit client (flatpak))

OBSERVED RESULT
App launches with notification containing error: org.freedesktop.DBus.Error.UnknownMethod 

EXPECTED RESULT
App launches without error.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch
KDE Plasma Version: 5.24.1
KDE Frameworks Version: 5.91
Qt Version: 5.15.2

ADDITIONAL INFORMATION
Might be regression with https://bugs.kde.org/show_bug.cgi?id=450000
Comment 1 Nicolas Fella 2022-02-15 21:02:19 UTC
This is most likely related to the DBus-activation support in KIO::ApplicationLauncherJob

However kstart5 --application org.gnome.Calendar works fine, so it seems somewhat kwin-specific
Comment 2 Nicolas Fella 2022-02-15 21:36:33 UTC
QDBusError("org.freedesktop.DBus.Error.UnknownMethod", "Method \"Activate\" with signature \"a{sv}\" on interface \"org.freedesktop.Application\" doesn't exist\n")

Happens only when called from kwin_wayland indeed
Comment 3 Nicolas Fella 2022-02-15 21:41:45 UTC
It looks like "Activate" is called twice:

QDBusMessage(type=MethodCall, service="", path="/", interface="org.freedesktop.Application", member="Activate", signature="", contents=() )
QDBusMessage(type=MethodCall, service="org.gnome.Calendar", path="/org/gnome/Calendar", interface="org.freedesktop.Application", member="Activate", signature="", contents=() )


when using kstart5 it's only once:
QDBusMessage(type=MethodCall, service="org.gnome.Calendar", path="/org/gnome/Calendar", interface="org.freedesktop.Application", member="Activate", signature="", contents=() )
Comment 4 Nicolas Fella 2022-02-15 22:10:45 UTC
Oh this is a fun one. Here's what happens:

- Kwin/overview use KIO::ApplicationLauncherJob to launch the app
- ApplicationLauncherJob finds that the target supports DBus activation
- ApplicationLauncherJob notices we are on Wayland and requests an XDG activation token: https://invent.kde.org/frameworks/kio/-/blob/master/src/gui/kprocessrunner.cpp#L313. It connects the token arriving to launching the app
- Further down it sets which app should be launched: https://invent.kde.org/frameworks/kio/-/blob/master/src/gui/kprocessrunner.cpp#L320
- Further down it starts the app when we are not waiting for a token: https://invent.kde.org/frameworks/kio/-/blob/master/src/gui/kprocessrunner.cpp#L343

So far so good. So why does it fail only in kwin_wayland? Usually the token arrives asynchronously, so the app is already set and it launches fine. However, in KWindowSystem::requestXdgActivationToken there is a check for KWindowSystemPrivateV2, and if that fails it directly emits xdgActivationTokenArrived: https://invent.kde.org/frameworks/kwindowsystem/-/blob/master/src/kwindowsystem.cpp#L819

This makes the token arrival no longer async and all the slots are triggered directly (since it's not a queued connection), which leads to the app being launched before m_service is set. boom
Comment 5 Nicolas Fella 2022-02-15 22:21:20 UTC
And why does the check fail? because kwin has its own kwindowsystem plugin that doesn't implement V2 of the interface
Comment 6 Bug Janitor Service 2022-02-15 22:34:36 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kwindowsystem/-/merge_requests/49
Comment 7 Nicolas Fella 2022-02-15 22:35:57 UTC
Another obvious fix would be to implement V2 of the interface in kwin, but not sure whether having a correct activation token is even important here
Comment 8 Nicolas Fella 2022-02-15 22:42:39 UTC
I think it is relevant for activating running instances of single-window apps from the overview?
Comment 9 Nicolas Fella 2022-02-16 12:44:17 UTC
Git commit 8d580e2fa466fdb47a82a19f42ba78424f424c41 by Nicolas Fella.
Committed on 15/02/2022 at 22:30.
Pushed by nicolasfella into branch 'master'.

Ensure that xdgActivationTokenArrived is always emitted asynchronously

Otherwise consumers that expect it to be async break

M  +6    -1    src/kwindowsystem.cpp

https://invent.kde.org/frameworks/kwindowsystem/commit/8d580e2fa466fdb47a82a19f42ba78424f424c41