|
From: Elias N. <eli...@us...> - 2003-03-30 19:26:42
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/linux In directory sc8-pr-cvs1:/tmp/cvs-serv14073/src/native/linux Modified Files: Makefile.am org_lwjgl_Display.cpp org_lwjgl_input_Keyboard.cpp org_lwjgl_input_Mouse.cpp org_lwjgl_opengl_BaseGL.cpp Added Files: Window.h org_lwjgl_Window.cpp Log Message: Linux/win32 changes for 0.6 --- NEW FILE: Window.h --- CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/linux/Window.h /* * Copyright (c) 2002 Light Weight Java Game Library Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of 'Light Weight Java Game Library' nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** * $Id: Window.h,v 1.1 2003/03/30 19:26:39 elias_naur Exp $ * * Include file to access public window features * * @author elias_naur <eli...@us...> * @version $Revision: 1.1 $ */ #ifndef _LWJGL_WINDOW_H_INCLUDED_ #define _LWJGL_WINDOW_H_INCLUDED_ #include <jni.h> #include <X11/X.h> #include <X11/Xlib.h> #include <X11/Xutil.h> /* * release input (keyboard, mouse) */ extern bool releaseInput(void); /* * Various functions to release/acquire keyboard and mouse */ extern void handlePointerMotion(XMotionEvent *); extern void handleButtonPress(XButtonEvent *); extern void handleButtonRelease(XButtonEvent *); extern void handleKeyEvent(XKeyEvent *); extern void releaseKeyboard(void); extern void releasePointer(void); extern void acquireKeyboard(void); extern void acquirePointer(void); /* * destroy the window */ extern void destroyWindow(void); /* * create a new X window with the specified visual */ extern void createWindow(JNIEnv *env, Display *disp, int screen, XVisualInfo *vis_info, jstring title, int x, int y, int width, int height, bool fullscreen); /* * get the current window width */ extern int getWindowWidth(void); /* * get the current window height */ extern int getWindowHeight(void); /* * get the current display */ extern Display *getCurrentDisplay(void); /* * get the current screen */ extern int getCurrentScreen(void); /* * get the current window */ extern Window getCurrentWindow(void); /* * Utility function to throw an Exception */ extern void throwException(JNIEnv * env, const char * err); /* * Utility function to throw a RuntimeException */ extern void throwRuntimeException(JNIEnv * env, const char * err); #endif /* _LWJGL_WINDOW_H_INCLUDED_ */ --- NEW FILE: org_lwjgl_Window.cpp --- CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/linux/org_lwjgl_Window.cpp /* * Copyright (c) 2002 Light Weight Java Game Library Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of 'Light Weight Java Game Library' nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** * $Id: org_lwjgl_Window.cpp,v 1.1 2003/03/30 19:26:39 elias_naur Exp $ * * Linux specific window functions. * * @author elias_naur <eli...@us...> * @version $Revision: 1.1 $ */ #include <X11/X.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <jni.h> #include <Window.h> #include "org_lwjgl_Window.h" static Atom delete_atom; static Display *current_disp; static Window current_win; static int current_screen; static bool current_fullscreen; static int current_height; static int current_width; static bool input_released; static void waitMapped(Display *disp, Window win) { XEvent event; do { XMaskEvent(disp, StructureNotifyMask, &event); } while ((event.type != MapNotify) || (event.xmap.event != win)); } bool releaseInput(void) { if (current_fullscreen) return false; releaseKeyboard(); releasePointer(); input_released = true; return true; } static void acquireInput(void) { if (input_released) { acquireKeyboard(); acquirePointer(); input_released = false; } } static void handleMessages(JNIEnv *env, jobject window_obj) { XEvent event; while (XPending(current_disp) > 0) { XNextEvent(current_disp, &event); switch (event.type) { case ClientMessage: if ((event.xclient.format == 32) && ((Atom)event.xclient.data.l[0] == delete_atom)) env->SetBooleanField(window_obj, env->GetFieldID(env->GetObjectClass(window_obj), "closeRequested", "Z"), JNI_TRUE); break; case FocusIn: acquireInput(); break; case MapNotify: env->SetBooleanField(window_obj, env->GetFieldID(env->GetObjectClass(window_obj), "dirty", "Z"), JNI_TRUE); env->SetBooleanField(window_obj, env->GetFieldID(env->GetObjectClass(window_obj), "minimized", "Z"), JNI_FALSE); break; case UnmapNotify: env->SetBooleanField(window_obj, env->GetFieldID(env->GetObjectClass(window_obj), "minimized", "Z"), JNI_TRUE); case Expose: env->SetBooleanField(window_obj, env->GetFieldID(env->GetObjectClass(window_obj), "dirty", "Z"), JNI_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; } } } static void setWindowTitle(const char *title) { XStoreName(current_disp, current_win, title); } JNIEXPORT void JNICALL Java_org_lwjgl_Window_nSetTitle (JNIEnv * env, jobject obj, jstring title_obj) { const char * title = env->GetStringUTFChars(title_obj, NULL); setWindowTitle(title); env->ReleaseStringUTFChars(title_obj, title); } void createWindow(JNIEnv* env, Display *disp, int screen, XVisualInfo *vis_info, jstring title, int x, int y, int width, int height, bool fullscreen) { Window root_win; Window win; XSetWindowAttributes attribs; Colormap cmap; int attribmask; current_disp = disp; current_screen = screen; input_released = false; current_fullscreen = fullscreen; current_width = width; current_height = height; root_win = RootWindow(disp, screen); cmap = XCreateColormap(disp, root_win, vis_info->visual, AllocNone); attribs.colormap = cmap; attribs.event_mask = ExposureMask | FocusChangeMask | VisibilityChangeMask| StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; attribs.background_pixel = 0xFF000000; attribmask = CWColormap | CWBackPixel | CWEventMask; if (fullscreen) { attribmask |= CWOverrideRedirect; attribs.override_redirect = True; } win = XCreateWindow(disp, root_win, x, y, width, height, 0, vis_info->depth, InputOutput, vis_info->visual, attribmask, &attribs); XFreeColormap(disp, cmap); #ifdef _DEBUG printf("Created window\n"); #endif current_win = win; Java_org_lwjgl_Window_nSetTitle(env, NULL, title); XSizeHints * size_hints = XAllocSizeHints(); size_hints->flags = PMinSize | PMaxSize; size_hints->min_width = width; size_hints->max_width = width; size_hints->min_height = height; 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); XClearWindow(disp, win); XSync(disp, True); } void destroyWindow() { XDestroyWindow(current_disp, current_win); current_disp = NULL; } Display *getCurrentDisplay(void) { return current_disp; } int getCurrentScreen(void) { return current_screen; } Window getCurrentWindow(void) { return current_win; } int getWindowWidth(void) { return current_width; } int getWindowHeight(void) { return current_height; } /* * Class: org_lwjgl_Window * Method: tick * Signature: ()V */ JNIEXPORT void JNICALL Java_org_lwjgl_Window_tick (JNIEnv *env, jobject obj) { handleMessages(env, obj); } /* * Utility function to throw an Exception */ void throwException(JNIEnv * env, const char * err) { jclass cls = env->FindClass("java/lang/Exception"); env->ThrowNew(cls, err); env->DeleteLocalRef(cls); } /* * Utility function to throw a RuntimeException */ void throwRuntimeException(JNIEnv * env, const char * err) { jclass cls = env->FindClass("java/lang/RuntimeException"); env->ThrowNew(cls, err); env->DeleteLocalRef(cls); } Index: Makefile.am CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/linux/Makefile.am =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/linux/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Makefile.am 11 Jan 2003 21:03:22 -0000 1.2 +++ Makefile.am 30 Mar 2003 19:26:39 -0000 1.3 @@ -9,6 +9,7 @@ org_lwjgl_input_Controller.cpp \ org_lwjgl_input_Keyboard.cpp \ org_lwjgl_input_Mouse.cpp \ - org_lwjgl_opengl_BaseGL.cpp + org_lwjgl_opengl_BaseGL.cpp \ + org_lwjgl_Window.cpp 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.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- org_lwjgl_Display.cpp 27 Mar 2003 18:27:35 -0000 1.31 +++ org_lwjgl_Display.cpp 30 Mar 2003 19:26:39 -0000 1.32 @@ -51,155 +51,8 @@ #include <jni.h> #include "org_lwjgl_Display.h" -Display * disp; -int screen; -Window win; - -static jfieldID fid_close; -static bool current_fullscreen; -static bool current_minimized; -static bool input_released; -static int win_width; -static int win_height; -static XF86VidModeModeInfo **avail_modes; -static XVisualInfo * vis_info; -static Atom delete_atom; -static jclass saved_clazz; - -extern void handlePointerMotion(XMotionEvent *); -extern void handleButtonPress(XButtonEvent *); -extern void handleButtonRelease(XButtonEvent *); -extern void handleKeyEvent(XKeyEvent *); -extern void releaseKeyboard(void); -extern void releasePointer(void); -extern void acquireKeyboard(void); -extern void acquirePointer(void); - -struct pixelformat { - 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: - case 24: - bpe = 8; - break; - case 16: - bpe = 4; - break; - default: - return JNI_FALSE; - } - - int attriblist[] = { GLX_RGBA, - GLX_DOUBLEBUFFER, - GLX_DEPTH_SIZE, depth, - GLX_RED_SIZE, bpe, - GLX_GREEN_SIZE, bpe, - GLX_BLUE_SIZE, bpe, - GLX_ALPHA_SIZE, alpha, - GLX_STENCIL_SIZE, stencil, - None }; - return glXChooseVisual(disp, screen, attriblist); -} - -static void dumpVisualInfo(Display *disp, XVisualInfo *vis_info) { - int alpha, depth, stencil, r, g, b; - glXGetConfig(disp, vis_info, GLX_RED_SIZE, &r); - glXGetConfig(disp, vis_info, GLX_GREEN_SIZE, &g); - glXGetConfig(disp, vis_info, GLX_BLUE_SIZE, &b); - glXGetConfig(disp, vis_info, GLX_ALPHA_SIZE, &alpha); - glXGetConfig(disp, vis_info, GLX_DEPTH_SIZE, &depth); - glXGetConfig(disp, vis_info, GLX_STENCIL_SIZE, &stencil); - printf("Pixel format chosen sizes: r = %d, g = %d, b = %d, a = %d, depth = %d, stencil = %d\n", r, g, b, alpha, depth, stencil); -} - -static void waitMapped(Display *disp, Window win) { - XEvent event; - - do { - XMaskEvent(disp, StructureNotifyMask, &event); - } while ((event.type != MapNotify) || (event.xmap.event != win)); -} - -static void setRepeatMode(int mode) { - XKeyboardControl repeat_mode; - repeat_mode.auto_repeat_mode = mode; - XChangeKeyboardControl(disp, KBAutoRepeatMode, &repeat_mode); -} - -bool releaseInput(void) { - if (current_fullscreen) - return false; - releaseKeyboard(); - releasePointer(); - input_released = true; - setRepeatMode(AutoRepeatModeDefault); - return true; -} - -static void acquireInput(void) { - if (input_released) { - setRepeatMode(AutoRepeatModeOff); - acquireKeyboard(); - acquirePointer(); - input_released = false; - } -} - -void handleMessages(JNIEnv *env) { - XEvent event; - while (XPending(disp) > 0) { - XNextEvent(disp, &event); - switch (event.type) { - case ClientMessage: - if ((event.xclient.format == 32) && ((Atom)event.xclient.data.l[0] == delete_atom)) - env->SetStaticBooleanField(saved_clazz, fid_close, JNI_TRUE); - break; - case FocusIn: - acquireInput(); - break; - case MapNotify: - current_minimized = false; - break; - 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; - } - } -} - -static bool loadGL(Display *disp, int screen) { - if (extgl_Open(disp, screen) != 0) { -#ifdef _DEBUG - printf("Could not load gl libs\n"); -#endif - return false; - } - return true; -} - -static void closeGL(void) { - extgl_Close(); -} +static int saved_width; +static int saved_height; static int getDisplayModes(Display *disp, int screen, int *num_modes, XF86VidModeModeInfo ***avail_modes) { int event_base, error_base, xvid_ver, xvid_rev; @@ -218,170 +71,101 @@ return 1; } -static bool isMinimized(JNIEnv *env, jclass clazz) { - handleMessages(env); - return current_minimized; -} - -int getWindowHeight(void) { - return win_height; -} - -int getWindowWidth(void) { - return win_width; -} - -XVisualInfo *getVisualInfo(void) { - return vis_info; -} - -/* - * Class: org_lwjgl_Display - * Method: isMinimized - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_isMinimized(JNIEnv *env, jclass clazz) { - 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) { - // 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; - XSetWindowAttributes attribs; - Colormap cmap; - int attribmask; +static bool setMode(int width, int height, bool lock_mode) { int num_modes, i; + XF86VidModeModeInfo **avail_modes; + int screen; + Display *disp = XOpenDisplay(NULL); - win_width = width; - win_height = height; - if (fullscreen == JNI_TRUE) - current_fullscreen = true; - else - current_fullscreen = false; - current_minimized = false; - input_released = false; - disp = XOpenDisplay(NULL); if (disp == NULL) { #ifdef _DEBUG printf("Could not open X connection\n"); #endif - return JNI_FALSE; + return false; } screen = DefaultScreen(disp); - if (!loadGL(disp, screen)) { - XCloseDisplay(disp); -#ifdef _DEBUG - printf("Could not load GL libs\n"); -#endif - return JNI_FALSE; - } if (!getDisplayModes(disp, screen, &num_modes, &avail_modes)) { XCloseDisplay(disp); #ifdef _DEBUG printf("Could not get display modes\n"); #endif - return JNI_FALSE; - } - root_win = RootWindow(disp, screen); - vis_info = chooseVisual(disp, screen, bpp, depth_bits, alpha_bits, stencil_bits); - if (vis_info == NULL) { - XCloseDisplay(disp); -#ifdef _DEBUG - printf("Could not choose glx visual\n"); -#endif - return JNI_FALSE; - } -#ifdef _DEBUG - dumpVisualInfo(disp, vis_info); -#endif - cmap = XCreateColormap(disp, root_win, vis_info->visual, AllocNone); - attribs.colormap = cmap; - attribs.event_mask = FocusChangeMask | VisibilityChangeMask| StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; - attribs.background_pixel = 0xFF000000; - attribmask = CWColormap | CWBackPixel | CWEventMask; - if (fullscreen) { - attribmask |= CWOverrideRedirect; - attribs.override_redirect = True; + return false; } - win = XCreateWindow(disp, root_win, 0, 0, width, height, 0, vis_info->depth, InputOutput, vis_info->visual, attribmask, &attribs); - XFreeColormap(disp, cmap); -#ifdef _DEBUG - printf("Created window\n"); -#endif - const char * title_str = env->GetStringUTFChars(title, NULL); - XStoreName(disp, win, title_str); - env->ReleaseStringUTFChars(title, title_str); - XSizeHints * size_hints = XAllocSizeHints(); - size_hints->flags = PMinSize | PMaxSize; - size_hints->min_width = width; - size_hints->max_width = width; - size_hints->min_height = height; - 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) { - for ( i = 0; i < num_modes; ++i ) { + XF86VidModeLockModeSwitch(disp, screen, 0); + for ( i = 0; i < num_modes; ++i ) { #ifdef _DEBUG - printf("Mode %d: %dx%d\n", i, avail_modes[i]->hdisplay, avail_modes[i]->vdisplay); + printf("Mode %d: %dx%d\n", i, avail_modes[i]->hdisplay, avail_modes[i]->vdisplay); #endif - if (avail_modes[i]->hdisplay == width && avail_modes[i]->vdisplay == height) { - if (!XF86VidModeSwitchToMode(disp, screen, avail_modes[i])) { - XFree(vis_info); - XFree(avail_modes); - XDestroyWindow(disp, win); - XCloseDisplay(disp); + if (avail_modes[i]->hdisplay == width && avail_modes[i]->vdisplay == height) { + if (!XF86VidModeSwitchToMode(disp, screen, avail_modes[i])) { #ifdef _DEBUG - printf("Could not switch mode\n"); + printf("Could not switch mode\n"); #endif - return JNI_FALSE; - } - XF86VidModeLockModeSwitch(disp, screen, 1); break; } +// XF86VidModeSetViewPort(disp, screen, 0, 0); + if (lock_mode) + XF86VidModeLockModeSwitch(disp, screen, 1); + XFree(avail_modes); + XCloseDisplay(disp); + return true; } - XF86VidModeSetViewPort(disp, screen, 0, 0); } - XClearWindow(disp, win); - setRepeatMode(AutoRepeatModeOff); - XSync(disp, True); - return JNI_TRUE; + XFree(avail_modes); + XCloseDisplay(disp); + return false; } -JNIEXPORT void JNICALL Java_org_lwjgl_Display_nDestroy(JNIEnv * env, jclass clazz) { - setRepeatMode(AutoRepeatModeDefault); - XDestroyWindow(disp, win); - if (current_fullscreen) { - XF86VidModeLockModeSwitch(disp, screen, 0); - if (!XF86VidModeSwitchToMode(disp, screen, avail_modes[0])) { +JNIEXPORT void JNICALL Java_org_lwjgl_Display_init + (JNIEnv * env, jclass clazz) +{ + int num_modes; + XF86VidModeModeInfo **avail_modes; + int screen; + Display *disp = XOpenDisplay(NULL); + if (disp == NULL) { #ifdef _DEBUG - printf("Could not switch mode\n"); + printf("Could not open X connection\n"); +#endif + return; + } + screen = DefaultScreen(disp); + + if (!getDisplayModes(disp, screen, &num_modes, &avail_modes)) { +#ifdef _DEBUG + printf("Could not get display modes\n"); #endif - } } - XFree(avail_modes); - avail_modes = NULL; - XFree(vis_info); - vis_info = NULL; - XCloseDisplay(disp); - disp = NULL; - closeGL(); + saved_width = avail_modes[0]->hdisplay; + saved_height = avail_modes[0]->vdisplay; + int bpp = XDefaultDepth(disp, screen); #ifdef _DEBUG - printf("Closed X connection\n"); + printf("Saved width, height %d, %d\n", saved_width, saved_height); #endif + jclass jclass_DisplayMode = env->FindClass("org/lwjgl/DisplayMode"); + jmethodID ctor = env->GetMethodID(jclass_DisplayMode, "<init>", "(IIII)V"); + jobject newMode = env->NewObject(jclass_DisplayMode, ctor, saved_width, saved_height, bpp, 0); + jfieldID fid_initialMode = env->GetStaticFieldID(clazz, "mode", "Lorg/lwjgl/DisplayMode;"); + env->SetStaticObjectField(clazz, fid_initialMode, newMode); + + XFree(avail_modes); + XCloseDisplay(disp); +} + +JNIEXPORT void JNICALL Java_org_lwjgl_Display_setDisplayMode(JNIEnv * env, jclass clazz, jobject mode) { + jclass cls_displayMode = env->FindClass("org/lwjgl/DisplayMode"); + jfieldID fid_width = env->GetFieldID(cls_displayMode, "width", "I"); + jfieldID fid_height = env->GetFieldID(cls_displayMode, "height", "I"); + int width = env->GetIntField(mode, fid_width); + int height = env->GetIntField(mode, fid_height); + if (setMode(width, height, true)) { + jfieldID fid_initialMode = env->GetStaticFieldID(clazz, "mode", "Lorg/lwjgl/DisplayMode;"); + env->SetStaticObjectField(clazz, fid_initialMode, mode); + } +} + +JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode(JNIEnv * env, jclass clazz) { + setMode(saved_width, saved_height, false); } /* @@ -393,7 +177,6 @@ (JNIEnv * env, jclass clazz) { int num_modes, i; - Display *disp = XOpenDisplay(NULL); int screen; XF86VidModeModeInfo **avail_modes; @@ -402,7 +185,6 @@ #ifdef _DEBUG printf("Could not open X connection\n"); #endif - XCloseDisplay(disp); return NULL; } 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.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- org_lwjgl_input_Keyboard.cpp 27 Mar 2003 15:16:35 -0000 1.19 +++ org_lwjgl_input_Keyboard.cpp 30 Mar 2003 19:26:39 -0000 1.20 @@ -44,6 +44,7 @@ #include <X11/Xutil.h> #include <string.h> #include <assert.h> +#include <Window.h> #include "org_lwjgl_input_Keyboard.h" #define KEYBOARD_BUFFER_SIZE 50 @@ -65,12 +66,6 @@ static bool created = false; static bool should_grab = false; -extern Display *disp; -extern Window win; - -extern bool releaseInput(void); -extern void handleMessages(JNIEnv *env); - /* * Class: org_lwjgl_input_Keyboard * Method: initIDs @@ -82,16 +77,25 @@ fid_readBuffer = env->GetStaticFieldID(clazz, "readBuffer", "Ljava/nio/ByteBuffer;"); } +static void setRepeatMode(int mode) { + XKeyboardControl repeat_mode; + repeat_mode.auto_repeat_mode = mode; + XChangeKeyboardControl(getCurrentDisplay(), KBAutoRepeatMode, &repeat_mode); +} + static int grabKeyboard(void) { - int result = XGrabKeyboard(disp, win, False, GrabModeAsync, GrabModeAsync, CurrentTime); - if (result == GrabSuccess) + int result = XGrabKeyboard(getCurrentDisplay(), getCurrentWindow(), False, GrabModeAsync, GrabModeAsync, CurrentTime); + if (result == GrabSuccess) { keyboard_grabbed = true; + setRepeatMode(AutoRepeatModeOff); + } return result; } static void ungrabKeyboard(void) { keyboard_grabbed = false; - XUngrabKeyboard(disp, CurrentTime); + XUngrabKeyboard(getCurrentDisplay(), CurrentTime); + setRepeatMode(AutoRepeatModeDefault); } void acquireKeyboard(void) { @@ -257,7 +261,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll (JNIEnv * env, jclass clazz, jint buf) { - handleMessages(env); updateGrab(); memcpy((unsigned char*)buf, key_buf, KEYBOARD_SIZE*sizeof(unsigned char)); } @@ -274,7 +277,6 @@ int buf_count = 0; int num_events = 0; - handleMessages(env); updateGrab(); while (buf_count < KEYBOARD_BUFFER_SIZE * 2 && (key_event = nextEventElement()) != NULL) { 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.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- org_lwjgl_input_Mouse.cpp 24 Mar 2003 18:10:04 -0000 1.20 +++ org_lwjgl_input_Mouse.cpp 30 Mar 2003 19:26:39 -0000 1.21 @@ -45,6 +45,7 @@ #include <X11/extensions/xf86vmode.h> #include <assert.h> #include <string.h> +#include <Window.h> #include "org_lwjgl_input_Mouse.h" #define NUM_BUTTONS 3 @@ -54,13 +55,6 @@ // scale the mouse wheel according to win32 #define WHEEL_SCALE 120 -extern Display *disp; -extern Window win; -extern int screen; -extern int getWindowWidth(void); -extern int getWindowHeight(void); -extern void handleMessages(JNIEnv* env); - static bool pointer_grabbed; static bool created = false; static bool should_grab = false; @@ -106,30 +100,30 @@ static int blankCursor(void) { unsigned int best_width, best_height; - if (XQueryBestCursor(disp, win, 1, 1, &best_width, &best_height) == 0) { + if (XQueryBestCursor(getCurrentDisplay(), getCurrentWindow(), 1, 1, &best_width, &best_height) == 0) { #ifdef _DEBUG printf("Could not query best cursor size\n"); #endif return 0; } - Pixmap mask = XCreatePixmap(disp, win, best_width, best_height, 1); + Pixmap mask = XCreatePixmap(getCurrentDisplay(), getCurrentWindow(), best_width, best_height, 1); XGCValues gc_values; gc_values.foreground = 0; - GC gc = XCreateGC(disp, mask, GCForeground, &gc_values); - XFillRectangle(disp, mask, gc, 0, 0, best_width, best_height); - XFreeGC(disp, gc); + GC gc = XCreateGC(getCurrentDisplay(), mask, GCForeground, &gc_values); + XFillRectangle(getCurrentDisplay(), mask, gc, 0, 0, best_width, best_height); + XFreeGC(getCurrentDisplay(), gc); XColor dummy_color; - blank_cursor = XCreatePixmapCursor(disp, mask, mask, &dummy_color, &dummy_color, 0, 0); - XFreePixmap(disp, mask); + blank_cursor = XCreatePixmapCursor(getCurrentDisplay(), mask, mask, &dummy_color, &dummy_color, 0, 0); + XFreePixmap(getCurrentDisplay(), mask); return 1; } static int grabPointer(void) { int result; int mask = FocusChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask; - result = XGrabPointer(disp, win, False, mask, GrabModeAsync, GrabModeAsync, win, blank_cursor, CurrentTime); - XWarpPointer(disp, None, win, 0, 0, 0, 0, current_x, current_y); - XF86VidModeSetViewPort(disp, screen, 0, 0); // make sure we have a centered window + result = XGrabPointer(getCurrentDisplay(), getCurrentWindow(), False, mask, GrabModeAsync, GrabModeAsync, getCurrentWindow(), blank_cursor, CurrentTime); + XWarpPointer(getCurrentDisplay(), None, getCurrentWindow(), 0, 0, 0, 0, current_x, current_y); + XF86VidModeSetViewPort(getCurrentDisplay(), getCurrentScreen(), 0, 0); // make sure we have a centered window if (result == GrabSuccess) pointer_grabbed = true; return result; @@ -137,7 +131,7 @@ static void ungrabPointer(void) { pointer_grabbed = false; - XUngrabPointer(disp, CurrentTime); + XUngrabPointer(getCurrentDisplay(), CurrentTime); } void acquirePointer(void) { @@ -200,7 +194,7 @@ { if (pointer_grabbed) ungrabPointer(); - XFreeCursor(disp, blank_cursor); + XFreeCursor(getCurrentDisplay(), blank_cursor); created = false; should_grab = false; } @@ -258,11 +252,11 @@ current_x > getWindowWidth() - POINTER_WARP_BORDER || current_y > getWindowHeight() - POINTER_WARP_BORDER) { curre... [truncated message content] |