Update of /cvsroot/java-game-lib/LWJGL/src/native/linux
In directory sc8-pr-cvs1:/tmp/cvs-serv18383
Modified Files:
org_lwjgl_Display.cpp org_lwjgl_input_Mouse.cpp
Log Message:
Added pointer warping to keep pointer in center of the display
Index: org_lwjgl_Display.cpp
CVS Browser:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/linux/org_lwjgl_Display.cpp
===================================================================
RCS file: /cvsroot/java-game-lib/LWJGL/src/native/linux/org_lwjgl_Display.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- org_lwjgl_Display.cpp 26 Nov 2002 03:30:41 -0000 1.4
+++ org_lwjgl_Display.cpp 28 Nov 2002 21:49:11 -0000 1.5
@@ -57,6 +57,8 @@
int current_fullscreen;
int current_focused;
Window win;
+int win_width;
+int win_height;
XF86VidModeModeInfo **avail_modes;
XVisualInfo * vis_info;
@@ -122,7 +124,8 @@
-
+ win_width = width;
+ win_height = height;
current_fullscreen = fullscreen;
current_focused = 0;
disp = XOpenDisplay(NULL);
Index: org_lwjgl_input_Mouse.cpp
CVS Browser:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/linux/org_lwjgl_input_Mouse.cpp
===================================================================
RCS file: /cvsroot/java-game-lib/LWJGL/src/native/linux/org_lwjgl_input_Mouse.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- org_lwjgl_input_Mouse.cpp 28 Nov 2002 09:29:40 -0000 1.5
+++ org_lwjgl_input_Mouse.cpp 28 Nov 2002 21:49:11 -0000 1.6
@@ -49,10 +49,15 @@
#define NUM_BUTTONS 3
+#define POINTER_WARP_BORDER 10
+#define WARP_RETRY 5
+
extern Display *disp;
extern Window win;
extern int screen;
extern int current_fullscreen;
+extern int win_width;
+extern int win_height;
bool pointer_grabbed;
@@ -182,10 +187,6 @@
#endif
return JNI_FALSE;
}
- XWarpPointer(disp, None, win, 0, 0, 0, 0, 0, 0);
- XEvent event;
- while (XCheckMaskEvent(disp, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &event))
- ; // delete events that are pending
return JNI_TRUE;
}
@@ -266,8 +267,8 @@
}
break;
case MotionNotify:
- current_x = event.xbutton.x;
- current_y = event.xbutton.y;
+ current_x = event.xmotion.x;
+ current_y = event.xmotion.y;
break;
default: assert(0);
}
@@ -275,6 +276,34 @@
return count;
}
+void warpPointer(void) {
+ int i;
+ // Reset pointer to middle of screen if inside a certain inner border
+ if (current_x < POINTER_WARP_BORDER || current_y < POINTER_WARP_BORDER ||
+ current_x > win_width - POINTER_WARP_BORDER || current_y > win_height - POINTER_WARP_BORDER) {
+ current_x = last_x = win_width/2;
+ current_y = last_y = win_height/2;
+ XWarpPointer(disp, None, win, 0, 0, 0, 0, current_x, current_y);
+ XEvent event;
+ // Try to catch the warp pointer event
+ for (i = 0; i < WARP_RETRY; i++) {
+ XMaskEvent(disp, PointerMotionMask, &event);
+ if (event.xmotion.x > current_x - POINTER_WARP_BORDER &&
+ event.xmotion.x < current_x + POINTER_WARP_BORDER &&
+ event.xmotion.y > current_y - POINTER_WARP_BORDER &&
+ event.xmotion.y < current_y + POINTER_WARP_BORDER)
+ break;
+#ifdef _DEBUG
+ printf("Skipped event searching for warp event %d, %d\n", event.xmotion.x, event.xmotion.y);
+#endif
+ }
+#ifdef _DEBUG
+ if (i == WARP_RETRY)
+ printf("Never got warp event\n");
+#endif
+ }
+}
+
/*
* Class: org_lwjgl_input_Mouse
* Method: nPoll
@@ -297,4 +326,6 @@
unsigned char * class_buttons = (unsigned char *) env->GetPrimitiveArrayCritical(buttonsArray, NULL);
memcpy(class_buttons, buttons, NUM_BUTTONS*sizeof(unsigned char));
env->ReleasePrimitiveArrayCritical(buttonsArray, class_buttons, 0);
+ if (current_fullscreen)
+ warpPointer();
}
|