func GetClipboardContents() []string {
	n := 0
	files := C.get_clipboard_content((*C.int)(unsafe.Pointer(&n)))
	defer C.freeStrv(unsafe.Pointer(files))

	if n <= 0 {
		return []string{}
	}

	// files is NULL terminal array, the last element is useless.
	// the first content is op.
	return convertToGoStrings(files, n)
}
Пример #2
0
// GetClipboardContent returns the contents of the system clipboard, if it
// contains or is convertible to a UTF-8 encoded string, image, and/or files.
//
// This function may only be called from the main thread.
func GetClipboardContent() (ClipboardContent, error) {
	var cc ClipboardContent

	ccc := C.get_clipboard_content()
	if ccc.text != nil {
		cc.Text = C.GoString(ccc.text)
	}
	if ccc.image.kind != nil {
		cc.Image = Image{
			Kind:  ImageKind(C.GoString(ccc.image.kind)),
			Bytes: C.GoBytes(ccc.image.bytes, ccc.image.length),
		}
	}
	if ccc.files.count > 0 {
		cc.Files = make([]string, int(ccc.files.count))
		for i := 0; i < int(ccc.files.count); i++ {
			var x *C.char
			p := (**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(ccc.files.names)) + uintptr(i)*unsafe.Sizeof(x)))
			cc.Files[i] = C.GoString(*p)
		}
	}

	return cc, nil
}