From e034c76f19bcf8b1b4a377608ecfeda06e577cd8 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 12 Apr 2004 10:33:39 +0000 Subject: [PATCH] LINUX:Improved warp event ignore --- src/native/linux/org_lwjgl_input_Mouse.cpp | 13 +++++++++++-- src/native/linux/org_lwjgl_opengl_Window.cpp | 12 +++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/native/linux/org_lwjgl_input_Mouse.cpp b/src/native/linux/org_lwjgl_input_Mouse.cpp index 213e879f..6e263510 100644 --- a/src/native/linux/org_lwjgl_input_Mouse.cpp +++ b/src/native/linux/org_lwjgl_input_Mouse.cpp @@ -161,9 +161,18 @@ void updatePointerGrab(void) { } static void doWarpPointer(void ) { - int i; +// int i; + XEvent ignore_warp_guard; + ignore_warp_guard.type = MotionNotify; + ignore_warp_guard.xmotion.state = 1; // Tell event loop to start ignoring motion events centerCursor(); + XSendEvent(getDisplay(), getCurrentWindow(), False, 0, &ignore_warp_guard); XWarpPointer(getDisplay(), None, getCurrentWindow(), 0, 0, 0, 0, current_x, current_y); + ignore_warp_guard.xmotion.state = 0; // Tell event loop to stop ignoring motion events + XSendEvent(getDisplay(), getCurrentWindow(), False, 0, &ignore_warp_guard); + + centerCursor(); +/* XWarpPointer(getDisplay(), None, getCurrentWindow(), 0, 0, 0, 0, current_x, current_y); XEvent event; // Try to catch the warp pointer event for (i = 0; i < WARP_RETRY; i++) { @@ -176,7 +185,7 @@ static void doWarpPointer(void ) { printfDebug("Skipped event searching for warp event %d, %d\n", event.xmotion.x, event.xmotion.y); } if (i == WARP_RETRY) - printfDebug("Never got warp event\n"); + printfDebug("Never got warp event\n");*/ } static void warpPointer(void) { diff --git a/src/native/linux/org_lwjgl_opengl_Window.cpp b/src/native/linux/org_lwjgl_opengl_Window.cpp index 4ff2329c..d9e1bf81 100644 --- a/src/native/linux/org_lwjgl_opengl_Window.cpp +++ b/src/native/linux/org_lwjgl_opengl_Window.cpp @@ -73,6 +73,7 @@ static bool minimized; static bool focused; static bool closerequested; static bool grab; +static bool ignore_motion_events; static Display *display_connection = NULL; static int display_connection_usage = 0; @@ -152,6 +153,14 @@ void setGrab(bool new_grab) { updateInputGrab(); } +static void handleMotion(XMotionEvent *event) { + if (event->send_event == True) { + // We got a warp ignore message + ignore_motion_events = event->state == 1 ? true : false; + } else if (!ignore_motion_events) + handlePointerMotion(event); +} + static void handleMessages() { XEvent event; Window win; @@ -194,7 +203,7 @@ static void handleMessages() { handleButtonRelease(&(event.xbutton)); break; case MotionNotify: - handlePointerMotion(&(event.xmotion)); + handleMotion(&(event.xmotion)); break; case KeyPress: case KeyRelease: @@ -223,6 +232,7 @@ static void createWindow(JNIEnv* env, int screen, XVisualInfo *vis_info, jstring closerequested = false; vsync_enabled = false; grab = false; + ignore_motion_events = false; Window root_win; Window win; XSetWindowAttributes attribs;