From 73f5f1d2147c83b9b429e30eb1b8d181d77611ac Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Tue, 5 Feb 2019 09:55:13 +0100 Subject: [PATCH] x11: capture pointer when a button is pressed --- src/input.c | 5 +++++ src/x11screen.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/input.c b/src/input.c index e9c5b708..8709ed3d 100644 --- a/src/input.c +++ b/src/input.c @@ -1739,6 +1739,10 @@ int Get_input(int sleep_time) } break; case ButtonPress: // left = 1, middle = 2, right = 3, wheelup = 4, wheeldown = 5 + XGrabPointer(X11_display, X11_window, True, + PointerMotionMask | ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, + X11_window, None, CurrentTime); //printf("Press button = %d state = 0x%08x\n", event.xbutton.button, event.xbutton.state); if (event.xkey.state & ShiftMask) mod |= MOD_SHIFT; @@ -1777,6 +1781,7 @@ int Get_input(int sleep_time) } break; case ButtonRelease: + XUngrabPointer(X11_display, CurrentTime); //printf("Release button = %d\n", event.xbutton.button); if(event.xbutton.button == 1 || event.xbutton.button == 3) { diff --git a/src/x11screen.c b/src/x11screen.c index 3bab4b3a..dba8d67e 100644 --- a/src/x11screen.c +++ b/src/x11screen.c @@ -333,5 +333,7 @@ void Define_icon(void) void Set_mouse_position(void) { - /// @todo implement screen capture and set position for x11. + XWarpPointer(X11_display, None, X11_window, + 0, 0, 0, 0, + Mouse_X * Pixel_width, Mouse_Y * Pixel_height); }