| 
      
      
      From: <eli...@us...> - 2008-01-07 18:29:06
      
     | 
| Revision: 2930
          http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=2930&view=rev
Author:   elias_naur
Date:     2008-01-07 10:29:04 -0800 (Mon, 07 Jan 2008)
Log Message:
-----------
Linux: use XkbSetDetectableAutoRepeat to detect repeated key events more reliably
Modified Paths:
--------------
    trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java
    trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeyboard.java
    trunk/LWJGL/src/native/linux/org_lwjgl_opengl_LinuxKeyboard.c
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java	2008-01-06 21:33:34 UTC (rev 2929)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java	2008-01-07 18:29:04 UTC (rev 2930)
@@ -857,7 +857,7 @@
 	public void destroyKeyboard() {
 		lockAWT();
 		try {
-			keyboard.destroy();
+			keyboard.destroy(getDisplay());
 			keyboard = null;
 		} finally {
 			unlockAWT();
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeyboard.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeyboard.java	2008-01-06 21:33:34 UTC (rev 2929)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeyboard.java	2008-01-07 18:29:04 UTC (rev 2930)
@@ -41,6 +41,7 @@
 import java.nio.charset.CharsetDecoder;
 
 import org.lwjgl.BufferUtils;
+import org.lwjgl.LWJGLUtil;
 import org.lwjgl.input.Keyboard;
 
 final class LinuxKeyboard {
@@ -122,13 +123,14 @@
 		modeswitch_mask = tmp_modeswitch_mask;
 		caps_lock_mask = tmp_caps_lock_mask;
 		shift_lock_mask = tmp_shift_lock_mask;
+		setDetectableKeyRepeat(display, true);
 		xim = openIM(display);
 		if (xim != 0) {
 			xic = createIC(xim, window);
 			if (xic != 0) {
 				setupIMEventMask(display, window, xic);
 			} else {
-				destroy();
+				destroy(display);
 			}
 		} else {
 			xic = 0;
@@ -146,11 +148,19 @@
 	private static native void setupIMEventMask(long display, long window, long xic);
 	private static native ByteBuffer allocateComposeStatus();
 
-	public void destroy() {
+	private static void setDetectableKeyRepeat(long display, boolean enabled) {
+		boolean success = nSetDetectableKeyRepeat(display, enabled);
+		if (!success)
+			LWJGLUtil.log("Failed to set detectable key repeat");
+	}
+	private static native boolean nSetDetectableKeyRepeat(long display, boolean enabled);
+
+	public void destroy(long display) {
 		if (xic != 0)
 			destroyIC(xic);
 		if (xim != 0)
 			closeIM(xim);
+		setDetectableKeyRepeat(display, false);
 	}
 	private static native void destroyIC(long xic);
 	private static native void closeIM(long xim);
@@ -300,10 +310,10 @@
 	private void handleKeyEvent(long event_ptr, long millis, int event_type, int event_keycode, int event_state) {
 		int keycode = getKeycode(event_ptr, event_state);
 		byte key_state = getKeyState(event_type);
+		boolean repeat = key_state == key_down_buffer[keycode];
 		key_down_buffer[keycode] = key_state;
 		long nanos = millis*1000000;
 		if (event_type == LinuxEvent.KeyPress) {
-			boolean repeat = false;
 			if (has_deferred_event) {
 				if (nanos == deferred_nanos && event_keycode == deferred_event_keycode) {
 					has_deferred_event = false;
Modified: trunk/LWJGL/src/native/linux/org_lwjgl_opengl_LinuxKeyboard.c
===================================================================
--- trunk/LWJGL/src/native/linux/org_lwjgl_opengl_LinuxKeyboard.c	2008-01-06 21:33:34 UTC (rev 2929)
+++ trunk/LWJGL/src/native/linux/org_lwjgl_opengl_LinuxKeyboard.c	2008-01-07 18:29:04 UTC (rev 2930)
@@ -41,6 +41,7 @@
 
 #include <X11/X.h>
 #include <X11/Xlib.h>
+#include <X11/XKBlib.h>
 #include <X11/Xutil.h>
 #include <X11/keysym.h>
 #include "common_tools.h"
@@ -52,6 +53,14 @@
 	return (intptr_t)modifier_map;
 }
 
+JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxKeyboard_nSetDetectableKeyRepeat(JNIEnv *env, jclass unused, jlong display_ptr, jboolean set_enabled) {
+	Display *disp = (Display *)(intptr_t)display_ptr;
+	Bool result;
+	Bool enabled = set_enabled == JNI_TRUE ? True : False;
+	Bool success = XkbSetDetectableAutoRepeat(disp, enabled, &result);
+	return success && enabled == result ? JNI_TRUE : JNI_FALSE;
+}
+
 JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxKeyboard_freeModifierMapping(JNIEnv *env, jclass unused, jlong mapping_ptr) {
 	XModifierKeymap *modifier_map = (XModifierKeymap *)(intptr_t)mapping_ptr;
 	XFreeModifiermap(modifier_map);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 |