neko/internal/api/room/keyboard.go

73 lines
1.6 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"
"github.com/demodesk/neko/pkg/types"
"github.com/demodesk/neko/pkg/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-09-17 00:58:50 +02:00
func (h *RoomHandler) keyboardMapSet(w http.ResponseWriter, r *http.Request) error {
2021-01-15 16:53:03 +01:00
data := &KeyboardMapData{}
2021-09-17 00:58:50 +02:00
if err := utils.HttpJsonRequest(w, r, data); err != nil {
return err
2020-11-18 21:53:06 +01:00
}
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-09-17 00:58:50 +02:00
return utils.HttpInternalServerError().WithInternalErr(err)
2021-01-12 23:48:15 +01:00
}
2020-11-18 21:53:06 +01:00
2021-09-17 00:58:50 +02:00
return utils.HttpSuccess(w)
2020-11-18 21:53:06 +01:00
}
2021-09-17 00:58:50 +02:00
func (h *RoomHandler) keyboardMapGet(w http.ResponseWriter, r *http.Request) error {
2021-01-15 16:53:03 +01:00
data, err := h.desktop.GetKeyboardMap()
2021-02-14 14:40:17 +01:00
if err != nil {
2021-09-17 00:58:50 +02:00
return utils.HttpInternalServerError().WithInternalErr(err)
2021-01-15 16:53:03 +01:00
}
2021-09-17 00:58:50 +02: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,
})
}
2021-09-17 00:58:50 +02:00
func (h *RoomHandler) keyboardModifiersSet(w http.ResponseWriter, r *http.Request) error {
2020-11-18 21:53:06 +01:00
data := &KeyboardModifiersData{}
2021-09-17 00:58:50 +02:00
if err := utils.HttpJsonRequest(w, r, data); err != nil {
return err
2020-11-18 21:53:06 +01:00
}
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,
})
2021-09-17 00:58:50 +02:00
return utils.HttpSuccess(w)
2020-11-18 21:53:06 +01:00
}
2021-01-12 23:35:46 +01:00
2021-09-17 00:58:50 +02:00
func (h *RoomHandler) keyboardModifiersGet(w http.ResponseWriter, r *http.Request) error {
2021-01-12 23:35:46 +01:00
data := h.desktop.GetKeyboardModifiers()
2021-09-17 00:58:50 +02:00
return 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,
})
}