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/config"
"demodesk/neko/internal/desktop/xorg" "demodesk/neko/internal/desktop/xorg"
"demodesk/neko/internal/desktop/xevent"
) )
var mu = sync.Mutex{} var mu = sync.Mutex{}
@ -50,6 +51,8 @@ func (manager *DesktopManagerCtx) Start() {
manager.logger.Warn().Err(err).Msg("unable to set initial screen size") manager.logger.Warn().Err(err).Msg("unable to set initial screen size")
} }
go xevent.EventLoop(manager.display)
go func() { go func() {
defer func() { defer func() {
xorg.DisplayClose() 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) SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int)
GetCursorImage() *CursorImage GetCursorImage() *CursorImage
// xevent
OnCursorChanged(listener func(serial uint64))
OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8))
// clipboard // clipboard
ReadClipboard() string ReadClipboard() string
WriteClipboard(data string) WriteClipboard(data string)

View File

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