mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
changing keyboard layout as go exec.
This commit is contained in:
parent
4844225a0b
commit
7f18c5842d
@ -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)
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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()
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user