Archived
2
0

change kbd layout using setxkbmap

This commit is contained in:
Miroslav Šedivý 2020-06-15 23:14:23 +02:00
parent 70e8b215cb
commit 4a7800c93f
6 changed files with 27 additions and 2 deletions

View File

@ -218,3 +218,7 @@ func (manager *RemoteManager) ScreenConfigurations() map[int]types.ScreenConfigu
func (manager *RemoteManager) GetScreenSize() *types.ScreenSize { func (manager *RemoteManager) GetScreenSize() *types.ScreenSize {
return xorg.GetScreenSize() return xorg.GetScreenSize()
} }
func (manager *RemoteManager) SetKeyboard(layout string) {
xorg.SetKeyboard(layout)
}

View File

@ -22,4 +22,5 @@ type RemoteManager interface {
ReadClipboard() string ReadClipboard() string
WriteClipboard(data string) WriteClipboard(data string)
ResetKeys() ResetKeys()
SetKeyboard(layout string)
} }

View File

@ -34,8 +34,9 @@ func (h *MessageHandler) controlRelease(id string, session types.Session) error
func (h *MessageHandler) controlRequest(id string, session types.Session, payload *message.ControlRequest) error { func (h *MessageHandler) controlRequest(id string, session types.Session, payload *message.ControlRequest) error {
// check for host // check for host
if !h.sessions.HasHost() { if !h.sessions.HasHost() {
// TODO: Keyboard Layout change. // keyboard layout change
h.logger.Warn().Msgf("should set keyboard to %s", payload.KeyboardLayout) h.logger.Debug().Msgf("change keyboard to %s", payload.KeyboardLayout)
h.remote.SetKeyboard(payload.KeyboardLayout)
// set host // set host
h.sessions.SetHost(id) h.sessions.SetHost(id)

View File

@ -165,3 +165,10 @@ short XGetScreenRate() {
XRRScreenConfiguration *conf = XRRGetScreenInfo(display, RootWindow(display, 0)); XRRScreenConfiguration *conf = XRRGetScreenInfo(display, RootWindow(display, 0));
return XRRConfigCurrentRate(conf); return XRRConfigCurrentRate(conf);
} }
void SetKeyboard(char *layout) {
// TOOD: refactor, use native API.
char cmd[12] = "setxkbmap ";
strcat(cmd, layout);
system(cmd);
}

View File

@ -210,6 +210,16 @@ func GetScreenSize() *types.ScreenSize {
return nil return nil
} }
func SetKeyboard(layout string) {
mu.Lock()
defer mu.Unlock()
layoutUnsafe := C.CString(layout)
defer C.free(unsafe.Pointer(layoutUnsafe))
C.SetKeyboard(layoutUnsafe)
}
//export goCreateScreenSize //export goCreateScreenSize
func goCreateScreenSize(index C.int, width C.int, height C.int, mwidth C.int, mheight C.int) { func goCreateScreenSize(index C.int, width C.int, height C.int, mwidth C.int, mheight C.int) {
ScreenConfigurations[int(index)] = types.ScreenConfiguration{ ScreenConfigurations[int(index)] = types.ScreenConfiguration{

View File

@ -38,5 +38,7 @@
void XDisplayClose(void); void XDisplayClose(void);
void XDisplaySet(char *input); void XDisplaySet(char *input);
void SetKeyboard(char *layout);
#endif #endif