Skip to content

Fix blurry captures with fractional scaling on Wayland - #5060

Closed
tlipinski wants to merge 1 commit into
flameshot-org:masterfrom
tlipinski:fix/wayland-fractional-scale-blur
Closed

tlipinski wants to merge 1 commit into
flameshot-org:masterfrom
tlipinski:fix/wayland-fractional-scale-blur

Conversation

@tlipinski

@tlipinski tlipinski commented Nov 15, 2026 •

Copy link
Copy Markdown

Fix blurry captures with fractional scaling on Wayland

Note

This PR was made with AI assistance (Claude Code). All test cases listed above were run and checked manually on real hardware.

Problem

On Wayland with fractional scaling, captures come out blurry. cropToMonitor() resized each monitor's crop to its logical size times QScreen::devicePixelRatio(). On Wayland, that value comes from wl_output.scale, which can only be a whole number, so compositors round it up. A monitor at 1.25 reports a DPR of 2.

Example: a 1920×1200 panel at scale 1.25 (1536×960 logical). The portal returns a correct 1920×1200 image, but flameshot saw 1.25 ≠ 2 and stretched it to 3072×1920 with smoothing. The capture window then shrank it back to 1.25 on screen, and saved files were the stretched 3072×1920 version.

Fix

On Linux, the portal returns the whole desktop at a single scale (the highest monitor scale), and the reported DPR is never lower than a monitor's real scale. So the crop is now handled like this:

  • Screen reports a lower scale than the image has (a lower-scale monitor that the portal enlarged): shrink the crop to the monitor's native size, as before.
  • Otherwise: keep the portal's pixels and tag them with their real ratio (image width / logical width) instead of enlarging them.

Enlarging was the only step that caused blur, and it no longer happens. Windows and macOS code is unchanged.

Testing

Hyprland, Qt 6.12.0, xdg-desktop-portal-hyprland. Laptop panel 1920×1200 at 1.25, external 2560×1440 at 1. Debug build with -DFLAMESHOT_DEBUG_CAPTURE=ON.

Setup Monitor Before After
Laptop only, 1.25 laptop stretched to 3072×1920, blurry 1920×1200 at DPR 1.25, sharp
Mixed (1.25 + 1) laptop stretched to 3072×1920, blurry 1920×1200 at DPR 1.25, sharp
Mixed (1.25 + 1) external 2560×1440 (shrunk from portal's 3200×1800) 2560×1440, unchanged
Same scale on both (1.25) both stretched to 2× (DPR 2 reported), blurry correct sizes, sharp

Crop positions inside the combined 5120×1800 portal image were checked to be correct.

The laptop-only row was measured with both builds (flameshot screen -n 0 -p …):

master:  "Scaling screenshot to: 3072 1920"                        -> PNG 3072 x 1920
this PR: "Screenshot DPR: 1.25 (screen reports 2), size 1920x1200" -> PNG 1920 x 1200

The other "before" values follow from the same code path and logged DPRs.

Not tested: X11, GNOME/KDE portals, a whole-number scale of 2, and a fractional monitor next to a monitor at scale 2. In that last case both report DPR 2, so the crop keeps the portal's pixels without shrinking.

Known limitation

With monitors at different scales, the lower-scale monitor's capture is still soft. This happens before flameshot gets the image: xdg-desktop-portal-hyprland runs plain grim, which builds the image at the highest scale and enlarges lower-scale monitors with smoothing. Flameshot can't recover the lost detail, and this PR doesn't change that case. Fixing it would mean capturing each monitor directly on wlroots-style compositors (e.g. grim -o <output> or the screen-capture protocol) instead of through the portal. I'm happy to discuss that separately if there's interest.

cropToMonitor() resized each monitor's crop to its logical size times
QScreen::devicePixelRatio(). With fractional scaling on Wayland that
value is the integer wl_output scale rounded up, e.g. 2 for a monitor at
1.25, so a correct 1920x1200 portal capture was stretched to 3072x1920
and then shrunk again on screen, which blurred it.

The portal returns the whole desktop at a single scale (the highest
monitor scale), and the reported DPR is never lower than a monitor's
real scale. So only shrink a crop when the screen reports a lower scale
than the image has (a lower-scale monitor that the portal enlarged).
Otherwise keep the pixels and tag them with their real ratio instead of
enlarging them.

With monitors at different scales, the lower-scale monitor's capture is
still soft: the portal (grim on wlroots compositors) has already
enlarged it before flameshot gets the image.
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