Skip to content

Native PNG clipboard synchronization from the Linux viewer to official Mac hosts #164

Open

Description

@Zhenqiang-Weng

Requested native behavior

Copying a screenshot/image on Linux and pasting into a Mac application should use the desktop session's clipboard protocol. The user should not need a "Send screenshot" action, a helper/preload switch, a remote terminal, file-transfer permission or a reconnect. This follows the request to replace the workaround in #156 with native viewer support. Clipboard synchronization should respect the existing overall clipboard enable/disable behavior.

Current-main evidence and reproduction

Baseline: 1dad755823a53af2c3b4a3e9b7d93e51a7d85a1e.

  1. Copy a synthetic PNG to the Linux clipboard (image data, not its filename).
  2. Focus the native remote desktop and use the Mac application's Paste menu, or physical GUI/Win+V, to isolate this from the separate Ctrl-to-Command shortcut request.
  3. Expected: an image preview appears in an image-capable scratch document/composer without sending anything.
  4. Current code cannot transfer that image: Window::poll_clipboard tests has_clipboard_text() and calls SDL_GetClipboardText; ClipboardRequest, backend reads/writes and SyncState use String; clipboard_rich::State negotiates only CF_UNICODETEXT and public.utf8-plain-text. An image-only selection is skipped. This limitation is independently visible in the README's text-only clipboard description.

The original Mac image-paste failure was observed on 0.2.45 and the file/terminal workaround was accepted locally. A complete image-transfer test of this current commit has not been performed; the current-main finding above is the explicit text-only implementation, not a claim of a tested image protocol.

Proposed native implementation

  1. Local MIME data: represent clipboard content as typed data (at least text and PNG), and read image bytes through the focused desktop window's native clipboard integration. The current SDL2 clipboard API only exposes text. SDL3 offers SDL_GetClipboardData("image/png", &size) / SDL_SetClipboardData; alternatively a platform backend would need to share the existing window/seat. SDL3 migration would be a separate dependency decision. Do not restore frequent wl-paste calls on GNOME, which previously caused temporary-window/Dock churn ([Bug] v0.2.0 Linux 控制端在 GNOME Wayland 下连接远端后,Dock 图标持续跳动(剪贴板轮询创建临时窗口) #37); a separate GTK Wayland clipboard connection cannot simply be assumed to inherit SDL's focus.
  2. Existing wire channel: extend the current format-list → data-request → confirmation/block exchange over TEXT_DATA_CHANNEL (clipboard RPC request case 9 / response case 5). Keep the desktop connection alive. There is no reason to invoke the file or terminal tools to carry clipboard bytes.
  3. Confirm the official Mac representation: macOS exposes PNG pasteboard data, but that alone does not prove the UU host's accepted format identifier/name or byte representation. With synthetic image data, capture only official format metadata and block/ack sizes, verify the host requests and accepts the image, then add a sanitized protocol fixture. Do not assume that a public.png offer is already known to work; inspect TIFF/DIB conversion requirements if the official peer asks for those instead.
  4. Binary bounds and lifecycle: add a separate image-size budget (keep the text limit), bounded blocks within the negotiated SCTP message size, request/transfer matching, timeout/cancellation on new ownership/disconnect, and no partial pasteboard replacement. Avoid echo loops. Only sizes/status are logged; no clipboard bytes or filenames.
  5. Paste ordering: ensure a newly copied image is offered/ready before forwarding the paste chord, so the Mac does not paste the previous clipboard content. Validate both selection changes and rapid Copy→Paste. The Mac service should populate its native pasteboard; Ctrl/Command mapping remains a separate input concern.

Validation needed for a mergeable implementation

  • Text regression and image-only/mixed MIME selections; empty, invalid and oversized data.
  • Multi-block images, missing/out-of-order/duplicate blocks, stale requests, cancellation and reconnect.
  • GNOME Wayland/XWayland, native X11, and the existing niri backend behavior; no additional visible/toplevel polling windows.
  • Real official Mac host: PNG paste in an image-capable scratch app, immediate Copy→Paste, focus changes and text↔image transitions. Verify remote-to-local separately before claiming bidirectional support.

Primary API references: SDL2 clipboard API, SDL3 arbitrary MIME clipboard data, SDL3 clipboard overview, Apple PNG pasteboard type.

This issue proposes built-in native support and records the remaining backend/protocol work. It does not present the old file/terminal bridge as native clipboard synchronization.

Activity

  1. VallierDev commented on Nov 3, 2026

    @VallierDev
    Owner

    Thanks for the precise pointers. Image clipboard needs the host/viewer clipboard format negotiation for images (format ids/names and payload encoding) to be established from the official clients first; today both directions are text-only, as you found. This is a larger change, so I've queued it for investigation rather than a quick patch.

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions