Archived
2
0

libclipboard

This commit is contained in:
Craig
2020-02-02 22:48:23 +00:00
parent 7253b5ac62
commit ed6f6f5a93
10 changed files with 103 additions and 146 deletions

View File

@ -0,0 +1,23 @@
#include "clip.h"
#include <libclipboard.h>
#include <string.h>
clipboard_c *CLIPBOARD = NULL;
clipboard_c *getClipboard(void) {
if (CLIPBOARD == NULL) {
CLIPBOARD = clipboard_new(NULL);
}
return CLIPBOARD;
}
void set_clipboard(char *src) {
clipboard_c *cb = getClipboard();
clipboard_set_text_ex(cb, src, strlen(src), 0);
}
char * get_clipboard() {
clipboard_c *cb = getClipboard();
return clipboard_text_ex(cb, NULL, 0);
}

View File

@ -0,0 +1,21 @@
// NOTE: I have no fucking clue what I'm doing with this,
// it works, but I am positive I'm doing this very wrong...
// should I be freeing these strings? does go cg them?
// pretty sure this *isn't* thread safe either.... /shrug
package clip
/*
#cgo linux LDFLAGS: -lclipboard
#include "clip.h"
*/
import "C"
func Read() string {
return C.GoString(C.get_clipboard())
}
func Write(data string) {
C.set_clipboard(C.CString(data))
}

View File

@ -0,0 +1,5 @@
#include <libclipboard.h>
clipboard_c *getClipboard(void);
void set_clipboard(char *src);
char * get_clipboard();