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"
|
"net/http"
|
||||||
|
|
||||||
"demodesk/neko/internal/utils"
|
"demodesk/neko/internal/utils"
|
||||||
|
"demodesk/neko/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type KeyboardLayoutData struct {
|
type KeyboardLayoutData struct {
|
||||||
@ -11,9 +12,8 @@ type KeyboardLayoutData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type KeyboardModifiersData struct {
|
type KeyboardModifiersData struct {
|
||||||
NumLock *bool `json:"numlock"`
|
NumLock *bool `json:"numlock"`
|
||||||
CapsLock *bool `json:"capslock"`
|
CapsLock *bool `json:"capslock"`
|
||||||
ScrollLock *bool `json:"scrollock"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *RoomHandler) keyboardLayoutSet(w http.ResponseWriter, r *http.Request) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var NumLock = 0
|
h.desktop.SetKeyboardModifiers(types.KeyboardModifiers{
|
||||||
if data.NumLock == nil {
|
NumLock: data.NumLock,
|
||||||
NumLock = -1
|
CapsLock: data.CapsLock,
|
||||||
} 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)
|
|
||||||
|
|
||||||
utils.HttpSuccess(w)
|
utils.HttpSuccess(w)
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,24 @@ func (manager *DesktopManagerCtx) SetKeyboardLayout(layout string) {
|
|||||||
xorg.SetKeyboardLayout(layout)
|
xorg.SetKeyboardLayout(layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int) {
|
func (manager *DesktopManagerCtx) SetKeyboardModifiers(mod types.KeyboardModifiers) {
|
||||||
xorg.SetKeyboardModifiers(NumLock, CapsLock, ScrollLock)
|
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 {
|
func (manager *DesktopManagerCtx) GetCursorImage() *types.CursorImage {
|
||||||
|
@ -126,27 +126,19 @@ void SetKeyboardLayout(char *layout) {
|
|||||||
system(cmd);
|
system(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetKeyboardModifiers(int num_lock, int caps_lock, int scroll_lock) {
|
void XSetKeyboardModifier(int mod, int on) {
|
||||||
Display *display = getXDisplay();
|
Display *display = getXDisplay();
|
||||||
|
XkbLockModifiers(display, XkbUseCoreKbd, mod, on ? mod : 0);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
XFlush(display);
|
XFlush(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int XGetKeyboardModifier(int mod) {
|
||||||
|
XkbStateRec xkbState;
|
||||||
|
Display *display = getXDisplay();
|
||||||
|
XkbGetState(display, XkbUseCoreKbd, &xkbState);
|
||||||
|
return xkbState.locked_mods & mod;
|
||||||
|
}
|
||||||
|
|
||||||
XFixesCursorImage *XGetCursorImage(void) {
|
XFixesCursorImage *XGetCursorImage(void) {
|
||||||
Display *display = getXDisplay();
|
Display *display = getXDisplay();
|
||||||
return XFixesGetCursorImage(display);
|
return XFixesGetCursorImage(display);
|
||||||
|
@ -17,6 +17,13 @@ import (
|
|||||||
"demodesk/neko/internal/types"
|
"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 ScreenConfigurations = make(map[int]types.ScreenConfiguration)
|
||||||
|
|
||||||
var debounce_button = make(map[int]time.Time)
|
var debounce_button = make(map[int]time.Time)
|
||||||
@ -211,11 +218,23 @@ func SetKeyboardLayout(layout string) {
|
|||||||
C.SetKeyboardLayout(layoutUnsafe)
|
C.SetKeyboardLayout(layoutUnsafe)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetKeyboardModifiers(num_lock int, caps_lock int, scroll_lock int) {
|
func SetKeyboardModifier(mod KbdModifiers, active bool) {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
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 {
|
func GetCursorImage() *types.CursorImage {
|
||||||
|
@ -26,5 +26,6 @@ int XGetScreenSize();
|
|||||||
short XGetScreenRate();
|
short XGetScreenRate();
|
||||||
|
|
||||||
void SetKeyboardLayout(char *layout);
|
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);
|
XFixesCursorImage *XGetCursorImage(void);
|
||||||
|
@ -21,6 +21,11 @@ type ScreenConfiguration struct {
|
|||||||
Rates map[int]int16
|
Rates map[int]int16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type KeyboardModifiers struct {
|
||||||
|
NumLock *bool
|
||||||
|
CapsLock *bool
|
||||||
|
}
|
||||||
|
|
||||||
type DesktopManager interface {
|
type DesktopManager interface {
|
||||||
Start()
|
Start()
|
||||||
Shutdown() error
|
Shutdown() error
|
||||||
@ -39,7 +44,8 @@ type DesktopManager interface {
|
|||||||
ScreenConfigurations() map[int]ScreenConfiguration
|
ScreenConfigurations() map[int]ScreenConfiguration
|
||||||
GetScreenSize() *ScreenSize
|
GetScreenSize() *ScreenSize
|
||||||
SetKeyboardLayout(layout string)
|
SetKeyboardLayout(layout string)
|
||||||
SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int)
|
SetKeyboardModifiers(mod KeyboardModifiers)
|
||||||
|
GetKeyboardModifiers() KeyboardModifiers
|
||||||
GetCursorImage() *CursorImage
|
GetCursorImage() *CursorImage
|
||||||
|
|
||||||
// xevent
|
// xevent
|
||||||
|
@ -22,27 +22,9 @@ func (h *MessageHandlerCtx) keyboardModifiers(session types.Session, payload *me
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var NumLock = 0
|
h.desktop.SetKeyboardModifiers(types.KeyboardModifiers{
|
||||||
if payload.NumLock == nil {
|
NumLock: payload.NumLock,
|
||||||
NumLock = -1
|
CapsLock: payload.CapsLock,
|
||||||
} 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)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user