Linux: Made most fields in LinuxDisplay non-static

This commit is contained in:
Elias Naur 2006-07-08 22:17:09 +00:00
parent c208833e25
commit af9e73ed11
2 changed files with 68 additions and 66 deletions

View File

@ -67,9 +67,6 @@ final class LinuxDisplay implements DisplayImplementation {
private static final int XF86VIDMODE = 11; private static final int XF86VIDMODE = 11;
private static final int NONE = 12; private static final int NONE = 12;
/** Current mode swithcing API */
private static int current_displaymode_extension = NONE;
/** Keep track on the current awt lock owner to avoid /** Keep track on the current awt lock owner to avoid
* depending on JAWT locking to be re-entrant (This is a * depending on JAWT locking to be re-entrant (This is a
* problem with GCJ). JAWT locking is not that well specified * problem with GCJ). JAWT locking is not that well specified
@ -81,29 +78,32 @@ final class LinuxDisplay implements DisplayImplementation {
private static int display_connection_usage_count = 0; private static int display_connection_usage_count = 0;
private static PeerInfo peer_info; /** Current mode swithcing API */
private int current_displaymode_extension = NONE;
private PeerInfo peer_info;
/** Saved gamma used to restore display settings */ /** Saved gamma used to restore display settings */
private static ByteBuffer saved_gamma; private ByteBuffer saved_gamma;
private static ByteBuffer current_gamma; private ByteBuffer current_gamma;
/** Saved mode to restore with */ /** Saved mode to restore with */
private static DisplayMode saved_mode; private DisplayMode saved_mode;
private static DisplayMode current_mode; private DisplayMode current_mode;
private static boolean keyboard_grabbed; private boolean keyboard_grabbed;
private static boolean pointer_grabbed; private boolean pointer_grabbed;
private static boolean input_released; private boolean input_released;
private static boolean grab; private boolean grab;
private static boolean focused; private boolean focused;
private static boolean minimized; private boolean minimized;
private static boolean dirty; private boolean dirty;
private static boolean close_requested; private boolean close_requested;
private static ByteBuffer current_cursor; private ByteBuffer current_cursor;
private static ByteBuffer blank_cursor; private ByteBuffer blank_cursor;
private static LinuxKeyboard keyboard; private LinuxKeyboard keyboard;
private static LinuxMouse mouse; private LinuxMouse mouse;
private static ByteBuffer getCurrentGammaRamp() throws LWJGLException { private static ByteBuffer getCurrentGammaRamp() throws LWJGLException {
lockAWT(); lockAWT();
@ -263,7 +263,7 @@ final class LinuxDisplay implements DisplayImplementation {
private static native void openDisplay() throws LWJGLException; private static native void openDisplay() throws LWJGLException;
private static native void closeDisplay(); private static native void closeDisplay();
private static int getWindowMode(boolean fullscreen) throws LWJGLException { private int getWindowMode(boolean fullscreen) throws LWJGLException {
if (fullscreen) { if (fullscreen) {
if (current_displaymode_extension == XRANDR && isNetWMFullscreenSupported()) { if (current_displaymode_extension == XRANDR && isNetWMFullscreenSupported()) {
LWJGLUtil.log("Using NetWM for fullscreen window"); LWJGLUtil.log("Using NetWM for fullscreen window");
@ -280,7 +280,7 @@ final class LinuxDisplay implements DisplayImplementation {
private static native int getScreen(); private static native int getScreen();
private static native long getWindow(); private static native long getWindow();
private static void ungrabKeyboard() { private void ungrabKeyboard() {
if (keyboard_grabbed) { if (keyboard_grabbed) {
nUngrabKeyboard(getDisplay()); nUngrabKeyboard(getDisplay());
keyboard_grabbed = false; keyboard_grabbed = false;
@ -288,7 +288,7 @@ final class LinuxDisplay implements DisplayImplementation {
} }
private static native int nUngrabKeyboard(long display); private static native int nUngrabKeyboard(long display);
private static void grabKeyboard() { private void grabKeyboard() {
if (!keyboard_grabbed) { if (!keyboard_grabbed) {
int res = nGrabKeyboard(getDisplay(), getWindow()); int res = nGrabKeyboard(getDisplay(), getWindow());
if (res == GrabSuccess) if (res == GrabSuccess)
@ -297,7 +297,7 @@ final class LinuxDisplay implements DisplayImplementation {
} }
private static native int nGrabKeyboard(long display, long window); private static native int nGrabKeyboard(long display, long window);
private static void grabPointer() { private void grabPointer() {
if (!pointer_grabbed) { if (!pointer_grabbed) {
int result = nGrabPointer(getDisplay(), getWindow()); int result = nGrabPointer(getDisplay(), getWindow());
if (result == GrabSuccess) { if (result == GrabSuccess) {
@ -312,7 +312,7 @@ final class LinuxDisplay implements DisplayImplementation {
private static native int nGrabPointer(long display, long window); private static native int nGrabPointer(long display, long window);
private static native void nSetViewPort(long display, long window, int screen); private static native void nSetViewPort(long display, long window, int screen);
private static void ungrabPointer() { private void ungrabPointer() {
if (pointer_grabbed) { if (pointer_grabbed) {
pointer_grabbed = false; pointer_grabbed = false;
nUngrabPointer(getDisplay()); nUngrabPointer(getDisplay());
@ -320,15 +320,15 @@ final class LinuxDisplay implements DisplayImplementation {
} }
private static native int nUngrabPointer(long display); private static native int nUngrabPointer(long display);
private static boolean isFullscreen() { private boolean isFullscreen() {
return current_window_mode == FULLSCREEN_LEGACY || current_window_mode == FULLSCREEN_NETWM; return current_window_mode == FULLSCREEN_LEGACY || current_window_mode == FULLSCREEN_NETWM;
} }
private static boolean shouldGrab() { private boolean shouldGrab() {
return !input_released && grab; return !input_released && grab;
} }
private static void updatePointerGrab() { private void updatePointerGrab() {
if (isFullscreen() || shouldGrab()) { if (isFullscreen() || shouldGrab()) {
grabPointer(); grabPointer();
} else { } else {
@ -337,7 +337,7 @@ final class LinuxDisplay implements DisplayImplementation {
updateCursor(); updateCursor();
} }
private static void updateCursor() { private void updateCursor() {
ByteBuffer cursor; ByteBuffer cursor;
if (shouldGrab()) { if (shouldGrab()) {
cursor = blank_cursor; cursor = blank_cursor;
@ -348,11 +348,11 @@ final class LinuxDisplay implements DisplayImplementation {
} }
private static native void nDefineCursor(long display, long window, ByteBuffer cursor_handle); private static native void nDefineCursor(long display, long window, ByteBuffer cursor_handle);
private static boolean isLegacyFullscreen() { private boolean isLegacyFullscreen() {
return current_window_mode == FULLSCREEN_LEGACY; return current_window_mode == FULLSCREEN_LEGACY;
} }
private static void updateKeyboardGrab() { private void updateKeyboardGrab() {
if (isLegacyFullscreen()) if (isLegacyFullscreen())
grabKeyboard(); grabKeyboard();
else else
@ -393,7 +393,7 @@ final class LinuxDisplay implements DisplayImplementation {
} }
private static native void nCreateWindow(ByteBuffer peer_info_handle, DisplayMode mode, int window_mode, int x, int y) throws LWJGLException; private static native void nCreateWindow(ByteBuffer peer_info_handle, DisplayMode mode, int window_mode, int x, int y) throws LWJGLException;
private static void updateInputGrab() { private void updateInputGrab() {
updatePointerGrab(); updatePointerGrab();
updateKeyboardGrab(); updateKeyboardGrab();
} }
@ -473,7 +473,7 @@ final class LinuxDisplay implements DisplayImplementation {
doSetGamma(convertToNativeRamp(gammaRamp)); doSetGamma(convertToNativeRamp(gammaRamp));
} }
private static void doSetGamma(ByteBuffer native_gamma) throws LWJGLException { private void doSetGamma(ByteBuffer native_gamma) throws LWJGLException {
lockAWT(); lockAWT();
try { try {
nSetGammaRamp(getScreen(), native_gamma); nSetGammaRamp(getScreen(), native_gamma);
@ -580,7 +580,7 @@ final class LinuxDisplay implements DisplayImplementation {
public void update() { public void update() {
lockAWT(); lockAWT();
try { try {
nUpdate(current_displaymode_extension, current_window_mode, saved_gamma, current_gamma, saved_mode, current_mode); nUpdate();
checkInput(); checkInput();
} catch (LWJGLException e) { } catch (LWJGLException e) {
LWJGLUtil.log("Caught exception while processing messages: " + e); LWJGLUtil.log("Caught exception while processing messages: " + e);
@ -588,7 +588,7 @@ final class LinuxDisplay implements DisplayImplementation {
unlockAWT(); unlockAWT();
} }
} }
private static native void nUpdate(int extension, int current_window_mode, ByteBuffer saved_gamma, ByteBuffer current_gamma, DisplayMode saved_mode, DisplayMode current_mode) throws LWJGLException; private native void nUpdate() throws LWJGLException;
public void reshape(int x, int y, int width, int height) { public void reshape(int x, int y, int width, int height) {
lockAWT(); lockAWT();
@ -667,7 +667,7 @@ final class LinuxDisplay implements DisplayImplementation {
} }
} }
private static void checkInput() { private void checkInput() {
focused = nGetInputFocus(getDisplay()) == getWindow(); focused = nGetInputFocus(getDisplay()) == getWindow();
if (focused) { if (focused) {
acquireInput(); acquireInput();
@ -677,7 +677,7 @@ final class LinuxDisplay implements DisplayImplementation {
} }
private static native long nGetInputFocus(long display); private static native long nGetInputFocus(long display);
private static void releaseInput() { private void releaseInput() {
if (isLegacyFullscreen() || input_released) if (isLegacyFullscreen() || input_released)
return; return;
input_released = true; input_released = true;
@ -695,7 +695,7 @@ final class LinuxDisplay implements DisplayImplementation {
} }
private static native void nIconifyWindow(long display, long window, int screen); private static native void nIconifyWindow(long display, long window, int screen);
private static void acquireInput() { private void acquireInput() {
if (isLegacyFullscreen() || !input_released) if (isLegacyFullscreen() || !input_released)
return; return;
input_released = false; input_released = false;
@ -970,41 +970,41 @@ final class LinuxDisplay implements DisplayImplementation {
private static native void nSetWindowIcon(ByteBuffer icon, int icons_size, int width, int height); private static native void nSetWindowIcon(ByteBuffer icon, int icons_size, int width, int height);
/* Callbacks from nUpdate() */ /* Callbacks from nUpdate() */
private static void handleButtonEvent(long millis, int type, int button, int state) { private void handleButtonEvent(long millis, int type, int button, int state) {
if (mouse != null) if (mouse != null)
mouse.handleButtonEvent(grab, millis, type, (byte)button); mouse.handleButtonEvent(grab, millis, type, (byte)button);
} }
private static void handleKeyEvent(long event_ptr, long millis, int type, int keycode, int state) { private void handleKeyEvent(long event_ptr, long millis, int type, int keycode, int state) {
if (keyboard != null) if (keyboard != null)
keyboard.handleKeyEvent(event_ptr, millis, type, keycode, state); keyboard.handleKeyEvent(event_ptr, millis, type, keycode, state);
} }
private static void handlePointerMotionEvent(long millis, long root_window, int x_root, int y_root, int x, int y, int state) { private void handlePointerMotionEvent(long millis, long root_window, int x_root, int y_root, int x, int y, int state) {
if (mouse != null) if (mouse != null)
mouse.handlePointerMotion(grab, pointer_grabbed, shouldGrab(), millis, root_window, x_root, y_root, x, y); mouse.handlePointerMotion(grab, pointer_grabbed, shouldGrab(), millis, root_window, x_root, y_root, x, y);
} }
private static void handleWarpEvent(int x, int y) { private void handleWarpEvent(int x, int y) {
if (mouse != null) if (mouse != null)
mouse.handleWarpEvent(x, y); mouse.handleWarpEvent(x, y);
} }
private static void handleExposeEvent() { private void handleExposeEvent() {
dirty = true; dirty = true;
} }
private static void handleUnmapNotifyEvent() { private void handleUnmapNotifyEvent() {
dirty = true; dirty = true;
minimized = true; minimized = true;
} }
private static void handleMapNotifyEvent() { private void handleMapNotifyEvent() {
dirty = true; dirty = true;
minimized = false; minimized = false;
} }
private static void handleCloseEvent() { private void handleCloseEvent() {
close_requested = true; close_requested = true;
} }
} }

View File

@ -167,30 +167,33 @@ static bool isLegacyFullscreen(jint window_mode) {
return window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_LEGACY; return window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_LEGACY;
} }
static void handleMessages(JNIEnv *env, jclass disp_class) { static void handleMessages(JNIEnv *env, jobject disp_obj) {
XEvent event; XEvent event;
jmethodID handleKeyEvent_method = (*env)->GetStaticMethodID(env, disp_class, "handleKeyEvent", "(JJIII)V"); jclass disp_class = (*env)->GetObjectClass(env, disp_obj);
if (disp_class == NULL)
return;
jmethodID handleKeyEvent_method = (*env)->GetMethodID(env, disp_class, "handleKeyEvent", "(JJIII)V");
if (handleKeyEvent_method == NULL) if (handleKeyEvent_method == NULL)
return; return;
jmethodID handleButtonEvent_method = (*env)->GetStaticMethodID(env, disp_class, "handleButtonEvent", "(JIII)V"); jmethodID handleButtonEvent_method = (*env)->GetMethodID(env, disp_class, "handleButtonEvent", "(JIII)V");
if (handleButtonEvent_method == NULL) if (handleButtonEvent_method == NULL)
return; return;
jmethodID handlePointerMotionEvent_method = (*env)->GetStaticMethodID(env, disp_class, "handlePointerMotionEvent", "(JJIIIII)V"); jmethodID handlePointerMotionEvent_method = (*env)->GetMethodID(env, disp_class, "handlePointerMotionEvent", "(JJIIIII)V");
if (handlePointerMotionEvent_method == NULL) if (handlePointerMotionEvent_method == NULL)
return; return;
jmethodID handleWarpEvent_method = (*env)->GetStaticMethodID(env, disp_class, "handleWarpEvent", "(II)V"); jmethodID handleWarpEvent_method = (*env)->GetMethodID(env, disp_class, "handleWarpEvent", "(II)V");
if (handleWarpEvent_method == NULL) if (handleWarpEvent_method == NULL)
return; return;
jmethodID handleMapNotifyEvent_method = (*env)->GetStaticMethodID(env, disp_class, "handleMapNotifyEvent", "()V"); jmethodID handleMapNotifyEvent_method = (*env)->GetMethodID(env, disp_class, "handleMapNotifyEvent", "()V");
if (handleMapNotifyEvent_method == NULL) if (handleMapNotifyEvent_method == NULL)
return; return;
jmethodID handleUnmapNotifyEvent_method = (*env)->GetStaticMethodID(env, disp_class, "handleUnmapNotifyEvent", "()V"); jmethodID handleUnmapNotifyEvent_method = (*env)->GetMethodID(env, disp_class, "handleUnmapNotifyEvent", "()V");
if (handleUnmapNotifyEvent_method == NULL) if (handleUnmapNotifyEvent_method == NULL)
return; return;
jmethodID handleExposeEvent_method = (*env)->GetStaticMethodID(env, disp_class, "handleExposeEvent", "()V"); jmethodID handleExposeEvent_method = (*env)->GetMethodID(env, disp_class, "handleExposeEvent", "()V");
if (handleExposeEvent_method == NULL) if (handleExposeEvent_method == NULL)
return; return;
jmethodID handleCloseEvent_method = (*env)->GetStaticMethodID(env, disp_class, "handleCloseEvent", "()V"); jmethodID handleCloseEvent_method = (*env)->GetMethodID(env, disp_class, "handleCloseEvent", "()V");
if (handleCloseEvent_method == NULL) if (handleCloseEvent_method == NULL)
return; return;
while (!(*env)->ExceptionOccurred(env) && XPending(getDisplay()) > 0) { while (!(*env)->ExceptionOccurred(env) && XPending(getDisplay()) > 0) {
@ -203,29 +206,29 @@ static void handleMessages(JNIEnv *env, jclass disp_class) {
switch (event.type) { switch (event.type) {
case ClientMessage: case ClientMessage:
if (event.xclient.message_type == warp_atom) { if (event.xclient.message_type == warp_atom) {
(*env)->CallStaticVoidMethod(env, disp_class, handleWarpEvent_method, (jint)event.xclient.data.l[0], (jint)event.xclient.data.l[1]); (*env)->CallVoidMethod(env, disp_obj, handleWarpEvent_method, (jint)event.xclient.data.l[0], (jint)event.xclient.data.l[1]);
} else if ((event.xclient.format == 32) && ((Atom)event.xclient.data.l[0] == delete_atom)) } else if ((event.xclient.format == 32) && ((Atom)event.xclient.data.l[0] == delete_atom))
(*env)->CallStaticVoidMethod(env, disp_class, handleCloseEvent_method); (*env)->CallVoidMethod(env, disp_obj, handleCloseEvent_method);
break; break;
case MapNotify: case MapNotify:
(*env)->CallStaticVoidMethod(env, disp_class, handleMapNotifyEvent_method); (*env)->CallVoidMethod(env, disp_obj, handleMapNotifyEvent_method);
break; break;
case UnmapNotify: case UnmapNotify:
(*env)->CallStaticVoidMethod(env, disp_class, handleUnmapNotifyEvent_method); (*env)->CallVoidMethod(env, disp_obj, handleUnmapNotifyEvent_method);
break; break;
case Expose: case Expose:
(*env)->CallStaticVoidMethod(env, disp_class, handleExposeEvent_method); (*env)->CallVoidMethod(env, disp_obj, handleExposeEvent_method);
break; break;
case ButtonPress: /* Fall through */ case ButtonPress: /* Fall through */
case ButtonRelease: case ButtonRelease:
(*env)->CallStaticVoidMethod(env, disp_class, handleButtonEvent_method, (jlong)event.xbutton.time, (jint)event.xbutton.type, (jint)event.xbutton.button, (jint)event.xbutton.state); (*env)->CallVoidMethod(env, disp_obj, handleButtonEvent_method, (jlong)event.xbutton.time, (jint)event.xbutton.type, (jint)event.xbutton.button, (jint)event.xbutton.state);
break; break;
case MotionNotify: case MotionNotify:
(*env)->CallStaticVoidMethod(env, disp_class, handlePointerMotionEvent_method, (jlong)event.xbutton.time, (jlong)event.xbutton.root, (jint)event.xbutton.x_root, (jint)event.xbutton.y_root, (jint)event.xbutton.x, (jint)event.xbutton.y, (jint)event.xbutton.state); (*env)->CallVoidMethod(env, disp_obj, handlePointerMotionEvent_method, (jlong)event.xbutton.time, (jlong)event.xbutton.root, (jint)event.xbutton.x_root, (jint)event.xbutton.y_root, (jint)event.xbutton.x, (jint)event.xbutton.y, (jint)event.xbutton.state);
break; break;
case KeyPress: case KeyPress:
case KeyRelease: case KeyRelease:
(*env)->CallStaticVoidMethod(env, disp_class, handleKeyEvent_method, (jlong)(intptr_t)&(event.xkey), (jlong)event.xkey.time, (jint)event.xkey.type, (jint)event.xkey.keycode, (jint)event.xkey.state); (*env)->CallVoidMethod(env, disp_obj, handleKeyEvent_method, (jlong)(intptr_t)&(event.xkey), (jlong)event.xkey.time, (jint)event.xkey.type, (jint)event.xkey.keycode, (jint)event.xkey.state);
break; break;
} }
} }
@ -378,9 +381,8 @@ Window getCurrentWindow(void) {
} }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nUpdate JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nUpdate
(JNIEnv *env, jclass clazz, jint extension, jint window_mode, jobject saved_gamma, jobject current_gamma, jobject saved_mode, jobject current_mode) (JNIEnv *env, jobject disp_obj) {
{ handleMessages(env, disp_obj);
handleMessages(env, clazz);
} }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateWindow(JNIEnv *env, jclass clazz, jobject peer_info_handle, jobject mode, jint window_mode, jint x, jint y) { JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateWindow(JNIEnv *env, jclass clazz, jobject peer_info_handle, jobject mode, jint window_mode, jint x, jint y) {