When a window on a different desktop gets activated, bring it to the current desktop instead of switching to the other desktop
This is my first issue, so please be gentle :)
https://bugs.kde.org/show_bug.cgi?id=438375
When a window that is on a different virtual desktop than the current one gets activated, the current behavior is that the active virtual desktop will be switched to the one the activated window is on. This may seem reasonable for a scenario where the user explicitly intends to activate an existing window on a different desktop. However, the following scenario is also (perhaps even more?) common: When an application responds to a launch command by requesting to activate an existing instance instead of opening a new one (such as Firefox or KDE System Settings), an existing window on any desktop will get activated even when what the user had in mind was opening a new window (on the desktop they are currently in).
This means that opening an application, such as following a URL or accessing a system setting, unexpectedly results in the user being teleported to a different virtual desktop. This can be very irritating, see e.g.
- https://forum.kde.org/viewtopic.php?f=20&t=87631
- https://forum.manjaro.org/t/stop-switching-workspace-when-opening-same-app-from-different-workspace/59377
- https://www.reddit.com/r/kde/comments/qw75om/firefox_activities/
- https://www.reddit.com/r/kde/comments/raxyb4/kde_activities_cannot_open_2nd_instance_of_chrome/
- https://www.reddit.com/r/kde/comments/swl1fb/15_minute_bug/
The more expected behavior at least for me would be to have windows always open on the desktop where they are called from.
Targeting this with a KWin script appears to be impossible to due to the logic of how the desktop changing and window activation signals are emitted.
So I went into the source code, and changing
void Workspace::activateClient(AbstractClient* c, bool force) {
...
if (!c->isOnCurrentDesktop()) {
....
VirtualDesktopManager::self()->setCurrent(c->desktops().constLast());
to
Workspace::self()->sendClientToDesktop(c, VirtualDesktopManager::self()->current(), false);
solved the problem for me. (Thanks again to whoever throwaway6560192 is for helping me to get the custom build to run.)
Since there does seem to be an interest in such a change, I have considered submitting a merge request. Just exchanging the line won't do though: In my understanding some consider the current behavior a feature not a bug, and at least for the use case of activating a window on a different desktop through the task manager, the switching behavior will have to be kept.
So either one would have to somehow distinguish whether the user explicitly intended to activate the instance on the other desktop or if the application (or whichever component is responsible for this) requested to activate an existing instance instead of creating a new one, but I don't know how, if at all, this could be implemented.
Or one makes this optional through a system setting, so that users who don't need cross-desktop task switching and are annoyed by the current behavior can opt in to the policy of always activating windows on the current desktop. XFCE has something like this: https://unix.stackexchange.com/questions/97918/stop-browser-window-from-switching-workspace-and-getting-focus-when-opening-a-li/98432#98432 Before I dig into the KCM, which looks like quite an undertaking:
Would there be any interest in incorporating such an option into KWin?
Is there a better way of handling this?