Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/windy/platforms/emscripten/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,14 @@ proc getClipboardString*(): string =
"getClipboardString is not supported on emscripten"
)

proc getClipboardContentKinds*(): set[ClipboardContentKind] =
## Image clipboard is not implemented on Emscripten yet.
discard

proc getClipboardImage*(): Image =
## Image clipboard is not implemented on Emscripten yet.
nil

proc closeIme*(window: Window) =
if window.state.imeCompositionString.len > 0:
window.state.imeCompositionString = ""
Expand Down
8 changes: 8 additions & 0 deletions src/windy/platforms/linux/x11.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,14 @@ proc setClipboardString*(s: string) =
clipboardContent = s
display.XSetSelectionOwner(xaClipboard, clipboardWindow)

proc getClipboardContentKinds*(): set[ClipboardContentKind] =
## Image clipboard is not implemented on X11 yet.
discard

proc getClipboardImage*(): Image =
## Image clipboard is not implemented on X11 yet.
nil

proc pollEvents*() =
for window in windows:
if window.onFrame != nil:
Expand Down
1 change: 1 addition & 0 deletions src/windy/platforms/macos/macdefs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ var
NSApp* {.importc.}: NSApplication
NSPasteboardTypeString* {.importc.}: NSPasteboardType
NSPasteboardTypeTIFF* {.importc.}: NSPasteboardType
NSPasteboardTypePNG* {.importc.}: NSPasteboardType
NSFilenamesPboardType* {.importc.}: NSPasteboardType
NSDefaultRunLoopMode* {.importc.}: NSRunLoopMode

Expand Down
12 changes: 11 additions & 1 deletion src/windy/platforms/macos/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1305,10 +1305,12 @@ proc getClipboardContentKinds*(): set[ClipboardContentKind] =

if types.containsObject(NSPasteboardTypeString.ID):
result.incl TextContent
if types.containsObject(NSPasteboardTypeTIFF.ID):
if types.containsObject(NSPasteboardTypePNG.ID) or
types.containsObject(NSPasteboardTypeTIFF.ID):
result.incl ImageContent

proc getClipboardImage*(): Image =
## Reads a PNG or TIFF image from the system pasteboard.
init()
autoreleasepool:
let
Expand All @@ -1318,6 +1320,14 @@ proc getClipboardImage*(): Image =
if types.int == 0:
return

if types.containsObject(NSPasteboardTypePNG.ID):
let data = pboard.dataForType(NSPasteboardTypePNG)
if data.int != 0:
try:
return decodePng(data.bytes, data.length.int).convertToImage()
except:
discard

if not types.containsObject(NSPasteboardTypeTIFF.ID):
return

Expand Down
Loading