diff --git a/internal/desktop/xorg.go b/internal/desktop/xorg.go index ff09a5d0..df182169 100644 --- a/internal/desktop/xorg.go +++ b/internal/desktop/xorg.go @@ -26,6 +26,10 @@ func (manager *DesktopManagerCtx) OnCursorPosition(listener func(x, y int)) { cursorListeners = append(cursorListeners, listener) } +func (manager *DesktopManagerCtx) GetCursorPosition() (int, int) { + return xorg.GetCursorPosition() +} + func (manager *DesktopManagerCtx) Scroll(x, y int) { xorg.Scroll(x, y) } diff --git a/internal/desktop/xorg/xorg.c b/internal/desktop/xorg/xorg.c index fd5be1f9..8d446440 100644 --- a/internal/desktop/xorg/xorg.c +++ b/internal/desktop/xorg/xorg.c @@ -21,6 +21,15 @@ void XMove(int x, int y) { 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) { int ydir = 4; /* Button 4 is up, 5 is down. */ int xdir = 6; diff --git a/internal/desktop/xorg/xorg.go b/internal/desktop/xorg/xorg.go index 92f41b1e..72dc04e9 100644 --- a/internal/desktop/xorg/xorg.go +++ b/internal/desktop/xorg/xorg.go @@ -68,6 +68,17 @@ func Move(x, y int) { 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) { mu.Lock() defer mu.Unlock() diff --git a/internal/desktop/xorg/xorg.h b/internal/desktop/xorg/xorg.h index caa99fc8..8fad29c9 100644 --- a/internal/desktop/xorg/xorg.h +++ b/internal/desktop/xorg/xorg.h @@ -16,6 +16,7 @@ int XDisplayOpen(char *input); void XDisplayClose(void); void XMove(int x, int y); +void XCursorPosition(int *x, int *y); void XScroll(int x, int y); void XButton(unsigned int button, int down); void XKey(unsigned long key, int down); diff --git a/internal/types/desktop.go b/internal/types/desktop.go index c1018115..83076e76 100644 --- a/internal/types/desktop.go +++ b/internal/types/desktop.go @@ -49,6 +49,7 @@ type DesktopManager interface { // xorg Move(x, y int) OnCursorPosition(listener func(x, y int)) + GetCursorPosition() (int, int) Scroll(x, y int) ButtonDown(code int) error KeyDown(code uint64) error