neko/internal/desktop/clipboard/clipboard.go

36 lines
540 B
Go
Raw Normal View History

2020-11-02 04:09:48 +13:00
package clipboard
/*
2021-01-12 03:57:14 +13:00
#cgo linux LDFLAGS: /usr/local/lib/libclipboard.a -lxcb
2020-11-02 04:09:48 +13:00
#include "clipboard.h"
*/
import "C"
import (
"sync"
"unsafe"
)
var mu = sync.Mutex{}
func ReadClipboard() string {
mu.Lock()
defer mu.Unlock()
clipboardUnsafe := C.ClipboardGet()
defer C.free(unsafe.Pointer(clipboardUnsafe))
return C.GoString(clipboardUnsafe)
}
func WriteClipboard(data string) {
mu.Lock()
defer mu.Unlock()
clipboardUnsafe := C.CString(data)
defer C.free(unsafe.Pointer(clipboardUnsafe))
C.ClipboardSet(clipboardUnsafe)
}