From: <ka...@us...> - 2012-01-31 23:24:35
|
Revision: 3736 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3736&view=rev Author: kappa1 Date: 2012-01-31 23:24:28 +0000 (Tue, 31 Jan 2012) Log Message: ----------- Linux Mouse: added support for using more than 3 buttons on a mouse, supports mice with upto 256 buttons. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxMouse.java trunk/LWJGL/src/native/linux/org_lwjgl_opengl_LinuxMouse.c Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxMouse.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxMouse.java 2012-01-29 20:35:22 UTC (rev 3735) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxMouse.java 2012-01-31 23:24:28 UTC (rev 3736) @@ -43,17 +43,23 @@ import org.lwjgl.input.Mouse; final class LinuxMouse { - private static final int NUM_BUTTONS = 3; private static final int POINTER_WARP_BORDER = 10; // scale the mouse wheel according to DirectInput private static final int WHEEL_SCALE = 120; + private int button_count; + /* X11 constants */ private static final int Button1 = 1; private static final int Button2 = 2; private static final int Button3 = 3; private static final int Button4 = 4; private static final int Button5 = 5; + + private static final int Button6 = 6; // wheel tilt left *rare* + private static final int Button7 = 7; // wheel tilt right *rare* + private static final int Button8 = 8; // back button + private static final int Button9 = 9; // forward button private static final int ButtonPress = 4; private static final int ButtonRelease = 5; @@ -70,7 +76,7 @@ private int accum_dx; private int accum_dy; private int accum_dz; - private byte[] buttons = new byte[NUM_BUTTONS]; + private byte[] buttons;// = new byte[NUM_BUTTONS]; private EventQueue event_queue; private long last_event_nanos; @@ -79,6 +85,8 @@ this.window = window; this.input_window = input_window; this.warp_atom = LinuxDisplay.nInternAtom(display, "_LWJGL", false); + button_count = nGetButtonCount(display); + buttons = new byte[button_count]; reset(false, false); } @@ -189,6 +197,8 @@ } private static native int nGetWindowHeight(long display, long window); private static native int nGetWindowWidth(long display, long window); + + private static native int nGetButtonCount(long display); private static native long nQueryPointer(long display, long window, IntBuffer result); @@ -213,7 +223,23 @@ case Button3: button_num = (byte)1; break; + case Button6: + button_num = (byte)5; + break; + case Button7: + button_num = (byte)6; + break; + case Button8: + button_num = (byte)3; // back button + break; + case Button9: + button_num = (byte)4; // forward button + break; default: + if (button > Button9 && button <= button_count) { + button_num = (byte)(button-1); + break; + } return; } buttons[button_num] = state; Modified: trunk/LWJGL/src/native/linux/org_lwjgl_opengl_LinuxMouse.c =================================================================== --- trunk/LWJGL/src/native/linux/org_lwjgl_opengl_LinuxMouse.c 2012-01-29 20:35:22 UTC (rev 3735) +++ trunk/LWJGL/src/native/linux/org_lwjgl_opengl_LinuxMouse.c 2012-01-31 23:24:28 UTC (rev 3736) @@ -103,3 +103,16 @@ warp_event.xclient.data.l[1] = y; XSendEvent(disp, win, False, 0, &warp_event); } + +JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxMouse_nGetButtonCount(JNIEnv *env, jclass unused, jlong display_ptr) { + Display *disp = (Display *)(intptr_t)display_ptr; + + int count = 256; + + unsigned char * pointer_map = malloc(sizeof(unsigned char) * count); + count = XGetPointerMapping(disp, pointer_map, count); + + free(pointer_map); + + return count; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |