mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
36 lines
540 B
Go
36 lines
540 B
Go
package clipboard
|
|
|
|
/*
|
|
#cgo linux LDFLAGS: /usr/local/lib/libclipboard.a -lxcb
|
|
|
|
#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)
|
|
}
|