mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
Add Xorg modifiers (#57)
* implement additional modifiers to xorg. * xorg modifiers to API. * update modifiers api & add ws. * scroll pos rename to delta and add ctrl key.
This commit is contained in:
@ -25,13 +25,19 @@ func (s ScreenSize) String() string {
|
||||
}
|
||||
|
||||
type KeyboardModifiers struct {
|
||||
NumLock *bool
|
||||
CapsLock *bool
|
||||
Shift *bool `json:"shift"`
|
||||
CapsLock *bool `json:"capslock"`
|
||||
Control *bool `json:"control"`
|
||||
Alt *bool `json:"alt"`
|
||||
NumLock *bool `json:"numlock"`
|
||||
Meta *bool `json:"meta"`
|
||||
Super *bool `json:"super"`
|
||||
AltGr *bool `json:"altgr"`
|
||||
}
|
||||
|
||||
type KeyboardMap struct {
|
||||
Layout string
|
||||
Variant string
|
||||
Layout string `json:"layout"`
|
||||
Variant string `json:"variant"`
|
||||
}
|
||||
|
||||
type ClipboardText struct {
|
||||
@ -48,7 +54,7 @@ type DesktopManager interface {
|
||||
// xorg
|
||||
Move(x, y int)
|
||||
GetCursorPosition() (int, int)
|
||||
Scroll(x, y int)
|
||||
Scroll(deltaX, deltaY int, controlKey bool)
|
||||
ButtonDown(code uint32) error
|
||||
KeyDown(code uint32) error
|
||||
ButtonUp(code uint32) error
|
||||
|
@ -115,6 +115,16 @@ type ControlHost struct {
|
||||
HostID string `json:"host_id,omitempty"`
|
||||
}
|
||||
|
||||
type ControlScroll struct {
|
||||
// TOOD: remove this once the client is fixed
|
||||
X int `json:"x"`
|
||||
Y int `json:"y"`
|
||||
|
||||
DeltaX int `json:"delta_x"`
|
||||
DeltaY int `json:"delta_y"`
|
||||
ControlKey bool `json:"control_key"`
|
||||
}
|
||||
|
||||
type ControlPos struct {
|
||||
X int `json:"x"`
|
||||
Y int `json:"y"`
|
||||
@ -159,13 +169,11 @@ type ClipboardData struct {
|
||||
/////////////////////////////
|
||||
|
||||
type KeyboardMap struct {
|
||||
Layout string `json:"layout"`
|
||||
Variant string `json:"variant"`
|
||||
types.KeyboardMap
|
||||
}
|
||||
|
||||
type KeyboardModifiers struct {
|
||||
CapsLock *bool `json:"capslock"`
|
||||
NumLock *bool `json:"numlock"`
|
||||
types.KeyboardModifiers
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
|
@ -30,33 +30,33 @@ void XCursorPosition(int *x, int *y) {
|
||||
XQueryPointer(display, root, &root, &window, x, y, &i, &i, &mask);
|
||||
}
|
||||
|
||||
void XScroll(int x, int y) {
|
||||
int ydir = 4; /* Button 4 is up, 5 is down. */
|
||||
int xdir = 6;
|
||||
|
||||
void XScroll(int deltaX, int deltaY) {
|
||||
Display *display = getXDisplay();
|
||||
|
||||
if (y < 0) {
|
||||
ydir = 5;
|
||||
int ydir;
|
||||
if (deltaY > 0) {
|
||||
ydir = 4; // button 4 is up
|
||||
} else {
|
||||
ydir = 5; // button 5 is down
|
||||
}
|
||||
|
||||
if (x < 0) {
|
||||
xdir = 7;
|
||||
int xdir;
|
||||
if (deltaX > 0) {
|
||||
xdir = 6; // button 6 is right
|
||||
} else {
|
||||
xdir = 7; // button 7 is left
|
||||
}
|
||||
|
||||
int xi;
|
||||
int yi;
|
||||
|
||||
for (xi = 0; xi < abs(x); xi++) {
|
||||
XTestFakeButtonEvent(display, xdir, 1, CurrentTime);
|
||||
XTestFakeButtonEvent(display, xdir, 0, CurrentTime);
|
||||
}
|
||||
|
||||
for (yi = 0; yi < abs(y); yi++) {
|
||||
for (int i = 0; i < abs(deltaY); i++) {
|
||||
XTestFakeButtonEvent(display, ydir, 1, CurrentTime);
|
||||
XTestFakeButtonEvent(display, ydir, 0, CurrentTime);
|
||||
}
|
||||
|
||||
for (int i = 0; i < abs(deltaX); i++) {
|
||||
XTestFakeButtonEvent(display, xdir, 1, CurrentTime);
|
||||
XTestFakeButtonEvent(display, xdir, 0, CurrentTime);
|
||||
}
|
||||
|
||||
XSync(display, 0);
|
||||
}
|
||||
|
||||
@ -368,17 +368,19 @@ XRRModeInfo XCreateScreenModeInfo(int hdisplay, int vdisplay, short vrefresh) {
|
||||
return modeinfo;
|
||||
}
|
||||
|
||||
void XSetKeyboardModifier(int mod, int on) {
|
||||
void XSetKeyboardModifier(unsigned char mod, int on) {
|
||||
Display *display = getXDisplay();
|
||||
XkbLockModifiers(display, XkbUseCoreKbd, mod, on ? mod : 0);
|
||||
XFlush(display);
|
||||
}
|
||||
|
||||
char XGetKeyboardModifiers() {
|
||||
unsigned char XGetKeyboardModifiers() {
|
||||
XkbStateRec xkbState;
|
||||
Display *display = getXDisplay();
|
||||
XkbGetState(display, XkbUseCoreKbd, &xkbState);
|
||||
return xkbState.locked_mods;
|
||||
// XkbStateFieldFromRec() doesn't work properly because
|
||||
// state.lookup_mods isn't properly updated, so we do this manually
|
||||
return XkbBuildCoreState(XkbStateMods(&xkbState), xkbState.group);
|
||||
}
|
||||
|
||||
XFixesCursorImage *XGetCursorImage(void) {
|
||||
|
@ -23,8 +23,14 @@ import (
|
||||
type KbdMod uint8
|
||||
|
||||
const (
|
||||
KbdModCapsLock KbdMod = 2
|
||||
KbdModNumLock KbdMod = 16
|
||||
KbdModShift KbdMod = C.ShiftMask
|
||||
KbdModCapsLock KbdMod = C.LockMask
|
||||
KbdModControl KbdMod = C.ControlMask
|
||||
KbdModAlt KbdMod = C.Mod1Mask
|
||||
KbdModNumLock KbdMod = C.Mod2Mask
|
||||
KbdModMeta KbdMod = C.Mod3Mask
|
||||
KbdModSuper KbdMod = C.Mod4Mask
|
||||
KbdModAltGr KbdMod = C.Mod5Mask
|
||||
)
|
||||
|
||||
type ScreenConfiguration struct {
|
||||
@ -82,11 +88,16 @@ func GetCursorPosition() (int, int) {
|
||||
return int(x), int(y)
|
||||
}
|
||||
|
||||
func Scroll(x, y int) {
|
||||
func Scroll(deltaX, deltaY int, controlKey bool) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
C.XScroll(C.int(x), C.int(y))
|
||||
if controlKey {
|
||||
C.XSetKeyboardModifier(C.uchar(C.ControlMask), 1)
|
||||
defer C.XSetKeyboardModifier(C.uchar(C.ControlMask), 0)
|
||||
}
|
||||
|
||||
C.XScroll(C.int(deltaX), C.int(deltaY))
|
||||
}
|
||||
|
||||
func ButtonDown(code uint32) error {
|
||||
@ -248,7 +259,7 @@ func SetKeyboardModifier(mod KbdMod, active bool) {
|
||||
num = C.int(1)
|
||||
}
|
||||
|
||||
C.XSetKeyboardModifier(C.int(mod), num)
|
||||
C.XSetKeyboardModifier(C.uchar(mod), num)
|
||||
}
|
||||
|
||||
func GetKeyboardModifiers() KbdMod {
|
||||
|
@ -22,7 +22,7 @@ void XDisplayClose(void);
|
||||
|
||||
void XMove(int x, int y);
|
||||
void XCursorPosition(int *x, int *y);
|
||||
void XScroll(int x, int y);
|
||||
void XScroll(int deltaX, int deltaY);
|
||||
void XButton(unsigned int button, int down);
|
||||
|
||||
typedef struct xkeyentry_t {
|
||||
@ -42,8 +42,8 @@ void XGetScreenConfigurations();
|
||||
void XCreateScreenMode(int width, int height, short rate);
|
||||
XRRModeInfo XCreateScreenModeInfo(int hdisplay, int vdisplay, short vrefresh);
|
||||
|
||||
void XSetKeyboardModifier(int mod, int on);
|
||||
char XGetKeyboardModifiers();
|
||||
void XSetKeyboardModifier(unsigned char mod, int on);
|
||||
unsigned char XGetKeyboardModifiers();
|
||||
XFixesCursorImage *XGetCursorImage(void);
|
||||
|
||||
char *XGetScreenshot(int *w, int *h);
|
||||
|
Reference in New Issue
Block a user