mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
replace libclipboard with xclip.
This commit is contained in:
parent
ced0a89bbe
commit
11e74459ac
16
Dockerfile
16
Dockerfile
@ -11,17 +11,7 @@ RUN set -eux; \
|
||||
apt-get update; \
|
||||
apt-get install -y --no-install-recommends \
|
||||
libx11-dev libxrandr-dev libxtst-dev libgtk-3-dev \
|
||||
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
|
||||
git cmake make; \
|
||||
#
|
||||
# install libclipboard
|
||||
cd /tmp; \
|
||||
git clone https://github.com/jtanx/libclipboard; \
|
||||
cd libclipboard; \
|
||||
cmake .; \
|
||||
make -j`nproc`; \
|
||||
make install; \
|
||||
rm -rf /tmp/libclipboard; \
|
||||
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev; \
|
||||
#
|
||||
# clean up
|
||||
apt-get clean -y; \
|
||||
@ -53,8 +43,8 @@ RUN set -eux; \
|
||||
pulseaudio dbus-x11 xserver-xorg-video-dummy xserver-xorg-input-void \
|
||||
libcairo2 libxcb1 libxrandr2 libxv1 libopus0 libvpx5 \
|
||||
#
|
||||
# file chooser handler
|
||||
xdotool \
|
||||
# file chooser handler, clipboard
|
||||
xdotool xclip \
|
||||
#
|
||||
# gst
|
||||
gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
|
||||
|
@ -11,8 +11,11 @@ type ClipboardPayload struct {
|
||||
}
|
||||
|
||||
func (h *RoomHandler) clipboardRead(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO: error check?
|
||||
text := h.desktop.ReadClipboard()
|
||||
text, err := h.desktop.ReadClipboard()
|
||||
if err != nil {
|
||||
utils.HttpInternalServerError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
utils.HttpSuccess(w, ClipboardPayload{
|
||||
Text: text,
|
||||
@ -25,7 +28,11 @@ func (h *RoomHandler) clipboardWrite(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: error check?
|
||||
h.desktop.WriteClipboard(data.Text)
|
||||
err := h.desktop.WriteClipboard(data.Text)
|
||||
if err != nil {
|
||||
utils.HttpInternalServerError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
utils.HttpSuccess(w)
|
||||
}
|
||||
|
@ -1,13 +1,17 @@
|
||||
package desktop
|
||||
|
||||
import (
|
||||
"demodesk/neko/internal/desktop/clipboard"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (manager *DesktopManagerCtx) ReadClipboard() string {
|
||||
return clipboard.ReadClipboard()
|
||||
func (manager *DesktopManagerCtx) ReadClipboard() (string, error) {
|
||||
out, err := exec.Command("xclip", "-selection", "clipboard", "-o").Output()
|
||||
return string(out), err
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) WriteClipboard(data string) {
|
||||
clipboard.WriteClipboard(data)
|
||||
func (manager *DesktopManagerCtx) WriteClipboard(data string) error {
|
||||
cmd := exec.Command("xclip", "-selection", "clipboard", "-i")
|
||||
cmd.Stdin = strings.NewReader(data)
|
||||
return cmd.Run()
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
#include "clipboard.h"
|
||||
|
||||
static clipboard_c *CLIPBOARD = NULL;
|
||||
|
||||
clipboard_c *getClipboard(void) {
|
||||
if (CLIPBOARD == NULL) {
|
||||
CLIPBOARD = clipboard_new(NULL);
|
||||
}
|
||||
|
||||
return CLIPBOARD;
|
||||
}
|
||||
|
||||
void ClipboardSet(char *src) {
|
||||
clipboard_c *cb = getClipboard();
|
||||
clipboard_set_text_ex(cb, src, strlen(src), 0);
|
||||
}
|
||||
|
||||
char *ClipboardGet() {
|
||||
clipboard_c *cb = getClipboard();
|
||||
return clipboard_text_ex(cb, NULL, 0);
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <libclipboard.h>
|
||||
#include <string.h>
|
||||
|
||||
clipboard_c *getClipboard(void);
|
||||
|
||||
void ClipboardSet(char *src);
|
||||
char *ClipboardGet();
|
@ -67,8 +67,8 @@ type DesktopManager interface {
|
||||
OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8))
|
||||
|
||||
// clipboard
|
||||
ReadClipboard() string
|
||||
WriteClipboard(data string)
|
||||
ReadClipboard() (string, error)
|
||||
WriteClipboard(data string) error
|
||||
|
||||
// drop
|
||||
DropFiles(x int, y int, files []string) bool
|
||||
|
@ -16,6 +16,5 @@ func (h *MessageHandlerCtx) clipboardSet(session types.Session, payload *message
|
||||
return nil
|
||||
}
|
||||
|
||||
h.desktop.WriteClipboard(payload.Text)
|
||||
return nil
|
||||
return h.desktop.WriteClipboard(payload.Text)
|
||||
}
|
||||
|
@ -117,13 +117,15 @@ func (ws *WebSocketManagerCtx) Start() {
|
||||
return
|
||||
}
|
||||
|
||||
text := ws.desktop.ReadClipboard()
|
||||
err := session.Send(message.ClipboardData{
|
||||
text, err := ws.desktop.ReadClipboard()
|
||||
if err != nil {
|
||||
ws.logger.Warn().Err(err).Msg("could not get clipboard content")
|
||||
}
|
||||
|
||||
if err := session.Send(message.ClipboardData{
|
||||
Event: event.CLIPBOARD_UPDATED,
|
||||
Text: text,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
}); err != nil {
|
||||
ws.logger.Warn().Err(err).Msg("could not sync clipboard")
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user