From 6e5ed9d1ffe950f50b9f9a1128468f0aa6c69732 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 21 Nov 2005 13:32:52 +0000 Subject: [PATCH] Linux: Moved a display connection creation to java --- src/java/org/lwjgl/opengl/LinuxDisplay.java | 32 +++++++++++++-------- src/native/linux/display.c | 18 ++---------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/java/org/lwjgl/opengl/LinuxDisplay.java b/src/java/org/lwjgl/opengl/LinuxDisplay.java index e31d7416..13e3bf88 100644 --- a/src/java/org/lwjgl/opengl/LinuxDisplay.java +++ b/src/java/org/lwjgl/opengl/LinuxDisplay.java @@ -79,20 +79,28 @@ final class LinuxDisplay implements DisplayImplementation { private static PeerInfo peer_info; private static int getBestDisplayModeExtension() throws LWJGLException { - if (System.getenv("LWJGL_DISABLE_XRANDR") == null && isXrandrSupported()) { - LWJGLUtil.log("Using Xrandr for display mode switching"); - return XRANDR; - } else if (isXF86VidModeSupported()) { - LWJGLUtil.log("Using XF86VidMode for display mode switching"); - return XF86VIDMODE; - } else { - LWJGLUtil.log("No display mode extensions available"); - return NONE; + lockAWT(); + try { + incDisplay(); + int result; + if (System.getenv("LWJGL_DISABLE_XRANDR") == null && isXrandrSupported()) { + LWJGLUtil.log("Using Xrandr for display mode switching"); + result = XRANDR; + } else if (isXF86VidModeSupported()) { + LWJGLUtil.log("Using XF86VidMode for display mode switching"); + result = XF86VIDMODE; + } else { + LWJGLUtil.log("No display mode extensions available"); + result = NONE; + } + decDisplay(); + return result; + } finally { + unlockAWT(); } - } - private static native boolean isXrandrSupported() throws LWJGLException; - private static native boolean isXF86VidModeSupported() throws LWJGLException; + private static native boolean isXrandrSupported(); + private static native boolean isXF86VidModeSupported(); private static boolean isNetWMFullscreenSupported() throws LWJGLException { if (System.getenv("LWJGL_DISABLE_NETWM") != null) diff --git a/src/native/linux/display.c b/src/native/linux/display.c index 5048a92c..65c75a3a 100644 --- a/src/native/linux/display.c +++ b/src/native/linux/display.c @@ -130,26 +130,12 @@ static bool isXF86VidModeSupported(JNIEnv *env, Display *disp) { } JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_isXrandrSupported(JNIEnv *env, jclass unused) { - Display *disp = XOpenDisplay(NULL); - if (disp == NULL) { - throwException(env, "Could not open display"); - return JNI_FALSE; - } - - jboolean result = isXrandrSupported(env, disp) ? JNI_TRUE : JNI_FALSE; - XCloseDisplay(disp); + jboolean result = isXrandrSupported(env, getDisplay()) ? JNI_TRUE : JNI_FALSE; return result; } JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_isXF86VidModeSupported(JNIEnv *env, jclass unused) { - Display *disp = XOpenDisplay(NULL); - if (disp == NULL) { - throwException(env, "Could not open display"); - return JNI_FALSE; - } - - jboolean result = isXF86VidModeSupported(env, disp) ? JNI_TRUE : JNI_FALSE; - XCloseDisplay(disp); + jboolean result = isXF86VidModeSupported(env, getDisplay()) ? JNI_TRUE : JNI_FALSE; return result; }