update keyboard WS.

This commit is contained in:
Miroslav Šedivý 2020-11-30 17:45:53 +01:00
parent e93d167be6
commit 83be51ea0f
5 changed files with 65 additions and 64 deletions

View File

@ -22,7 +22,6 @@ const (
CONTROL_LOCKED = "control/locked" // TODO: Remove.
CONTROL_REQUESTING = "control/requesting" // TODO: Remove.
CONTROL_GIVE = "control/give" // TODO: Remove.
CONTROL_KEYBOARD = "control/keyboard" // TODO: Remove.
CONTROL_HOST = "control/host" // TODO: New.
CONTROL_RELEASE = "control/release"
CONTROL_REQUEST = "control/request"
@ -46,8 +45,8 @@ const (
)
const (
KEYBOARD_MODIFIERS = "keyboard/modifiers" // TODO: New.
KEYBOARD_LAYOUT = "keyboard/layout" // TODO: New.
KEYBOARD_MODIFIERS = "keyboard/modifiers"
KEYBOARD_LAYOUT = "keyboard/layout"
)
const (

View File

@ -99,15 +99,13 @@ type ClipboardData struct {
}
// Keyboard
// TODO: New.
type KeyboardModifiers struct {
Event string `json:"event,omitempty"`
CapsLock bool `json:"caps_lock"`
NumLock bool `json:"num_lock"`
ScrollLock bool `json:"scroll_lock"`
CapsLock *bool `json:"caps_lock"`
NumLock *bool `json:"num_lock"`
ScrollLock *bool `json:"scroll_lock"`
}
// TODO: New.
type KeyboardLayout struct {
Event string `json:"event,omitempty"`
Layout string `json:"layout"`
@ -152,15 +150,6 @@ type MemberDisconnected struct {
ID string `json:"id"`
}
// TODO: Remove.
type Keyboard struct {
Event string `json:"event"`
Layout *string `json:"layout,omitempty"`
CapsLock *bool `json:"capsLock,omitempty"`
NumLock *bool `json:"numLock,omitempty"`
ScrollLock *bool `json:"scrollLock,omitempty"`
}
// TODO: Remove.
type Control struct {
Event string `json:"event"`

View File

@ -81,45 +81,3 @@ func (h *MessageHandlerCtx) controlGive(session types.Session, payload *message.
return nil
}
func (h *MessageHandlerCtx) controlKeyboard(session types.Session, payload *message.Keyboard) error {
if !session.IsHost() {
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
return nil
}
// change layout
if payload.Layout != nil {
h.desktop.SetKeyboardLayout(*payload.Layout)
}
var NumLock = 0
if payload.NumLock == nil {
NumLock = -1
} else if *payload.NumLock {
NumLock = 1
}
var CapsLock = 0
if payload.CapsLock == nil {
CapsLock = -1
} else if *payload.CapsLock {
CapsLock = 1
}
var ScrollLock = 0
if payload.ScrollLock == nil {
ScrollLock = -1
} else if *payload.ScrollLock {
ScrollLock = 1
}
h.logger.Debug().
Int("NumLock", NumLock).
Int("CapsLock", CapsLock).
Int("ScrollLock", ScrollLock).
Msg("setting keyboard modifiers")
h.desktop.SetKeyboardModifiers(NumLock, CapsLock, ScrollLock)
return nil
}

View File

@ -63,11 +63,6 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error {
err = utils.Unmarshal(payload, raw, func() error {
return h.controlGive(session, payload)
})
case event.CONTROL_KEYBOARD:
payload := &message.Keyboard{}
err = utils.Unmarshal(payload, raw, func() error {
return h.controlKeyboard(session, payload)
})
// Clipboard Events
case event.CLIPBOARD_SET:
@ -76,6 +71,18 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error {
return h.clipboardSet(session, payload)
})
// Keyboard Events
case event.KEYBOARD_MODIFIERS:
payload := &message.KeyboardLayout{}
err = utils.Unmarshal(payload, raw, func() error {
return h.keyboardLayout(session, payload)
})
case event.KEYBOARD_LAYOUT:
payload := &message.KeyboardModifiers{}
err = utils.Unmarshal(payload, raw, func() error {
return h.keyboardModifiers(session, payload)
})
// Screen Events
case event.SCREEN_RESOLUTION:
err = h.screenSize(session)

View File

@ -0,0 +1,48 @@
package handler
import (
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/message"
)
func (h *MessageHandlerCtx) keyboardLayout(session types.Session, payload *message.KeyboardLayout) error {
if !session.IsHost() {
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
return nil
}
h.desktop.SetKeyboardLayout(payload.Layout)
return nil
}
func (h *MessageHandlerCtx) keyboardModifiers(session types.Session, payload *message.KeyboardModifiers) error {
if !session.IsHost() {
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
return nil
}
var NumLock = 0
if payload.NumLock == nil {
NumLock = -1
} else if *payload.NumLock {
NumLock = 1
}
var CapsLock = 0
if payload.CapsLock == nil {
CapsLock = -1
} else if *payload.CapsLock {
CapsLock = 1
}
var ScrollLock = 0
if payload.ScrollLock == nil {
ScrollLock = -1
} else if *payload.ScrollLock {
ScrollLock = 1
}
h.desktop.SetKeyboardModifiers(NumLock, CapsLock, ScrollLock)
return nil
}