|
From: Elias N. <eli...@us...> - 2004-09-30 12:32:09
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/linux In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14824/linux Modified Files: org_lwjgl_input_Mouse.c Log Message: Linux: improved cursor position tracking Index: org_lwjgl_input_Mouse.c =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/linux/org_lwjgl_input_Mouse.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- org_lwjgl_input_Mouse.c 28 Sep 2004 13:02:38 -0000 1.14 +++ org_lwjgl_input_Mouse.c 30 Sep 2004 12:31:59 -0000 1.15 @@ -326,17 +326,13 @@ return v1 < v2 ? v1 : v2; } -void handlePointerMotion(XMotionEvent *event) { - int x = event->x; - int y = event->y; - setCursorPos(x, y); +static void doHandlePointerMotion(int root_x, int root_y, int win_x, int win_y) { + setCursorPos(win_x, win_y); if (!pointer_grabbed || !shouldGrab()) return; - int x_root = event->x_root; - int y_root = event->y_root; // find the window position in root coordinates - int win_left = x_root - x; - int win_top = y_root - y; + int win_left = root_x - win_x; + int win_top = root_y - win_y; int win_right = win_left + getWindowWidth(); int win_bottom = win_top + getWindowHeight(); // cap the window position to the screen dimensions @@ -345,8 +341,8 @@ int border_right = min(getScreenModeWidth(), win_right); int border_bottom = min(getScreenModeHeight(), win_bottom); // determine whether the cursor is outside the bounds - bool outside_limits = x_root < border_left + POINTER_WARP_BORDER || y_root < border_top + POINTER_WARP_BORDER || - x_root > border_right - POINTER_WARP_BORDER || y_root > border_bottom - POINTER_WARP_BORDER; + bool outside_limits = root_x < border_left + POINTER_WARP_BORDER || root_y < border_top + POINTER_WARP_BORDER || + root_x > border_right - POINTER_WARP_BORDER || root_y > border_bottom - POINTER_WARP_BORDER; if (outside_limits) { // Find the center of the limits in window coordinates int center_x = (border_right - border_left)/2; @@ -355,6 +351,10 @@ } } +void handlePointerMotion(XMotionEvent *event) { + doHandlePointerMotion(event->x_root, event->y_root, event->x, event->y); +} + JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nPoll(JNIEnv * env, jclass clazz, jobject coord_buffer_obj, jobject button_buffer_obj) { int *coords = (int *)(*env)->GetDirectBufferAddress(env, coord_buffer_obj); int coords_length = (*env)->GetDirectBufferCapacity(env, coord_buffer_obj); @@ -389,7 +389,13 @@ } JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nGrabMouse(JNIEnv * env, jclass clazz, jboolean new_grab) { + Window root_return, child_return; + int root_x, root_y, win_x, win_y; + unsigned int mask_return; + setGrab(new_grab == JNI_TRUE ? true : false); resetCursorToCenter(); + XQueryPointer(getDisplay(), getCurrentWindow(), &root_return, &child_return, &root_x, &root_y, &win_x, &win_y, &mask_return); + doHandlePointerMotion(root_x, root_y, win_x, win_y); accum_dx = accum_dy = 0; } |