From: <eli...@us...> - 2006-07-03 18:08:54
|
Revision: 2425 Author: elias_naur Date: 2006-07-03 11:07:44 -0700 (Mon, 03 Jul 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2425&view=rev Log Message: ----------- Linux: Moved most input related stuff from native to java Modified Paths: -------------- trunk/LWJGL/build.xml trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java trunk/LWJGL/src/native/common/common_tools.c trunk/LWJGL/src/native/common/common_tools.h trunk/LWJGL/src/native/linux/Window.h trunk/LWJGL/src/native/linux/display.c trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c trunk/LWJGL/src/native/win32/dinputhelper.c trunk/LWJGL/src/native/win32/dinputhelper.h Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeyboard.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeycodes.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxMouse.java trunk/LWJGL/src/native/linux/org_lwjgl_opengl_LinuxKeyboard.c trunk/LWJGL/src/native/linux/org_lwjgl_opengl_LinuxMouse.c Removed Paths: ------------- trunk/LWJGL/src/native/linux/org_lwjgl_input_Keyboard.c trunk/LWJGL/src/native/linux/org_lwjgl_input_Mouse.c Modified: trunk/LWJGL/build.xml =================================================================== --- trunk/LWJGL/build.xml 2006-07-03 12:00:12 UTC (rev 2424) +++ trunk/LWJGL/build.xml 2006-07-03 18:07:44 UTC (rev 2425) @@ -450,6 +450,7 @@ <target name="headers" description="invokes javah on java classes" depends="compile"> <!-- platform specific classes --> <javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/linux" force="yes"> + <class name="org.lwjgl.opengl.LinuxMouse" /> <class name="org.lwjgl.opengl.LinuxKeyboard" /> <class name="org.lwjgl.opengl.LinuxDisplay" /> <class name="org.lwjgl.opengl.LinuxPeerInfo" /> Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2006-07-03 12:00:12 UTC (rev 2424) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2006-07-03 18:07:44 UTC (rev 2425) @@ -47,6 +47,13 @@ import org.lwjgl.input.Keyboard; final class LinuxDisplay implements DisplayImplementation { + /* X11 constants */ + private final static int GrabSuccess = 0; + private final static int AutoRepeatModeOff = 0; + private final static int AutoRepeatModeOn = 1; + private final static int AutoRepeatModeDefault = 2; + + /** Window mode enum */ private static final int FULLSCREEN_LEGACY = 1; private static final int FULLSCREEN_NETWM = 2; @@ -63,8 +70,6 @@ /** Current mode swithcing API */ private static int current_displaymode_extension = NONE; - private static final int NUM_BUTTONS = 3; - /** Keep track on the current awt lock owner to avoid * depending on JAWT locking to be re-entrant (This is a * problem with GCJ). JAWT locking is not that well specified @@ -86,6 +91,17 @@ private static DisplayMode saved_mode; private static DisplayMode current_mode; + private static boolean keyboard_grabbed; + private static boolean pointer_grabbed; + private static boolean input_released; + private static boolean grab; + private static boolean focused; + private static ByteBuffer current_cursor; + private static ByteBuffer blank_cursor; + + private static LinuxKeyboard keyboard; + private static LinuxMouse mouse; + private static ByteBuffer getCurrentGammaRamp() throws LWJGLException { lockAWT(); try { @@ -257,15 +273,113 @@ return WINDOWED; } + private static native long getDisplay(); + private static native int getScreen(); + private static native long getWindow(); + + private static void ungrabKeyboard() { + if (keyboard_grabbed) { + nUngrabKeyboard(getDisplay()); + keyboard_grabbed = false; + } + } + private static native int nUngrabKeyboard(long display); + + private static void grabKeyboard() { + if (!keyboard_grabbed) { + int res = nGrabKeyboard(getDisplay(), getWindow()); + if (res == GrabSuccess) + keyboard_grabbed = true; + } + } + private static native int nGrabKeyboard(long display, long window); + + private static void grabPointer() { + if (!pointer_grabbed) { + int result = nGrabPointer(getDisplay(), getWindow()); + if (result == GrabSuccess) { + pointer_grabbed = true; + // make sure we have a centered window + if (isLegacyFullscreen()) { + nSetViewPort(getDisplay(), getWindow(), getScreen()); + } + } + } + } + private static native int nGrabPointer(long display, long window); + private static native void nSetViewPort(long display, long window, int screen); + + private static void ungrabPointer() { + if (pointer_grabbed) { + pointer_grabbed = false; + nUngrabPointer(getDisplay()); + } + } + private static native int nUngrabPointer(long display); + + private static boolean isFullscreen() { + return current_window_mode == FULLSCREEN_LEGACY || current_window_mode == FULLSCREEN_NETWM; + } + + private static boolean shouldGrab() { + return !input_released && grab; + } + + private static void updatePointerGrab() { + if (isFullscreen() || shouldGrab()) { + grabPointer(); + } else { + ungrabPointer(); + } + updateCursor(); + } + + private static void updateCursor() { + ByteBuffer cursor; + if (shouldGrab()) { + cursor = blank_cursor; + } else { + cursor = current_cursor; + } + nDefineCursor(getDisplay(), getWindow(), cursor); + } + private static native void nDefineCursor(long display, long window, ByteBuffer cursor_handle); + + private static boolean isLegacyFullscreen() { + return current_window_mode == FULLSCREEN_LEGACY; + } + + private static void updateKeyboardGrab() { + if (isLegacyFullscreen()) + grabKeyboard(); + else + ungrabKeyboard(); + } + public void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException { lockAWT(); try { - ByteBuffer handle = peer_info.lockAndGetHandle(); + incDisplay(); try { - current_window_mode = getWindowMode(fullscreen); - nCreateWindow(handle, mode, current_window_mode, x, y); - } finally { - peer_info.unlock(); + ByteBuffer handle = peer_info.lockAndGetHandle(); + try { + current_window_mode = getWindowMode(fullscreen); + nCreateWindow(handle, mode, current_window_mode, x, y); + blank_cursor = createBlankCursor(); + current_cursor = null; + focused = true; + input_released = false; + pointer_grabbed = false; + keyboard_grabbed = false; + grab = false; + updateInputGrab(); + nSetRepeatMode(getDisplay(), AutoRepeatModeOff); + } finally { + peer_info.unlock(); + } + } catch (LWJGLException e) { + decDisplay(); + throw e; } } finally { unlockAWT(); @@ -273,23 +387,41 @@ } private static native void nCreateWindow(ByteBuffer peer_info_handle, DisplayMode mode, int window_mode, int x, int y) throws LWJGLException; + private static void updateInputGrab() { + updatePointerGrab(); + updateKeyboardGrab(); + } + public void destroyWindow() { lockAWT(); - nDestroyWindow(); - unlockAWT(); + try { + try { + setNativeCursor(null); + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to reset cursor: " + e.getMessage()); + } + nDestroyCursor(blank_cursor); + blank_cursor = null; + ungrabKeyboard(); + nDestroyWindow(); + nSetRepeatMode(getDisplay(), AutoRepeatModeDefault); + decDisplay(); + } finally { + unlockAWT(); + } } private static native void nDestroyWindow(); public void switchDisplayMode(DisplayMode mode) throws LWJGLException { lockAWT(); try { - nSwitchDisplayMode(current_displaymode_extension, mode); + nSwitchDisplayMode(getScreen(), current_displaymode_extension, mode); current_mode = mode; } finally { unlockAWT(); } } - private static native void nSwitchDisplayMode(int extension, DisplayMode mode) throws LWJGLException; + private static native void nSwitchDisplayMode(int screen, int extension, DisplayMode mode) throws LWJGLException; public void resetDisplayMode() { lockAWT(); @@ -312,7 +444,7 @@ try { incDisplay(); try { - return nGetGammaRampLength(); + return nGetGammaRampLength(getDisplay(), getScreen()); } catch (LWJGLException e) { LWJGLUtil.log("Got exception while querying gamma length: " + e); return 0; @@ -327,7 +459,7 @@ unlockAWT(); } } - private static native int nGetGammaRampLength() throws LWJGLException; + private static native int nGetGammaRampLength(long display, int screen) throws LWJGLException; public void setGammaRamp(FloatBuffer gammaRamp) throws LWJGLException { if (!isXF86VidModeSupported()) @@ -338,13 +470,13 @@ private static void doSetGamma(ByteBuffer native_gamma) throws LWJGLException { lockAWT(); try { - nSetGammaRamp(native_gamma); + nSetGammaRamp(getScreen(), native_gamma); current_gamma = native_gamma; } finally { unlockAWT(); } } - private static native void nSetGammaRamp(ByteBuffer gammaRamp) throws LWJGLException; + private static native void nSetGammaRamp(int screen, ByteBuffer gammaRamp) throws LWJGLException; private static ByteBuffer convertToNativeRamp(FloatBuffer ramp) throws LWJGLException { return nConvertToNativeRamp(ramp, ramp.position(), ramp.remaining()); @@ -406,34 +538,42 @@ public void setTitle(String title) { lockAWT(); - nSetTitle(title); - unlockAWT(); + try { + nSetTitle(title); + } finally { + unlockAWT(); + } } private static native void nSetTitle(String title); public boolean isCloseRequested() { lockAWT(); - boolean result = nIsCloseRequested(); - unlockAWT(); - return result; + try { + return nIsCloseRequested(); + } finally { + unlockAWT(); + } } private static native boolean nIsCloseRequested(); public boolean isVisible() { lockAWT(); - boolean result = nIsVisible(); - unlockAWT(); - return result; + try { + return nIsVisible(); + } finally { + unlockAWT(); + } } private static native boolean nIsVisible(); public boolean isActive() { lockAWT(); - boolean result = nIsActive(current_window_mode); - unlockAWT(); - return result; + try { + return focused || isLegacyFullscreen(); + } finally { + unlockAWT(); + } } - private static native boolean nIsActive(int window_mode); public boolean isDirty() { lockAWT(); @@ -452,17 +592,22 @@ lockAWT(); try { nUpdate(current_displaymode_extension, current_window_mode, saved_gamma, current_gamma, saved_mode, current_mode); + checkInput(); } catch (LWJGLException e) { LWJGLUtil.log("Caught exception while processing messages: " + e); + } finally { + 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; public void reshape(int x, int y, int width, int height) { lockAWT(); - nReshape(x, y, width, height); - unlockAWT(); + try { + nReshape(x, y, width, height); + } finally { + unlockAWT(); + } } private static native void nReshape(int x, int y, int width, int height); @@ -488,61 +633,118 @@ } public int getButtonCount() { - return NUM_BUTTONS; + return mouse.getButtonCount(); } public void createMouse() { lockAWT(); - nCreateMouse(current_window_mode); - unlockAWT(); + try { + mouse = new LinuxMouse(getDisplay(), getWindow()); + } finally { + unlockAWT(); + } } - private static native void nCreateMouse(int window_mode); public void destroyMouse() { - lockAWT(); - nDestroyMouse(); - unlockAWT(); + mouse = null; } - private static native void nDestroyMouse(); public void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons) { update(); lockAWT(); - nPollMouse(coord_buffer, buttons); - unlockAWT(); + try { + mouse.poll(grab, coord_buffer, buttons); + } finally { + unlockAWT(); + } } - private static native void nPollMouse(IntBuffer coord_buffer, ByteBuffer buttons); public int readMouse(IntBuffer buffer) { update(); lockAWT(); - int count = nReadMouse(buffer, buffer.position()); - unlockAWT(); - return count; + try { + return mouse.read(buffer); + } finally { + unlockAWT(); + } } - private static native int nReadMouse(IntBuffer buffer, int buffer_position); public void setCursorPosition(int x, int y) { lockAWT(); - nSetCursorPosition(x, y); - unlockAWT(); + try { + mouse.setCursorPosition(x, y); + } finally { + unlockAWT(); + } } - private native void nSetCursorPosition(int x, int y); - public void grabMouse(boolean grab) { + private static void checkInput() { + focused = nGetInputFocus(getDisplay()) == getWindow(); + if (focused) { + acquireInput(); + } else { + releaseInput(); + } + } + private static native long nGetInputFocus(long display); + + private static void releaseInput() { + if (isLegacyFullscreen() || input_released) + return; + input_released = true; + nSetRepeatMode(getDisplay(), AutoRepeatModeDefault); + updateInputGrab(); + if (current_window_mode == FULLSCREEN_NETWM) { + nIconifyWindow(getDisplay(), getWindow(), getScreen()); + try { + nSwitchDisplayMode(getScreen(), current_displaymode_extension, saved_mode); + nSetGammaRamp(getScreen(), saved_gamma); + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to restore saved mode: " + e.getMessage()); + } + } + } + private static native void nIconifyWindow(long display, long window, int screen); + + private static void acquireInput() { + if (isLegacyFullscreen() || !input_released) + return; + input_released = false; + nSetRepeatMode(getDisplay(), AutoRepeatModeOff); + updateInputGrab(); + if (current_window_mode == FULLSCREEN_NETWM) { + try { + nSwitchDisplayMode(getScreen(), current_displaymode_extension, current_mode); + nSetGammaRamp(getScreen(), current_gamma); + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to restore mode: " + e.getMessage()); + } + } + } + private static native void nSetRepeatMode(long display, int mode); + + public void grabMouse(boolean new_grab) { lockAWT(); - nGrabMouse(current_window_mode, grab); - unlockAWT(); + try { + if (new_grab != grab) { + grab = new_grab; + updateInputGrab(); + mouse.changeGrabbed(grab, pointer_grabbed, shouldGrab()); + } + } finally { + unlockAWT(); + } } - private static native void nGrabMouse(int window_mode, boolean grab); public int getNativeCursorCapabilities() { lockAWT(); try { incDisplay(); - int caps = nGetNativeCursorCapabilities(); - decDisplay(); - return caps; + try { + return nGetNativeCursorCapabilities(); + } finally { + decDisplay(); + } } catch (LWJGLException e) { throw new RuntimeException(e); } finally { @@ -552,19 +754,24 @@ private static native int nGetNativeCursorCapabilities() throws LWJGLException; public void setNativeCursor(Object handle) throws LWJGLException { + current_cursor = (ByteBuffer)handle; lockAWT(); - nSetNativeCursor(handle); - unlockAWT(); + try { + updateCursor(); + } finally { + unlockAWT(); + } } - private static native void nSetNativeCursor(Object handle) throws LWJGLException; public int getMinCursorSize() { lockAWT(); try { incDisplay(); - int min_size = nGetMinCursorSize(); - decDisplay(); - return min_size; + try { + return nGetMinCursorSize(); + } finally { + decDisplay(); + } } catch (LWJGLException e) { LWJGLUtil.log("Exception occurred in getMinCursorSize: " + e); return 0; @@ -578,9 +785,11 @@ lockAWT(); try { incDisplay(); - int max_size = nGetMaxCursorSize(); - decDisplay(); - return max_size; + try { + return nGetMaxCursorSize(); + } finally { + decDisplay(); + } } catch (LWJGLException e) { LWJGLUtil.log("Exception occurred in getMaxCursorSize: " + e); return 0; @@ -594,36 +803,41 @@ public void createKeyboard() throws LWJGLException { lockAWT(); try { - nCreateKeyboard(current_window_mode); + keyboard = new LinuxKeyboard(getDisplay(), getWindow()); } finally { unlockAWT(); } } - private static native void nCreateKeyboard(int window_mode) throws LWJGLException; public void destroyKeyboard() { lockAWT(); - nDestroyKeyboard(); - unlockAWT(); + try { + keyboard.destroy(); + keyboard = null; + } finally { + unlockAWT(); + } } - private static native void nDestroyKeyboard(); public void pollKeyboard(ByteBuffer keyDownBuffer) { update(); lockAWT(); - nPollKeyboard(keyDownBuffer); - unlockAWT(); + try { + keyboard.poll(keyDownBuffer); + } finally { + unlockAWT(); + } } - private static native void nPollKeyboard(ByteBuffer keyDownBuffer); public int readKeyboard(IntBuffer buffer) { update(); lockAWT(); - int count = nReadKeyboard(buffer, buffer.position()); - unlockAWT(); - return count; + try { + return keyboard.read(buffer); + } finally { + unlockAWT(); + } } - private static native int nReadKeyboard(IntBuffer buffer, int buffer_position); /* public int isStateKeySet(int key) { return Keyboard.STATE_UNKNOWN; @@ -631,6 +845,11 @@ */ private static native ByteBuffer nCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException; + private static ByteBuffer createBlankCursor() { + return nCreateBlankCursor(getDisplay(), getWindow()); + } + private static native ByteBuffer nCreateBlankCursor(long display, long window); + public Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException { lockAWT(); try { @@ -648,9 +867,12 @@ public void destroyCursor(Object cursorHandle) { lockAWT(); - nDestroyCursor(cursorHandle); - decDisplay(); - unlockAWT(); + try { + nDestroyCursor(cursorHandle); + decDisplay(); + } finally { + unlockAWT(); + } } private static native void nDestroyCursor(Object cursorHandle); @@ -658,9 +880,11 @@ lockAWT(); try { incDisplay(); - int caps = nGetPbufferCapabilities(); - decDisplay(); - return caps; + try { + return nGetPbufferCapabilities(); + } finally { + decDisplay(); + } } catch (LWJGLException e) { LWJGLUtil.log("Exception occurred in getPbufferCapabilities: " + e); return 0; @@ -753,4 +977,25 @@ } private static native void nSetWindowIcon(ByteBuffer icon, int icons_size, int width, int height); + + /* Callbacks from nUpdate() */ + private static void handleButtonEvent(long millis, int type, int button, int state) { + if (mouse != null) + mouse.handleButtonEvent(grab, type, button); + } + + private static void handleKeyEvent(long event_ptr, long millis, int type, int keycode, int state) { + if (keyboard != null) + keyboard.handleKeyEvent(event_ptr, millis, type, keycode, state); + } + + private static void handlePointerMotionEvent(long root_window, int x_root, int y_root, int x, int y, int state) { + if (mouse != null) + mouse.handlePointerMotion(grab, pointer_grabbed, shouldGrab(), root_window, x_root, y_root, x, y); + } + + private static void handleWarpEvent(int x, int y) { + if (mouse != null) + mouse.handleWarpEvent(x, y); + } } Copied: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeyboard.java (from rev 2397, trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java) =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeyboard.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeyboard.java 2006-07-03 18:07:44 UTC (rev 2425) @@ -0,0 +1,305 @@ +/* + * Copyright (c) 2002-2004 LWJGL 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 'LWJGL' 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. + */ +package org.lwjgl.opengl; + +/** + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.CharBuffer; + +import org.lwjgl.BufferUtils; +import org.lwjgl.input.Keyboard; + +import java.nio.charset.CharsetDecoder; +import java.nio.charset.Charset; + +final class LinuxKeyboard { + private static final int LockMapIndex = 1; + private static final int KeyPress = 2; + private static final int KeyRelease = 3; + private static final long NoSymbol = 0; + private static final long ShiftMask = 1 << 0; + private static final long LockMask = 1 << 1; + private static final int XLookupChars = 2; + private static final int XLookupBoth = 4; + + + private static final int EVENT_SIZE = 3; + private static final int KEYBOARD_BUFFER_SIZE = 50; + + private final long xim; + private final long xic; + + private final int numlock_mask; + private final int modeswitch_mask; + private final int caps_lock_mask; + private final int shift_lock_mask; + + private final ByteBuffer compose_status; + + private final byte[] key_down_buffer = new byte[Keyboard.KEYBOARD_SIZE]; + private final EventQueue event_queue = new EventQueue(EVENT_SIZE); + + private final int[] tmp_event = new int[3]; + private final int[] temp_translation_buffer = new int[KEYBOARD_BUFFER_SIZE]; + private final ByteBuffer native_translation_buffer = BufferUtils.createByteBuffer(KEYBOARD_BUFFER_SIZE); + private final CharsetDecoder utf8_decoder = Charset.forName("UTF-8").newDecoder(); + private final CharBuffer char_buffer = CharBuffer.allocate(KEYBOARD_BUFFER_SIZE); + + public LinuxKeyboard(long display, long window) { + long modifier_map = getModifierMapping(display); + int tmp_numlock_mask = 0; + int tmp_modeswitch_mask = 0; + int tmp_caps_lock_mask = 0; + int tmp_shift_lock_mask = 0; + if (modifier_map != 0) { + int max_keypermod = getMaxKeyPerMod(modifier_map); + // Find modifier masks + int i, j; + for (i = 0; i < 8; i++) { + for (j = 0; j < max_keypermod; j++) { + int key_code = lookupModifierMap(modifier_map, i*max_keypermod + j); + int key_sym = (int)keycodeToKeySym(display, key_code); + int mask = 1 << i; + switch (key_sym) { + case LinuxKeycodes.XK_Num_Lock: + tmp_numlock_mask |= mask; + break; + case LinuxKeycodes.XK_Mode_switch: + tmp_modeswitch_mask |= mask; + break; + case LinuxKeycodes.XK_Caps_Lock: + if (i == LockMapIndex) { + tmp_caps_lock_mask = mask; + tmp_shift_lock_mask = 0; + } + break; + case LinuxKeycodes.XK_Shift_Lock: + if (i == LockMapIndex && tmp_caps_lock_mask == 0) + tmp_shift_lock_mask = mask; + break; + default: + break; + } + } + } + freeModifierMapping(modifier_map); + } + numlock_mask = tmp_numlock_mask; + modeswitch_mask = tmp_modeswitch_mask; + caps_lock_mask = tmp_caps_lock_mask; + shift_lock_mask = tmp_shift_lock_mask; + xim = openIM(display); + if (xim != 0) { + xic = createIC(xim, window); + if (xic != 0) { + setupIMEventMask(display, window, xic); + } else { + destroy(); + } + } else { + xic = 0; + } + compose_status = allocateComposeStatus(); + } + private static native long getModifierMapping(long display); + private static native void freeModifierMapping(long modifier_map); + private static native int getMaxKeyPerMod(long modifier_map); + private static native int lookupModifierMap(long modifier_map, int index); + private static native long keycodeToKeySym(long display, int key_code); + + private static native long openIM(long display); + private static native long createIC(long xim, long window); + private static native void setupIMEventMask(long display, long window, long xic); + private static native ByteBuffer allocateComposeStatus(); + + public void destroy() { + destroyIC(xic); + closeIM(xim); + } + private static native void destroyIC(long xic); + private static native void closeIM(long xim); + + public int read(IntBuffer buffer) { + return event_queue.copyEvents(buffer); + } + + public void poll(ByteBuffer keyDownBuffer) { + int old_position = keyDownBuffer.position(); + keyDownBuffer.put(key_down_buffer); + keyDownBuffer.position(old_position); + } + + private void putKeyboardEvent(int keycode, int state, int ch) { + tmp_event[0] = keycode; + tmp_event[1] = state; + tmp_event[2] = ch; + event_queue.putEvent(tmp_event); + } + + private int lookupStringISO88591(long event_ptr, int[] translation_buffer) { + int i; + + int num_chars = lookupString(event_ptr, native_translation_buffer, compose_status); + for (i = 0; i < num_chars; i++) { + translation_buffer[i] = ((int)native_translation_buffer.get(i)) & 0xff; + } + return num_chars; + } + private static native int lookupString(long event_ptr, ByteBuffer buffer, ByteBuffer compose_status); + + private int lookupStringUnicode(long event_ptr, int[] translation_buffer) { + int status = utf8LookupString(xic, event_ptr, native_translation_buffer, native_translation_buffer.position(), native_translation_buffer.remaining()); + if (status != XLookupChars && status != XLookupBoth) + return 0; + native_translation_buffer.flip(); + utf8_decoder.decode(native_translation_buffer, char_buffer, true); + native_translation_buffer.compact(); + char_buffer.flip(); + int i = 0; + while (char_buffer.hasRemaining() && i < translation_buffer.length) { + translation_buffer[i++] = char_buffer.get(); + } + char_buffer.compact(); + return i; + } + private static native int utf8LookupString(long xic, long event_ptr, ByteBuffer buffer, int pos, int size); + + private int lookupString(long event_ptr, int[] translation_buffer) { + if (xic != 0) { + return lookupStringUnicode(event_ptr, translation_buffer); + } else + return lookupStringISO88591(event_ptr, translation_buffer); + } + + private void translateEvent(long event_ptr, int event_type, int keycode, int key_state) { + int num_chars, i; + int ch; + + if (event_type == KeyRelease) { + putKeyboardEvent(keycode, key_state, 0); + return; + } + num_chars = lookupString(event_ptr, temp_translation_buffer); + if (num_chars > 0) { + ch = temp_translation_buffer[0]; + putKeyboardEvent(keycode, key_state, ch); + for (i = 1; i < num_chars; i++) { + ch = temp_translation_buffer[i]; + putKeyboardEvent(0, 0, ch); + } + } else { + putKeyboardEvent(keycode, key_state, 0); + } + } + + private static boolean isKeypadKeysym(long keysym) { + return (0xFF80 <= keysym && keysym <= 0xFFBD) || + (0x11000000 <= keysym && keysym <= 0x1100FFFF); + } + + private static boolean isNoSymbolOrVendorSpecific(long keysym) { + return keysym == NoSymbol || (keysym & (1 << 28)) != 0; + } + + private static long getKeySym(long event_ptr, int group, int index) { + long keysym = lookupKeysym(event_ptr, group*2 + index); + if (isNoSymbolOrVendorSpecific(keysym) && index == 1) { + keysym = lookupKeysym(event_ptr, group*2 + 0); + } + if (isNoSymbolOrVendorSpecific(keysym) && group == 1) + keysym = getKeySym(event_ptr, 0, index); + return keysym; + } + private static native long lookupKeysym(long event_ptr, int index); + private static native long toUpper(long keysym); + + private long mapEventToKeySym(long event_ptr, int event_state) { + int group; + long keysym; + if ((event_state & modeswitch_mask) != 0) + group = 1; + else + group = 0; + if ((event_state & numlock_mask) != 0 && isKeypadKeysym(keysym = getKeySym(event_ptr, group, 1))) { + if ((event_state & (ShiftMask | shift_lock_mask)) != 0) { + return getKeySym(event_ptr, group, 0); + } else { + return keysym; + } + } else if ((event_state & (ShiftMask | LockMask)) == 0) { + return getKeySym(event_ptr, group, 0); + } else if ((event_state & ShiftMask) == 0) { + keysym = getKeySym(event_ptr, group, 0); + if ((event_state & caps_lock_mask) != 0) + keysym = toUpper(keysym); + return keysym; + } else { + keysym = getKeySym(event_ptr, group, 1); + if ((event_state & caps_lock_mask) != 0) + keysym = toUpper(keysym); + return keysym; + } + } + + private int getKeycode(long event_ptr, int event_state) { + long keysym = mapEventToKeySym(event_ptr, event_state); + int keycode = LinuxKeycodes.mapKeySymToLWJGLKeyCode(keysym); + if (keycode == Keyboard.KEY_NONE) { + // Try unshifted keysym mapping + keysym = lookupKeysym(event_ptr, 0); + keycode = LinuxKeycodes.mapKeySymToLWJGLKeyCode(keysym); + } + return keycode; + } + + private byte getKeyState(int event_type) { + switch (event_type) { + case KeyPress: + return 1; + case KeyRelease: + return 0; + default: + throw new IllegalArgumentException("Unknown event_type: " + event_type); + } + } + + public 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); + key_down_buffer[keycode] = key_state; + translateEvent(event_ptr, event_type, keycode, key_state); + } +} Added: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeycodes.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeycodes.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeycodes.java 2006-07-03 18:07:44 UTC (rev 2425) @@ -0,0 +1,760 @@ +/* + * Copyright (c) 2002-2004 LWJGL 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 'LWJGL' 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. + */ +package org.lwjgl.opengl; + +/** + * @author elias_naur + */ + +import org.lwjgl.input.Keyboard; + +final class LinuxKeycodes { + public final static int XK_Kanji = 0xff21; + + public final static int XK_ISO_Left_Tab = 0xfe20; + + public final static int XK_dead_grave = 0xfe50; + public final static int XK_dead_acute = 0xfe51; + public final static int XK_dead_circumflex = 0xfe52; + public final static int XK_dead_tilde = 0xfe53; + public final static int XK_dead_macron = 0xfe54; + public final static int XK_dead_breve = 0xfe55; + public final static int XK_dead_abovedot = 0xfe56; + public final static int XK_dead_diaeresis = 0xfe57; + public final static int XK_dead_abovering = 0xfe58; + public final static int XK_dead_doubleacute = 0xfe59; + public final static int XK_dead_caron = 0xfe5a; + public final static int XK_dead_cedilla = 0xfe5b; + public final static int XK_dead_ogonek = 0xfe5c; + public final static int XK_dead_iota = 0xfe5d; + public final static int XK_dead_voiced_sound = 0xfe5e; + public final static int XK_dead_semivoiced_sound = 0xfe5f; + public final static int XK_dead_belowdot = 0xfe60; + public final static int XK_dead_hook = 0xfe61; + public final static int XK_dead_horn = 0xfe62; + + public final static int XK_BackSpace = 0xff08; + public final static int XK_Tab = 0xff09; + public final static int XK_Linefeed = 0xff0a; + public final static int XK_Clear = 0xff0b; + public final static int XK_Return = 0xff0d; + public final static int XK_Pause = 0xff13; + public final static int XK_Scroll_Lock = 0xff14; + public final static int XK_Sys_Req = 0xff15; + public final static int XK_Escape = 0xff1b; + public final static int XK_Delete = 0xffff; + + public final static int XK_Home = 0xff50; + public final static int XK_Left = 0xff51; + public final static int XK_Up = 0xff52; + public final static int XK_Right = 0xff53; + public final static int XK_Down = 0xff54; + public final static int XK_Prior = 0xff55; + public final static int XK_Page_Up = 0xff55; + public final static int XK_Next = 0xff56; + public final static int XK_Page_Down = 0xff56; + public final static int XK_End = 0xff57; + public final static int XK_Begin = 0xff58; + + +/* Misc functions */ + + public final static int XK_Select = 0xff60; + public final static int XK_Print = 0xff61; + public final static int XK_Execute = 0xff62; + public final static int XK_Insert = 0xff63; + public final static int XK_Undo = 0xff65; + public final static int XK_Redo = 0xff66; + public final static int XK_Menu = 0xff67; + public final static int XK_Find = 0xff68; + public final static int XK_Cancel = 0xff69; + public final static int XK_Help = 0xff6a; + public final static int XK_Break = 0xff6b; + public final static int XK_Mode_switch = 0xff7e; + public final static int XK_script_switch = 0xff7e; + public final static int XK_Num_Lock = 0xff7f; + +/* Keypad functions, keypad numbers cleverly chosen to map to ASCII */ + + public final static int XK_KP_Space = 0xff80; + public final static int XK_KP_Tab = 0xff89; + public final static int XK_KP_Enter = 0xff8d; + public final static int XK_KP_F1 = 0xff91; + public final static int XK_KP_F2 = 0xff92; + public final static int XK_KP_F3 = 0xff93; + public final static int XK_KP_F4 = 0xff94; + public final static int XK_KP_Home = 0xff95; + public final static int XK_KP_Left = 0xff96; + public final static int XK_KP_Up = 0xff97; + public final static int XK_KP_Right = 0xff98; + public final static int XK_KP_Down = 0xff99; + public final static int XK_KP_Prior = 0xff9a; + public final static int XK_KP_Page_Up = 0xff9a; + public final static int XK_KP_Next = 0xff9b; + public final static int XK_KP_Page_Down = 0xff9b; + public final static int XK_KP_End = 0xff9c; + public final static int XK_KP_Begin = 0xff9d; + public final static int XK_KP_Insert = 0xff9e; + public final static int XK_KP_Delete = 0xff9f; + public final static int XK_KP_Equal = 0xffbd; + public final static int XK_KP_Multiply = 0xffaa; + public final static int XK_KP_Add = 0xffab; + public final static int XK_KP_Separator = 0xffac; + public final static int XK_KP_Subtract = 0xffad; + public final static int XK_KP_Decimal = 0xffae; + public final static int XK_KP_Divide = 0xffaf; + + public final static int XK_KP_0 = 0xffb0; + public final static int XK_KP_1 = 0xffb1; + public final static int XK_KP_2 = 0xffb2; + public final static int XK_KP_3 = 0xffb3; + public final static int XK_KP_4 = 0xffb4; + public final static int XK_KP_5 = 0xffb5; + public final static int XK_KP_6 = 0xffb6; + public final static int XK_KP_7 = 0xffb7; + public final static int XK_KP_8 = 0xffb8; + public final static int XK_KP_9 = 0xffb9; + + + +/* + * Auxilliary functions; note the duplicate definitions for left and right + * function keys; Sun keyboards and a few other manufactures have such + * function key groups on the left and/or right sides of the keyboard. + * We've not found a keyboard with more than 35 function keys total. + */ + + public final static int XK_F1 = 0xffbe; + public final static int XK_F2 = 0xffbf; + public final static int XK_F3 = 0xffc0; + public final static int XK_F4 = 0xffc1; + public final static int XK_F5 = 0xffc2; + public final static int XK_F6 = 0xffc3; + public final static int XK_F7 = 0xffc4; + public final static int XK_F8 = 0xffc5; + public final static int XK_F9 = 0xffc6; + public final static int XK_F10 = 0xffc7; + public final static int XK_F11 = 0xffc8; + public final static int XK_L1 = 0xffc8; + public final static int XK_F12 = 0xffc9; + public final static int XK_L2 = 0xffc9; + public final static int XK_F13 = 0xffca; + public final static int XK_L3 = 0xffca; + public final static int XK_F14 = 0xffcb; + public final static int XK_L4 = 0xffcb; + public final static int XK_F15 = 0xffcc; + public final static int XK_L5 = 0xffcc; + public final static int XK_F16 = 0xffcd; + public final static int XK_L6 = 0xffcd; + public final static int XK_F17 = 0xffce; + public final static int XK_L7 = 0xffce; + public final static int XK_F18 = 0xffcf; + public final static int XK_L8 = 0xffcf; + public final static int XK_F19 = 0xffd0; + public final static int XK_L9 = 0xffd0; + public final static int XK_F20 = 0xffd1; + public final static int XK_L10 = 0xffd1; + public final static int XK_F21 = 0xffd2; + public final static int XK_R1 = 0xffd2; + public final static int XK_F22 = 0xffd3; + public final static int XK_R2 = 0xffd3; + public final static int XK_F23 = 0xffd4; + public final static int XK_R3 = 0xffd4; + public final static int XK_F24 = 0xffd5; + public final static int XK_R4 = 0xffd5; + public final static int XK_F25 = 0xffd6; + public final static int XK_R5 = 0xffd6; + public final static int XK_F26 = 0xffd7; + public final static int XK_R6 = 0xffd7; + public final static int XK_F27 = 0xffd8; + public final static int XK_R7 = 0xffd8; + public final static int XK_F28 = 0xffd9; + public final static int XK_R8 = 0xffd9; + public final static int XK_F29 = 0xffda; + public final static int XK_R9 = 0xffda; + public final static int XK_F30 = 0xffdb; + public final static int XK_R10 = 0xffdb; + public final static int XK_F31 = 0xffdc; + public final static int XK_R11 = 0xffdc; + public final static int XK_F32 = 0xffdd; + public final static int XK_R12 = 0xffdd; + public final static int XK_F33 = 0xffde; + public final static int XK_R13 = 0xffde; + public final static int XK_F34 = 0xffdf; + public final static int XK_R14 = 0xffdf; + public final static int XK_F35 = 0xffe0; + public final static int XK_R15 = 0xffe0; + +/* Modifiers */ + + public final static int XK_Shift_L = 0xffe1; + public final static int XK_Shift_R = 0xffe2; + public final static int XK_Control_L = 0xffe3; + public final static int XK_Control_R = 0xffe4; + public final static int XK_Caps_Lock = 0xffe5; + public final static int XK_Shift_Lock = 0xffe6; + + public final static int XK_Meta_L = 0xffe7; + public final static int XK_Meta_R = 0xffe8; + public final static int XK_Alt_L = 0xffe9; + public final static int XK_Alt_R = 0xffea; + public final static int XK_Super_L = 0xffeb; + public final static int XK_Super_R = 0xffec; + public final static int XK_Hyper_L = 0xffed; + public final static int XK_Hyper_R = 0xffee; + public final static int XK_space = 0x0020; + public final static int XK_exclam = 0x0021; + public final static int XK_quotedbl = 0x0022; + public final static int XK_numbersign = 0x0023; + public final static int XK_dollar = 0x0024; + public final static int XK_percent = 0x0025; + public final static int XK_ampersand = 0x0026; + public final static int XK_apostrophe = 0x0027; + public final static int XK_quoteright = 0x0027; + public final static int XK_parenleft = 0x0028; + public final static int XK_parenright = 0x0029; + public final static int XK_asterisk = 0x002a; + public final static int XK_plus = 0x002b; + public final static int XK_comma = 0x002c; + public final static int XK_minus = 0x002d; + public final static int XK_period = 0x002e; + public final static int XK_slash = 0x002f; + + public final static int XK_0 = 0x0030; + public final static int XK_1 = 0x0031; + public final static int XK_2 = 0x0032; + public final static int XK_3 = 0x0033; + public final static int XK_4 = 0x0034; + public final static int XK_5 = 0x0035; + public final static int XK_6 = 0x0036; + public final static int XK_7 = 0x0037; + public final static int XK_8 = 0x0038; + public final static int XK_9 = 0x0039; + public final static int XK_colon = 0x003a; + public final static int XK_semicolon = 0x003b; + public final static int XK_less = 0x003c; + public final static int XK_equal = 0x003d; + public final static int XK_greater = 0x003e; + public final static int XK_question = 0x003f; + public final static int XK_at = 0x0040; + public final static int XK_A = 0x0041; + public final static int XK_B = 0x0042; + public final static int XK_C = 0x0043; + public final static int XK_D = 0x0044; + public final static int XK_E = 0x0045; + public final static int XK_F = 0x0046; + public final static int XK_G = 0x0047; + public final static int XK_H = 0x0048; + public final static int XK_I = 0x0049; + public final static int XK_J = 0x004a; + public final static int XK_K = 0x004b; + public final static int XK_L = 0x004c; + public final static int XK_M = 0x004d; + public final static int XK_N = 0x004e; + public final static int XK_O = 0x004f; + public final static int XK_P = 0x0050; + public final static int XK_Q = 0x0051; + public final static int XK_R = 0x0052; + public final static int XK_S = 0x0053; + public final static int XK_T = 0x0054; + public final static int XK_U = 0x0055; + public final static int XK_V = 0x0056; + public final static int XK_W = 0x0057; + public final static int XK_X = 0x0058; + public final static int XK_Y = 0x0059; + public final static int XK_Z = 0x005a; + public final static int XK_bracketleft = 0x005b; + public final static int XK_backslash = 0x005c; + public final static int XK_bracketright = 0x005d; + public final static int XK_asciicircum = 0x005e; + public final static int XK_underscore = 0x005f; + public final static int XK_grave = 0x0060; + public final static int XK_quoteleft = 0x0060; + public final static int XK_a = 0x0061; + public final static int XK_b = 0x0062; + public final static int XK_c = 0x0063; + public final static int XK_d = 0x0064; + public final static int XK_e = 0x0065; + public final static int XK_f = 0x0066; + public final static int XK_g = 0x0067; + public final static int XK_h = 0x0068; + public final static int XK_i = 0x0069; + public final static int XK_j = 0x006a; + public final static int XK_k = 0x006b; + public final static int XK_l = 0x006c; + public final static int XK_m = 0x006d; + public final static int XK_n = 0x006e; + public final static int XK_o = 0x006f; + public final static int XK_p = 0x0070; + public final static int XK_q = 0x0071; + public final static int XK_r = 0x0072; + public final static int XK_s = 0x0073; + public final static int XK_t = 0x0074; + public final static int XK_u = 0x0075; + public final static int XK_v = 0x0076; + public final static int XK_w = 0x0077; + public final static int XK_x = 0x0078; + public final static int XK_y = 0x0079; + public final static int XK_z = 0x007a; + public final static int XK_braceleft = 0x007b; + public final static int XK_bar = 0x007c; + public final static int XK_braceright = 0x007d; + public final static int XK_asciitilde = 0x007e; + + public final static int XK_nobreakspace = 0x00a0; + public final static int XK_exclamdown = 0x00a1; + public final static int XK_cent = 0x00a2; + public final static int XK_sterling = 0x00a3; + public final static int XK_currency = 0x00a4; + public final static int XK_yen = 0x00a5; + public final static int XK_brokenbar = 0x00a6; + public final static int XK_section = 0x00a7; + public final static int XK_diaeresis = 0x00a8; + public final static int XK_copyright = 0x00a9; + public final static int XK_ordfeminine = 0x00aa; + public final static int XK_guillemotleft = 0x00ab; + public final static int XK_notsign = 0x00ac; + public final static int XK_hyphen = 0x00ad; + public final static int XK_registered = 0x00ae; + public final static int XK_macron = 0x00af; + public final static int XK_degree = 0x00b0; + public final static int XK_plusminus = 0x00b1; + public final static int XK_twosuperior = 0x00b2; + public final static int XK_threesuperior = 0x00b3; + public final static int XK_acute = 0x00b4; + public final static int XK_mu = 0x00b5; + public final static int XK_paragraph = 0x00b6; + public final static int XK_periodcentered = 0x00b7; + public final static int XK_cedilla = 0x00b8; + public final static int XK_onesuperior = 0x00b9; + public final static int XK_masculine = 0x00ba; + public final static int XK_guillemotright = 0x00bb; + public final static int XK_onequarter = 0x00bc; + public final static int XK_onehalf = 0x00bd; + public final static int XK_threequarters = 0x00be; + public final static int XK_questiondown = 0x00bf; + public final static int XK_Agrave = 0x00c0; + public final static int XK_Aacute = 0x00c1; + public final static int XK_Acircumflex = 0x00c2; + public final static int XK_Atilde = 0x00c3; + public final static int XK_Adiaeresis = 0x00c4; + public final static int XK_Aring = 0x00c5; + public final static int XK_AE = 0x00c6; + public final static int XK_Ccedilla = 0x00c7; + public final static int XK_Egrave = 0x00c8; + public final static int XK_Eacute = 0x00c9; + public final static int XK_Ecircumflex = 0x00ca; + public final static int XK_Ediaeresis = 0x00cb; + public final static int XK_Igrave = 0x00cc; + public final static int XK_Iacute = 0x00cd; + public final static int XK_Icircumflex = 0x00ce; + public final static int XK_Idiaeresis = 0x00cf; + public final static int XK_ETH = 0x00d0; + public final static int XK_Eth = 0x00d0; + public final static int XK_Ntilde = 0x00d1; + public final static int XK_Ograve = 0x00d2; + public final static int XK_Oacute = 0x00d3; + public final static int XK_Ocircumflex = 0x00d4; + public final static int XK_Otilde = 0x00d5; + public final static int XK_Odiaeresis = 0x00d6; + public final static int XK_multiply = 0x00d7; + public final static int XK_Oslash = 0x00d8; + public final static int XK_Ooblique = 0x00d8; + public final static int XK_Ugrave = 0x00d9; + public final static int XK_Uacute = 0x00da; + public final static int XK_Ucircumflex = 0x00db; + public final static int XK_Udiaeresis = 0x00dc; + public final static int XK_Yacute = 0x00dd; + public final static int XK_THORN = 0x00de; + public final static int XK_Thorn = 0x00de; + public final static int XK_ssharp = 0x00df; + public final static int XK_agrave = 0x00e0; + public final static int XK_aacute = 0x00e1; + public final static int XK_acircumflex = 0x00e2; + public final static int XK_atilde = 0x00e3; + public final static int XK_adiaeresis = 0x00e4; + public final static int XK_aring = 0x00e5; + public final static int XK_ae = 0x00e6; + public final static int XK_ccedilla = 0x00e7; + public final static int XK_egrave = 0x00e8; + public final static int XK_eacute = 0x00e9; + public final static int XK_ecircumflex = 0x00ea; + public final static int XK_ediaeresis = 0x00eb; + public final static int XK_igrave = 0x00ec; + public final static int XK_iacute = 0x00ed; + public final static int XK_icircumflex = 0x00ee; + public final static int XK_idiaeresis = 0x00ef; + public final static int XK_eth = 0x00f0; + public final static int XK_ntilde = 0x00f1; + public final static int XK_ograve = 0x00f2; + public final static int XK_oacute = 0x00f3; + public final static int XK_ocircumflex = 0x00f4; + public final static int XK_otilde = 0x00f5; + public final static int XK_odiaeresis = 0x00f6; + public final static int XK_division = 0x00f7; + public final static int XK_oslash = 0x00f8; + public final static int XK_ooblique = 0x00f8; + public final static int XK_ugrave = 0x00f9; + public final static int XK_uacute = 0x00fa; + public final static int XK_ucircumflex = 0x00fb; + public final static int XK_udiaeresis = 0x00fc; + public final static int XK_yacute = 0x00fd; + public final static int XK_thorn = 0x00fe; + public final static int XK_ydiaeresis = 0x00ff; + + public static int mapKeySymToLWJGLKeyCode(long keysym) { + switch ((int)keysym) { + case XK_BackSpace: + return Keyboard.KEY_BACK; + case XK_ISO_Left_Tab: + case XK_Tab: + return Keyboard.KEY_TAB; + case XK_Return: + return Keyboard.KEY_RETURN; + case XK_Pause: + return Keyboard.KEY_PAUSE; + case XK_Scroll_Lock: + return Keyboard.KEY_SCROLL; + case XK_Sys_Req: + return Keyboard.KEY_SYSRQ; + case XK_Escape: + return Keyboard.KEY_ESCAPE; + case XK_Delete: + return Keyboard.KEY_DELETE; + + /* Japanese keyboard support */ + + case XK_Kanji: + return Keyboard.KEY_KANJI; + + /* Cursor control & motion */ + + case XK_Home: + return Keyboard.KEY_HOME; + case XK_Left: + return Keyboard.KEY_LEFT; + case XK_Up: + return Keyboard.KEY_UP; + case XK_Right: + return Keyboard.KEY_RIGHT; + case XK_Down: + return Keyboard.KEY_DOWN; + case XK_Page_Up: + return Keyboard.KEY_PRIOR; + case XK_Page_Down: + return Keyboard.KEY_NEXT; + case XK_End: + return Keyboard.KEY_END; + + + /* Misc Functions */ + + case XK_Break: + return Keyboard.KEY_PAUSE; + case XK_Insert: + return Keyboard.KEY_INSERT; + case XK_Num_Lock: + return Keyboard.KEY_NUMLOCK; + + /* Keypad Functions, keypad numbers cleverly chosen to map to ascii */ + + case XK_KP_Space: + return Keyboard.KEY_SPACE; + case XK_KP_Tab: + return Keyboard.KEY_TAB; + case XK_KP_Enter: + return Keyboard.KEY_NUMPADENTER; + case XK_KP_F1: + return Keyboard.KEY_F1; + case XK_KP_F2: + return Keyboard.KEY_F2; + case XK_KP_F3: + return Keyboard.KEY_F3; + case XK_KP_F4: + return Keyboard.KEY_F4; + case XK_KP_Home: + return Keyboard.KEY_HOME; + case XK_KP_Left: + return Keyboard.KEY_LEFT; + case XK_KP_Up: + return Keyboard.KEY_UP; + case XK_KP_Right: + return Keyboard.KEY_RIGHT; + case XK_KP_Down: + return Keyboard.KEY_DOWN; + case XK_KP_Page_Up: + return Keyboard.KEY_PRIOR; + case XK_KP_Page_Down: + return Keyboard.KEY_NEXT; + case XK_KP_End: + return Keyboard.KEY_END; + case XK_KP_Insert: + return Keyboard.KEY_INSERT; + case XK_KP_Delete: + return Keyboard.KEY_DELETE; + case XK_KP_Equal: + return Keyboard.KEY_NUMPADEQUALS; + case XK_KP_Multiply: + return Keyboard.KEY_MULTIPLY; + case XK_KP_Add: + return Keyboard.KEY_ADD; + case XK_KP_Subtract: + return Keyboard.KEY_SUBT... [truncated message content] |