changing keyboard layout as go exec.

This commit is contained in:
Miroslav Šedivý 2021-01-12 23:48:15 +01:00
parent 4844225a0b
commit 7f18c5842d
7 changed files with 14 additions and 29 deletions

View File

@ -22,7 +22,11 @@ func (h *RoomHandler) keyboardLayoutSet(w http.ResponseWriter, r *http.Request)
return
}
h.desktop.SetKeyboardLayout(data.Layout)
err := h.desktop.SetKeyboardLayout(data.Layout)
if err != nil{
utils.HttpInternalServerError(w, "Unable to change keyboard layout.")
return
}
utils.HttpSuccess(w)
}

View File

@ -1,6 +1,8 @@
package desktop
import (
"os/exec"
"demodesk/neko/internal/types"
"demodesk/neko/internal/desktop/xorg"
)
@ -53,8 +55,11 @@ func (manager *DesktopManagerCtx) ChangeScreenSize(width int, height int, rate i
return xorg.ChangeScreenSize(width, height, rate)
}
func (manager *DesktopManagerCtx) SetKeyboardLayout(layout string) {
xorg.SetKeyboardLayout(layout)
func (manager *DesktopManagerCtx) SetKeyboardLayout(layout string) error {
// TOOD: Use native API.
cmd := exec.Command("setxkbmap", layout)
_, err := cmd.Output()
return err
}
func (manager *DesktopManagerCtx) SetKeyboardModifiers(mod types.KeyboardModifiers) {

View File

@ -119,13 +119,6 @@ short XGetScreenRate() {
return XRRConfigCurrentRate(conf);
}
void SetKeyboardLayout(char *layout) {
// TOOD: refactor, use native API.
char cmd[13] = "setxkbmap ";
strncat(cmd, layout, 2);
system(cmd);
}
void XSetKeyboardModifier(int mod, int on) {
Display *display = getXDisplay();
XkbLockModifiers(display, XkbUseCoreKbd, mod, on ? mod : 0);

View File

@ -12,7 +12,6 @@ import (
"sync"
"time"
"unsafe"
"regexp"
"demodesk/neko/internal/types"
)
@ -204,20 +203,6 @@ func GetScreenSize() *types.ScreenSize {
return nil
}
func SetKeyboardLayout(layout string) {
mu.Lock()
defer mu.Unlock()
if !regexp.MustCompile(`^[a-zA-Z]+$`).MatchString(layout) {
return
}
layoutUnsafe := C.CString(layout)
defer C.free(unsafe.Pointer(layoutUnsafe))
C.SetKeyboardLayout(layoutUnsafe)
}
func SetKeyboardModifier(mod KbdModifiers, active bool) {
mu.Lock()
defer mu.Unlock()

View File

@ -25,7 +25,6 @@ void XSetScreenConfiguration(int index, short rate);
int XGetScreenSize();
short XGetScreenRate();
void SetKeyboardLayout(char *layout);
void XSetKeyboardModifier(int mod, int on);
char XGetKeyboardModifiers();
XFixesCursorImage *XGetCursorImage(void);

View File

@ -43,7 +43,7 @@ type DesktopManager interface {
ResetKeys()
ScreenConfigurations() map[int]ScreenConfiguration
GetScreenSize() *ScreenSize
SetKeyboardLayout(layout string)
SetKeyboardLayout(layout string) error
SetKeyboardModifiers(mod KeyboardModifiers)
GetKeyboardModifiers() KeyboardModifiers
GetCursorImage() *CursorImage

View File

@ -12,8 +12,7 @@ func (h *MessageHandlerCtx) keyboardLayout(session types.Session, payload *messa
return nil
}
h.desktop.SetKeyboardLayout(payload.Layout)
return nil
return h.desktop.SetKeyboardLayout(payload.Layout)
}
func (h *MessageHandlerCtx) keyboardModifiers(session types.Session, payload *message.KeyboardModifiers) error {