Skip to content

fix: restore multi-monitor screenshot capture in Qt6#405

Open
itspartaru wants to merge 1 commit into
olav-st:masterfrom
itspartaru:fix/multi-monitor-qt6
Open

fix: restore multi-monitor screenshot capture in Qt6#405
itspartaru wants to merge 1 commit into
olav-st:masterfrom
itspartaru:fix/multi-monitor-qt6

Conversation

@itspartaru
Copy link
Copy Markdown

Problem

After the Qt6 migration, screenshot capture on multi-monitor setups is broken.
captureAllMonitors(), captureFullscreen(), and captureSelection() all produce
incorrect 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 which
spans 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 be
negative (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 all QGuiApplication::screens(), grab each one
    with s->grabWindow(0), and composite onto a canvas sized to the full virtual desktop
  • captureFullscreen() and captureSelection(): translate screen geometry relative
    to the virtual desktop origin before cropping

Tested on a two-monitor setup (primary 2560×1440 + secondary 1920×1200) on X11/Qt6.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant