|
From: Elias N. <eli...@us...> - 2003-02-14 11:23:04
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/linux In directory sc8-pr-cvs1:/tmp/cvs-serv7005/linux Modified Files: org_lwjgl_Display.cpp org_lwjgl_input_Keyboard.cpp org_lwjgl_input_Mouse.cpp org_lwjgl_opengl_BaseGL.cpp Log Message: Don't fail create if grab doesn't succeed on the first try 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.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- org_lwjgl_Display.cpp 12 Feb 2003 17:12:01 -0000 1.18 +++ org_lwjgl_Display.cpp 14 Feb 2003 11:23:01 -0000 1.19 @@ -84,7 +84,7 @@ int stencil; }; -int fillFormat(struct pixelformat *formats, int index, int bpp, int depth, int alpha, int stencil) { +static int fillFormat(struct pixelformat *formats, int index, int bpp, int depth, int alpha, int stencil) { for (int i = 0; i < index; i++) if (formats[i].bpp == bpp && formats[i].depth == depth && @@ -98,7 +98,7 @@ return 1; } -struct pixelformat *getGLXAvailablePixelFormats(Display *disp, int screen, int *length) { +static struct pixelformat *getGLXAvailablePixelFormats(Display *disp, int screen, int *length) { if (extgl_Extensions.glx.GLX13 == 1) { int num_formats; int attriblist[] = {GLX_DOUBLEBUFFER, True, @@ -148,7 +148,7 @@ return NULL; } -XVisualInfo *chooseVisual(Display *disp, int screen, int bpp, int depth, int alpha, int stencil) { +static XVisualInfo *chooseVisual(Display *disp, int screen, int bpp, int depth, int alpha, int stencil) { int bpe; switch (bpp) { case 32: @@ -174,7 +174,7 @@ return glXChooseVisual(disp, screen, attriblist); } -struct pixelformat *getAvailablePixelFormats(Display *disp, int screen, int *length) { +static struct pixelformat *getAvailablePixelFormats(Display *disp, int screen, int *length) { struct pixelformat *formats = getGLXAvailablePixelFormats(disp, screen, length); if (formats != NULL) return formats; @@ -195,7 +195,7 @@ return formats; } -void waitMapped(Display *disp, Window win) { +static void waitMapped(Display *disp, Window win) { XEvent event; do { @@ -250,7 +250,7 @@ } } -bool loadGL(Display *disp, int screen) { +static bool loadGL(Display *disp, int screen) { if (gl_loaded == true) return true; if (extgl_Open(disp, screen) != 0) { @@ -263,12 +263,12 @@ return true; } -void closeGL(void) { +static void closeGL(void) { gl_loaded = false; extgl_Close(); } -int getDisplayModes(Display *disp, int screen, int *num_modes, XF86VidModeModeInfo ***avail_modes) { +static int getDisplayModes(Display *disp, int screen, int *num_modes, XF86VidModeModeInfo ***avail_modes) { int event_base, error_base, xvid_ver, xvid_rev; if (!XF86VidModeQueryExtension(disp, &event_base, &error_base)) { @@ -285,7 +285,7 @@ return 1; } -bool isMinimized() { +static bool isMinimized() { handleMessages(); return current_minimized; } Index: org_lwjgl_input_Keyboard.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/linux/org_lwjgl_input_Keyboard.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/linux/org_lwjgl_input_Keyboard.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- org_lwjgl_input_Keyboard.cpp 12 Feb 2003 17:12:01 -0000 1.14 +++ org_lwjgl_input_Keyboard.cpp 14 Feb 2003 11:23:01 -0000 1.15 @@ -63,6 +63,7 @@ static bool buffer_enabled; static bool translation_enabled; static bool created = false; +static bool should_grab = false; extern Display *disp; extern Window win; @@ -88,14 +89,14 @@ fid_readBuffer = env->GetStaticFieldID(clazz, "readBuffer", "Ljava/nio/ByteBuffer;"); } -int grabKeyboard(void) { +static int grabKeyboard(void) { int result = XGrabKeyboard(disp, win, False, GrabModeAsync, GrabModeAsync, CurrentTime); if (result == GrabSuccess) keyboard_grabbed = true; return result; } -void ungrabKeyboard(void) { +static void ungrabKeyboard(void) { keyboard_grabbed = false; XUngrabKeyboard(disp, CurrentTime); } @@ -103,13 +104,23 @@ void acquireKeyboard(void) { if (!created) return; - grabKeyboard(); + should_grab = true; } void releaseKeyboard(void) { if (!created) return; - ungrabKeyboard(); + should_grab = false; +} + +static void updateGrab(void) { + if (should_grab) { + if (!keyboard_grabbed) + grabKeyboard(); + } else { + if (keyboard_grabbed) + ungrabKeyboard(); + } } /* @@ -123,13 +134,8 @@ keyboard_grabbed = false; translation_enabled = false; buffer_enabled = false; - - if (grabKeyboard() != GrabSuccess) { -#ifdef _DEBUG - printf("Could not grab keyboard\n"); -#endif - return JNI_FALSE; - } + should_grab = true; + updateGrab(); for (int i = 0; i < KEYBOARD_SIZE; i++) key_map[i] = i; key_map[0x6b] = 0xdb; // Left doze key @@ -169,7 +175,7 @@ created = false; } -XKeyEvent *nextEventElement(void) { +static XKeyEvent *nextEventElement(void) { if (list_start == list_end) return NULL; XKeyEvent *result = &(saved_key_events[list_start]); @@ -177,7 +183,7 @@ return result; } -void putEventElement(XKeyEvent *event) { +static void putEventElement(XKeyEvent *event) { int next_index = (list_end + 1)%KEY_EVENT_BACKLOG; if (next_index == list_start) return; @@ -185,13 +191,13 @@ list_end = next_index; } -unsigned char getKeycode(XKeyEvent *event) { +static unsigned char getKeycode(XKeyEvent *event) { unsigned char keycode = (unsigned char)((event->keycode - 8) & 0xff); keycode = key_map[keycode]; return keycode; } -int translateEvent(int *position, XKeyEvent *event) { +static int translateEvent(int *position, XKeyEvent *event) { static char temp_translation_buffer[KEYBOARD_BUFFER_SIZE]; static XComposeStatus status; int num_chars, i; @@ -222,7 +228,7 @@ return num_chars; } -unsigned char eventState(XKeyEvent *event) { +static unsigned char eventState(XKeyEvent *event) { if (event->type == KeyPress) { return 1; } else if (event->type == KeyRelease) { @@ -262,7 +268,7 @@ unsigned char state; handleMessages(); - + updateGrab(); memcpy((unsigned char*)buf, key_buf, KEYBOARD_SIZE*sizeof(unsigned char)); } @@ -281,7 +287,7 @@ int num_events = 0; handleMessages(); - + updateGrab(); while (buf_count < KEYBOARD_BUFFER_SIZE * 2 && (key_event = nextEventElement()) != NULL) { num_events++; unsigned char keycode = getKeycode(key_event); 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.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- org_lwjgl_input_Mouse.cpp 12 Feb 2003 17:12:01 -0000 1.14 +++ org_lwjgl_input_Mouse.cpp 14 Feb 2003 11:23:01 -0000 1.15 @@ -61,6 +61,7 @@ static bool pointer_grabbed; static bool created = false; +static bool should_grab = false; static jfieldID fid_has_wheel = NULL; static jfieldID fid_button_count = NULL; @@ -101,7 +102,7 @@ fid_dwheel = env->GetStaticFieldID(clazz, "dwheel", "I"); } -int blankCursor(void) { +static int blankCursor(void) { unsigned int best_width, best_height; if (XQueryBestCursor(disp, win, 1, 1, &best_width, &best_height) == 0) { #ifdef _DEBUG @@ -121,7 +122,7 @@ return 1; } -int grabPointer(void) { +static int grabPointer(void) { int result; int mask = FocusChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask; result = XGrabPointer(disp, win, False, mask, GrabModeAsync, GrabModeAsync, win, blank_cursor, CurrentTime); @@ -132,7 +133,7 @@ return result; } -void ungrabPointer(void) { +static void ungrabPointer(void) { pointer_grabbed = false; XUngrabPointer(disp, CurrentTime); } @@ -140,13 +141,24 @@ void acquirePointer(void) { if (!created) return; - grabPointer(); + should_grab = true; } void releasePointer(void) { if (!created) return; - ungrabPointer(); + should_grab = false; +} + + +static void updateGrab(void) { + if (should_grab) { + if (!pointer_grabbed) + grabPointer(); + } else { + if (pointer_grabbed) + ungrabPointer(); + } } /* @@ -172,13 +184,9 @@ #endif return JNI_FALSE; } - if (grabPointer() != GrabSuccess) { -#ifdef _DEBUG - printf("Could not grab pointer\n"); -#endif - return JNI_FALSE; - } created = true; + should_grab = true; + updateGrab(); return JNI_TRUE; } @@ -194,6 +202,7 @@ ungrabPointer(); XFreeCursor(disp, blank_cursor); created = false; + should_grab = false; } void handleButtonPress(XButtonEvent *event) { @@ -240,7 +249,7 @@ current_y = event->y; } -void warpPointer(void) { +static void warpPointer(void) { int i; if (!pointer_grabbed) return; @@ -279,6 +288,7 @@ (JNIEnv * env, jclass clazz) { handleMessages(); + updateGrab(); int moved_x = current_x - last_x; int moved_y = current_y - last_y; int moved_z = current_z - last_z; Index: org_lwjgl_opengl_BaseGL.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/linux/org_lwjgl_opengl_BaseGL.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/linux/org_lwjgl_opengl_BaseGL.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- org_lwjgl_opengl_BaseGL.cpp 9 Feb 2003 17:01:01 -0000 1.7 +++ org_lwjgl_opengl_BaseGL.cpp 14 Feb 2003 11:23:01 -0000 1.8 @@ -49,11 +49,11 @@ extern void handleMessages(); -void makeCurrent(void) { +static void makeCurrent(void) { glXMakeCurrent(disp, win, context); } -void releaseContext(void) { +static void releaseContext(void) { glXMakeCurrent(disp, None, NULL); } |