Bug 494332

Summary: After switching to empty desktop focus is moved to plasma-shell and kept there even after switching back to desktop with windows
Product: [Plasma] kwin Reporter: Mykola Krachkovsky <w01dnick>
Component: multi-screenAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: mariusz.libera, nate
Priority: NOR Keywords: multiscreen, regression
Version: 6.2.0   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In: 6.2.1
Sentry Crash Report:

Description Mykola Krachkovsky 2024-10-09 07:43:45 UTC
DISCLAIMER
I'm not sure if this is kwin bug or plasma-shell. Sorry, if I misplaced it. Also I've tested in only on Wayland, so not sure if it is really a Wayland specific.

SUMMARY
When you are at desktop with window(s) and moving to empty desktop with hotkey, focus is assigned to desktop (plasma-shell). But when you move back to desktop with window(s), focus is still at desktop, not last active window at this desktop as it was before 6.2.

Also this seems related to multi-screen setup (I have two screens). When window is opened on external monitor — bug is present, when focused window is on internal laptop screen — it's not.
When switching from desktop A with 2 windows on both screens and window is active on screen 2 after switching to desktop B where only one window on screen 1 and back to A, window on screen 1 is active, not screen 2 as was before.

Same behaviour is present with open/close (not doing anything) Plasma menu (press Meta to open and press again to close) — focus is switched to screen 1 window or desktop. Plasma panel on screen 1 if this is important.

STEPS TO REPRODUCE
1. On desktop A open window on screen 2.
2. Switch to empty desktop B.
3. Switch back to desktop A.

OBSERVED RESULT
Desktop (plasma-shell) is focused. Pressing Menu key shows context menu for desktop on top-left corner of screen 1.

EXPECTED RESULT
Window on desktop A focused.

SOFTWARE/OS VERSIONS
Operating System: openSUSE Tumbleweed 20241007
KDE Plasma Version: 6.2.0
KDE Frameworks Version: 6.6.0
Qt Version: 6.7.3
Kernel Version: 6.11.2-1-default (64-bit)
Graphics Platform: Wayland
Processors: 24 × Intel® Core™ i7-14650HX
Memory: 31.1 ГіБ of RAM
Graphics Processor: Mesa Intel® Graphics

ADDITIONAL INFORMATION
Comment 1 Vlad Zahorodnii 2024-10-09 08:58:43 UTC
If you uncheck "separate screen focus" in "window behavior" system settings, does it change anything?
Comment 2 Mykola Krachkovsky 2024-10-09 09:10:57 UTC
(In reply to Vlad Zahorodnii from comment #1)
> If you uncheck "separate screen focus" in "window behavior" system settings,
> does it change anything?

Yes, unchecking it fixes the problem, it works as it was before 6.2.
Comment 3 Bug Janitor Service 2024-10-09 09:45:23 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/6581
Comment 4 Vlad Zahorodnii 2024-10-09 09:45:46 UTC
(In reply to Mykola Krachkovsky from comment #2)
> (In reply to Vlad Zahorodnii from comment #1)
> > If you uncheck "separate screen focus" in "window behavior" system settings,
> > does it change anything?
> 
> Yes, unchecking it fixes the problem, it works as it was before 6.2.

Ок, дякую
Comment 5 Vlad Zahorodnii 2024-10-09 17:49:50 UTC
*** Bug 494355 has been marked as a duplicate of this bug. ***
Comment 6 Vlad Zahorodnii 2024-10-10 13:44:47 UTC
Git commit 1d1b1adf805821cb08decad0eab4cf2ea10bc301 by Vlad Zahorodnii.
Committed on 09/10/2024 at 21:18.
Pushed by vladz into branch 'master'.

Remove "topmost" boolean trap in Workspace::findDesktop()

M  +3    -3    src/activation.cpp
M  +7    -18   src/layers.cpp
M  +5    -5    src/workspace.cpp
M  +1    -1    src/workspace.h

https://invent.kde.org/plasma/kwin/-/commit/1d1b1adf805821cb08decad0eab4cf2ea10bc301
Comment 7 Vlad Zahorodnii 2024-10-10 13:44:53 UTC
Git commit 47a2a2e12a52d1c28ba1043071190c9707640bee by Vlad Zahorodnii.
Committed on 09/10/2024 at 21:18.
Pushed by vladz into branch 'master'.

Prefer activating desktop window on active output

Workspace::findDesktop() doesn't take into account the current active
output, and instead returns the first top desktop window found in the
stack. This means that the active output may drift and the focus chain
logic can break.
Related: bug 493735

M  +5    -4    src/activation.cpp
M  +3    -3    src/layers.cpp
M  +5    -5    src/workspace.cpp
M  +1    -1    src/workspace.h

https://invent.kde.org/plasma/kwin/-/commit/47a2a2e12a52d1c28ba1043071190c9707640bee
Comment 8 Vlad Zahorodnii 2024-10-10 14:28:35 UTC
Git commit 8421b203e039d5719c41e630ee6a957651f307e1 by Vlad Zahorodnii.
Committed on 10/10/2024 at 13:45.
Pushed by vladz into branch 'Plasma/6.2'.

Remove "topmost" boolean trap in Workspace::findDesktop()
(cherry picked from commit 1d1b1adf805821cb08decad0eab4cf2ea10bc301)

M  +3    -3    src/activation.cpp
M  +7    -18   src/layers.cpp
M  +5    -5    src/workspace.cpp
M  +1    -1    src/workspace.h

https://invent.kde.org/plasma/kwin/-/commit/8421b203e039d5719c41e630ee6a957651f307e1
Comment 9 Vlad Zahorodnii 2024-10-10 14:28:41 UTC
Git commit 72d64a3b96f1fb7111852f876de2bb68aa7645f5 by Vlad Zahorodnii.
Committed on 10/10/2024 at 13:45.
Pushed by vladz into branch 'Plasma/6.2'.

Prefer activating desktop window on active output

Workspace::findDesktop() doesn't take into account the current active
output, and instead returns the first top desktop window found in the
stack. This means that the active output may drift and the focus chain
logic can break.
Related: bug 493735
(cherry picked from commit 47a2a2e12a52d1c28ba1043071190c9707640bee)

M  +5    -4    src/activation.cpp
M  +3    -3    src/layers.cpp
M  +5    -5    src/workspace.cpp
M  +1    -1    src/workspace.h

https://invent.kde.org/plasma/kwin/-/commit/72d64a3b96f1fb7111852f876de2bb68aa7645f5
Comment 10 Mykola Krachkovsky 2024-10-13 19:09:35 UTC
(In reply to Vlad Zahorodnii from comment #4)
> Ок, дякую

Дякую Вам! Чекатиму на 6.2.1.