|
From: Elias N. <eli...@us...> - 2003-02-09 17:01:07
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/linux In directory sc8-pr-cvs1:/tmp/cvs-serv22891/linux Modified Files: org_lwjgl_Display.cpp org_lwjgl_input_Keyboard.cpp org_lwjgl_input_Mouse.cpp org_lwjgl_opengl_BaseGL.cpp Log Message: Added closeRequested support to linux 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.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- org_lwjgl_Display.cpp 9 Feb 2003 11:06:51 -0000 1.16 +++ org_lwjgl_Display.cpp 9 Feb 2003 17:01:01 -0000 1.17 @@ -55,6 +55,7 @@ int screen; Window win; +static jfieldID fid_close; static bool current_fullscreen; static bool current_focused; static bool current_minimized; @@ -62,7 +63,15 @@ static int win_height; 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 *); +extern void handleButtonPress(XButtonEvent *); +extern void handleButtonRelease(XButtonEvent *); +extern void handleKeyEvent(XKeyEvent *); struct pixelformat { int bpp; @@ -192,8 +201,13 @@ void handleMessages(void) { XEvent event; - while (XCheckMaskEvent(disp, EnterWindowMask | LeaveWindowMask | StructureNotifyMask, &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); + break; case EnterNotify: current_focused = true; break; @@ -206,6 +220,19 @@ case UnmapNotify: current_minimized = true; break; + case ButtonPress: + handleButtonPress(&(event.xbutton)); + break; + case ButtonRelease: + handleButtonRelease(&(event.xbutton)); + break; + case MotionNotify: + handlePointerMotion(&(event.xmotion)); + break; + case KeyPress: + case KeyRelease: + handleKeyEvent(&(event.xkey)); + break; } } } @@ -249,12 +276,12 @@ return current_fullscreen; } -bool isFocused(void) { +bool isFocused() { handleMessages(); return current_focused; } -bool isMinimized(void) { +bool isMinimized() { handleMessages(); return current_minimized; } @@ -281,6 +308,10 @@ } 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; + saved_clazz = clazz; + fid_close = env->GetStaticFieldID(clazz, "closeRequested", "Z"); + Window root_win; XSetWindowAttributes attribs; Colormap cmap; @@ -350,6 +381,8 @@ size_hints->max_height = height; XSetWMNormalHints(disp, win, size_hints); XFree(size_hints); + delete_atom = XInternAtom(disp, "WM_DELETE_WINDOW", False); + XSetWMProtocols(disp, win, &delete_atom, 1); XMapRaised(disp, win); waitMapped(disp, win); if (fullscreen) { 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.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- org_lwjgl_input_Keyboard.cpp 8 Feb 2003 19:55:07 -0000 1.12 +++ org_lwjgl_input_Keyboard.cpp 9 Feb 2003 17:01:01 -0000 1.13 @@ -48,7 +48,7 @@ #define KEYBOARD_BUFFER_SIZE 50 #define KEYBOARD_SIZE 256 -#define KEY_EVENT_BACKLOG 20 +#define KEY_EVENT_BACKLOG 40 static unsigned char readBuffer[KEYBOARD_BUFFER_SIZE * 2]; static jfieldID fid_readBuffer; @@ -69,6 +69,7 @@ extern bool isFullscreen(void); extern bool isFocused(void); +extern void handleMessages(void); /* * Class: org_lwjgl_input_Keyboard @@ -100,7 +101,7 @@ XUngrabKeyboard(disp, CurrentTime); } -int updateKeyboardGrab(void) { +int updateKeyboardGrab() { if (isFullscreen()) { if (!keyboard_grabbed) return grabKeyboard(); @@ -233,6 +234,14 @@ assert(0); } +void handleKeyEvent(XKeyEvent *event) { + unsigned char keycode = getKeycode(event); + unsigned char state = eventState(event); + key_buf[keycode] = state; + if (buffer_enabled) + putEventElement(event); +} + /* * Class: org_lwjgl_input_Keyboard * Method: nPoll @@ -245,14 +254,8 @@ unsigned char state; updateKeyboardGrab(); + handleMessages(); - while (XCheckMaskEvent(disp, KeyPressMask | KeyReleaseMask, &event)) { - unsigned char keycode = getKeycode(&(event.xkey)); - state = eventState(&(event.xkey)); - key_buf[keycode] = state; - if (buffer_enabled) - putEventElement(&(event.xkey)); - } memcpy((unsigned char*)buf, key_buf, KEYBOARD_SIZE*sizeof(unsigned char)); } @@ -271,6 +274,7 @@ int num_events = 0; updateKeyboardGrab(); + handleMessages(); while (buf_count < KEYBOARD_BUFFER_SIZE * 2 && (key_event = nextEventElement()) != NULL) { num_events++; @@ -283,17 +287,6 @@ num_events += translateEvent(&buf_count, key_event); } - while (buf_count < KEYBOARD_BUFFER_SIZE * 2 && XCheckMaskEvent(disp, KeyPressMask | KeyReleaseMask, &event)) { - num_events++; - unsigned char keycode = getKeycode(&(event.xkey)); - unsigned char state = eventState(&(event.xkey)); -// printf("Reading a key %d %d count %d\n", (int)keycode, (int)state, num_events); - key_buf[keycode] = state; - readBuffer[buf_count++] = keycode; - readBuffer[buf_count++] = state; - if (translation_enabled) - num_events += translateEvent(&buf_count, &(event.xkey)); - } return num_events; } 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.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- org_lwjgl_input_Mouse.cpp 8 Feb 2003 20:36:31 -0000 1.12 +++ org_lwjgl_input_Mouse.cpp 9 Feb 2003 17:01:01 -0000 1.13 @@ -59,6 +59,7 @@ extern bool isFocused(void); extern int getWindowWidth(void); extern int getWindowHeight(void); +extern void handleMessages(void); static bool pointer_grabbed; @@ -140,7 +141,7 @@ XUngrabPointer(disp, CurrentTime); } -int updatePointerGrab(void) { +int updatePointerGrab(JNIEnv *env, jclass clazz) { if (isFullscreen()) { if (!pointer_grabbed) return grabPointer(); @@ -179,7 +180,7 @@ #endif return JNI_FALSE; } - if (updatePointerGrab() != GrabSuccess) { + if (updatePointerGrab(env, clazz) != GrabSuccess) { #ifdef _DEBUG printf("Could not grab pointer\n"); #endif @@ -201,58 +202,48 @@ XFreeCursor(disp, blank_cursor); } -int checkPointer() { - XEvent event; - int count = 0; - updatePointerGrab(); - while (XCheckMaskEvent(disp, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &event)) { - count++; - switch (event.type) { - case ButtonPress: - switch (event.xbutton.button) { - case Button1: - buttons[0] = JNI_TRUE; - break; - case Button2: - buttons[1] = JNI_TRUE; - break; - case Button3: - buttons[2] = JNI_TRUE; - break; - case Button4: - current_z--; - break; - case Button5: - current_z++; - break; - default: assert(0); - } - break; - case ButtonRelease: - switch (event.xbutton.button) { - case Button1: - buttons[0] = JNI_FALSE; - break; - case Button2: - buttons[1] = JNI_FALSE; - break; - case Button3: - buttons[2] = JNI_FALSE; - break; - case Button4: /* Fall through */ - case Button5: - break; - default: assert(0); - } - break; - case MotionNotify: - current_x = event.xmotion.x; - current_y = event.xmotion.y; - break; - default: assert(0); - } +void handleButtonPress(XButtonEvent *event) { + switch (event->button) { + case Button1: + buttons[0] = JNI_TRUE; + break; + case Button2: + buttons[1] = JNI_TRUE; + break; + case Button3: + buttons[2] = JNI_TRUE; + break; + case Button4: + current_z--; + break; + case Button5: + current_z++; + break; + default: assert(0); } - return count; +} + +void handleButtonRelease(XButtonEvent *event) { + switch (event->button) { + case Button1: + buttons[0] = JNI_FALSE; + break; + case Button2: + buttons[1] = JNI_FALSE; + break; + case Button3: + buttons[2] = JNI_FALSE; + break; + case Button4: /* Fall through */ + case Button5: + break; + default: assert(0); + } +} + +void handlePointerMotion(XMotionEvent *event) { + current_x = event->x; + current_y = event->y; } void warpPointer(void) { @@ -291,7 +282,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nPoll (JNIEnv * env, jclass clazz) { - checkPointer(); + updatePointerGrab(env, clazz); + handleMessages(); 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.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- org_lwjgl_opengl_BaseGL.cpp 8 Feb 2003 19:55:07 -0000 1.6 +++ org_lwjgl_opengl_BaseGL.cpp 9 Feb 2003 17:01:01 -0000 1.7 @@ -42,11 +42,13 @@ #include "extgl.h" #include "org_lwjgl_opengl_BaseGL.h" -GLXContext context = NULL; // OpenGL rendering context +static GLXContext context = NULL; // OpenGL rendering context extern XVisualInfo * getVisualInfo(void); extern Window win; extern Display * disp; +extern void handleMessages(); + void makeCurrent(void) { glXMakeCurrent(disp, win, context); } @@ -113,6 +115,7 @@ */ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers(JNIEnv * env, jobject obj) { + handleMessages(); glXSwapBuffers(disp, win); } |