From 8296ae06cbb14c913738bcbc254b3018ecf0f8f0 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 23 Oct 2006 19:51:22 +0000 Subject: [PATCH] Linux: Moved the pointer warp X11 atom from native to java --- src/java/org/lwjgl/opengl/LinuxDisplay.java | 24 ++++++++++++++++--- src/native/linux/org_lwjgl_opengl_Display.c | 20 ++++++++++------ .../linux/org_lwjgl_opengl_LinuxMouse.c | 5 ++-- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/java/org/lwjgl/opengl/LinuxDisplay.java b/src/java/org/lwjgl/opengl/LinuxDisplay.java index c3670ec9..24fefe26 100644 --- a/src/java/org/lwjgl/opengl/LinuxDisplay.java +++ b/src/java/org/lwjgl/opengl/LinuxDisplay.java @@ -84,6 +84,9 @@ final class LinuxDisplay implements DisplayImplementation { /** Current mode swithcing API */ private int current_displaymode_extension = NONE; + /** Atom used for the pointer warp messages */ + private long warp_atom; + private PeerInfo peer_info; /** Saved gamma used to restore display settings */ @@ -447,6 +450,20 @@ final class LinuxDisplay implements DisplayImplementation { } private static native void nSwitchDisplayMode(long display, int screen, int extension, DisplayMode mode) throws LWJGLException; + static long getWarpAtom() throws LWJGLException { + return internAtom("_LWJGL", false); + } + + private static long internAtom(String atom_name, boolean only_if_exists) throws LWJGLException { + incDisplay(); + try { + return nInternAtom(getDisplay(), atom_name, only_if_exists); + } finally { + decDisplay(); + } + } + private static native long nInternAtom(long display, String atom_name, boolean only_if_exists); + public void resetDisplayMode() { lockAWT(); try { @@ -527,6 +544,7 @@ final class LinuxDisplay implements DisplayImplementation { public DisplayMode init() throws LWJGLException { lockAWT(); try { + warp_atom = getWarpAtom(); current_displaymode_extension = getBestDisplayModeExtension(); if (current_displaymode_extension == NONE) throw new LWJGLException("No display mode extension is available"); @@ -607,7 +625,7 @@ final class LinuxDisplay implements DisplayImplementation { public void update() { lockAWT(); try { - nUpdate(getDisplay()); + nUpdate(getDisplay(), warp_atom); checkInput(); } catch (LWJGLException e) { LWJGLUtil.log("Caught exception while processing messages: " + e); @@ -615,7 +633,7 @@ final class LinuxDisplay implements DisplayImplementation { unlockAWT(); } } - private native void nUpdate(long display) throws LWJGLException; + private native void nUpdate(long display, long warp_atom) throws LWJGLException; public void reshape(int x, int y, int width, int height) { lockAWT(); @@ -655,7 +673,7 @@ final class LinuxDisplay implements DisplayImplementation { public void createMouse() { lockAWT(); try { - mouse = new LinuxMouse(getDisplay(), getWindow()); + mouse = new LinuxMouse(getDisplay(), getWindow(), warp_atom); } finally { unlockAWT(); } diff --git a/src/native/linux/org_lwjgl_opengl_Display.c b/src/native/linux/org_lwjgl_opengl_Display.c index f866c4cf..5534ae56 100644 --- a/src/native/linux/org_lwjgl_opengl_Display.c +++ b/src/native/linux/org_lwjgl_opengl_Display.c @@ -81,7 +81,6 @@ static Visual *current_visual; static int current_screen; static bool async_x_error; static char error_message[ERR_MSG_SIZE]; -static Atom warp_atom; int getCurrentScreen(void) { return current_screen; @@ -119,12 +118,18 @@ static jlong openDisplay(JNIEnv *env) { return (intptr_t)NULL; } current_screen = XDefaultScreen(display_connection); - warp_atom = XInternAtom(display_connection, "_LWJGL_WARP", False); return (intptr_t)display_connection; } -Atom getWarpAtom(void) { - return warp_atom; + +JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nInternAtom(JNIEnv *env, jclass unused, jlong display_ptr, jstring atom_name_obj, jboolean only_if_exists) { + Display *disp = (Display *)(intptr_t)display_ptr; + char *atom_name = GetStringNativeChars(env, atom_name_obj); + if (atom_name == NULL) + return 0; + Atom atom = XInternAtom(disp, atom_name, only_if_exists ? True : False); + free(atom_name); + return atom; } static void waitMapped(Display *disp, Window win) { @@ -157,7 +162,7 @@ static bool isLegacyFullscreen(jint window_mode) { return window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_LEGACY; } -static void handleMessages(JNIEnv *env, Display *disp, jobject disp_obj) { +static void handleMessages(JNIEnv *env, Display *disp, jobject disp_obj, Atom warp_atom) { XEvent event; jclass disp_class = (*env)->GetObjectClass(env, disp_obj); if (disp_class == NULL) @@ -375,9 +380,10 @@ Window getCurrentWindow(void) { return current_win; } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nUpdate(JNIEnv *env, jobject disp_obj, jlong display) { +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nUpdate(JNIEnv *env, jobject disp_obj, jlong display, jlong warp_atom_ptr) { Display *disp = (Display *)(intptr_t)display; - handleMessages(env, disp, disp_obj); + Atom warp_atom = (Atom)warp_atom_ptr; + handleMessages(env, disp, disp_obj, warp_atom); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateWindow(JNIEnv *env, jclass clazz, jlong display, jobject peer_info_handle, jobject mode, jint window_mode, jint x, jint y) { diff --git a/src/native/linux/org_lwjgl_opengl_LinuxMouse.c b/src/native/linux/org_lwjgl_opengl_LinuxMouse.c index 827a0fb0..fbc487dc 100644 --- a/src/native/linux/org_lwjgl_opengl_LinuxMouse.c +++ b/src/native/linux/org_lwjgl_opengl_LinuxMouse.c @@ -91,13 +91,14 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_LinuxMouse_nQueryPointer(JNIEnv *e return root_return; } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxMouse_nSendWarpEvent(JNIEnv *env, jclass unusued, jlong display_ptr, jlong window_ptr, jint x, jint y) { +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxMouse_nSendWarpEvent(JNIEnv *env, jclass unusued, jlong display_ptr, jlong window_ptr, jlong warp_atom_ptr, jint x, jint y) { + Atom warp_atom = (Atom)warp_atom_ptr; Display *disp = (Display *)(intptr_t)display_ptr; Window win = (Window)window_ptr; XEvent warp_event; warp_event.type = ClientMessage; warp_event.xclient.window = win; - warp_event.xclient.message_type = getWarpAtom(); + warp_event.xclient.message_type = warp_atom; warp_event.xclient.format = 32; warp_event.xclient.data.l[0] = x; warp_event.xclient.data.l[1] = y;