Bug 407288 - Kate doesn't bring existing session into foreground
Summary: Kate doesn't bring existing session into foreground
Status: RESOLVED NOT A BUG
Alias: None
Product: kate
Classification: Applications
Component: application (show other bugs)
Version: 23.04.3
Platform: Microsoft Windows Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords: regression, usability
: 407286 409677 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-05-07 11:20 UTC by Cristian Adam
Modified: 2024-04-01 01:52 UTC (History)
11 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cristian Adam 2019-05-07 11:20:58 UTC
I have installed kate-18.12.3-443-windows-msvc2017_64-cl.exe on Windows 10.

I configured Kate to be the editor application in Total Commander (similar application to Krusader :)

When I press F4 to edit a file, Kate springs into action. If there is no session open, it opens the application and brings into foreground.

If an existing session exists, then it just highlights in in the taskbar without bringing it to foreground.

I have to then press Alt-Tab to reach Kate, which is not what I expect as an user.

Until this bug exists in Kate I'm forced to use Notepad++, which works as expected.
Comment 1 Nate Graham 2019-05-12 20:20:19 UTC
Can confirm the behavior on Linux too, on both Manjaro (Kate 19.04.0) and KDE Neon dev unstable (Kate from git master).
Comment 2 Nate Graham 2019-05-12 20:20:48 UTC
*** Bug 407286 has been marked as a duplicate of this bug. ***
Comment 3 Christoph Cullmann 2019-05-22 15:09:51 UTC
We do this in the code:


void KateAppAdaptor::activate()
{
    KateMainWindow *win = m_app->activeKateMainWindow();
    if (!win) {
        return;
    }

    // like QtSingleApplication
    win->setWindowState(win->windowState() & ~Qt::WindowMinimized);
    win->raise();
    win->activateWindow();
}

Before we were more "foreful", this got removed in bug 371220
Comment 4 Nate Graham 2019-05-22 16:49:45 UTC
I think what's happening here is that KWin is ignoring the non-forceful request to raise the window because of some issue with the way the call is structured or how Kate is activated. KWin requires that it be done in a very specific way or else activateWindow() doesn't work. CCing some KWin developers who can shed more light on the situation.
Comment 5 Christoph Cullmann 2019-05-24 13:34:06 UTC
This is the only thing that works for me:

+
+    // try to raise window, see bug 407288
+    KWindowSystem::raiseWindow(win->winId());

but the documentation states only pagers should use that.
Comment 6 Christoph Cullmann 2019-05-24 13:36:44 UTC
Git commit 7ecdd0eaf94b3bba392f547a15594fb389e75f30 by Christoph Cullmann.
Committed on 24/05/2019 at 13:36.
Pushed by cullmann into branch 'master'.

try a bit harder to raise window for already running application

M  +2    -6    kate/kateapp.cpp
M  +3    -0    kate/kateappadaptor.cpp

https://commits.kde.org/kate/7ecdd0eaf94b3bba392f547a15594fb389e75f30
Comment 7 Christoph Cullmann 2019-05-24 13:37:45 UTC
I commited now the aggressive variant.
That at least works here reasonable well, even if you open a file, hide the window, open the same file again from some konsole via "kate ...".
All other calls didn't to the trick for that.
Comment 8 Nate Graham 2019-05-24 13:43:20 UTC
Thanks! Is this backportable to the stable branch?
Comment 9 Christoph Cullmann 2019-05-24 14:25:33 UTC
If somebody wants to cherry-pick that, feel free.
I am not sure if that is the right way to fix it thought, given the docs state one shall not use that method for what we do :=)
Comment 10 Nate Graham 2019-05-24 14:37:37 UTC
Some of the KWin developers may be able to help. I'll see if I can make them aware.
Comment 11 george fb 2019-05-26 13:06:47 UTC
There's info on how to activate windows here https://phabricator.kde.org/D16648#450590
Comment 12 Christoph Cullmann 2019-05-26 13:15:55 UTC
That means I should try

    KStartupInfo::setNewStartupId(win(), KStartupInfo::startupId());
    KWindowSystem::activateWindow(win()->effectiveWinId());

instead of 

    KWindowSystem::raiseWindow(win->winId());

?
Comment 13 Nate Graham 2019-05-26 14:43:14 UTC
Worth a try, at least. :)
Comment 14 Dominik Haumann 2019-05-29 21:56:00 UTC
There is another addition proposed here:
https://phabricator.kde.org/D21485
Comment 15 Sergio Martins 2019-05-30 19:19:11 UTC
Git commit 18b05cb14bddfc1568d3082dfd862c62bcf77440 by Sergio Martins.
Committed on 30/05/2019 at 19:18.
Pushed by smartins into branch 'master'.

Fix window activation on Windows

Windows doesn't use the dbus stuff and instead uses qtsingleapplication,
which does support window activation if setActivationWindow is called.

setActivationWindow wasn't called anywhere.

Differential Revision: 21485

M  +4    -0    kate/main.cpp

https://commits.kde.org/kate/18b05cb14bddfc1568d3082dfd862c62bcf77440
Comment 16 george fb 2019-06-02 11:39:11 UTC
> KStartupInfo::setNewStartupId(window(), KStartupInfo::startupId());
> KWindowSystem::activateWindow(window()->effectiveWinId());
Works for Dolphin so it should work for Kate too.
Comment 17 Christoph Cullmann 2019-07-14 11:58:45 UTC
Git commit fd101540c21847df6df90cb6c546f6fdf92b74f6 by Christoph Cullmann.
Committed on 14/07/2019 at 11:58.
Pushed by cullmann into branch 'master'.

use same code as dolphin for window raising
works fine for me, too, even for minimized windows

M  +4    -1    kate/kateappadaptor.cpp

https://commits.kde.org/kate/fd101540c21847df6df90cb6c546f6fdf92b74f6
Comment 18 Nate Graham 2019-07-15 21:01:16 UTC
*** Bug 409677 has been marked as a duplicate of this bug. ***
Comment 19 Glenn Kubota 2023-08-03 18:33:30 UTC
I have installed Kate 23.04.3 in Windows 11 Enterprise (Version 21H2, OS build 22000.2176) and found that this bug has occurred again. If I double-click on a text file in Windows File Explorer, then Kate will open that file in the foreground as it should. If I then bring File Explorer to the foreground and double-click a different text file, that file will open in Kate, but Kate will remain in the background.
Comment 20 Christoph Cullmann 2023-08-04 17:09:54 UTC
Yeah, doesn't work as it should.
Comment 21 Christoph Cullmann 2023-12-29 17:57:51 UTC
We do now


void KateAppAdaptor::activate(const QString &token)
{
    KateMainWindow *win = m_app->activeKateMainWindow();
    if (!win) {
        return;
    }

    // like QtSingleApplication
    win->setWindowState(win->windowState() & ~Qt::WindowMinimized);
    win->raise();
    win->activateWindow();

    // try to raise window, see bug 407288
    if (KWindowSystem::isPlatformX11()) {
#if HAVE_X11
        KStartupInfo::setNewStartupId(win->windowHandle(), token.toUtf8());
#endif
    } else if (KWindowSystem::isPlatformWayland()) {
        KWindowSystem::setCurrentXdgActivationToken(token);
    }

    KWindowSystem::activateWindow(win->windowHandle());
}

that still is not enough, I would assume that is the same issue as on Wayland, Windows just doesn't allow for the window to be raised, one just gets the notification in the task bar.
Comment 22 Christoph Cullmann 2024-03-27 22:14:41 UTC
I don't think we can fix that, like on Wayland the security mechanism to avoid focus stealing and Co. don't allow for that.
Comment 23 Nate Graham 2024-03-27 23:49:04 UTC
It's definitely possible to fix on Wayland, you just have to handle the activation token properly. I'm CCing some people who know how to do this.
Comment 24 Christoph Cullmann 2024-03-28 09:02:32 UTC
(In reply to Nate Graham from comment #23)
> It's definitely possible to fix on Wayland, you just have to handle the
> activation token properly. I'm CCing some people who know how to do this.

If I start Kate it the terminal with

kate xxx.txt

I fail to see what I should send over via dbus to the main instance.

But if that is feasible on Wayland, help is welcome.
Comment 25 Aleix Pol 2024-03-28 19:15:37 UTC
This bug is a bit confusing, it's originally for Microsoft Windows but it seems to have mutated?

On Wayland, if it's not working with Krusader or whatever, we need to have the application adapted to produce a token that will be handed over.

In the case of Konsole, we are not doing that because konsole (bash?) doesn't have a way to create this token. We should make Konsole create the environment variable that communicates the token. As such it's a Konsole bug, not Kate's.

Kate works fine, that's why it works when launched from an app that does the right thing, like dolphin.
Comment 26 Christoph Cullmann 2024-03-28 20:55:11 UTC
(In reply to Aleix Pol from comment #25)
> This bug is a bit confusing, it's originally for Microsoft Windows but it
> seems to have mutated?
> 
> On Wayland, if it's not working with Krusader or whatever, we need to have
> the application adapted to produce a token that will be handed over.
> 
> In the case of Konsole, we are not doing that because konsole (bash?)
> doesn't have a way to create this token. We should make Konsole create the
> environment variable that communicates the token. As such it's a Konsole
> bug, not Kate's.
> 
> Kate works fine, that's why it works when launched from an app that does the
> right thing, like dolphin.

Ok, if for Wayland Kate is fine, we can close this. At least for Windows I found no proper way to make it work.

Thanks for taking a look at this @aleix!
Comment 27 Nate Graham 2024-04-01 01:52:26 UTC
Ah in that case the issue is Bug 442265.

Looks like it's my bad that this mutated back in 2019 from a Windows bug into a Wayland bug. Sorry about that.