Bug 513549

Summary: Focused window changes when switching between virtual desktops
Product: [Plasma] kwin Reporter: nopisonnope
Component: generalAssignee: KWin default assignee <kwin-bugs-null>
Status: REPORTED ---    
Severity: normal CC: nate
Priority: NOR    
Version First Reported In: 6.5.4   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description nopisonnope 2025-12-18 17:57:04 UTC
***
If you're not sure this is actually a bug, instead post about it at https://discuss.kde.org

If you're reporting a crash, attach a backtrace with debug symbols; see https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports

Please remove this comment after reading and before submitting - thanks!
***

SUMMARY
If you have multiple screens and multiple virtual desktops (like: two monitor setup and 8 virtual desktops) with windows scattered over both screens, then switching from virtual desktop to another, doing some work there and then switching back to previous one will change the window having focus.

Another way to put this down: Focus is given based on last active screen priority rather than last active window priority.

STEPS TO REPRODUCE
1. Prepare setup with two virtual desktops and two screens (monitors). Open two windows on desktop 1, one on each screen and two windows on desktop 2, also one on each screen.
2. Give window on screen 1 on desktop 1 focus.
3. Switch to desktop 2
4. Give window on screen 2 on desktop 2 focus.
5. Switch back to desktop 1.

OBSERVED RESULT
Window on screen 2 will have focus once you activate desktop 1.

EXPECTED RESULT
Historically (since at least KDE 3.2) the behavior KWin followed was that focus would be given to window on screen 1 as this was the last window focused when I left the desktop. This also makes sense from the point of view that I never commanded the system to change the focus.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux 
KDE Plasma Version: 6.5.4
KDE Frameworks Version: 6.21.0
Qt Version: 6.10.1

ADDITIONAL INFORMATION
Session is using Wayland as compositor. This behavior is present for quite some time but now it got really annoying that I have tons of windows on tons of desktops and I always have to switch windows after switching desktops because focus is always wrong.
Comment 1 Nate Graham 2025-12-18 19:52:03 UTC
Can't reproduce on git master with 2 screens and multiple virtual desktops.
Comment 2 nopisonnope 2025-12-18 20:42:50 UTC
Further details: Desktops have to be switched using keyboard shortcut "Switch to desktop X".

I can confirm that this is not reproducible if desktops are switched using pager wither or using mouse wheel scroll on root desktop window on 6.4.3.