Skip to content

Fix broken screenshots on copy by forcing opaque alpha (#5) - #15

Open
CodyKoInABox wants to merge 3 commits into
mainfrom
cursor/fix-clipboard-png-alpha-f039
Open

CodyKoInABox wants to merge 3 commits into
mainfrom
cursor/fix-clipboard-png-alpha-f039

Conversation

@CodyKoInABox

Copy link
Copy Markdown
Owner

Cause

Region captures and cursor-monitor fullscreen captures went through capture_monitor, which passed the capture backend's RGBA buffer through unchanged. The alpha byte was only normalized as a side effect of native cursor compositing (composite_cursor writes u8::MAX). With include_cursor disabled, or when the cursor is not showing, frames kept whatever alpha the backend returned.

Both export paths store that alpha verbatim:

  • The CF_DIBV5 payload uses an alpha mask, so apps that honor it paste the screenshot as transparent or broken.
  • The PNG encoder writes RGBA as-is, so saved files had the same problem.

The virtual-desktop path had a pre-fill loop for opaque alpha, but composite_monitor overwrote it with each monitor's alpha, so it did not protect monitor pixels either.

Changes

  • capture_monitor forces alpha to opaque before building the Frame.
  • Virtual-desktop alpha is forced after compositing, replacing the ineffective pre-fill. Gap pixels still come out as opaque black.
  • rgba_to_bgra (clipboard) always writes opaque alpha, so the copied DIB is opaque regardless of the source frame.

Tests

  • forced_alpha_makes_every_capture_pixel_opaque
  • composited_zero_alpha_monitor_pixels_become_opaque
  • converts_rgba_to_opaque_bgra (replaces the previous passthrough assertion)

Tests are Windows-only and run in the Windows CI job. Not run locally (Linux host cannot build the windows target deps), and not verified on a real desktop.

Fixes #5

Open in Web Open in Cursor 

cursoragent and others added 2 commits November 6, 2026 18:16
Single-monitor captures (region and cursor-monitor fullscreen) passed the
capture backend's alpha byte through unchanged. Only cursor compositing
normalized it, so with include_cursor disabled the frame could carry zero
alpha. The clipboard DIB and PNG encoder both store that alpha verbatim,
so pasted and saved screenshots rendered as transparent or broken.

- Normalize alpha at the capture boundary for single-monitor captures.
- Normalize alpha after virtual-desktop compositing instead of before it,
  since compositing overwrote the pre-filled values.
- Write opaque alpha into the CF_DIBV5 payload.

Fixes #5

Co-authored-by: codykoinabox <codykoinabox@gmail.com>
Current stable clippy flags chunks_exact with a constant chunk size
(chunks_exact_to_as_chunks), and CI runs clippy with -D warnings. Switch
the affected pixel loops to slice::as_chunks, which is stable since Rust
1.88, the crate's MSRV. Behavior is unchanged: both forms drop the same
partial tail, which is always empty for valid RGBA buffers.

Co-authored-by: codykoinabox <codykoinabox@gmail.com>
The bin target hits the same chunks_exact_to_as_chunks lint that the library
targets already hit, so CI's clippy -D warnings still fails without it.

Co-authored-by: codykoinabox <codykoinabox@gmail.com>

This branch has not been deployed

No deployments
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.

when copying, png is broken

2 participants