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
|
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)
|
utils.HttpSuccess(w)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package desktop
|
package desktop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
"demodesk/neko/internal/types"
|
"demodesk/neko/internal/types"
|
||||||
"demodesk/neko/internal/desktop/xorg"
|
"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)
|
return xorg.ChangeScreenSize(width, height, rate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) SetKeyboardLayout(layout string) {
|
func (manager *DesktopManagerCtx) SetKeyboardLayout(layout string) error {
|
||||||
xorg.SetKeyboardLayout(layout)
|
// TOOD: Use native API.
|
||||||
|
cmd := exec.Command("setxkbmap", layout)
|
||||||
|
_, err := cmd.Output()
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) SetKeyboardModifiers(mod types.KeyboardModifiers) {
|
func (manager *DesktopManagerCtx) SetKeyboardModifiers(mod types.KeyboardModifiers) {
|
||||||
|
@ -119,13 +119,6 @@ short XGetScreenRate() {
|
|||||||
return XRRConfigCurrentRate(conf);
|
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) {
|
void XSetKeyboardModifier(int mod, int on) {
|
||||||
Display *display = getXDisplay();
|
Display *display = getXDisplay();
|
||||||
XkbLockModifiers(display, XkbUseCoreKbd, mod, on ? mod : 0);
|
XkbLockModifiers(display, XkbUseCoreKbd, mod, on ? mod : 0);
|
||||||
|
@ -12,7 +12,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
"regexp"
|
|
||||||
|
|
||||||
"demodesk/neko/internal/types"
|
"demodesk/neko/internal/types"
|
||||||
)
|
)
|
||||||
@ -204,20 +203,6 @@ func GetScreenSize() *types.ScreenSize {
|
|||||||
return nil
|
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) {
|
func SetKeyboardModifier(mod KbdModifiers, active bool) {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
@ -25,7 +25,6 @@ void XSetScreenConfiguration(int index, short rate);
|
|||||||
int XGetScreenSize();
|
int XGetScreenSize();
|
||||||
short XGetScreenRate();
|
short XGetScreenRate();
|
||||||
|
|
||||||
void SetKeyboardLayout(char *layout);
|
|
||||||
void XSetKeyboardModifier(int mod, int on);
|
void XSetKeyboardModifier(int mod, int on);
|
||||||
char XGetKeyboardModifiers();
|
char XGetKeyboardModifiers();
|
||||||
XFixesCursorImage *XGetCursorImage(void);
|
XFixesCursorImage *XGetCursorImage(void);
|
||||||
|
@ -43,7 +43,7 @@ type DesktopManager interface {
|
|||||||
ResetKeys()
|
ResetKeys()
|
||||||
ScreenConfigurations() map[int]ScreenConfiguration
|
ScreenConfigurations() map[int]ScreenConfiguration
|
||||||
GetScreenSize() *ScreenSize
|
GetScreenSize() *ScreenSize
|
||||||
SetKeyboardLayout(layout string)
|
SetKeyboardLayout(layout string) error
|
||||||
SetKeyboardModifiers(mod KeyboardModifiers)
|
SetKeyboardModifiers(mod KeyboardModifiers)
|
||||||
GetKeyboardModifiers() KeyboardModifiers
|
GetKeyboardModifiers() KeyboardModifiers
|
||||||
GetCursorImage() *CursorImage
|
GetCursorImage() *CursorImage
|
||||||
|
@ -12,8 +12,7 @@ func (h *MessageHandlerCtx) keyboardLayout(session types.Session, payload *messa
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
h.desktop.SetKeyboardLayout(payload.Layout)
|
return h.desktop.SetKeyboardLayout(payload.Layout)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandlerCtx) keyboardModifiers(session types.Session, payload *message.KeyboardModifiers) error {
|
func (h *MessageHandlerCtx) keyboardModifiers(session types.Session, payload *message.KeyboardModifiers) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user