mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add button events to control WebSocket.
This commit is contained in:
parent
f4a4e0152e
commit
7d5ec0190a
@ -38,6 +38,13 @@ func (manager *DesktopManagerCtx) KeyUp(code uint32) error {
|
||||
return xorg.KeyUp(code)
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) ButtonPress(code uint32) error {
|
||||
xorg.ResetKeys()
|
||||
defer xorg.ResetKeys()
|
||||
|
||||
return xorg.ButtonDown(code)
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) KeyPress(codes ...uint32) error {
|
||||
xorg.ResetKeys()
|
||||
defer xorg.ResetKeys()
|
||||
|
@ -79,6 +79,30 @@ func (h *MessageHandlerCtx) controlScroll(session types.Session, payload *messag
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) controlButtonPress(session types.Session, payload *message.ControlButton) error {
|
||||
if err := h.controlRequest(session); err != nil && !errors.Is(err, ErrIsAlreadyTheHost) {
|
||||
return err
|
||||
}
|
||||
|
||||
return h.desktop.ButtonPress(payload.Code)
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) controlButtonDown(session types.Session, payload *message.ControlButton) error {
|
||||
if err := h.controlRequest(session); err != nil && !errors.Is(err, ErrIsAlreadyTheHost) {
|
||||
return err
|
||||
}
|
||||
|
||||
return h.desktop.ButtonDown(payload.Code)
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) controlButtonUp(session types.Session, payload *message.ControlButton) error {
|
||||
if err := h.controlRequest(session); err != nil && !errors.Is(err, ErrIsAlreadyTheHost) {
|
||||
return err
|
||||
}
|
||||
|
||||
return h.desktop.ButtonUp(payload.Code)
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) controlKeyPress(session types.Session, payload *message.ControlKey) error {
|
||||
if err := h.controlRequest(session); err != nil && !errors.Is(err, ErrIsAlreadyTheHost) {
|
||||
return err
|
||||
|
@ -87,6 +87,21 @@ func (h *MessageHandlerCtx) Message(session types.Session, data types.WebSocketM
|
||||
err = utils.Unmarshal(payload, data.Payload, func() error {
|
||||
return h.controlScroll(session, payload)
|
||||
})
|
||||
case event.CONTROL_BUTTONPRESS:
|
||||
payload := &message.ControlButton{}
|
||||
err = utils.Unmarshal(payload, data.Payload, func() error {
|
||||
return h.controlButtonPress(session, payload)
|
||||
})
|
||||
case event.CONTROL_BUTTONDOWN:
|
||||
payload := &message.ControlButton{}
|
||||
err = utils.Unmarshal(payload, data.Payload, func() error {
|
||||
return h.controlButtonDown(session, payload)
|
||||
})
|
||||
case event.CONTROL_BUTTONUP:
|
||||
payload := &message.ControlButton{}
|
||||
err = utils.Unmarshal(payload, data.Payload, func() error {
|
||||
return h.controlButtonUp(session, payload)
|
||||
})
|
||||
case event.CONTROL_KEYPRESS:
|
||||
payload := &message.ControlKey{}
|
||||
err = utils.Unmarshal(payload, data.Payload, func() error {
|
||||
@ -102,6 +117,7 @@ func (h *MessageHandlerCtx) Message(session types.Session, data types.WebSocketM
|
||||
err = utils.Unmarshal(payload, data.Payload, func() error {
|
||||
return h.controlKeyUp(session, payload)
|
||||
})
|
||||
// actions
|
||||
case event.CONTROL_CUT:
|
||||
err = h.controlCut(session)
|
||||
case event.CONTROL_COPY:
|
||||
|
@ -54,6 +54,7 @@ type DesktopManager interface {
|
||||
KeyDown(code uint32) error
|
||||
ButtonUp(code uint32) error
|
||||
KeyUp(code uint32) error
|
||||
ButtonPress(code uint32) error
|
||||
KeyPress(codes ...uint32) error
|
||||
ResetKeys()
|
||||
ScreenConfigurations() map[int]ScreenConfiguration
|
||||
|
@ -32,8 +32,11 @@ const (
|
||||
CONTROL_RELEASE = "control/release"
|
||||
CONTROL_REQUEST = "control/request"
|
||||
// mouse
|
||||
CONTROL_MOVE = "control/move"
|
||||
CONTROL_SCROLL = "control/scroll"
|
||||
CONTROL_MOVE = "control/move"
|
||||
CONTROL_SCROLL = "control/scroll"
|
||||
CONTROL_BUTTONPRESS = "control/buttonpress"
|
||||
CONTROL_BUTTONDOWN = "control/buttondown"
|
||||
CONTROL_BUTTONUP = "control/buttonup"
|
||||
// keyboard
|
||||
CONTROL_KEYPRESS = "control/keypress"
|
||||
CONTROL_KEYDOWN = "control/keydown"
|
||||
|
@ -106,6 +106,10 @@ type ControlPos struct {
|
||||
Y int `json:"y"`
|
||||
}
|
||||
|
||||
type ControlButton struct {
|
||||
Code uint32 `json:"code"`
|
||||
}
|
||||
|
||||
type ControlKey struct {
|
||||
Keysym uint32 `json:"keysym"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user