Skip to content

xwayland: add clipboard support for images, RTF, and HTML#160

Open
Iweisc wants to merge 3 commits intomicrosoft:workingfrom
Iweisc:xwayland-clipboard-formats
Open

xwayland: add clipboard support for images, RTF, and HTML#160
Iweisc wants to merge 3 commits intomicrosoft:workingfrom
Iweisc:xwayland-clipboard-formats

Conversation

@Iweisc
Copy link
Copy Markdown

@Iweisc Iweisc commented Feb 7, 2026

The xwayland selection bridge hardcodes UTF8_STRING and TEXT as the only supported clipboard targets, so X11 apps can't paste images, RTF, or HTML that come through the RDP backend — even though Wayland apps can.

This patch replaces the hardcoded target handling with a format mapping table (similar to the one in rdpclip.c) that maps X11 atoms to Wayland MIME types. Supported formats: image/bmp, image/png, text/rtf, text/html, plus the existing text types.

Since Windows clipboard provides images as BMP (CF_DIB) but most Linux apps expect image/png, this also adds a BMP-to-PNG conversion path using Cairo. When the source only offers image/bmp, the bridge advertises image/png and converts on the fly.

Tested on WSLg with xclip — TARGETS correctly lists the new formats after copying from Windows.

Fixes microsoft/wslg#236

The XWayland selection bridge only forwarded text (UTF8_STRING/TEXT),
silently dropping all other formats. This meant X11 apps could not
paste images, rich text, or HTML copied from Windows via the RDP
clipboard backend, even though native Wayland apps could.

Add a format mapping table that bridges additional X11 atoms to their
Wayland MIME types: image/bmp, image/png, text/rtf, and text/html.
Rewrite the target advertisement, selection request handling, and
data source send paths to use this table instead of hardcoded checks.

Additionally, implement BMP-to-PNG conversion using Cairo so that
image/png is advertised to X11 apps when the source only provides
image/bmp, since most Linux applications expect PNG for clipboard
images.

Fixes: microsoft/wslg#236
@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented Feb 7, 2026

@microsoft-github-policy-service agree

The BMP-to-PNG conversion branch in weston_wm_handle_selection_request
was unreachable because the generic format table lookup always matched
image_png first. This caused X11 apps to receive empty data when
requesting image/png from a Wayland source that only offered image/bmp.

Move the conversion check before the format table lookup, guarded by
source_offers_mime_type to verify the source actually has image/bmp but
not image/png. Also fix an integer overflow in the BMP row size
calculation by using size_t.
@Iweisc Iweisc force-pushed the xwayland-clipboard-formats branch from 6ffeb40 to 22eeac6 Compare February 7, 2026 14:55
…version

Premultiply RGB by alpha for Cairo ARGB32 format in the 32-bit BMP
path. Use INCR incremental transfer for converted PNGs exceeding
64KB instead of writing the entire buffer in a single
xcb_change_property call which could exceed X11 max request size.
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.

Can't copy an image in Windows and paste it into a X11 app

1 participant