mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
xevent cursor change.
This commit is contained in:
parent
0f19b6ed57
commit
910f0af995
@ -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()
|
||||
|
13
internal/desktop/xevent.go
Normal file
13
internal/desktop/xevent.go
Normal 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)
|
||||
}
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user