Bug 501527 - kwin selects wrong monitor as active
Summary: kwin selects wrong monitor as active
Status: REPORTED
Alias: None
Product: kwin
Classification: Plasma
Component: multi-screen (other bugs)
Version First Reported In: 6.3.3
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords: multiscreen, wayland-only
Depends on:
Blocks:
 
Reported: 2025-03-15 10:56 UTC by nodscher
Modified: 2025-11-09 17:11 UTC (History)
3 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 nodscher 2025-03-15 10:56:11 UTC
SUMMARY
After upgrading to an amd gpu my secondary monitor is now active by default. My mouse gets put get correctly put on the primary Monitor, but remembered apps are put on the secondary one. Additionally both sddm and kscreenlocker type on the secondary one (this is especially bad in kscreenlocker because it notices that it is on the wrong screen when i move the mouse and the password get split across the monitors). 

In tried deleting the kwin output config, but that didn't help. In my testing it only seems to be dependent on the order the monitors are picked up in. If I disconnect the primary physically and then reconnect it, kscreenlocker types on the primary one (but turning it off and on in software has no effect).

I'm not sure if this is a bug with kwin, but since this happens in plasma and sddm, but not gdm, so that's my guess.

It also happens on a complete clean install.

STEPS TO REPRODUCE (maybe)
1. Connect 2 Monitors
2. Disconnect and reconnect one physically
3. lock screen with shortcut
4. kscreenlocker will type on that screen

OBSERVED RESULT
last connected screen (I think) is active by default

EXPECTED RESULT
primary Monitor (or the monitor where the mouse is) should be active by default.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 6.3.3
KDE Frameworks Version: 6.11.0
Qt Version: 6.8.2
Kernel Version: 6.14.0-rc6-1-mainline (64-bit) (But same thing with stable kernel)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 5800X 8-Core Processor
Memory: 31.3 GiB of RAM
Graphics Processor: AMD Radeon Graphics (rx 9070)
Comment 1 nodscher 2025-03-15 11:09:26 UTC
On x11 plasma and kscreenlocker behave as expected and select the monitor where the mouse is.
On wayland it is like described above

SDDM selects the secondary monitor on wayland and x
Comment 2 nodscher 2025-11-09 17:11:07 UTC
Hi,
I looked into this myself and this is what happens here as far as I can tell:

kwin adds outputs in the order the gpu driver gives it --> plasma/sddm/kscreenlocker want to be on all screens so they loop over the screens in that same order --> they create windows (or whatever) in that order --> whatever window was created last, as well as its screen, has the focus

that means that the focus in those cases is determined by the order the gpu gives to kwin, which happens to make my primary monitor "primary" on nvidia and my secondary on amd/nouveau

(theoretically sddm has code to change focus itself, but that doesn't seem to do anything)

changing the append to prepend in DrmBackend::addOutput fixes the issue in my specific case

I tried to make a "proper" fix myself, by making the output list the inverse of the OutputOrder, but I didn't manage to get that Information in drm_backend.cpp (probably just because I don't know cpp though)

Also kscreenlocker checked where the cursor was for a while, both fixing this and making it still work properly if the cursor was on a different screen, but that broke again in 6.5 (or 6.4.5). I would try to bisect it, but I'm not sure how to bisect plasma with it's many subprojects. Simply downgrading plasma-desktop plasma-workspace and kscreenlocker didn't make a difference.