fix: restore multi-monitor screenshot capture in Qt6#405
Open
itspartaru wants to merge 1 commit into
Open
Conversation
Qt6's QScreen::grabWindow(0) captures only the screen it belongs to, unlike Qt5's QDesktopWidget-based approach which grabbed the full X11 virtual desktop. This broke fullscreen and area capture on multi-monitor setups — the image always showed the primary screen content regardless of which monitor the cursor was on. Fix by iterating all QScreens, grabbing each one individually, and compositing them onto a canvas sized to the full virtual desktop. Translate all coordinates relative to the virtual desktop origin so per-monitor crop and selection capture work correctly when monitors are arranged with negative Qt logical coordinates. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After the Qt6 migration, screenshot capture on multi-monitor setups is broken.
captureAllMonitors(),captureFullscreen(), andcaptureSelection()all produceincorrect results — the image shows only the primary screen content regardless of
which monitor the cursor is on.
Root cause: Qt6's
QScreen::grabWindow(0)captures only the screen it belongs to,whereas Qt5's
QApplication::desktop()->winId()referred to the X11 root window whichspans the full virtual desktop. The single-line change in the Qt6 migration
(
grabWindow(desktopWinId, ...)→grabWindow(0, ...)) silently broke this behavior.Additionally,
QScreen::geometry()returns Qt logical coordinates which can benegative (e.g. a monitor to the left of the primary has negative X). The old code
passed these coordinates directly to
QImage::copy()which uses pixel coordinates —a mismatch that causes wrong crops.
Fix
captureAllMonitors(): iterate allQGuiApplication::screens(), grab each onewith
s->grabWindow(0), and composite onto a canvas sized to the full virtual desktopcaptureFullscreen()andcaptureSelection(): translate screen geometry relativeto the virtual desktop origin before cropping
Tested on a two-monitor setup (primary 2560×1440 + secondary 1920×1200) on X11/Qt6.