From a7ec7cda5b455a9796f1429b3bd20188cb5fa0a3 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 21 Mar 2003 23:28:00 +0000 Subject: [PATCH] Various linux fixes --- src/native/linux/org_lwjgl_Display.cpp | 20 ++++++++++++------- .../linux/org_lwjgl_input_Controller.cpp | 4 ++-- src/native/linux/org_lwjgl_input_Keyboard.cpp | 13 +++--------- src/native/linux/org_lwjgl_input_Mouse.cpp | 4 ++-- src/native/linux/org_lwjgl_opengl_BaseGL.cpp | 4 ++-- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/native/linux/org_lwjgl_Display.cpp b/src/native/linux/org_lwjgl_Display.cpp index e7fd7458..435b2f40 100644 --- a/src/native/linux/org_lwjgl_Display.cpp +++ b/src/native/linux/org_lwjgl_Display.cpp @@ -65,7 +65,6 @@ static XF86VidModeModeInfo **avail_modes; static XVisualInfo * vis_info; static Atom delete_atom; static bool gl_loaded = false; -static JNIEnv *saved_env; static jclass saved_clazz; extern void handlePointerMotion(XMotionEvent *); @@ -229,14 +228,14 @@ static void acquireInput(void) { } } -void handleMessages(void) { +void handleMessages(JNIEnv *env) { XEvent event; while (XPending(disp) > 0) { XNextEvent(disp, &event); switch (event.type) { case ClientMessage: if ((event.xclient.format == 32) && (event.xclient.data.l[0] == delete_atom)) - saved_env->SetStaticBooleanField(saved_clazz, fid_close, JNI_TRUE); + env->SetStaticBooleanField(saved_clazz, fid_close, JNI_TRUE); break; case FocusIn: acquireInput(); @@ -299,8 +298,8 @@ static int getDisplayModes(Display *disp, int screen, int *num_modes, XF86VidMod return 1; } -static bool isMinimized() { - handleMessages(); +static bool isMinimized(JNIEnv *env, jclass clazz) { + handleMessages(env); return current_minimized; } @@ -322,12 +321,19 @@ XVisualInfo *getVisualInfo(void) { * Signature: ()Z */ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_isMinimized(JNIEnv *env, jclass clazz) { - return isMinimized() ? JNI_TRUE : JNI_FALSE; + return isMinimized(env, clazz) ? JNI_TRUE : JNI_FALSE; } JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate(JNIEnv * env, jclass clazz, jint width, jint height, jint bpp, jint freq, jint alpha_bits, jint depth_bits, jint stencil_bits, jboolean fullscreen, jstring title) { - saved_env = env; + // Get a global class instance, just to be sure + static jobject globalClassLock = NULL; + + if (globalClassLock == NULL) { + globalClassLock = env->NewGlobalRef(clazz); + } + saved_clazz = clazz; + fid_close = env->GetStaticFieldID(clazz, "closeRequested", "Z"); Window root_win; diff --git a/src/native/linux/org_lwjgl_input_Controller.cpp b/src/native/linux/org_lwjgl_input_Controller.cpp index a51be2db..6794425f 100644 --- a/src/native/linux/org_lwjgl_input_Controller.cpp +++ b/src/native/linux/org_lwjgl_input_Controller.cpp @@ -32,9 +32,9 @@ /** * $Id$ * - * Win32 controller handling. + * Linux controller handling. * - * @author Brian Matzon + * @author Elias Naur * @version $Revision$ */ #include diff --git a/src/native/linux/org_lwjgl_input_Keyboard.cpp b/src/native/linux/org_lwjgl_input_Keyboard.cpp index 1356faa0..2844f186 100644 --- a/src/native/linux/org_lwjgl_input_Keyboard.cpp +++ b/src/native/linux/org_lwjgl_input_Keyboard.cpp @@ -69,7 +69,7 @@ extern Display *disp; extern Window win; extern bool releaseInput(void); -extern void handleMessages(void); +extern void handleMessages(JNIEnv *env); /* * Class: org_lwjgl_input_Keyboard @@ -79,13 +79,6 @@ extern void handleMessages(void); JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_initIDs (JNIEnv * env, jclass clazz) { - // Get a global class instance, just to be sure - static jobject globalClassLock = NULL; - - if (globalClassLock == NULL) { - globalClassLock = env->NewGlobalRef(clazz); - } - fid_readBuffer = env->GetStaticFieldID(clazz, "readBuffer", "Ljava/nio/ByteBuffer;"); } @@ -267,7 +260,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll XEvent event; unsigned char state; - handleMessages(); + handleMessages(env); updateGrab(); memcpy((unsigned char*)buf, key_buf, KEYBOARD_SIZE*sizeof(unsigned char)); } @@ -286,7 +279,7 @@ JNIEXPORT int JNICALL Java_org_lwjgl_input_Keyboard_nRead int state; int num_events = 0; - handleMessages(); + handleMessages(env); updateGrab(); while (buf_count < KEYBOARD_BUFFER_SIZE * 2 && (key_event = nextEventElement()) != NULL) { num_events++; diff --git a/src/native/linux/org_lwjgl_input_Mouse.cpp b/src/native/linux/org_lwjgl_input_Mouse.cpp index ca85b6a0..cddf7099 100644 --- a/src/native/linux/org_lwjgl_input_Mouse.cpp +++ b/src/native/linux/org_lwjgl_input_Mouse.cpp @@ -59,7 +59,7 @@ extern Window win; extern int screen; extern int getWindowWidth(void); extern int getWindowHeight(void); -extern void handleMessages(void); +extern void handleMessages(JNIEnv* env); static bool pointer_grabbed; static bool created = false; @@ -289,7 +289,7 @@ static void warpPointer(void) { JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nPoll (JNIEnv * env, jclass clazz) { - handleMessages(); + handleMessages(env); updateGrab(); int moved_x = current_x - last_x; int moved_y = current_y - last_y; diff --git a/src/native/linux/org_lwjgl_opengl_BaseGL.cpp b/src/native/linux/org_lwjgl_opengl_BaseGL.cpp index 48d23930..fbccefa6 100644 --- a/src/native/linux/org_lwjgl_opengl_BaseGL.cpp +++ b/src/native/linux/org_lwjgl_opengl_BaseGL.cpp @@ -47,7 +47,7 @@ extern XVisualInfo * getVisualInfo(void); extern Window win; extern Display * disp; -extern void handleMessages(); +extern void handleMessages(JNIEnv* env); static void makeCurrent(void) { glXMakeCurrent(disp, win, context); @@ -115,7 +115,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroy */ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers(JNIEnv * env, jobject obj) { - handleMessages(); + handleMessages(env); glXSwapBuffers(disp, win); }