forked from go-gl/glfw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clipboard.go
36 lines (30 loc) · 909 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
35
36
package glfw3
//#include <stdlib.h>
//#include <GLFW/glfw3.h>
import "C"
import (
"errors"
"unsafe"
)
//SetClipboardString sets the system clipboard to the specified UTF-8 encoded
//string.
//
//This function may only be called from the main thread. See
//https://code.google.com/p/go-wiki/wiki/LockOSThread
func (w *Window) SetClipboardString(str string) {
cp := C.CString(str)
defer C.free(unsafe.Pointer(cp))
C.glfwSetClipboardString(w.data, cp)
}
//GetClipboardString returns the contents of the system clipboard, if it
//contains or is convertible to a UTF-8 encoded string.
//
//This function may only be called from the main thread. See
//https://code.google.com/p/go-wiki/wiki/LockOSThread
func (w *Window) GetClipboardString() (string, error) {
cs := C.glfwGetClipboardString(w.data)
if cs == nil {
return "", errors.New("Can't get clipboard string.")
}
return C.GoString(cs), nil
}