Bug 447538 - On Wayland, Kate doesn't prefer opening files in an instance on the current virtual desktop
Summary: On Wayland, Kate doesn't prefer opening files in an instance on the current v...
Status: REPORTED
Alias: None
Product: kwayland-integration
Classification: Frameworks and Libraries
Component: general (other bugs)
Version First Reported In: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-12-26 13:03 UTC by Ahmad Samir
Modified: 2025-12-15 19:11 UTC (History)
6 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ahmad Samir 2021-12-26 13:03:30 UTC
Basically the code uses KWindowSystem::currentDesktop()[1] to check which virtual desktop you're on, and if there is a Kate instance running there already open the file in it, and if there isn't it starts a new instance then open the file with it.

The issue is that on Wayland currentDesktop() always returns 0, so the logic doesn't work, opening a file with Kate could end up opening that file on an instance that's already running on a different virtual desktop.

[1]https://invent.kde.org/utilities/kate/-/blob/master/kate/main.cpp#L407
Comment 1 Christoph Cullmann 2022-01-08 18:59:02 UTC
I would consider this more an issue of the kwayland-integration.
Or is there some replacement function for this?
Comment 2 Ahmad Samir 2022-01-08 19:12:25 UTC
The fix will probably have to be somewhere in kwayland*, then we can use it in Kate.
Comment 3 Nicolas Fella 2022-12-21 12:25:50 UTC
As of right now upstream Wayland has no concept of virtual desktops. That means that the existing virtual desktops in e.g. Plasma are completely compositor-defined and applications generally have no information about what desktop they are on. 

There may or may no come a Wayland protocol that allows this in the future, but as of right now this part of KWindowSystem can't reasonably be implemented on Wayland.

That's why https://invent.kde.org/frameworks/kwindowsystem/-/merge_requests/72 renames it to make this explicit
Comment 4 Ahmad Samir 2024-03-05 10:27:25 UTC
I don't know much about Wayland; so here is an observation, assuming there is a kate instance on the current virtual desktop, and focus stealing prevention is set to none:
- Ctrl+Clicking in konsole opens the file in that kate instance and activates the window
- From that konsole window, using `kate /path/to/some/file`, the file is opened in kate, but the window isn't activated, and the task manager highlights the kate window as requesting attention
Comment 5 Evan Hilton 2025-12-15 19:11:19 UTC
I've created a KWin script that mitigates this bug. It's not a complete fix as it requires that a Kate instance already be open on the workspace in question, but as long as an instance already exists files will open on the same workspace. I should also note that it works by giving Kate focus on workspace switch, so if you rely on a specific window gaining focus on workspace switch this may not work well for you.

You can find it here: https://github.com/ehilton2931/kate-autofocus. I may get around to uploading it to the KDE store eventually, but there's some additional functionality for multi-monitor setups that I want to add first.

Even with this mitigation, I do hope that this bug will be properly fixed before the X11 session is dropped. This is a key part of my workflow and while the script does mean this bug is no longer a showstopper for me, the need for a preexisting Kate instance is still annoying.