keysym as uint32.

This commit is contained in:
Miroslav Šedivý 2021-02-23 21:25:55 +01:00
parent 8f2639412d
commit dc29f71b0c
5 changed files with 53 additions and 53 deletions

View File

@ -34,19 +34,19 @@ func (manager *DesktopManagerCtx) Scroll(x, y int) {
xorg.Scroll(x, y) xorg.Scroll(x, y)
} }
func (manager *DesktopManagerCtx) ButtonDown(code int) error { func (manager *DesktopManagerCtx) ButtonDown(code uint32) error {
return xorg.ButtonDown(code) return xorg.ButtonDown(code)
} }
func (manager *DesktopManagerCtx) KeyDown(code uint64) error { func (manager *DesktopManagerCtx) KeyDown(code uint32) error {
return xorg.KeyDown(code) return xorg.KeyDown(code)
} }
func (manager *DesktopManagerCtx) ButtonUp(code int) error { func (manager *DesktopManagerCtx) ButtonUp(code uint32) error {
return xorg.ButtonUp(code) return xorg.ButtonUp(code)
} }
func (manager *DesktopManagerCtx) KeyUp(code uint64) error { func (manager *DesktopManagerCtx) KeyUp(code uint32) error {
return xorg.KeyUp(code) return xorg.KeyUp(code)
} }

View File

@ -28,8 +28,8 @@ const (
var ScreenConfigurations = make(map[int]types.ScreenConfiguration) var ScreenConfigurations = make(map[int]types.ScreenConfiguration)
var debounce_button = make(map[int]time.Time) var debounce_button = make(map[uint32]time.Time)
var debounce_key = make(map[uint64]time.Time) var debounce_key = make(map[uint32]time.Time)
var mu = sync.Mutex{} var mu = sync.Mutex{}
func GetScreenConfigurations() { func GetScreenConfigurations() {
@ -86,7 +86,7 @@ func Scroll(x, y int) {
C.XScroll(C.int(x), C.int(y)) C.XScroll(C.int(x), C.int(y))
} }
func ButtonDown(code int) error { func ButtonDown(code uint32) error {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
@ -100,7 +100,7 @@ func ButtonDown(code int) error {
return nil return nil
} }
func KeyDown(code uint64) error { func KeyDown(code uint32) error {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
@ -114,7 +114,7 @@ func KeyDown(code uint64) error {
return nil return nil
} }
func ButtonUp(code int) error { func ButtonUp(code uint32) error {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
@ -128,7 +128,7 @@ func ButtonUp(code int) error {
return nil return nil
} }
func KeyUp(code uint64) error { func KeyUp(code uint32) error {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()

View File

@ -51,10 +51,10 @@ type DesktopManager interface {
OnCursorPosition(listener func(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 int) error ButtonDown(code uint32) error
KeyDown(code uint64) error KeyDown(code uint32) error
ButtonUp(code int) error ButtonUp(code uint32) error
KeyUp(code uint64) error KeyUp(code uint32) error
ResetKeys() ResetKeys()
ScreenConfigurations() map[int]ScreenConfiguration ScreenConfigurations() map[int]ScreenConfiguration
SetScreenSize(ScreenSize) error SetScreenSize(ScreenSize) error

View File

@ -118,7 +118,7 @@ type ControlScroll struct {
// TODO: New. // TODO: New.
type ControlKey struct { type ControlKey struct {
Event string `json:"event,omitempty"` Event string `json:"event,omitempty"`
Key uint64 `json:"key"` Key uint32 `json:"key"`
} }
///////////////////////////// /////////////////////////////

View File

@ -13,7 +13,8 @@ const (
OP_SCROLL = 0x02 OP_SCROLL = 0x02
OP_KEY_DOWN = 0x03 OP_KEY_DOWN = 0x03
OP_KEY_UP = 0x04 OP_KEY_UP = 0x04
OP_KEY_CLK = 0x05 OP_BTN_DOWN = 0x05
OP_BTN_UP = 0x06
) )
type PayloadHeader struct { type PayloadHeader struct {
@ -35,7 +36,7 @@ type PayloadScroll struct {
type PayloadKey struct { type PayloadKey struct {
PayloadHeader PayloadHeader
Key uint64 Key uint32
} }
func (manager *WebRTCManagerCtx) handle(msg webrtc.DataChannelMessage) error { func (manager *WebRTCManagerCtx) handle(msg webrtc.DataChannelMessage) error {
@ -80,49 +81,48 @@ func (manager *WebRTCManagerCtx) handle(msg webrtc.DataChannelMessage) error {
return err return err
} }
if payload.Key < 8 { if err := manager.desktop.KeyDown(payload.Key); err != nil {
err := manager.desktop.ButtonDown(int(payload.Key)) manager.logger.Warn().Err(err).Msg("key down failed")
if err != nil { break
manager.logger.Warn().Err(err).Msg("button down failed")
return nil
}
manager.logger.Debug().Msgf("button down %d", payload.Key)
} else {
err := manager.desktop.KeyDown(uint64(payload.Key))
if err != nil {
manager.logger.Warn().Err(err).Msg("key down failed")
return nil
}
manager.logger.Debug().Msgf("key down %d", payload.Key)
} }
manager.logger.Debug().Msgf("key down %d", payload.Key)
case OP_KEY_UP: case OP_KEY_UP:
payload := &PayloadKey{} payload := &PayloadKey{}
err := binary.Read(buffer, binary.BigEndian, payload) if err := binary.Read(buffer, binary.BigEndian, payload); err != nil {
if err != nil {
return err return err
} }
if payload.Key < 8 { if err := manager.desktop.KeyUp(payload.Key); err != nil {
err := manager.desktop.ButtonUp(int(payload.Key)) manager.logger.Warn().Err(err).Msg("key up failed")
if err != nil { break
manager.logger.Warn().Err(err).Msg("button up failed")
return nil
}
manager.logger.Debug().Msgf("button up %d", payload.Key)
} else {
err := manager.desktop.KeyUp(uint64(payload.Key))
if err != nil {
manager.logger.Warn().Err(err).Msg("key up failed")
return nil
}
manager.logger.Debug().Msgf("key up %d", payload.Key)
} }
case OP_KEY_CLK:
// unused manager.logger.Debug().Msgf("key up %d", payload.Key)
case OP_BTN_DOWN:
payload := &PayloadKey{}
if err := binary.Read(buffer, binary.BigEndian, payload); err != nil {
return err
}
if err := manager.desktop.ButtonDown(payload.Key); err != nil {
manager.logger.Warn().Err(err).Msg("button down failed")
break
}
manager.logger.Debug().Msgf("button down %d", payload.Key)
case OP_BTN_UP:
payload := &PayloadKey{}
if err := binary.Read(buffer, binary.BigEndian, payload); err != nil {
return err
}
if err := manager.desktop.ButtonUp(payload.Key); err != nil {
manager.logger.Warn().Err(err).Msg("button up failed")
break
}
manager.logger.Debug().Msgf("button up %d", payload.Key)
} }
return nil return nil