-
-
Notifications
You must be signed in to change notification settings - Fork 219
/
clipboard.go
34 lines (30 loc) · 901 Bytes
/
clipboard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package sdl
// #include "sdl_wrapper.h"
import "C"
import "unsafe"
// SetClipboardText puts UTF-8 text into the clipboard.
// (https://wiki.libsdl.org/SDL_SetClipboardText)
func SetClipboardText(text string) error {
_text := C.CString(text)
defer C.free(unsafe.Pointer(_text))
if C.SDL_SetClipboardText(_text) < 0 {
return GetError()
}
return nil
}
// GetClipboardText returns UTF-8 text from the clipboard.
// (https://wiki.libsdl.org/SDL_GetClipboardText)
func GetClipboardText() (string, error) {
text := C.SDL_GetClipboardText()
if text == nil {
return "", GetError()
}
defer C.SDL_free(unsafe.Pointer(text))
_text := C.GoString(text)
return _text, nil
}
// HasClipboardText reports whether the clipboard exists and contains a text string that is non-empty.
// (https://wiki.libsdl.org/SDL_HasClipboardText)
func HasClipboardText() bool {
return C.SDL_HasClipboardText() > 0
}