mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
broadcast cursor position via WebSockets.
This commit is contained in:
parent
e8286dec96
commit
f22922191a
@ -9,8 +9,16 @@ import (
|
||||
"demodesk/neko/internal/desktop/xorg"
|
||||
)
|
||||
|
||||
var mousePosX int
|
||||
var mousePosY int
|
||||
|
||||
func (manager *DesktopManagerCtx) Move(x, y int) {
|
||||
xorg.Move(x, y)
|
||||
mousePosX, mousePosY = x, y
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) GetMousePositon() (x, y int) {
|
||||
return mousePosX, mousePosY
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) Scroll(x, y int) {
|
||||
|
@ -48,6 +48,7 @@ type DesktopManager interface {
|
||||
|
||||
// xorg
|
||||
Move(x, y int)
|
||||
GetMousePositon() (x, y int)
|
||||
Scroll(x, y int)
|
||||
ButtonDown(code int) error
|
||||
KeyDown(code uint64) error
|
||||
|
@ -47,7 +47,8 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
CURSOR_IMAGE = "cursor/image"
|
||||
CURSOR_IMAGE = "cursor/image"
|
||||
CURSOR_POSITION = "cursor/position"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -172,6 +172,13 @@ type CursorImage struct {
|
||||
Y uint16 `json:"y"`
|
||||
}
|
||||
|
||||
type CursorPosition struct {
|
||||
Event string `json:"event,omitempty"`
|
||||
MemberId string `json:"member_id"`
|
||||
X uint16 `json:"x"`
|
||||
Y uint16 `json:"y"`
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// Broadcast
|
||||
/////////////////////////////
|
||||
|
@ -41,6 +41,7 @@ type WebSocketManagerCtx struct {
|
||||
desktop types.DesktopManager
|
||||
handler *handler.MessageHandlerCtx
|
||||
handlers []types.HandlerFunction
|
||||
shutdown chan bool
|
||||
}
|
||||
|
||||
func (ws *WebSocketManagerCtx) Start() {
|
||||
@ -133,9 +134,51 @@ func (ws *WebSocketManagerCtx) Start() {
|
||||
})
|
||||
|
||||
ws.fileChooserDialogEvents()
|
||||
|
||||
go func() {
|
||||
ws.logger.Debug().Msg("cursor position broadcast start")
|
||||
|
||||
defer func() {
|
||||
ws.logger.Debug().Msg("cursor position broadcast shutdown")
|
||||
}()
|
||||
|
||||
var posX int
|
||||
var posY int
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ws.shutdown:
|
||||
return
|
||||
default:
|
||||
time.Sleep(40 * time.Millisecond)
|
||||
|
||||
session := ws.sessions.GetHost()
|
||||
if session == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
x, y := ws.desktop.GetMousePositon()
|
||||
if posX == x && posY == y {
|
||||
continue
|
||||
}
|
||||
|
||||
memberId := session.ID()
|
||||
posX = x
|
||||
posY = y
|
||||
|
||||
ws.sessions.Broadcast(message.CursorPosition{
|
||||
Event: event.CURSOR_POSITION,
|
||||
MemberId: memberId,
|
||||
X: uint16(x),
|
||||
Y: uint16(y),
|
||||
}, []string{ memberId })
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (ws *WebSocketManagerCtx) Shutdown() error {
|
||||
ws.shutdown <- true
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user