Bug 408497

Summary: Apps launched with "Run in terminal" not working under Wayland when Konsole is the default terminal emulator
Product: [Frameworks and Libraries] frameworks-kio Reporter: Andrey E. <pseudo-account>
Component: generalAssignee: David Faure <faure>
Status: RESOLVED FIXED    
Severity: normal CC: bugseforuns, johann.hoechtl, kde, kdelibs-bugs, nate, plasma-bugs, wbauer1
Priority: NOR    
Version: 5.67.0   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 5.68.0

Description Andrey E. 2019-06-09 18:12:11 UTC
SUMMARY
Can't run Htop using shortcut in Kicker menu. But I can run Konsole and enter "htop".

STEPS TO REPRODUCE
1. Run KDE Wayland
2. sudo apt install htop
3. Run Htop using shortcut in menu (Kicker or Kickoff)

OBSERVED RESULT
No window

EXPECTED RESULT
Konsole window with htop

SOFTWARE/OS VERSIONS
Operating System: KDE neon 5.15
KDE Plasma Version: 5.15.5
KDE Frameworks Version: 5.59.0
Qt Version: 5.12.3
Kernel Version: 4.15.0-51-generic
OS Type: 64-bit
Processors: 4 × Intel® Core™ i5-3210M CPU @ 2.50GHz
Memory: 5,7 ГиБ
Comment 1 Christoph Feck 2019-06-25 15:16:17 UTC
Does is work in an X11 session? Is it restricted to "htop" or also other command line applications?
Comment 2 Andrey E. 2019-06-25 17:09:13 UTC
(In reply to Christoph Feck from comment #1)
> Does is work in an X11 session? Is it restricted to "htop" or also other
> command line applications?

Htop works fine while X11 session, but doesn't appears while Wayland session.
I didn't test that bug with other console utilities which have shortcuts in Kicker or Kickoff menu.

When I use Konsole directly, I don't have any bugs (X11 or Wayland).
Comment 3 Patrick Silva 2019-07-08 19:49:35 UTC
I can confirm this problem on Arch Linux.
Htop opens as expected on Wayland session if I set Gnome Termnial as default terminal emulator in system settings > applications > default applications.

Operating System: Arch Linux 
KDE Plasma Version: 5.16.2
KDE Frameworks Version: 5.59.0
Qt Version: 5.13.0
Comment 4 Nate Graham 2020-02-24 16:55:08 UTC
*** Bug 417115 has been marked as a duplicate of this bug. ***
Comment 5 Wolfgang Bauer 2020-02-24 18:24:37 UTC
The reason is (likely) this code in kio (https://cgit.kde.org/kio.git/tree/src/core/desktopexecparser.cpp#n429):
        if (terminal == QLatin1String("konsole")) {
            if (!d->service.workingDirectory().isEmpty()) {
                terminal += QLatin1String(" --workdir ") + KShell::quoteArg(d->service.workingDirectory());
            }
            terminal += QLatin1String(" -qwindowtitle '%c' %i");
        }

%i expands to "--icon xxx", which is not supported (by Qt) on Wayland.

See https://community.kde.org/Guidelines_and_HOWTOs/Wayland_Porting_Notes#Exec_key_of_.desktop_files :
> The Exec key of your .desktop file should not contain the %i "field code".
> Your application won't start on Wayland otherwise, because the specification
> expands that code in the --icon argument, which is accepted by QGuiApplication > only on XCB platforms. This code review contains a discussion about the
> upstream decision. You can use the -qwindowicon argument as replacement. It
> still won't work on Wayland (it will on most other platforms) but now your app > will start everywhere.
> 
> // Don't
> Exec=someapp %i %U
> // Do
> Exec=someapp -qwindowicon someicon %U

So IMHO, one way to fix it would be to explicitly handle the "-icon" option in konsole, the other to make kio not use that option on Wayland.
Comment 6 Nate Graham 2020-02-24 21:14:22 UTC
Nice find. Wanna submit a patch? Both might be desirable, but the %i fix seems more important since it's a Wayland incompatibility and could bite other apps too.
Comment 7 David Edmundson 2020-02-25 00:18:33 UTC
>So IMHO, one way to fix it would be to explicitly handle the "-icon" option in konsole, the other to make kio not use that option on Wayland.

There's no point doing the -icon thing on wayland, there is no spec for window icons to be passed. It would just be a lie for compatibility.

Lets do the kio thing
Comment 8 Wolfgang Bauer 2020-02-25 08:38:20 UTC
(In reply to Nate Graham from comment #6)
> Nice find. Wanna submit a patch?
When I find the time...

> Both might be desirable, but the %i fix
> seems more important since it's a Wayland incompatibility and could bite
> other apps too.
It cannot bite other applications, as this code is specific for calling konsole, see the 'if'.

I do agree that it should better be fixed in kio though.

But if you mean "fixing" the %i handling in general (e.g. to use "-qwindowicon" instead which would also "work" on Wayland, although it would have no effect), that is not a good idea either, as it is written in the freedesktop.org .desktop file specifications that %i shall be expanded to "--icon xxx".
Quoting from https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.1.html#exec-variables :
> %i	 The Icon key of the desktop entry expanded as two arguments, first --icon
> and then the value of the Icon key. Should not expand to any arguments if the
> Icon key is empty or missing.

And non-Qt applications likely won't support -qwindowicon anyway, although they might "support" --icon even on Wayland. ;-)
Comment 9 Wolfgang Bauer 2020-02-25 08:41:26 UTC
Although, as changing the window icon apparently is not possible on Wayland anyway, maybe the best fix would indeed to just always expand %i to an empty string on Wayland?
Comment 10 Wolfgang Bauer 2020-02-25 10:10:47 UTC
Ok, I can confirm now that removing the %i when calling konsole indeed fixes the bug on Wayland.

But what would be the best way to test for Wayland or xcb inside kio?
Using QGuiApplication::platformName() doesn't work (it gives a compiler error) because kio (this part at least) isn't linked against QGuiApplication I think.

And removing it unconditionally would be a "regression" on X11/xcb... :-/
Although, specifying "--icon someicon" seems to have no effect on Plasma/X11 either anyway, so that might be acceptable (it does work on other desktops I tried though).
Comment 11 Wolfgang Bauer 2020-02-25 14:16:24 UTC
Hm, seems my thinking went a bit overboard now... ;-)

In the konsole specific code, we can of course just use "-qwindowicon someicon" instead of "%i", that's supported by Qt on any Platform and won't change existing behavior in any way either ("--icon" is just a synonym for "-qwindowicon" on xcb, it's handled by the very same code path in Qt).

Patch is upcoming, I just want to test a few things before.
Comment 12 Wolfgang Bauer 2020-02-25 15:23:50 UTC
https://phabricator.kde.org/D27654
Comment 13 Wolfgang Bauer 2020-02-28 10:28:31 UTC
Git commit 07ab04bfe77475438fca0996d48116bbc17eedd6 by Wolfgang Bauer.
Committed on 28/02/2020 at 10:25.
Pushed by wbauer into branch 'master'.

Fix running konsole on Wayland

%i expands to "--icon someicon", but Qt recognizes this option only on
X11/xcb.
So konsole failed to start on Wayland.

To fix this problem, pass "-qwindowicon" instead, which is supported on
all platforms.

See https://community.kde.org/Guidelines_and_HOWTOs/Wayland_Porting_Notes#Exec_key_of_.desktop_files for details.
FIXED-IN: 5.68.0
Differential Revision: https://phabricator.kde.org/D27654

M  +4    -1    src/core/desktopexecparser.cpp

https://commits.kde.org/kio/07ab04bfe77475438fca0996d48116bbc17eedd6