Bug 505202

Summary: Cannot screenshot Wine windows with Spectacle's "Active Window" mode
Product: [Plasma] kwin Reporter: Jared Adams <jaxad0127>
Component: generalAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: major CC: 4wy78uwh, kde, kdedev, nate, serdarthtux, xaver.hugl
Priority: NOR    
Version First Reported In: 6.3.5   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In: 6.5.3
Sentry Crash Report:

Description Jared Adams 2025-06-04 11:34:36 UTC
SUMMARY
Attempting to capture Active Window for Wine fails.

STEPS TO REPRODUCE
1. Open a Wine application (winecfg will trigger the bug)
2. Open Spectacle
3. Try to use Active Window option on Wine window
4. Failure

OBSERVED RESULT
An error occurred while taking a screenshot.
KWin screenshot request failed:
Invalid window requested
Potentially relevant information:
- Method: CaptureActiveWindow
- Method specific arguments: QMap(("include-decoration", QVariant(bool, true))("include-shadow", QVariant(bool, true))("native-resolution", QVariant(bool, true)))

EXPECTED RESULT
Successful capture.

SOFTWARE/OS VERSIONS
Operating System: CachyOS Linux 
KDE Plasma Version: 6.3.5
KDE Frameworks Version: 6.14.0
Qt Version: 6.9.0
Kernel Version: 6.15.0-2-cachyos (64-bit)
Graphics Platform: Wayland

ADDITIONAL INFORMATION
Original Reddit post: https://www.reddit.com/r/kde/comments/1l2w6m1/unable_to_screenshot_wine_windows_in_spectacle/
Comment 1 TraceyC 2025-06-04 18:34:28 UTC
I'm not able to reproduce this on git-master Solus, Neon Testing or Fedora 42 in a Wayland session

Can you check something? In System Settings -> Window Behavior - on the Focus tab, what setting do you have for "Window activation policy"?
Comment 2 Jared Adams 2025-06-04 20:13:13 UTC
I am using Focus follows mouse (mouse precedence). Playing around with them:
- Click to focus works fine for all windows
- Focus follows mouse works for most, fails Wine
- Focus under mouse fails all
- Focus strictly under mouse fails all
(mouse precedence doesn't change anything)

A 1 second delay doesn't have the problem.
Comment 3 TraceyC 2025-06-09 20:23:15 UTC
Thanks for the details. I'm able to reproduce this on git-master using the settings that triggered the bug for you:

- Focus under mouse
- Zero second delay

I'll let the KWin developers take it from here.
Comment 4 Zamundaaa 2025-11-06 22:46:49 UTC
I looked at the problem, and the issue is that X11 focus stuff is stupid. When the Spectacle window goes away, KWin sends a message to Wine that it should get focus, and then Wine will eventually respond that it actually takes focus. Until it does, the active window is nullptr.
Comment 5 Bug Janitor Service 2025-11-06 22:55:05 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/8381
Comment 6 Zamundaaa 2025-11-17 17:52:46 UTC
Git commit bc6deccf95e3d64cfc84953335767b28d94cdd4d by Xaver Hugl.
Committed on 17/11/2025 at 17:31.
Pushed by zamundaaa into branch 'master'.

plugins/screenshot: also take pending focus requests into account

When selecting "active window" in Spectacle, Spectacle closes its window and
the active window gets switched to the next window. If that next window is an
X11 window, it doesn't become the active window immediately though, it takes
until the application responds for that to happen.

To still make the screenshot work, use mostRecentlyActivatedWindow instead.

M  +1    -1    src/plugins/screenshot/screenshotdbusinterface2.cpp

https://invent.kde.org/plasma/kwin/-/commit/bc6deccf95e3d64cfc84953335767b28d94cdd4d
Comment 7 Zamundaaa 2025-11-17 20:32:06 UTC
Git commit 7ddb462c1aa1f73b468d59cd9b131b43882c1b22 by Xaver Hugl.
Committed on 17/11/2025 at 20:11.
Pushed by zamundaaa into branch 'Plasma/6.5'.

plugins/screenshot: also take pending focus requests into account

When selecting "active window" in Spectacle, Spectacle closes its window and
the active window gets switched to the next window. If that next window is an
X11 window, it doesn't become the active window immediately though, it takes
until the application responds for that to happen.

To still make the screenshot work, use mostRecentlyActivatedWindow instead.


(cherry picked from commit bc6deccf95e3d64cfc84953335767b28d94cdd4d)

Co-authored-by: Xaver Hugl <xaver.hugl@kde.org>

M  +1    -1    src/plugins/screenshot/screenshotdbusinterface2.cpp

https://invent.kde.org/plasma/kwin/-/commit/7ddb462c1aa1f73b468d59cd9b131b43882c1b22