implement xorg GetCursorPosition.

This commit is contained in:
Miroslav Šedivý 2021-02-17 21:55:11 +01:00
parent 2ac3f9876f
commit 5310acfbf0
5 changed files with 26 additions and 0 deletions

View File

@ -26,6 +26,10 @@ func (manager *DesktopManagerCtx) OnCursorPosition(listener func(x, y int)) {
cursorListeners = append(cursorListeners, listener) cursorListeners = append(cursorListeners, listener)
} }
func (manager *DesktopManagerCtx) GetCursorPosition() (int, int) {
return xorg.GetCursorPosition()
}
func (manager *DesktopManagerCtx) Scroll(x, y int) { func (manager *DesktopManagerCtx) Scroll(x, y int) {
xorg.Scroll(x, y) xorg.Scroll(x, y)
} }

View File

@ -21,6 +21,15 @@ void XMove(int x, int y) {
XSync(display, 0); XSync(display, 0);
} }
void XCursorPosition(int *x, int *y) {
Display *display = getXDisplay();
Window root = DefaultRootWindow(display);
Window window;
int i;
unsigned mask;
XQueryPointer(display, root, &root, &window, x, y, &i, &i, &mask);
}
void XScroll(int x, int y) { void XScroll(int x, int y) {
int ydir = 4; /* Button 4 is up, 5 is down. */ int ydir = 4; /* Button 4 is up, 5 is down. */
int xdir = 6; int xdir = 6;

View File

@ -68,6 +68,17 @@ func Move(x, y int) {
C.XMove(C.int(x), C.int(y)) C.XMove(C.int(x), C.int(y))
} }
func GetCursorPosition() (int, int) {
mu.Lock()
defer mu.Unlock()
var x C.int
var y C.int
C.XCursorPosition(&x, &y)
return int(x), int(y)
}
func Scroll(x, y int) { func Scroll(x, y int) {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()

View File

@ -16,6 +16,7 @@ int XDisplayOpen(char *input);
void XDisplayClose(void); void XDisplayClose(void);
void XMove(int x, int y); void XMove(int x, int y);
void XCursorPosition(int *x, int *y);
void XScroll(int x, int y); void XScroll(int x, int y);
void XButton(unsigned int button, int down); void XButton(unsigned int button, int down);
void XKey(unsigned long key, int down); void XKey(unsigned long key, int down);

View File

@ -49,6 +49,7 @@ type DesktopManager interface {
// xorg // xorg
Move(x, y int) Move(x, y int)
OnCursorPosition(listener func(x, y int)) OnCursorPosition(listener func(x, y int))
GetCursorPosition() (int, int)
Scroll(x, y int) Scroll(x, y int)
ButtonDown(code int) error ButtonDown(code int) error
KeyDown(code uint64) error KeyDown(code uint64) error