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)
}
func (manager *DesktopManagerCtx) ButtonDown(code int) error {
func (manager *DesktopManagerCtx) ButtonDown(code uint32) error {
return xorg.ButtonDown(code)
}
func (manager *DesktopManagerCtx) KeyDown(code uint64) error {
func (manager *DesktopManagerCtx) KeyDown(code uint32) error {
return xorg.KeyDown(code)
}
func (manager *DesktopManagerCtx) ButtonUp(code int) error {
func (manager *DesktopManagerCtx) ButtonUp(code uint32) error {
return xorg.ButtonUp(code)
}
func (manager *DesktopManagerCtx) KeyUp(code uint64) error {
func (manager *DesktopManagerCtx) KeyUp(code uint32) error {
return xorg.KeyUp(code)
}

View File

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

View File

@ -51,10 +51,10 @@ type DesktopManager interface {
OnCursorPosition(listener func(x, y int))
GetCursorPosition() (int, int)
Scroll(x, y int)
ButtonDown(code int) error
KeyDown(code uint64) error
ButtonUp(code int) error
KeyUp(code uint64) error
ButtonDown(code uint32) error
KeyDown(code uint32) error
ButtonUp(code uint32) error
KeyUp(code uint32) error
ResetKeys()
ScreenConfigurations() map[int]ScreenConfiguration
SetScreenSize(ScreenSize) error

View File

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

View File

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