Skip to content

fix(macos): fix clipboard copy failing from tray and GUI#4629

Open
Mitnitsky wants to merge 1 commit intoflameshot-org:masterfrom
Mitnitsky:vmitnitsky/fix_macos_clipboard
Open

fix(macos): fix clipboard copy failing from tray and GUI#4629
Mitnitsky wants to merge 1 commit intoflameshot-org:masterfrom
Mitnitsky:vmitnitsky/fix_macos_clipboard

Conversation

@Mitnitsky
Copy link
Copy Markdown
Contributor

@Mitnitsky Mitnitsky commented Apr 7, 2026

Problem

Copying screenshots to clipboard on macOS was broken in two ways:

  1. 3-second delay + clipboard empty: copyToClipboard() created a
    KDSingleApplication instance and called isPrimaryInstance(), which
    always returned false because the daemon already holds the socket.
    This triggered IPC message delivery instead of using the in-process
    daemon directly. The IPC timed out after ~3 seconds and clipboard was
    never set.

  2. Lazy clipboard data lost on exit: setData("image/png") puts a
    lazy reference on the macOS pasteboard — if the process exits before
    paste, data is lost ("Cannot keep promise"). The separate
    saveJpegToClipboardMacOS() workaround used osascript with a temp
    file and incorrectly declared JPEG data as PNG UTI («class PNGf»).

Fix

  • Remove the isPrimaryInstance() check on macOS — use instance() to
    check if the daemon singleton exists in-process, matching non-macOS
    behavior. IPC fallback is preserved for true secondary processes (CLI).
  • Add macOS branch in saveToClipboardMime() using setImageData(QImage)
    for native pasteboard persistence (public.tiff) plus setData() for
    exact format availability (PNG or JPEG).
  • Delete saveJpegToClipboardMacOS() entirely — the fixed
    saveToClipboardMime() now handles both formats correctly.

All changes are guarded with #if defined(Q_OS_MACOS). The Linux, Windows,
and Wayland clipboard paths are unchanged.

Testing

Tested on macOS 26.4 (Tahoe), Apple Silicon, Qt 6.11.0:

  • Tray menu Ctrl+C: clipboard set instantly (was 3s delay + empty)
  • CLI flameshot full --clipboard: works via IPC fallback
  • Both JPEG and PNG modes verified with `osascript -e 'clipboard info'

closes #4630

@borgmanJeremy
Copy link
Copy Markdown
Collaborator

This worked well and can be merged after addressing clang-format. The bug was introduced here. I am not sure why I didn't catch it in original testing: #4473

The clipboard copy from tray menu and capture GUI was broken on macOS:

1. FlameshotDaemon::copyToClipboard() created a KDSingleApplication
   instance and called isPrimaryInstance(), which always returned false
   (the daemon already holds the socket). This caused a 3-second IPC
   timeout before falling back. Fix: use instance() to check if the
   daemon singleton exists in-process, matching non-macOS behavior.

2. saveToClipboardMime() used setData("image/...") which puts a lazy
   reference on the macOS pasteboard. If the app exits before paste,
   data is lost ("Cannot keep promise"). Fix: use setImageData() for
   native pasteboard persistence, plus setData() for exact format.

3. saveJpegToClipboardMacOS() used osascript with a temp file and
   incorrectly labeled JPEG data as PNG UTI. Removed entirely — the
   fixed saveToClipboardMime() now handles both JPEG and PNG.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Mitnitsky Mitnitsky force-pushed the vmitnitsky/fix_macos_clipboard branch from 04ff785 to f6c61b1 Compare April 8, 2026 07:05
@Mitnitsky
Copy link
Copy Markdown
Contributor Author

Addressed the clang-format, should pass now

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.

[MacOS-ARM64]: Image is not saved in clipboard

2 participants