mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
[v3] move linux clipboard logic to linux_cgo
This commit is contained in:
@@ -2,29 +2,8 @@
|
||||
|
||||
package application
|
||||
|
||||
/*
|
||||
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0
|
||||
|
||||
#include "gtk/gtk.h"
|
||||
#include "webkit2/webkit2.h"
|
||||
|
||||
static gchar* getClipboardText() {
|
||||
GtkClipboard *clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
|
||||
return gtk_clipboard_wait_for_text(clip);
|
||||
}
|
||||
|
||||
static void setClipboardText(gchar* text) {
|
||||
GtkClipboard *clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
|
||||
gtk_clipboard_set_text(clip, text, -1);
|
||||
|
||||
clip = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
|
||||
gtk_clipboard_set_text(clip, text, -1);
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"sync"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var clipboardLock sync.RWMutex
|
||||
@@ -34,18 +13,14 @@ type linuxClipboard struct{}
|
||||
func (m linuxClipboard) setText(text string) bool {
|
||||
clipboardLock.Lock()
|
||||
defer clipboardLock.Unlock()
|
||||
cText := C.CString(text)
|
||||
C.setClipboardText(cText)
|
||||
C.free(unsafe.Pointer(cText))
|
||||
clipboardSet(text)
|
||||
return true
|
||||
}
|
||||
|
||||
func (m linuxClipboard) text() (string, bool) {
|
||||
clipboardLock.RLock()
|
||||
defer clipboardLock.RUnlock()
|
||||
clipboardText := C.getClipboardText()
|
||||
result := C.GoString(clipboardText)
|
||||
return result, true
|
||||
return clipboardGet(), true
|
||||
}
|
||||
|
||||
func newClipboardImpl() *linuxClipboard {
|
||||
|
||||
@@ -273,6 +273,23 @@ func showAllWindows(application pointer) {
|
||||
}
|
||||
}
|
||||
|
||||
// Clipboard
|
||||
func clipboardGet() string {
|
||||
clip := C.gtk_clipboard_get(C.GDK_SELECTION_CLIPBOARD)
|
||||
text := C.gtk_clipboard_wait_for_text(clip)
|
||||
return C.GoString(text)
|
||||
}
|
||||
|
||||
func clipboardSet(text string) {
|
||||
cText := C.CString(text)
|
||||
clip := C.gtk_clipboard_get(C.GDK_SELECTION_CLIPBOARD)
|
||||
C.gtk_clipboard_set_text(clip, cText, -1)
|
||||
|
||||
clip = C.gtk_clipboard_get(C.GDK_SELECTION_PRIMARY)
|
||||
C.gtk_clipboard_set_text(clip, cText, -1)
|
||||
C.free(unsafe.Pointer(cText))
|
||||
}
|
||||
|
||||
// Menu
|
||||
func menuAddSeparator(menu *Menu) {
|
||||
C.gtk_menu_shell_append(
|
||||
|
||||
Reference in New Issue
Block a user