xevent cursor change.

This commit is contained in:
Miroslav Šedivý 2021-01-10 15:58:17 +01:00
parent 0f19b6ed57
commit 910f0af995
4 changed files with 39 additions and 16 deletions

View File

@ -11,6 +11,7 @@ import (
"demodesk/neko/internal/config"
"demodesk/neko/internal/desktop/xorg"
"demodesk/neko/internal/desktop/xevent"
)
var mu = sync.Mutex{}
@ -50,6 +51,8 @@ func (manager *DesktopManagerCtx) Start() {
manager.logger.Warn().Err(err).Msg("unable to set initial screen size")
}
go xevent.EventLoop(manager.display)
go func() {
defer func() {
xorg.DisplayClose()

View File

@ -0,0 +1,13 @@
package desktop
import (
"demodesk/neko/internal/desktop/xevent"
)
func (manager *DesktopManagerCtx) OnCursorChanged(listener func(serial uint64)) {
xevent.OnCursorChanged(listener)
}
func (manager *DesktopManagerCtx) OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8)) {
xevent.OnEventError(listener)
}

View File

@ -42,6 +42,10 @@ type DesktopManager interface {
SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int)
GetCursorImage() *CursorImage
// xevent
OnCursorChanged(listener func(serial uint64))
OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8))
// clipboard
ReadClipboard() string
WriteClipboard(data string)

View File

@ -99,6 +99,25 @@ func (ws *WebSocketManagerCtx) Start() {
}
})
// TOOD: Throttle events.
ws.desktop.OnCursorChanged(func(serial uint64) {
cur := ws.desktop.GetCursorImage()
uri, err := utils.GetCursorImageURI(cur)
if err != nil {
ws.logger.Warn().Err(err).Msg("could create cursor image")
return
}
ws.sessions.Broadcast(message.CursorImage{
Event: event.CURSOR_IMAGE,
Uri: uri,
Width: cur.Width,
Height: cur.Height,
X: cur.Xhot,
Y: cur.Yhot,
}, nil)
})
go func() {
ws.logger.Info().Msg("clipboard loop started")
@ -107,28 +126,12 @@ func (ws *WebSocketManagerCtx) Start() {
}()
current := ws.desktop.ReadClipboard()
cursor := uint64(0)
for {
select {
case <-ws.shutdown:
return
default:
cur := ws.desktop.GetCursorImage()
if cursor != cur.Serial || cur.Serial == 0 {
cursor = cur.Serial
uri, _ := utils.GetCursorImageURI(cur)
ws.sessions.Broadcast(message.CursorImage{
Event: event.CURSOR_IMAGE,
Uri: uri,
Width: cur.Width,
Height: cur.Height,
X: cur.Xhot,
Y: cur.Yhot,
}, nil)
}
session := ws.sessions.GetHost()
if session == nil {
break