neko/internal/api/room/keyboard.go

74 lines
1.5 KiB
Go
Raw Normal View History

2020-10-29 22:23:30 +01:00
package room
2020-11-18 21:53:06 +01:00
import (
"net/http"
2021-01-12 22:54:13 +01:00
"demodesk/neko/internal/types"
2021-02-14 14:40:17 +01:00
"demodesk/neko/internal/utils"
2020-11-18 21:53:06 +01:00
)
2021-01-15 16:53:03 +01:00
type KeyboardMapData struct {
2021-01-12 23:52:44 +01:00
Layout string `json:"layout"`
Variant string `json:"variant"`
2020-11-18 21:53:06 +01:00
}
type KeyboardModifiersData struct {
2021-01-12 22:54:13 +01:00
NumLock *bool `json:"numlock"`
CapsLock *bool `json:"capslock"`
2020-11-18 21:53:06 +01:00
}
2021-01-15 16:53:03 +01:00
func (h *RoomHandler) keyboardMapSet(w http.ResponseWriter, r *http.Request) {
data := &KeyboardMapData{}
2020-11-18 21:53:06 +01:00
if !utils.HttpJsonRequest(w, r, data) {
return
}
2021-01-15 16:53:03 +01:00
err := h.desktop.SetKeyboardMap(types.KeyboardMap{
2021-02-14 14:40:17 +01:00
Layout: data.Layout,
2021-01-15 16:53:03 +01:00
Variant: data.Variant,
})
2021-02-14 14:40:17 +01:00
if err != nil {
2021-04-24 21:37:43 +02:00
utils.HttpInternalServerError(w, "unable to change keyboard map")
2021-01-12 23:48:15 +01:00
return
}
2020-11-18 21:53:06 +01:00
utils.HttpSuccess(w)
}
2021-01-15 16:53:03 +01:00
func (h *RoomHandler) keyboardMapGet(w http.ResponseWriter, r *http.Request) {
data, err := h.desktop.GetKeyboardMap()
2021-02-14 14:40:17 +01:00
if err != nil {
2021-04-24 21:37:43 +02:00
utils.HttpInternalServerError(w, "unable to get keyboard map")
2021-01-15 16:53:03 +01:00
return
}
utils.HttpSuccess(w, KeyboardMapData{
2021-02-14 14:40:17 +01:00
Layout: data.Layout,
2021-01-15 16:53:03 +01:00
Variant: data.Variant,
})
}
2020-11-18 22:35:50 +01:00
func (h *RoomHandler) keyboardModifiersSet(w http.ResponseWriter, r *http.Request) {
2020-11-18 21:53:06 +01:00
data := &KeyboardModifiersData{}
if !utils.HttpJsonRequest(w, r, data) {
return
}
2021-01-12 22:54:13 +01:00
h.desktop.SetKeyboardModifiers(types.KeyboardModifiers{
2021-02-14 14:40:17 +01:00
NumLock: data.NumLock,
2021-01-12 22:54:13 +01:00
CapsLock: data.CapsLock,
})
2020-11-18 21:53:06 +01:00
utils.HttpSuccess(w)
}
2021-01-12 23:35:46 +01:00
func (h *RoomHandler) keyboardModifiersGet(w http.ResponseWriter, r *http.Request) {
data := h.desktop.GetKeyboardModifiers()
utils.HttpSuccess(w, KeyboardModifiersData{
2021-02-14 14:40:17 +01:00
NumLock: data.NumLock,
2021-01-12 23:35:46 +01:00
CapsLock: data.CapsLock,
})
}