From b641b66e124496f59459e7e88c947a427f99c00a Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 12 Apr 2004 12:20:59 +0000 Subject: [PATCH] LINUX: Fixed warp ignores --- src/native/linux/Window.h | 2 ++ src/native/linux/org_lwjgl_input_Mouse.cpp | 18 +++++++++--------- src/native/linux/org_lwjgl_opengl_Window.cpp | 7 +++++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/native/linux/Window.h b/src/native/linux/Window.h index 66755574..1abaad1e 100644 --- a/src/native/linux/Window.h +++ b/src/native/linux/Window.h @@ -54,6 +54,8 @@ */ extern bool releaseInput(void); + extern void resetCursor(int x, int y); + /* * Various functions to release/acquire keyboard and mouse */ diff --git a/src/native/linux/org_lwjgl_input_Mouse.cpp b/src/native/linux/org_lwjgl_input_Mouse.cpp index 6e263510..24afb40b 100644 --- a/src/native/linux/org_lwjgl_input_Mouse.cpp +++ b/src/native/linux/org_lwjgl_input_Mouse.cpp @@ -93,8 +93,8 @@ static void transformCursorPos(int x, int y) { setCursorPos(x, y); } -static void centerCursor() { - transformCursorPos(getWindowWidth()/2, getWindowHeight()/2); +void resetCursor(int x, int y) { + transformCursorPos(x, y); last_x = current_x; last_y = current_y; } @@ -161,18 +161,18 @@ void updatePointerGrab(void) { } static void doWarpPointer(void ) { -// 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(); + // Tell event loop to start ignoring motion events + ignore_warp_guard.xmotion.state = 1; 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 + XWarpPointer(getDisplay(), None, getCurrentWindow(), 0, 0, 0, 0, getWindowWidth()/2, getWindowHeight()/2); + // Tell event loop to stop ignoring motion events + ignore_warp_guard.xmotion.state = 0; XSendEvent(getDisplay(), getCurrentWindow(), False, 0, &ignore_warp_guard); - centerCursor(); -/* XWarpPointer(getDisplay(), None, getCurrentWindow(), 0, 0, 0, 0, current_x, current_y); +/* 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++) { diff --git a/src/native/linux/org_lwjgl_opengl_Window.cpp b/src/native/linux/org_lwjgl_opengl_Window.cpp index d9e1bf81..c4ef7c8a 100644 --- a/src/native/linux/org_lwjgl_opengl_Window.cpp +++ b/src/native/linux/org_lwjgl_opengl_Window.cpp @@ -157,8 +157,11 @@ 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) + } else if (ignore_motion_events) { + resetCursor(event->x, event->y); + } else { handlePointerMotion(event); + } } static void handleMessages() { @@ -418,7 +421,7 @@ static void dumpVisualInfo(XVisualInfo *vis_info) { glXGetConfig(getDisplay(), vis_info, GLX_SAMPLE_BUFFERS_ARB, &sample_buffers); glXGetConfig(getDisplay(), vis_info, GLX_SAMPLES_ARB, &samples); } - printf("Pixel format info: r = %d, g = %d, b = %d, a = %d, depth = %d, stencil = %d, sample buffers = %d, samples = %d\n", r, g, b, alpha, depth, stencil, sample_buffers, samples); + printfDebug("Pixel format info: r = %d, g = %d, b = %d, a = %d, depth = %d, stencil = %d, sample buffers = %d, samples = %d\n", r, g, b, alpha, depth, stencil, sample_buffers, samples); } static void destroy(void) {