mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
cursor position bypass desktop module.
This commit is contained in:
parent
66618b9e62
commit
663270b0f5
@ -9,21 +9,8 @@ import (
|
|||||||
"demodesk/neko/internal/types"
|
"demodesk/neko/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: Refactor.
|
|
||||||
var cursorListeners []func(x, y int)
|
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) Move(x, y int) {
|
func (manager *DesktopManagerCtx) Move(x, y int) {
|
||||||
xorg.Move(x, y)
|
xorg.Move(x, y)
|
||||||
|
|
||||||
// TODO: Refactor.
|
|
||||||
for _, listener := range cursorListeners {
|
|
||||||
listener(x, y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Refactor.
|
|
||||||
func (manager *DesktopManagerCtx) OnCursorPosition(listener func(x, y int)) {
|
|
||||||
cursorListeners = append(cursorListeners, listener)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) GetCursorPosition() (int, int) {
|
func (manager *DesktopManagerCtx) GetCursorPosition() (int, int) {
|
||||||
|
@ -48,7 +48,6 @@ type DesktopManager interface {
|
|||||||
|
|
||||||
// xorg
|
// xorg
|
||||||
Move(x, y int)
|
Move(x, y int)
|
||||||
OnCursorPosition(listener func(x, y int))
|
|
||||||
GetCursorPosition() (int, int)
|
GetCursorPosition() (int, int)
|
||||||
Scroll(x, y int)
|
Scroll(x, y int)
|
||||||
ButtonDown(code uint32) error
|
ButtonDown(code uint32) error
|
||||||
|
@ -80,7 +80,7 @@ func (manager *ImageCtx) GetCached(serial uint64) (*ImageEntry, error) {
|
|||||||
return entry, nil
|
return entry, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *ImageCtx) GetCurrent() (*ImageEntry, error) {
|
func (manager *ImageCtx) Get() (*ImageEntry, error) {
|
||||||
if manager.current != nil {
|
if manager.current != nil {
|
||||||
return manager.current, nil
|
return manager.current, nil
|
||||||
}
|
}
|
||||||
|
@ -25,14 +25,6 @@ type PositionCtx struct {
|
|||||||
listeners map[uintptr]*func(x, y int)
|
listeners map[uintptr]*func(x, y int)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *PositionCtx) Start() {
|
|
||||||
manager.desktop.OnCursorPosition(func(x, y int) {
|
|
||||||
for _, emit := range manager.listeners {
|
|
||||||
(*emit)(x, y)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (manager *PositionCtx) Shutdown() {
|
func (manager *PositionCtx) Shutdown() {
|
||||||
manager.logger.Info().Msgf("shutting down")
|
manager.logger.Info().Msgf("shutting down")
|
||||||
|
|
||||||
@ -43,10 +35,16 @@ func (manager *PositionCtx) Shutdown() {
|
|||||||
manager.emitMu.Unlock()
|
manager.emitMu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *PositionCtx) GetCurrent() (x, y int) {
|
func (manager *PositionCtx) Get() (x, y int) {
|
||||||
return manager.desktop.GetCursorPosition()
|
return manager.desktop.GetCursorPosition()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (manager *PositionCtx) Set(x, y int) {
|
||||||
|
for _, emit := range manager.listeners {
|
||||||
|
(*emit)(x, y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (manager *PositionCtx) AddListener(listener *func(x, y int)) {
|
func (manager *PositionCtx) AddListener(listener *func(x, y int)) {
|
||||||
manager.emitMu.Lock()
|
manager.emitMu.Lock()
|
||||||
defer manager.emitMu.Unlock()
|
defer manager.emitMu.Unlock()
|
||||||
|
@ -62,6 +62,7 @@ func (manager *WebRTCManagerCtx) handle(msg webrtc.DataChannelMessage) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
manager.desktop.Move(int(payload.X), int(payload.Y))
|
manager.desktop.Move(int(payload.X), int(payload.Y))
|
||||||
|
manager.curPosition.Set(int(payload.X), int(payload.Y))
|
||||||
case OP_SCROLL:
|
case OP_SCROLL:
|
||||||
payload := &PayloadScroll{}
|
payload := &PayloadScroll{}
|
||||||
if err := binary.Read(buffer, binary.BigEndian, payload); err != nil {
|
if err := binary.Read(buffer, binary.BigEndian, payload); err != nil {
|
||||||
|
@ -86,7 +86,6 @@ func (manager *WebRTCManagerCtx) Start() {
|
|||||||
Msgf("webrtc starting")
|
Msgf("webrtc starting")
|
||||||
|
|
||||||
manager.curImage.Start()
|
manager.curImage.Start()
|
||||||
manager.curPosition.Start()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *WebRTCManagerCtx) Shutdown() error {
|
func (manager *WebRTCManagerCtx) Shutdown() error {
|
||||||
@ -314,7 +313,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
|||||||
manager.curPosition.AddListener(&cursorPosition)
|
manager.curPosition.AddListener(&cursorPosition)
|
||||||
|
|
||||||
// send initial cursor image
|
// send initial cursor image
|
||||||
entry, err := manager.curImage.GetCurrent()
|
entry, err := manager.curImage.Get()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
cursorImage(entry)
|
cursorImage(entry)
|
||||||
} else {
|
} else {
|
||||||
@ -322,7 +321,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send initial cursor position
|
// send initial cursor position
|
||||||
x, y := manager.curPosition.GetCurrent()
|
x, y := manager.curPosition.Get()
|
||||||
cursorPosition(x, y)
|
cursorPosition(x, y)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user