neko/internal/api/room/keyboard.go
2021-01-12 23:48:15 +01:00

55 lines
1.1 KiB
Go

package room
import (
"net/http"
"demodesk/neko/internal/utils"
"demodesk/neko/internal/types"
)
type KeyboardLayoutData struct {
Layout string `json:"layout"`
}
type KeyboardModifiersData struct {
NumLock *bool `json:"numlock"`
CapsLock *bool `json:"capslock"`
}
func (h *RoomHandler) keyboardLayoutSet(w http.ResponseWriter, r *http.Request) {
data := &KeyboardLayoutData{}
if !utils.HttpJsonRequest(w, r, data) {
return
}
err := h.desktop.SetKeyboardLayout(data.Layout)
if err != nil{
utils.HttpInternalServerError(w, "Unable to change keyboard layout.")
return
}
utils.HttpSuccess(w)
}
func (h *RoomHandler) keyboardModifiersSet(w http.ResponseWriter, r *http.Request) {
data := &KeyboardModifiersData{}
if !utils.HttpJsonRequest(w, r, data) {
return
}
h.desktop.SetKeyboardModifiers(types.KeyboardModifiers{
NumLock: data.NumLock,
CapsLock: data.CapsLock,
})
utils.HttpSuccess(w)
}
func (h *RoomHandler) keyboardModifiersGet(w http.ResponseWriter, r *http.Request) {
data := h.desktop.GetKeyboardModifiers()
utils.HttpSuccess(w, KeyboardModifiersData{
NumLock: data.NumLock,
CapsLock: data.CapsLock,
})
}