mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
clipboard set for control paste.
This commit is contained in:
parent
49ff490640
commit
d5425ea457
@ -7,6 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitlab.com/demodesk/neko/server/pkg/types"
|
"gitlab.com/demodesk/neko/server/pkg/types"
|
||||||
|
"gitlab.com/demodesk/neko/server/pkg/xevent"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) ClipboardGetText() (*types.ClipboardText, error) {
|
func (manager *DesktopManagerCtx) ClipboardGetText() (*types.ClipboardText, error) {
|
||||||
@ -63,6 +64,13 @@ func (manager *DesktopManagerCtx) ClipboardSetBinary(mime string, data []byte) e
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Refactor.
|
||||||
|
// We need to wait until the data came to the clipboard.
|
||||||
|
wait := make(chan struct{})
|
||||||
|
xevent.Emmiter.Once("clipboard-updated", func(payload ...interface{}) {
|
||||||
|
wait <- struct{}{}
|
||||||
|
})
|
||||||
|
|
||||||
err = cmd.Start()
|
err = cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := strings.TrimSpace(stderr.String())
|
msg := strings.TrimSpace(stderr.String())
|
||||||
@ -78,6 +86,8 @@ func (manager *DesktopManagerCtx) ClipboardSetBinary(mime string, data []byte) e
|
|||||||
|
|
||||||
// TODO: Refactor.
|
// TODO: Refactor.
|
||||||
// cmd.Wait()
|
// cmd.Wait()
|
||||||
|
<-wait
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,11 +99,18 @@ func (h *MessageHandlerCtx) controlCopy(session types.Session) error {
|
|||||||
return h.desktop.KeyPress(xorg.XK_Control_L, xorg.XK_c)
|
return h.desktop.KeyPress(xorg.XK_Control_L, xorg.XK_c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandlerCtx) controlPaste(session types.Session) error {
|
func (h *MessageHandlerCtx) controlPaste(session types.Session, payload *message.ClipboardData) error {
|
||||||
if err := h.controlRequest(session); err != nil && !errors.Is(err, ErrIsAlreadyTheHost) {
|
if err := h.controlRequest(session); err != nil && !errors.Is(err, ErrIsAlreadyTheHost) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if there have been set clipboard data, set them first
|
||||||
|
if payload != nil && payload.Text != "" {
|
||||||
|
if err := h.clipboardSet(session, payload); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return h.desktop.KeyPress(xorg.XK_Control_L, xorg.XK_v)
|
return h.desktop.KeyPress(xorg.XK_Control_L, xorg.XK_v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,10 @@ func (h *MessageHandlerCtx) Message(session types.Session, data types.WebSocketM
|
|||||||
case event.CONTROL_COPY:
|
case event.CONTROL_COPY:
|
||||||
err = h.controlCopy(session)
|
err = h.controlCopy(session)
|
||||||
case event.CONTROL_PASTE:
|
case event.CONTROL_PASTE:
|
||||||
err = h.controlPaste(session)
|
payload := &message.ClipboardData{}
|
||||||
|
err = utils.Unmarshal(payload, data.Payload, func() error {
|
||||||
|
return h.controlPaste(session, payload)
|
||||||
|
})
|
||||||
case event.CONTROL_SELECT_ALL:
|
case event.CONTROL_SELECT_ALL:
|
||||||
err = h.controlSelectAll(session)
|
err = h.controlSelectAll(session)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user