mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
xorg modifiers refactor.
This commit is contained in:
parent
d89dd11b18
commit
a0d8f1b880
@ -4,6 +4,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"demodesk/neko/internal/utils"
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
type KeyboardLayoutData struct {
|
||||
@ -11,9 +12,8 @@ type KeyboardLayoutData struct {
|
||||
}
|
||||
|
||||
type KeyboardModifiersData struct {
|
||||
NumLock *bool `json:"numlock"`
|
||||
CapsLock *bool `json:"capslock"`
|
||||
ScrollLock *bool `json:"scrollock"`
|
||||
NumLock *bool `json:"numlock"`
|
||||
CapsLock *bool `json:"capslock"`
|
||||
}
|
||||
|
||||
func (h *RoomHandler) keyboardLayoutSet(w http.ResponseWriter, r *http.Request) {
|
||||
@ -33,28 +33,9 @@ func (h *RoomHandler) keyboardModifiersSet(w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
var NumLock = 0
|
||||
if data.NumLock == nil {
|
||||
NumLock = -1
|
||||
} else if *data.NumLock {
|
||||
NumLock = 1
|
||||
}
|
||||
|
||||
var CapsLock = 0
|
||||
if data.CapsLock == nil {
|
||||
CapsLock = -1
|
||||
} else if *data.CapsLock {
|
||||
CapsLock = 1
|
||||
}
|
||||
|
||||
var ScrollLock = 0
|
||||
if data.ScrollLock == nil {
|
||||
ScrollLock = -1
|
||||
} else if *data.ScrollLock {
|
||||
ScrollLock = 1
|
||||
}
|
||||
|
||||
h.desktop.SetKeyboardModifiers(NumLock, CapsLock, ScrollLock)
|
||||
|
||||
h.desktop.SetKeyboardModifiers(types.KeyboardModifiers{
|
||||
NumLock: data.NumLock,
|
||||
CapsLock: data.CapsLock,
|
||||
})
|
||||
utils.HttpSuccess(w)
|
||||
}
|
||||
|
@ -57,8 +57,24 @@ func (manager *DesktopManagerCtx) SetKeyboardLayout(layout string) {
|
||||
xorg.SetKeyboardLayout(layout)
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int) {
|
||||
xorg.SetKeyboardModifiers(NumLock, CapsLock, ScrollLock)
|
||||
func (manager *DesktopManagerCtx) SetKeyboardModifiers(mod types.KeyboardModifiers) {
|
||||
if mod.NumLock != nil {
|
||||
xorg.SetKeyboardModifier(xorg.KBD_NUM_LOCK, *mod.NumLock)
|
||||
}
|
||||
|
||||
if mod.CapsLock != nil {
|
||||
xorg.SetKeyboardModifier(xorg.KBD_CAPS_LOCK, *mod.CapsLock)
|
||||
}
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) GetKeyboardModifiers() types.KeyboardModifiers {
|
||||
NumLock := xorg.GetKeyboardModifier(xorg.KBD_NUM_LOCK)
|
||||
CapsLock := xorg.GetKeyboardModifier(xorg.KBD_CAPS_LOCK)
|
||||
|
||||
return types.KeyboardModifiers{
|
||||
NumLock: &NumLock,
|
||||
CapsLock: &CapsLock,
|
||||
}
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) GetCursorImage() *types.CursorImage {
|
||||
|
@ -126,27 +126,19 @@ void SetKeyboardLayout(char *layout) {
|
||||
system(cmd);
|
||||
}
|
||||
|
||||
void SetKeyboardModifiers(int num_lock, int caps_lock, int scroll_lock) {
|
||||
void XSetKeyboardModifier(int mod, int on) {
|
||||
Display *display = getXDisplay();
|
||||
|
||||
if (num_lock != -1) {
|
||||
XkbLockModifiers(display, XkbUseCoreKbd, 16, num_lock * 16);
|
||||
}
|
||||
|
||||
if (caps_lock != -1) {
|
||||
XkbLockModifiers(display, XkbUseCoreKbd, 2, caps_lock * 2);
|
||||
}
|
||||
|
||||
if (scroll_lock != -1) {
|
||||
XKeyboardControl values;
|
||||
values.led_mode = scroll_lock ? LedModeOn : LedModeOff;
|
||||
values.led = 3;
|
||||
XChangeKeyboardControl(display, KBLedMode, &values);
|
||||
}
|
||||
|
||||
XkbLockModifiers(display, XkbUseCoreKbd, mod, on ? mod : 0);
|
||||
XFlush(display);
|
||||
}
|
||||
|
||||
int XGetKeyboardModifier(int mod) {
|
||||
XkbStateRec xkbState;
|
||||
Display *display = getXDisplay();
|
||||
XkbGetState(display, XkbUseCoreKbd, &xkbState);
|
||||
return xkbState.locked_mods & mod;
|
||||
}
|
||||
|
||||
XFixesCursorImage *XGetCursorImage(void) {
|
||||
Display *display = getXDisplay();
|
||||
return XFixesGetCursorImage(display);
|
||||
|
@ -17,6 +17,13 @@ import (
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
type KbdModifiers int
|
||||
|
||||
const (
|
||||
KBD_CAPS_LOCK KbdModifiers = 2
|
||||
KBD_NUM_LOCK KbdModifiers = 16
|
||||
)
|
||||
|
||||
var ScreenConfigurations = make(map[int]types.ScreenConfiguration)
|
||||
|
||||
var debounce_button = make(map[int]time.Time)
|
||||
@ -211,11 +218,23 @@ func SetKeyboardLayout(layout string) {
|
||||
C.SetKeyboardLayout(layoutUnsafe)
|
||||
}
|
||||
|
||||
func SetKeyboardModifiers(num_lock int, caps_lock int, scroll_lock int) {
|
||||
func SetKeyboardModifier(mod KbdModifiers, active bool) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
C.SetKeyboardModifiers(C.int(num_lock), C.int(caps_lock), C.int(scroll_lock))
|
||||
num := C.int(0)
|
||||
if active {
|
||||
num = C.int(1)
|
||||
}
|
||||
|
||||
C.XSetKeyboardModifier(C.int(mod), num)
|
||||
}
|
||||
|
||||
func GetKeyboardModifier(mod KbdModifiers) bool {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
return C.XGetKeyboardModifier(C.int(mod)) == C.int(1)
|
||||
}
|
||||
|
||||
func GetCursorImage() *types.CursorImage {
|
||||
|
@ -26,5 +26,6 @@ int XGetScreenSize();
|
||||
short XGetScreenRate();
|
||||
|
||||
void SetKeyboardLayout(char *layout);
|
||||
void SetKeyboardModifiers(int num_lock, int caps_lock, int scroll_lock);
|
||||
void XSetKeyboardModifier(int mod, int on);
|
||||
int XGetKeyboardModifier(int mod);
|
||||
XFixesCursorImage *XGetCursorImage(void);
|
||||
|
@ -21,6 +21,11 @@ type ScreenConfiguration struct {
|
||||
Rates map[int]int16
|
||||
}
|
||||
|
||||
type KeyboardModifiers struct {
|
||||
NumLock *bool
|
||||
CapsLock *bool
|
||||
}
|
||||
|
||||
type DesktopManager interface {
|
||||
Start()
|
||||
Shutdown() error
|
||||
@ -39,7 +44,8 @@ type DesktopManager interface {
|
||||
ScreenConfigurations() map[int]ScreenConfiguration
|
||||
GetScreenSize() *ScreenSize
|
||||
SetKeyboardLayout(layout string)
|
||||
SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int)
|
||||
SetKeyboardModifiers(mod KeyboardModifiers)
|
||||
GetKeyboardModifiers() KeyboardModifiers
|
||||
GetCursorImage() *CursorImage
|
||||
|
||||
// xevent
|
||||
|
@ -22,27 +22,9 @@ func (h *MessageHandlerCtx) keyboardModifiers(session types.Session, payload *me
|
||||
return nil
|
||||
}
|
||||
|
||||
var NumLock = 0
|
||||
if payload.NumLock == nil {
|
||||
NumLock = -1
|
||||
} else if *payload.NumLock {
|
||||
NumLock = 1
|
||||
}
|
||||
|
||||
var CapsLock = 0
|
||||
if payload.CapsLock == nil {
|
||||
CapsLock = -1
|
||||
} else if *payload.CapsLock {
|
||||
CapsLock = 1
|
||||
}
|
||||
|
||||
var ScrollLock = 0
|
||||
if payload.ScrollLock == nil {
|
||||
ScrollLock = -1
|
||||
} else if *payload.ScrollLock {
|
||||
ScrollLock = 1
|
||||
}
|
||||
|
||||
h.desktop.SetKeyboardModifiers(NumLock, CapsLock, ScrollLock)
|
||||
h.desktop.SetKeyboardModifiers(types.KeyboardModifiers{
|
||||
NumLock: payload.NumLock,
|
||||
CapsLock: payload.CapsLock,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user