Skip to content

Windows: copy and paste images through the Windows clipboard; show a second window - #170

Merged
danjboyd merged 1 commit into
mainfrom
windows-clipboard-images
Oct 12, 2026
Merged

danjboyd merged 1 commit into
mainfrom
windows-clipboard-images

Conversation

@danjboyd

@danjboyd danjboyd commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Fixes #168 and #169: two gaps in the Windows workflow audit. Both are in released builds.

#168: images don't cross the Windows clipboard.
GNUstep's gpbs bridges only text (gnustep/libs-back#246 would fix it, but the MSI uses MSYS2's stock gnustep-back). On Windows the app now uses the clipboard itself, through the new STWindowsIntegration.

  • Copy writes the registered PNG format (Office, browsers and Teams keep transparency) and a 32-bit CF_DIB for Paint and the rest. It doesn't write the pasteboard as well: that would make gpbs empty the clipboard and offer it as text.
  • Paste, Paste as New Image and Take Screenshot:
    • read PNG if it's there;
    • otherwise read the bitmap, drawn by GDI so any depth, palette or bitfields DIB works;
    • also accept image files copied in Explorer (CF_HDROP).
  • Elsewhere: off Windows nothing changes. The functions return NO or nil there, and tests that substitute their own pasteboard keep it.

#169: a second window never showed.
NSTask starts processes with SW_HIDE on Windows. So the instance started by Paste as New Image, or by Take Screenshot over an open image, loaded its image and stayed invisible.

  • On Windows it's now started with CreateProcessW instead.
  • On all GNUstep platforms, an empty window takes a pasted image itself, as Take Screenshot already did, rather than being left beside a new instance.

Verified on Windows 11 (WinUITheme, dev build)

  • Windows → app: a bitmap copied by another process enables the empty state's Paste, and pastes in place with the right colors.
  • App → Windows: after Copy, the clipboard holds PNG and DeviceIndependentBitmap, and Windows adds Bitmap and DIBV5 itself. Both decode to the image; the bitmap was all black until the conversion stopped going through drawing.
  • Paste as New Image over an open image: the new instance's window is visible.
  • Tests:
    • New WindowsIntegrationProbeTests (9 tests, Windows only): DIB out (alpha, RGB), a round trip, 24-bit, top-down bitfields and 8-bit palette DIBs in, a truncated DIB refused, and command-line quoting checked against CommandLineToArgvW. They don't touch the real clipboard.
    • New testAnEmptyWindowTakesThePastedImageItself.
    • Full suite on Windows: all classes pass, with the same 4 skips as before.
  • Not done here: the Snipping Tool overlay itself (it needs a person to drag), and the Linux and macOS builds. The non-Windows side is a stub plus the empty-window change.

🤖 Generated with Claude Code

https://claude.ai/code/session_019pvjXondXhjkzNDjySCxP5

…second window

GNUstep's pasteboard server bridges only text to the Windows clipboard, so a
copied image never reached other apps, and an image they copied, the Snipping
Tool's snip included, never reached the app (#168). On Windows the app now
reads and writes the clipboard itself (STWindowsIntegration):
- Copy puts PNG and a 32-bit bitmap there, and not on the pasteboard, which
  would make gpbs take the clipboard back as text.
- Paste reads PNG, else a bitmap of any depth via GDI, and the files Explorer
  copies.

NSTask starts a process hidden on Windows, so the instance that Paste as New
Image or Take Screenshot started never showed its window (#169). It is now
started with CreateProcessW. An empty window takes a pasted image itself, as
it already did a screenshot, rather than being left beside a new instance.

Fixes #168
Fixes #169

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019pvjXondXhjkzNDjySCxP5
@danjboyd
danjboyd merged commit e783eae into main Oct 12, 2026
3 checks passed
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.

Windows: images don't copy or paste between ScreenshotTool and other apps

1 participant