id_to_components = new HashMap<>();
+
+ private EventQueue event_queue = new EventQueue(EVENT_QUEUE_DEPTH);
+
+ /**
+ * Protected constructor for a controller containing the specified
+ * axes, child controllers, and rumblers
+ * @param name name for the controller
+ * @param components components for the controller
+ * @param children child controllers for the controller
+ * @param rumblers rumblers for the controller
+ */
+ protected AbstractController(String name, Component[] components, Controller[] children, Rumbler[] rumblers) {
+ this.name = name;
+ this.components = components;
+ this.children = children;
+ this.rumblers = rumblers;
+ // process from last to first to let earlier listed Components get higher priority
+ for (int i = components.length - 1; i >= 0; i--) {
+ id_to_components.put(components[i].getIdentifier(), components[i]);
+ }
+ }
+
+ /**
+ * Returns the controllers connected to make up this controller, or
+ * an empty array if this controller contains no child controllers.
+ * The objects in the array are returned in order of assignment priority
+ * (primary stick, secondary buttons, etc.).
+ */
+ public final Controller[] getControllers() {
+ return children;
+ }
+
+ /**
+ * Returns the components on this controller, in order of assignment priority.
+ * For example, the button controller on a mouse returns an array containing
+ * the primary or leftmost mouse button, followed by the secondary or
+ * rightmost mouse button (if present), followed by the middle mouse button
+ * (if present).
+ * The array returned is an empty array if this controller contains no components
+ * (such as a logical grouping of child controllers).
+ */
+ public final Component[] getComponents() {
+ return components;
+ }
+
+ /**
+ * Returns a single component based on its identifier, or null
+ * if no component with the specified type could be found.
+ */
+ public final Component getComponent(Component.Identifier id) {
+ return id_to_components.get(id);
+ }
+
+ /**
+ * Returns the rumblers for sending feedback to this controller, or an
+ * empty array if there are no rumblers on this controller.
+ */
+ public final Rumbler[] getRumblers() {
+ return rumblers;
+ }
+
+ /**
+ * Returns the port type for this Controller.
+ * @return PortType.UNKNOWN by default, can be overridden
+ */
+ public PortType getPortType() {
+ return PortType.UNKNOWN;
+ }
+
+ /**
+ * Returns the zero-based port number for this Controller.
+ * @return 0 by default, can be overridden
+ */
+ public int getPortNumber() {
+ return 0;
+ }
+
+ /**
+ * Returns a human-readable name for this Controller.
+ */
+ public final String getName() {
+ return name;
+ }
+
+ /**
+ * Returns a non-localized string description of this controller.
+ */
+ public String toString() {
+ return name;
+ }
+
+ /** Returns the type of the Controller.
+ */
+ public Type getType() {
+ return Type.UNKNOWN;
+ }
+
+ /**
+ * Creates a new EventQueue. Events in old queue are lost.
+ */
+ public final void setEventQueueSize(int size) {
+ try {
+ setDeviceEventQueueSize(size);
+ event_queue = new EventQueue(size);
+ } catch (IOException e) {
+ ControllerEnvironment.log("Failed to create new event queue of size " + size + ": " + e);
+ }
+ }
+
+ /**
+ * Plugins override this method to adjust their internal event queue size
+ */
+ protected void setDeviceEventQueueSize(int size) throws IOException {
+ }
+
+ public final EventQueue getEventQueue() {
+ return event_queue;
+ }
+
+ protected abstract boolean getNextDeviceEvent(Event event) throws IOException;
+
+ protected void pollDevice() throws IOException {
+ }
+
+ /* poll() is synchronized to protect the static event */
+ public synchronized boolean poll() {
+ Component[] components = getComponents();
+ try {
+ pollDevice();
+ for (int i = 0; i < components.length; i++) {
+ AbstractComponent component = (AbstractComponent)components[i];
+ if (component.isRelative()) {
+ component.setPollData(0);
+ } else {
+ // Let the component poll itself lazily
+ component.resetHasPolled();
+ }
+ }
+ while (getNextDeviceEvent(event)) {
+ AbstractComponent component = (AbstractComponent)event.getComponent();
+ float value = event.getValue();
+ if (component.isRelative()) {
+ if (value == 0)
+ continue;
+ component.setPollData(component.getPollData() + value);
+ } else {
+ if (value == component.getEventValue())
+ continue;
+ component.setEventValue(value);
+ }
+ if (!event_queue.isFull())
+ event_queue.add(event);
+ }
+ return true;
+ } catch (IOException e) {
+ ControllerEnvironment.log("Failed to poll device: " + e.getMessage());
+ return false;
+ }
+ }
+
+} // class AbstractController
diff --git a/src/core/net/java/games/input/Component.java b/src/core/net/java/games/input/Component.java
new file mode 100644
index 0000000..02fbcd5
--- /dev/null
+++ b/src/core/net/java/games/input/Component.java
@@ -0,0 +1,782 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+/**
+ * An axis is a single button, slider, or dial, which has a single range. An
+ * axis can hold information for motion (linear or rotational), velocity,
+ * force, or acceleration.
+ */
+public interface Component {
+
+ /**
+ * Returns the identifier of the axis.
+ */
+ public abstract Identifier getIdentifier();
+
+ /**
+ * Returns true
if data returned from poll
+ * is relative to the last call, or false
if data
+ * is absolute.
+ */
+ public abstract boolean isRelative();
+
+ /**
+ * Returns whether or not the axis is analog, or false if it is digital.
+ */
+ public abstract boolean isAnalog();
+
+ /**
+ * Returns the suggested dead zone for this axis. Dead zone is the
+ * amount polled data can vary before considered a significant change
+ * in value. An application can safely ignore changes less than this
+ * value in the positive or negative direction.
+ * @see #getPollData
+ */
+ public abstract float getDeadZone();
+
+ /**
+ * Returns the data from the last time the control has been polled.
+ * If this axis is a button, the value returned will be either 0.0f or 1.0f.
+ * If this axis is normalized, the value returned will be between -1.0f and
+ * 1.0f.
+ * @see Controller#poll
+ */
+ public abstract float getPollData();
+
+ /**
+ * Returns a human-readable name for this axis.
+ */
+ public abstract String getName();
+
+ /**
+ * Identifiers for different Axes.
+ */
+ public static class Identifier {
+
+ /**
+ * Name of axis type
+ */
+ private final String name;
+
+ /**
+ * Protected constructor
+ */
+ protected Identifier(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns a non-localized string description of this axis type.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Returns a non-localized string description of this axis type.
+ */
+ public String toString() {
+ return name;
+ }
+
+ public static class Axis extends Identifier {
+
+ /**
+ * @param name
+ */
+ protected Axis(String name) {
+ super(name);
+ }
+
+ /**
+ * An axis for specifying vertical data.
+ */
+ public static final Axis X = new Axis("x");
+
+ /**
+ * An axis for specifying horizontal data.
+ */
+ public static final Axis Y = new Axis("y");
+
+ /**
+ * An axis for specifying third dimensional up/down
+ * data, or linear data in any direction that is
+ * neither horizontal nor vertical.
+ */
+ public static final Axis Z = new Axis("z");
+
+ /**
+ * An axis for specifying left-right rotational data.
+ */
+ public static final Axis RX = new Axis("rx");
+
+ /**
+ * An axis for specifying forward-back rotational data.
+ */
+ public static final Axis RY = new Axis("ry");
+
+ /**
+ * An axis for specifying up-down rotational data
+ * (rudder control).
+ */
+ public static final Axis RZ = new Axis("rz");
+
+ /**
+ * An axis for a slider or mouse wheel.
+ */
+ public static final Axis SLIDER = new Axis("slider");
+
+ /**
+ * An axis for slider or mouse wheel acceleration data.
+ */
+ public static final Axis SLIDER_ACCELERATION = new Axis("slider-acceleration");
+
+ /**
+ * An axis for slider force data.
+ */
+ public static final Axis SLIDER_FORCE = new Axis("slider-force");
+
+ /**
+ * An axis for slider or mouse wheel velocity data.
+ */
+ public static final Axis SLIDER_VELOCITY = new Axis("slider-velocity");
+
+ /**
+ * An axis for specifying vertical acceleration data.
+ */
+ public static final Axis X_ACCELERATION = new Axis("x-acceleration");
+
+ /**
+ * An axis for specifying vertical force data.
+ */
+ public static final Axis X_FORCE = new Axis("x-force");
+
+ /**
+ * An axis for specifying vertical velocity data.
+ */
+ public static final Axis X_VELOCITY = new Axis("x-velocity");
+
+ /**
+ * An axis for specifying horizontal acceleration data.
+ */
+ public static final Axis Y_ACCELERATION = new Axis("y-acceleration");
+
+ /**
+ * An axis for specifying horizontal force data.
+ */
+ public static final Axis Y_FORCE = new Axis("y-force");
+
+ /**
+ * An axis for specifying horizontal velocity data.
+ */
+ public static final Axis Y_VELOCITY = new Axis("y-velocity");
+
+ /**
+ * An axis for specifying third dimensional up/down acceleration data.
+ */
+ public static final Axis Z_ACCELERATION = new Axis("z-acceleration");
+
+ /**
+ * An axis for specifying third dimensional up/down force data.
+ */
+ public static final Axis Z_FORCE = new Axis("z-force");
+
+ /**
+ * An axis for specifying third dimensional up/down velocity data.
+ */
+ public static final Axis Z_VELOCITY = new Axis("z-velocity");
+
+ /**
+ * An axis for specifying left-right angular acceleration data.
+ */
+ public static final Axis RX_ACCELERATION = new Axis("rx-acceleration");
+
+ /**
+ * An axis for specifying left-right angular force (torque) data.
+ */
+ public static final Axis RX_FORCE = new Axis("rx-force");
+
+ /**
+ * An axis for specifying left-right angular velocity data.
+ */
+ public static final Axis RX_VELOCITY = new Axis("rx-velocity");
+
+ /**
+ * An axis for specifying forward-back angular acceleration data.
+ */
+ public static final Axis RY_ACCELERATION = new Axis("ry-acceleration");
+
+ /**
+ * An axis for specifying forward-back angular force (torque) data.
+ */
+ public static final Axis RY_FORCE = new Axis("ry-force");
+
+ /**
+ * An axis for specifying forward-back angular velocity data.
+ */
+ public static final Axis RY_VELOCITY = new Axis("ry-velocity");
+
+ /**
+ * An axis for specifying up-down angular acceleration data.
+ */
+ public static final Axis RZ_ACCELERATION = new Axis("rz-acceleration");
+
+ /**
+ * An axis for specifying up-down angular force (torque) data.
+ */
+ public static final Axis RZ_FORCE = new Axis("rz-force");
+
+ /**
+ * An axis for specifying up-down angular velocity data.
+ */
+ public static final Axis RZ_VELOCITY = new Axis("rz-velocity");
+
+ /**
+ * An axis for a point-of-view control.
+ */
+ public static final Axis POV = new Axis("pov");
+
+ /**
+ * An unknown axis.
+ */
+ public static final Axis UNKNOWN = new Axis("unknown");
+
+ }
+
+ public static class Button extends Identifier {
+
+ public Button(String name) {
+ super(name);
+ }
+
+ /** First device button
+ */
+ public static final Button _0 = new Button("0");
+
+ /** Second device button
+ */
+ public static final Button _1 = new Button("1");
+
+ /** Thrid device button
+ */
+ public static final Button _2 = new Button("2");
+
+ /** Fourth device button
+ */
+ public static final Button _3 = new Button("3");
+
+ /** Fifth device button
+ */
+ public static final Button _4 = new Button("4");
+
+ /** Sixth device button
+ */
+ public static final Button _5 = new Button("5");
+
+ /** Seventh device button
+ */
+ public static final Button _6 = new Button("6");
+
+ /** Eighth device button
+ */
+ public static final Button _7 = new Button("7");
+
+ /** Ninth device button
+ */
+ public static final Button _8 = new Button("8");
+
+ /** 10th device button
+ */
+ public static final Button _9 = new Button("9");
+ public static final Button _10 = new Button("10");
+ public static final Button _11 = new Button("11");
+ public static final Button _12 = new Button("12");
+ public static final Button _13 = new Button("13");
+ public static final Button _14 = new Button("14");
+ public static final Button _15 = new Button("15");
+ public static final Button _16 = new Button("16");
+ public static final Button _17 = new Button("17");
+ public static final Button _18 = new Button("18");
+ public static final Button _19 = new Button("19");
+ public static final Button _20 = new Button("20");
+ public static final Button _21 = new Button("21");
+ public static final Button _22 = new Button("22");
+ public static final Button _23 = new Button("23");
+ public static final Button _24 = new Button("24");
+ public static final Button _25 = new Button("25");
+ public static final Button _26 = new Button("26");
+ public static final Button _27 = new Button("27");
+ public static final Button _28 = new Button("28");
+ public static final Button _29 = new Button("29");
+ public static final Button _30 = new Button("30");
+ public static final Button _31 = new Button("31");
+
+ /** Joystick trigger button
+ */
+ public static final Button TRIGGER = new Button("Trigger");
+
+ /** Joystick thumb button
+ */
+ public static final Button THUMB = new Button("Thumb");
+
+ /** Second joystick thumb button
+ */
+ public static final Button THUMB2 = new Button("Thumb 2");
+
+ /** Joystick top button
+ */
+ public static final Button TOP = new Button("Top");
+
+ /** Second joystick top button
+ */
+ public static final Button TOP2 = new Button("Top 2");
+
+ /** The joystick button you play with with you little finger (Pinkie on *that* side
+ * of the pond :P)
+ */
+ public static final Button PINKIE = new Button("Pinkie");
+
+ /** Joystick button on the base of the device
+ */
+ public static final Button BASE = new Button("Base");
+
+ /** Second joystick button on the base of the device
+ */
+ public static final Button BASE2 = new Button("Base 2");
+
+ /** Thrid joystick button on the base of the device
+ */
+ public static final Button BASE3 = new Button("Base 3");
+
+ /** Fourth joystick button on the base of the device
+ */
+ public static final Button BASE4 = new Button("Base 4");
+
+ /** Fifth joystick button on the base of the device
+ */
+ public static final Button BASE5 = new Button("Base 5");
+
+ /** Sixth joystick button on the base of the device
+ */
+ public static final Button BASE6 = new Button("Base 6");
+
+ /** erm, dunno, but it's in the defines so it might exist.
+ */
+ public static final Button DEAD = new Button("Dead");
+
+ /** 'A' button on a gamepad
+ */
+ public static final Button A = new Button("A");
+
+ /** 'B' button on a gamepad
+ */
+ public static final Button B = new Button("B");
+
+ /** 'C' button on a gamepad
+ */
+ public static final Button C = new Button("C");
+
+ /** 'X' button on a gamepad
+ */
+ public static final Button X = new Button("X");
+
+ /** 'Y' button on a gamepad
+ */
+ public static final Button Y = new Button("Y");
+
+ /** 'Z' button on a gamepad
+ */
+ public static final Button Z = new Button("Z");
+
+ /** Left thumb button on a gamepad
+ */
+ public static final Button LEFT_THUMB = new Button("Left Thumb");
+
+ /** Right thumb button on a gamepad
+ */
+ public static final Button RIGHT_THUMB = new Button("Right Thumb");
+
+ /** Second left thumb button on a gamepad
+ */
+ public static final Button LEFT_THUMB2 = new Button("Left Thumb 2");
+
+ /** Second right thumb button on a gamepad
+ */
+ public static final Button RIGHT_THUMB2 = new Button("Right Thumb 2");
+
+ /** 'Select' button on a gamepad
+ */
+ public static final Button SELECT = new Button("Select");
+
+ /** 'Start' button on a gamepad
+ */
+ public static final Button START = new Button("Start");
+
+ /** 'Mode' button on a gamepad
+ */
+ public static final Button MODE = new Button("Mode");
+
+ /** Another left thumb button on a gamepad (how many thumbs do you have??)
+ */
+ public static final Button LEFT_THUMB3 = new Button("Left Thumb 3");
+
+ /** Another right thumb button on a gamepad
+ */
+ public static final Button RIGHT_THUMB3 = new Button("Right Thumb 3");
+
+ /** Digitiser pen tool button
+ */
+ public static final Button TOOL_PEN = new Button("Pen");
+
+ /** Digitiser rubber (eraser) tool button
+ */
+ public static final Button TOOL_RUBBER = new Button("Rubber");
+
+ /** Digitiser brush tool button
+ */
+ public static final Button TOOL_BRUSH = new Button("Brush");
+
+ /** Digitiser pencil tool button
+ */
+ public static final Button TOOL_PENCIL = new Button("Pencil");
+
+ /** Digitiser airbrush tool button
+ */
+ public static final Button TOOL_AIRBRUSH = new Button("Airbrush");
+
+ /** Digitiser finger tool button
+ */
+ public static final Button TOOL_FINGER = new Button("Finger");
+
+ /** Digitiser mouse tool button
+ */
+ public static final Button TOOL_MOUSE = new Button("Mouse");
+
+ /** Digitiser lens tool button
+ */
+ public static final Button TOOL_LENS = new Button("Lens");
+
+ /** Digitiser touch button
+ */
+ public static final Button TOUCH = new Button("Touch");
+
+ /** Digitiser stylus button
+ */
+ public static final Button STYLUS = new Button("Stylus");
+
+ /** Second digitiser stylus button
+ */
+ public static final Button STYLUS2 = new Button("Stylus 2");
+
+ /**
+ * An unknown button
+ */
+ public static final Button UNKNOWN = new Button("Unknown");
+
+ /**
+ * Returns the back mouse button.
+ */
+ public static final Button BACK = new Button("Back");
+
+ /**
+ * Returns the extra mouse button.
+ */
+ public static final Button EXTRA = new Button("Extra");
+
+ /**
+ * Returns the forward mouse button.
+ */
+ public static final Button FORWARD = new Button("Forward");
+
+ /**
+ * The primary or leftmost mouse button.
+ */
+ public static final Button LEFT = new Button("Left");
+
+ /**
+ * Returns the middle mouse button, not present if the mouse has fewer than three buttons.
+ */
+ public static final Button MIDDLE = new Button("Middle");
+
+ /**
+ * The secondary or rightmost mouse button, not present if the mouse is a single-button mouse.
+ */
+ public static final Button RIGHT = new Button("Right");
+
+ /**
+ * Returns the side mouse button.
+ */
+ public static final Button SIDE = new Button("Side");
+
+ /**
+ * Extra, unnamed, buttons
+ */
+ public static final Button EXTRA_1 = new Button("Extra 1");
+ public static final Button EXTRA_2 = new Button("Extra 2");
+ public static final Button EXTRA_3 = new Button("Extra 3");
+ public static final Button EXTRA_4 = new Button("Extra 4");
+ public static final Button EXTRA_5 = new Button("Extra 5");
+ public static final Button EXTRA_6 = new Button("Extra 6");
+ public static final Button EXTRA_7 = new Button("Extra 7");
+ public static final Button EXTRA_8 = new Button("Extra 8");
+ public static final Button EXTRA_9 = new Button("Extra 9");
+ public static final Button EXTRA_10 = new Button("Extra 10");
+ public static final Button EXTRA_11 = new Button("Extra 11");
+ public static final Button EXTRA_12 = new Button("Extra 12");
+ public static final Button EXTRA_13 = new Button("Extra 13");
+ public static final Button EXTRA_14 = new Button("Extra 14");
+ public static final Button EXTRA_15 = new Button("Extra 15");
+ public static final Button EXTRA_16 = new Button("Extra 16");
+ public static final Button EXTRA_17 = new Button("Extra 17");
+ public static final Button EXTRA_18 = new Button("Extra 18");
+ public static final Button EXTRA_19 = new Button("Extra 19");
+ public static final Button EXTRA_20 = new Button("Extra 20");
+ public static final Button EXTRA_21 = new Button("Extra 21");
+ public static final Button EXTRA_22 = new Button("Extra 22");
+ public static final Button EXTRA_23 = new Button("Extra 23");
+ public static final Button EXTRA_24 = new Button("Extra 24");
+ public static final Button EXTRA_25 = new Button("Extra 25");
+ public static final Button EXTRA_26 = new Button("Extra 26");
+ public static final Button EXTRA_27 = new Button("Extra 27");
+ public static final Button EXTRA_28 = new Button("Extra 28");
+ public static final Button EXTRA_29 = new Button("Extra 29");
+ public static final Button EXTRA_30 = new Button("Extra 30");
+ public static final Button EXTRA_31 = new Button("Extra 31");
+ public static final Button EXTRA_32 = new Button("Extra 32");
+ public static final Button EXTRA_33 = new Button("Extra 33");
+ public static final Button EXTRA_34 = new Button("Extra 34");
+ public static final Button EXTRA_35 = new Button("Extra 35");
+ public static final Button EXTRA_36 = new Button("Extra 36");
+ public static final Button EXTRA_37 = new Button("Extra 37");
+ public static final Button EXTRA_38 = new Button("Extra 38");
+ public static final Button EXTRA_39 = new Button("Extra 39");
+ public static final Button EXTRA_40 = new Button("Extra 40");
+ }
+
+ /**
+ * KeyIDs for standard PC (LATIN-1) keyboards
+ */
+ public static class Key extends Identifier {
+ /**
+ * Protected constructor
+ */
+ protected Key(String name) {
+ super(name);
+ }
+
+ /**
+ * Standard keyboard (LATIN-1) keys
+ * UNIX X11 keysym values are listed to the right
+ */
+ public static final Key VOID = new Key("Void"); // MS 0x00 UNIX 0xFFFFFF
+ public static final Key ESCAPE = new Key("Escape"); // MS 0x01 UNIX 0xFF1B
+ public static final Key _1 = new Key("1"); // MS 0x02 UNIX 0x031 EXCLAM 0x021
+ public static final Key _2 = new Key("2"); // MS 0x03 UNIX 0x032 AT 0x040
+ public static final Key _3 = new Key("3"); // MS 0x04 UNIX 0x033 NUMBERSIGN 0x023
+ public static final Key _4 = new Key("4"); // MS 0x05 UNIX 0x034 DOLLAR 0x024
+ public static final Key _5 = new Key("5"); // MS 0x06 UNIX 0x035 PERCENT 0x025
+ public static final Key _6 = new Key("6"); // MS 0x07 UNIX 0x036 CIRCUMFLEX 0x05e
+ public static final Key _7 = new Key("7"); // MS 0x08 UNIX 0x037 AMPERSAND 0x026
+ public static final Key _8 = new Key("8"); // MS 0x09 UNIX 0x038 ASTERISK 0x02a
+ public static final Key _9 = new Key("9"); // MS 0x0A UNIX 0x039 PARENLEFT 0x028
+ public static final Key _0 = new Key("0"); // MS 0x0B UNIX 0x030 PARENRIGHT 0x029
+ public static final Key MINUS = new Key("-"); // MS 0x0C UNIX 0x02d UNDERSCORE 0x05f
+ public static final Key EQUALS = new Key("="); // MS 0x0D UNIX 0x03d PLUS 0x02b
+ public static final Key BACK = new Key("Back"); // MS 0x0E UNIX 0xFF08
+ public static final Key TAB = new Key("Tab"); // MS 0x0F UNIX 0xFF09
+ public static final Key Q = new Key("Q"); // MS 0x10 UNIX 0x071 UPPER 0x051
+ public static final Key W = new Key("W"); // MS 0x11 UNIX 0x077 UPPER 0x057
+ public static final Key E = new Key("E"); // MS 0x12 UNIX 0x065 UPPER 0x045
+ public static final Key R = new Key("R"); // MS 0x13 UNIX 0x072 UPPER 0x052
+ public static final Key T = new Key("T"); // MS 0x14 UNIX 0x074 UPPER 0x054
+ public static final Key Y = new Key("Y"); // MS 0x15 UNIX 0x079 UPPER 0x059
+ public static final Key U = new Key("U"); // MS 0x16 UNIX 0x075 UPPER 0x055
+ public static final Key I = new Key("I"); // MS 0x17 UNIX 0x069 UPPER 0x049
+ public static final Key O = new Key("O"); // MS 0x18 UNIX 0x06F UPPER 0x04F
+ public static final Key P = new Key("P"); // MS 0x19 UNIX 0x070 UPPER 0x050
+ public static final Key LBRACKET = new Key("["); // MS 0x1A UNIX 0x05b BRACE 0x07b
+ public static final Key RBRACKET = new Key("]"); // MS 0x1B UNIX 0x05d BRACE 0x07d
+ public static final Key RETURN = new Key("Return"); // MS 0x1C UNIX 0xFF0D
+ public static final Key LCONTROL = new Key("Left Control"); // MS 0x1D UNIX 0xFFE3
+ public static final Key A = new Key("A"); // MS 0x1E UNIX 0x061 UPPER 0x041
+ public static final Key S = new Key("S"); // MS 0x1F UNIX 0x073 UPPER 0x053
+ public static final Key D = new Key("D"); // MS 0x20 UNIX 0x064 UPPER 0x044
+ public static final Key F = new Key("F"); // MS 0x21 UNIX 0x066 UPPER 0x046
+ public static final Key G = new Key("G"); // MS 0x22 UNIX 0x067 UPPER 0x047
+ public static final Key H = new Key("H"); // MS 0x23 UNIX 0x068 UPPER 0x048
+ public static final Key J = new Key("J"); // MS 0x24 UNIX 0x06A UPPER 0x04A
+ public static final Key K = new Key("K"); // MS 0x25 UNIX 0x06B UPPER 0x04B
+ public static final Key L = new Key("L"); // MS 0x26 UNIX 0x06C UPPER 0x04C
+ public static final Key SEMICOLON = new Key(";"); // MS 0x27 UNIX 0x03b COLON 0x03a
+ public static final Key APOSTROPHE = new Key("'"); // MS 0x28 UNIX 0x027 QUOTEDBL 0x022
+ public static final Key GRAVE = new Key("~"); // MS 0x29 UNIX 0x060 TILDE 0x07e
+ public static final Key LSHIFT = new Key("Left Shift"); // MS 0x2A UNIX 0xFFE1
+ public static final Key BACKSLASH = new Key("\\"); // MS 0x2B UNIX 0x05c BAR 0x07c
+ public static final Key Z = new Key("Z"); // MS 0x2C UNIX 0x07A UPPER 0x05A
+ public static final Key X = new Key("X"); // MS 0x2D UNIX 0x078 UPPER 0x058
+ public static final Key C = new Key("C"); // MS 0x2E UNIX 0x063 UPPER 0x043
+ public static final Key V = new Key("V"); // MS 0x2F UNIX 0x076 UPPER 0x056
+ public static final Key B = new Key("B"); // MS 0x30 UNIX 0x062 UPPER 0x042
+ public static final Key N = new Key("N"); // MS 0x31 UNIX 0x06E UPPER 0x04E
+ public static final Key M = new Key("M"); // MS 0x32 UNIX 0x06D UPPER 0x04D
+ public static final Key COMMA = new Key(","); // MS 0x33 UNIX 0x02c LESS 0x03c
+ public static final Key PERIOD = new Key("."); // MS 0x34 UNIX 0x02e GREATER 0x03e
+ public static final Key SLASH = new Key("/"); // MS 0x35 UNIX 0x02f QUESTION 0x03f
+ public static final Key RSHIFT = new Key("Right Shift"); // MS 0x36 UNIX 0xFFE2
+ public static final Key MULTIPLY = new Key("Multiply"); // MS 0x37 UNIX 0xFFAA
+ public static final Key LALT = new Key("Left Alt"); // MS 0x38 UNIX 0xFFE9
+ public static final Key SPACE = new Key(" "); // MS 0x39 UNIX 0x020
+ public static final Key CAPITAL = new Key("Caps Lock"); // MS 0x3A UNIX 0xFFE5 SHIFTLOCK 0xFFE6
+ public static final Key F1 = new Key("F1"); // MS 0x3B UNIX 0xFFBE
+ public static final Key F2 = new Key("F2"); // MS 0x3C UNIX 0xFFBF
+ public static final Key F3 = new Key("F3"); // MS 0x3D UNIX 0xFFC0
+ public static final Key F4 = new Key("F4"); // MS 0x3E UNIX 0xFFC1
+ public static final Key F5 = new Key("F5"); // MS 0x3F UNIX 0xFFC2
+ public static final Key F6 = new Key("F6"); // MS 0x40 UNIX 0xFFC3
+ public static final Key F7 = new Key("F7"); // MS 0x41 UNIX 0xFFC4
+ public static final Key F8 = new Key("F8"); // MS 0x42 UNIX 0xFFC5
+ public static final Key F9 = new Key("F9"); // MS 0x43 UNIX 0xFFC6
+ public static final Key F10 = new Key("F10"); // MS 0x44 UNIX 0xFFC7
+ public static final Key NUMLOCK = new Key("Num Lock"); // MS 0x45 UNIX 0xFF7F
+ public static final Key SCROLL = new Key("Scroll Lock"); // MS 0x46 UNIX 0xFF14
+ public static final Key NUMPAD7 = new Key("Num 7"); // MS 0x47 UNIX 0xFFB7 HOME 0xFF95
+ public static final Key NUMPAD8 = new Key("Num 8"); // MS 0x48 UNIX 0xFFB8 UP 0xFF97
+ public static final Key NUMPAD9 = new Key("Num 9"); // MS 0x49 UNIX 0xFFB9 PRIOR 0xFF9A
+ public static final Key SUBTRACT = new Key("Num -"); // MS 0x4A UNIX 0xFFAD
+ public static final Key NUMPAD4 = new Key("Num 4"); // MS 0x4B UNIX 0xFFB4 LEFT 0xFF96
+ public static final Key NUMPAD5 = new Key("Num 5"); // MS 0x4C UNIX 0xFFB5
+ public static final Key NUMPAD6 = new Key("Num 6"); // MS 0x4D UNIX 0xFFB6 RIGHT 0xFF98
+ public static final Key ADD = new Key("Num +"); // MS 0x4E UNIX 0xFFAB
+ public static final Key NUMPAD1 = new Key("Num 1"); // MS 0x4F UNIX 0xFFB1 END 0xFF9C
+ public static final Key NUMPAD2 = new Key("Num 2"); // MS 0x50 UNIX 0xFFB2 DOWN 0xFF99
+ public static final Key NUMPAD3 = new Key("Num 3"); // MS 0x51 UNIX 0xFFB3 NEXT 0xFF9B
+ public static final Key NUMPAD0 = new Key("Num 0"); // MS 0x52 UNIX 0xFFB0 INSERT 0xFF9E
+ public static final Key DECIMAL = new Key("Num ."); // MS 0x53 UNIX 0xFFAE DELETE 0xFF9F
+ public static final Key F11 = new Key("F11"); // MS 0x57 UNIX 0xFFC8
+ public static final Key F12 = new Key("F12"); // MS 0x58 UNIX 0xFFC9
+ public static final Key F13 = new Key("F13"); // MS 0x64 UNIX 0xFFCA
+ public static final Key F14 = new Key("F14"); // MS 0x65 UNIX 0xFFCB
+ public static final Key F15 = new Key("F15"); // MS 0x66 UNIX 0xFFCC
+ public static final Key KANA = new Key("Kana"); // MS 0x70 UNIX 0xFF2D
+ public static final Key CONVERT = new Key("Convert"); // MS 0x79 Japanese keyboard
+ public static final Key NOCONVERT = new Key("Noconvert"); // MS 0x7B Japanese keyboard
+ public static final Key YEN = new Key("Yen"); // MS 0x7D UNIX 0x0a5
+ public static final Key NUMPADEQUAL = new Key("Num ="); // MS 0x8D UNIX 0xFFBD
+ public static final Key CIRCUMFLEX = new Key("Circumflex"); // MS 0x90 Japanese keyboard
+ public static final Key AT = new Key("At"); // MS 0x91 UNIX 0x040
+ public static final Key COLON = new Key("Colon"); // MS 0x92 UNIX 0x03a
+ public static final Key UNDERLINE = new Key("Underline"); // MS 0x93 NEC PC98
+ public static final Key KANJI = new Key("Kanji"); // MS 0x94 UNIX 0xFF21
+ public static final Key STOP = new Key("Stop"); // MS 0x95 UNIX 0xFF69
+ public static final Key AX = new Key("Ax"); // MS 0x96 Japan AX
+ public static final Key UNLABELED = new Key("Unlabeled"); // MS 0x97 J3100
+ public static final Key NUMPADENTER = new Key("Num Enter"); // MS 0x9C UNIX 0xFF8D
+ public static final Key RCONTROL = new Key("Right Control"); // MS 0x9D UNIX 0xFFE4
+ public static final Key NUMPADCOMMA = new Key("Num ,"); // MS 0xB3 UNIX 0xFFAC
+ public static final Key DIVIDE = new Key("Num /"); // MS 0xB5 UNIX 0xFFAF
+ public static final Key SYSRQ = new Key("SysRq"); // MS 0xB7 UNIX 0xFF15 PRINT 0xFF61
+ public static final Key RALT = new Key("Right Alt"); // MS 0xB8 UNIX 0xFFEA
+ public static final Key PAUSE = new Key("Pause"); // MS 0xC5 UNIX 0xFF13 BREAK 0xFF6B
+ public static final Key HOME = new Key("Home"); // MS 0xC7 UNIX 0xFF50
+ public static final Key UP = new Key("Up"); // MS 0xC8 UNIX 0xFF52
+ public static final Key PAGEUP = new Key("Pg Up"); // MS 0xC9 UNIX 0xFF55
+ public static final Key LEFT = new Key("Left"); // MS 0xCB UNIX 0xFF51
+ public static final Key RIGHT = new Key("Right"); // MS 0xCD UNIX 0xFF53
+ public static final Key END = new Key("End"); // MS 0xCF UNIX 0xFF57
+ public static final Key DOWN = new Key("Down"); // MS 0xD0 UNIX 0xFF54
+ public static final Key PAGEDOWN = new Key("Pg Down"); // MS 0xD1 UNIX 0xFF56
+ public static final Key INSERT = new Key("Insert"); // MS 0xD2 UNIX 0xFF63
+ public static final Key DELETE = new Key("Delete"); // MS 0xD3 UNIX 0xFFFF
+ public static final Key LWIN = new Key("Left Windows"); // MS 0xDB UNIX META 0xFFE7 SUPER 0xFFEB HYPER 0xFFED
+ public static final Key RWIN = new Key("Right Windows"); // MS 0xDC UNIX META 0xFFE8 SUPER 0xFFEC HYPER 0xFFEE
+ public static final Key APPS = new Key("Apps"); // MS 0xDD UNIX 0xFF67
+ public static final Key POWER = new Key("Power"); // MS 0xDE Sun 0x1005FF76 SHIFT 0x1005FF7D
+ public static final Key SLEEP = new Key("Sleep"); // MS 0xDF No UNIX keysym
+ public static final Key UNKNOWN = new Key("Unknown");
+ } // class StandardKeyboard.KeyID
+
+ } // class Axis.Identifier
+
+ /**
+ * POV enum for different positions.
+ */
+ public static class POV {
+ /**
+ * Standard value for center HAT position
+ */
+ public static final float OFF = 0.0f;
+ /**
+ * Synonmous with OFF
+ */
+ public static final float CENTER = OFF;
+ /**
+ * Standard value for up-left HAT position
+ */
+ public static final float UP_LEFT = 0.125f;
+ /**
+ * Standard value for up HAT position
+ */
+ public static final float UP = 0.25f;
+ /**
+ * Standard value for up-right HAT position
+ */
+ public static final float UP_RIGHT = 0.375f;
+ /**
+ * Standard value for right HAT position
+ */
+ public static final float RIGHT = 0.50f;
+ /**
+ * Standard value for down-right HAT position
+ */
+ public static final float DOWN_RIGHT = 0.625f;
+ /**
+ * Standard value for down HAT position
+ */
+ public static final float DOWN = 0.75f;
+ /**
+ * Standard value for down-left HAT position
+ */
+ public static final float DOWN_LEFT = 0.875f;
+ /**
+ * Standard value for left HAT position
+ */
+ public static final float LEFT = 1.0f;
+ } // class Axis.POV
+} // interface Axis
diff --git a/src/core/net/java/games/input/Controller.java b/src/core/net/java/games/input/Controller.java
new file mode 100644
index 0000000..4d96964
--- /dev/null
+++ b/src/core/net/java/games/input/Controller.java
@@ -0,0 +1,263 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+/**
+ * A Controller represents a physical device, such as a keyboard, mouse,
+ * or joystick, or a logical grouping of related controls, such as a button
+ * pad or mouse ball. A controller can be composed of multiple controllers.
+ * For example, the ball of a mouse and its buttons are two separate
+ * controllers.
+ */
+public interface Controller {
+
+ /**
+ * Returns the controllers connected to make up this controller, or
+ * an empty array if this controller contains no child controllers.
+ * The objects in the array are returned in order of assignment priority
+ * (primary stick, secondary buttons, etc.).
+ */
+ public abstract Controller[] getControllers();
+
+ /**
+ * Returns the type of the Controller.
+ */
+ public abstract Type getType();
+
+ /**
+ * Returns the components on this controller, in order of assignment priority.
+ * For example, the button controller on a mouse returns an array containing
+ * the primary or leftmost mouse button, followed by the secondary or
+ * rightmost mouse button (if present), followed by the middle mouse button
+ * (if present).
+ * The array returned is an empty array if this controller contains no components
+ * (such as a logical grouping of child controllers).
+ */
+ public abstract Component[] getComponents();
+
+ /**
+ * Returns a single axis based on its type, or null
+ * if no axis with the specified type could be found.
+ */
+ public abstract Component getComponent(Component.Identifier id);
+
+ /**
+ * Returns the rumblers for sending feedback to this controller, or an
+ * empty array if there are no rumblers on this controller.
+ */
+ public abstract Rumbler[] getRumblers();
+
+ /**
+ * Polls axes for data. Returns false if the controller is no longer valid.
+ * Polling reflects the current state of the device when polled.
+ */
+ public abstract boolean poll();
+
+ /**
+ * Initialized the controller event queue to a new size. Existing events
+ * in the queue are lost.
+ */
+ public abstract void setEventQueueSize(int size);
+
+ /**
+ * Get the device event queue
+ */
+ public abstract EventQueue getEventQueue();
+
+ /**
+ * Returns the port type for this Controller.
+ */
+ public abstract PortType getPortType();
+
+ /**
+ * Returns the zero-based port number for this Controller.
+ */
+ public abstract int getPortNumber();
+
+ /**
+ * Returns a human-readable name for this Controller.
+ */
+ public abstract String getName();
+
+ /**
+ * Types of controller objects.
+ */
+ public static class Type {
+
+ /**
+ * Name of controller type
+ */
+ private final String name;
+
+ /**
+ * Protected constructor
+ */
+ protected Type(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns a non-localized string description of this controller type.
+ */
+ public String toString() {
+ return name;
+ }
+
+ /**
+ * Unkown controller type.
+ */
+ public static final Type UNKNOWN = new Type("Unknown");
+
+ /**
+ * Mouse controller.
+ */
+ public static final Type MOUSE = new Type("Mouse");
+
+ /**
+ * A keyboard controller
+ */
+ public static final Type KEYBOARD = new Type("Keyboard");
+
+ /**
+ * Fingerstick controller; note that this may be sometimes treated as a
+ * type of mouse or stick.
+ */
+ public static final Type FINGERSTICK = new Type("Fingerstick");
+
+ /**
+ * Gamepad controller.
+ */
+ public static final Type GAMEPAD = new Type("Gamepad");
+
+ /**
+ * Headtracker controller.
+ */
+ public static final Type HEADTRACKER = new Type("Headtracker");
+
+ /**
+ * Rudder controller.
+ */
+ public static final Type RUDDER = new Type("Rudder");
+
+ /**
+ * Stick controller, such as a joystick or flightstick.
+ */
+ public static final Type STICK = new Type("Stick");
+
+ /**
+ * A trackball controller; note that this may sometimes be treated as a
+ * type of mouse.
+ */
+ public static final Type TRACKBALL = new Type("Trackball");
+
+ /**
+ * A trackpad, such as a tablet, touchpad, or glidepad;
+ * note that this may sometimes be treated as a type of mouse.
+ */
+ public static final Type TRACKPAD = new Type("Trackpad");
+
+ /**
+ * A wheel controller, such as a steering wheel (note
+ * that a mouse wheel is considered part of a mouse, not a
+ * wheel controller).
+ */
+ public static final Type WHEEL = new Type("Wheel");
+ } // class Controller.Type
+
+ /**
+ * Common controller port types.
+ */
+ public static final class PortType {
+
+ /**
+ * Name of port type
+ */
+ private final String name;
+
+ /**
+ * Protected constructor
+ */
+ protected PortType(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns a non-localized string description of this port type.
+ */
+ public String toString() {
+ return name;
+ }
+
+ /**
+ * Unknown port type
+ */
+ public static final PortType UNKNOWN = new PortType("Unknown");
+
+ /**
+ * USB port
+ */
+ public static final PortType USB = new PortType("USB port");
+
+ /**
+ * Standard game port
+ */
+ public static final PortType GAME = new PortType("Game port");
+
+ /**
+ * Network port
+ */
+ public static final PortType NETWORK = new PortType("Network port");
+
+ /**
+ * Serial port
+ */
+ public static final PortType SERIAL = new PortType("Serial port");
+
+ /**
+ * i8042
+ */
+ public static final PortType I8042 = new PortType("i8042 (PS/2)");
+
+ /**
+ * Parallel port
+ */
+ public static final PortType PARALLEL = new PortType("Parallel port");
+
+ } // class Controller.PortType
+} // interface Controller
diff --git a/src/core/net/java/games/input/ControllerEnvironment.java b/src/core/net/java/games/input/ControllerEnvironment.java
new file mode 100644
index 0000000..6aa9ad8
--- /dev/null
+++ b/src/core/net/java/games/input/ControllerEnvironment.java
@@ -0,0 +1,161 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.io.File;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A ControllerEnvironment represents a collection of controllers that are
+ * physically or logically linked. By default, this corresponds to the
+ * environment for the local machine.
+ *
+ * In this reference implementation, this class can also be used to register
+ * controllers with the default environment as "plug-ins". A plug-in is
+ * created by subclassing ControllerEnvironment with a class that has a public
+ * no-argument constructor, implements the net.java.games.util.plugins.Plugin
+ * interface and has a name ending in "Plugin".
+ * (See net.java.games.input.DirectInputEnvironmentPlugin in the DXplugin
+ * part of the source tree for an example.)
+ *
+ * When the DefaultControllerEnvrionment is instanced it uses the plugin library
+ * to look for Plugins in both [java.home]/lib/controller and
+ * [user.dir]/controller. This allows controller plugins to be installed either
+ * globally for the entire Java environment or locally for just one particular
+ * Java app.
+ *
+ * For more information on the organization of plugins within the controller
+ * root directories, see net.java.games.util.plugins.Plugins (Note the
+ * plural -- "Plugins" not "Plugin" which is just a marker interface.)
+ *
+ */
+public abstract class ControllerEnvironment {
+
+ static void log(String msg) {
+ Logger.getLogger(ControllerEnvironment.class.getName()).info(msg);
+ }
+
+ /**
+ * The default controller environment
+ */
+ private static ControllerEnvironment defaultEnvironment =
+ new DefaultControllerEnvironment();
+
+ /**
+ * List of controller listeners
+ */
+ protected final ArrayList controllerListeners = new ArrayList<>();
+
+ /**
+ * Protected constructor for subclassing.
+ */
+ protected ControllerEnvironment() {
+ if(System.getProperty("jinput.loglevel") != null) {
+ String loggerName = ControllerEnvironment.class.getPackage().getName();
+ Level level = Level.parse(System.getProperty("jinput.loglevel"));
+ Logger.getLogger(loggerName).setLevel(level);
+ }
+ }
+
+ /**
+ * Returns a list of all controllers available to this environment,
+ * or an empty array if there are no controllers in this environment.
+ */
+ public abstract Controller[] getControllers();
+
+ /**
+ * Adds a listener for controller state change events.
+ */
+ public void addControllerListener(ControllerListener l) {
+ assert l != null;
+ controllerListeners.add(l);
+ }
+
+ /**
+ * Returns the isSupported status of this environment.
+ * What makes an environment supported or not is up to the
+ * particular plugin, but may include OS or available hardware.
+ */
+ public abstract boolean isSupported();
+
+ /**
+ * Removes a listener for controller state change events.
+ */
+ public void removeControllerListener(ControllerListener l) {
+ assert l != null;
+ controllerListeners.remove(l);
+ }
+
+ /**
+ * Creates and sends an event to the controller listeners that a controller
+ * has been added.
+ */
+ protected void fireControllerAdded(Controller c) {
+ ControllerEvent ev = new ControllerEvent(c);
+ Iterator it = controllerListeners.iterator();
+ while (it.hasNext()) {
+ it.next().controllerAdded(ev);
+ }
+ }
+
+ /**
+ * Creates and sends an event to the controller listeners that a controller
+ * has been lost.
+ */
+ protected void fireControllerRemoved(Controller c) {
+ ControllerEvent ev = new ControllerEvent(c);
+ Iterator it = controllerListeners.iterator();
+ while (it.hasNext()) {
+ it.next().controllerRemoved(ev);
+ }
+ }
+
+ /**
+ * Returns the default environment for input controllers.
+ * This usually corresponds to the environment for the local machine.
+ */
+ public static ControllerEnvironment getDefaultEnvironment() {
+ return defaultEnvironment;
+ }
+}
\ No newline at end of file
diff --git a/src/core/net/java/games/input/ControllerEvent.java b/src/core/net/java/games/input/ControllerEvent.java
new file mode 100644
index 0000000..14fbbcd
--- /dev/null
+++ b/src/core/net/java/games/input/ControllerEvent.java
@@ -0,0 +1,61 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+/**
+ * An event that is fired when the state of a controller changes
+ */
+public class ControllerEvent {
+
+ private Controller controller;
+
+ /**
+ * Creates a controller event object.
+ */
+ public ControllerEvent(Controller c) {
+ controller = c;
+ }
+
+ /**
+ * Returns the controller for this event.
+ */
+ public Controller getController() {
+ return controller;
+ }
+} // class ControllerEvent
diff --git a/src/core/net/java/games/input/ControllerListener.java b/src/core/net/java/games/input/ControllerListener.java
new file mode 100644
index 0000000..8c58eff
--- /dev/null
+++ b/src/core/net/java/games/input/ControllerListener.java
@@ -0,0 +1,55 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+/**
+ * A listener for changes in the state of controllers
+ */
+public interface ControllerListener {
+
+ /**
+ * Invoked when a controller is lost.
+ */
+ public abstract void controllerRemoved(ControllerEvent ev);
+
+ /**
+ * Invoked when a controller has been added.
+ */
+ public abstract void controllerAdded(ControllerEvent ev);
+} // interface ControllerListener
diff --git a/src/core/net/java/games/input/DefaultControllerEnvironment.java b/src/core/net/java/games/input/DefaultControllerEnvironment.java
new file mode 100644
index 0000000..e16d6a8
--- /dev/null
+++ b/src/core/net/java/games/input/DefaultControllerEnvironment.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ */
+package net.java.games.input;
+
+import net.java.games.util.plugins.Plugins;
+
+import java.io.File;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+import java.util.logging.Logger;
+
+/**
+ * The default controller environment.
+ *
+ * @version %I% %G%
+ * @author Michael Martak
+ */
+class DefaultControllerEnvironment extends ControllerEnvironment {
+ static String libPath;
+ private static Logger log = Logger.getLogger(DefaultControllerEnvironment.class.getName());
+
+ /**
+ * Static utility method for loading native libraries.
+ * It will try to load from either the path given by
+ * the net.java.games.input.librarypath property
+ * or through System.loadLibrary().
+ *
+ */
+ static void loadLibrary(final String lib_name) {
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ String lib_path = System.getProperty("net.java.games.input.librarypath");
+ if (lib_path != null) {
+ System.load(lib_path + File.separator + System.mapLibraryName(lib_name));
+ } else {
+ System.loadLibrary(lib_name);
+ }
+ return null;
+ });
+ }
+
+ static String getPrivilegedProperty(final String property) {
+ return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property));
+ }
+
+ static String getPrivilegedProperty(final String property, final String default_value) {
+ return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property, default_value));
+ }
+
+ /**
+ * List of all controllers in this environment
+ */
+ private ArrayList controllers;
+
+ private Collection loadedPluginNames = new ArrayList<>();
+
+ /**
+ * Public no-arg constructor.
+ */
+ public DefaultControllerEnvironment() {
+ }
+
+ /**
+ * Returns a list of all controllers available to this environment,
+ * or an empty array if there are no controllers in this environment.
+ */
+ @Override
+ public Controller[] getControllers() {
+ if (controllers == null) {
+ // Controller list has not been scanned.
+ controllers = new ArrayList<>();
+ AccessController.doPrivileged((PrivilegedAction) () -> scanControllers());
+ //Check the properties for specified controller classes
+ String pluginClasses = getPrivilegedProperty("jinput.plugins", "") + " " + getPrivilegedProperty("net.java.games.input.plugins", "");
+ if (!getPrivilegedProperty("jinput.useDefaultPlugin", "true").toLowerCase().trim().equals("false") && !getPrivilegedProperty("net.java.games.input.useDefaultPlugin", "true").toLowerCase().trim().equals("false")) {
+ String osName = getPrivilegedProperty("os.name", "").trim();
+ if (osName.equals("Linux")) {
+ pluginClasses = pluginClasses + " net.java.games.input.LinuxEnvironmentPlugin";
+ } else if (osName.equals("Mac OS X")) {
+ pluginClasses = pluginClasses + " net.java.games.input.OSXEnvironmentPlugin";
+ } else if (osName.equals("Windows XP") || osName.equals("Windows Vista") || osName.equals("Windows 7") || osName.equals("Windows 8") || osName.equals("Windows 8.1") || osName.equals("Windows 10")) {
+ pluginClasses = pluginClasses + " net.java.games.input.DirectAndRawInputEnvironmentPlugin";
+ } else if (osName.equals("Windows 98") || osName.equals("Windows 2000")) {
+ pluginClasses = pluginClasses + " net.java.games.input.DirectInputEnvironmentPlugin";
+ } else if (osName.startsWith("Windows")) {
+ log.warning("Found unknown Windows version: " + osName);
+ log.warning("Attempting to use default windows plug-in.");
+ pluginClasses = pluginClasses + " net.java.games.input.DirectAndRawInputEnvironmentPlugin";
+ } else {
+ log.warning("Trying to use default plugin, OS name " + osName + " not recognised");
+ }
+ }
+
+ StringTokenizer pluginClassTok = new StringTokenizer(pluginClasses, " \t\n\r\f,;:");
+ while (pluginClassTok.hasMoreTokens()) {
+ String className = pluginClassTok.nextToken();
+ try {
+ if (!loadedPluginNames.contains(className)) {
+ log.fine("Loading: " + className);
+ Class> ceClass = Class.forName(className);
+ ControllerEnvironment ce = (ControllerEnvironment) ceClass.getDeclaredConstructor().newInstance();
+ if (ce.isSupported()) {
+ addControllers(ce.getControllers());
+ loadedPluginNames.add(ce.getClass().getName());
+ } else {
+ log(ceClass.getName() + " is not supported");
+ }
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ Controller[] ret = new Controller[controllers.size()];
+ Iterator it = controllers.iterator();
+ int i = 0;
+ while (it.hasNext()) {
+ ret[i] = it.next();
+ i++;
+ }
+ return ret;
+ }
+
+ /* This is jeff's new plugin code using Jeff's Plugin manager */
+ private Void scanControllers() {
+ String pluginPathName = getPrivilegedProperty("jinput.controllerPluginPath");
+ if (pluginPathName == null) {
+ pluginPathName = "controller";
+ }
+
+ scanControllersAt(getPrivilegedProperty("java.home")
+ + File.separator + "lib" + File.separator + pluginPathName);
+ scanControllersAt(getPrivilegedProperty("user.dir")
+ + File.separator + pluginPathName);
+
+ return null;
+ }
+
+ private void scanControllersAt(String path) {
+ File file = new File(path);
+ if (!file.exists()) {
+ return;
+ }
+ try {
+ Plugins plugins = new Plugins(file);
+ @SuppressWarnings("unchecked")
+ Class[] envClasses = plugins.getExtends(ControllerEnvironment.class);
+ for (int i = 0; i < envClasses.length; i++) {
+ try {
+ ControllerEnvironment.log("ControllerEnvironment "
+ + envClasses[i].getName()
+ + " loaded by " + envClasses[i].getClassLoader());
+ ControllerEnvironment ce = envClasses[i].getDeclaredConstructor().newInstance();
+ if (ce.isSupported()) {
+ addControllers(ce.getControllers());
+ loadedPluginNames.add(ce.getClass().getName());
+ } else {
+ log(envClasses[i].getName() + " is not supported");
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Add the array of controllers to our list of controllers.
+ */
+ private void addControllers(Controller[] c) {
+ for (int i = 0; i < c.length; i++) {
+ controllers.add(c[i]);
+ }
+ }
+
+ public boolean isSupported() {
+ return true;
+ }
+}
diff --git a/src/core/net/java/games/input/Event.java b/src/core/net/java/games/input/Event.java
new file mode 100644
index 0000000..c6bc5e9
--- /dev/null
+++ b/src/core/net/java/games/input/Event.java
@@ -0,0 +1,76 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+public final class Event {
+ private Component component;
+ private float value;
+ private long nanos;
+
+ public final void set(Event other) {
+ this.set(other.getComponent(), other.getValue(), other.getNanos());
+ }
+
+ public final void set(Component component, float value, long nanos) {
+ this.component = component;
+ this.value = value;
+ this.nanos = nanos;
+ }
+
+ public final Component getComponent() {
+ return component;
+ }
+
+ public final float getValue() {
+ return value;
+ }
+
+ /**
+ * Return the time the event happened, in nanoseconds.
+ * The time is relative and therefore can only be used
+ * to compare with other event times.
+ */
+ public final long getNanos() {
+ return nanos;
+ }
+
+ public final String toString() {
+ return "Event: component = " + component + " | value = " + value;
+ }
+}
diff --git a/src/core/net/java/games/input/EventQueue.java b/src/core/net/java/games/input/EventQueue.java
new file mode 100644
index 0000000..a025d9c
--- /dev/null
+++ b/src/core/net/java/games/input/EventQueue.java
@@ -0,0 +1,95 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+/**
+ * A FIFO queue for input events.
+ */
+public final class EventQueue {
+ private final Event[] queue;
+
+ private int head;
+ private int tail;
+
+ /**
+ * This is an internal method and should not be called by applications using the API
+ */
+ public EventQueue(int size) {
+ queue = new Event[size + 1];
+ for (int i = 0; i < queue.length; i++)
+ queue[i] = new Event();
+ }
+
+ /**
+ * This is an internal method and should not be called by applications using the API
+ */
+ final synchronized void add(Event event) {
+ queue[tail].set(event);
+ tail = increase(tail);
+ }
+
+ /**
+ * Check if the queue is full
+ * @return true if the queue is full
+ */
+ final synchronized boolean isFull() {
+ return increase(tail) == head;
+ }
+
+ /**
+ * This is an internal method and should not be called by applications using the API
+ */
+ private final int increase(int x) {
+ return (x + 1)%queue.length;
+ }
+
+ /**
+ * Populates the provided event with the details of the event on the head of the queue.
+ *
+ * @param event The event to populate
+ * @return false if there were no events left on the queue, otherwise true.
+ */
+ public final synchronized boolean getNextEvent(Event event) {
+ if (head == tail)
+ return false;
+ event.set(queue[head]);
+ head = increase(head);
+ return true;
+ }
+}
diff --git a/src/core/net/java/games/input/Keyboard.java b/src/core/net/java/games/input/Keyboard.java
new file mode 100644
index 0000000..e168869
--- /dev/null
+++ b/src/core/net/java/games/input/Keyboard.java
@@ -0,0 +1,69 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+/**
+ * A Keyboard is a type of controller consisting of a single controller,
+ * they keypad, which contains several axes (the keys). By default, all keys
+ * are set to receive polling data.
+ */
+public abstract class Keyboard extends AbstractController {
+ /**
+ * Protected constructor.
+ * Subclasses should initialize the array of axes to an array of keys.
+ * @param name The name of the keyboard
+ */
+ protected Keyboard(String name, Component[] keys, Controller[] children, Rumbler[] rumblers) {
+ super(name, keys, children, rumblers);
+ }
+
+ /**
+ * Returns the type of the Controller.
+ */
+ public Type getType() {
+ return Type.KEYBOARD;
+ }
+
+ public final boolean isKeyDown(Component.Identifier.Key key_id) {
+ Component key = getComponent(key_id);
+ if (key == null)
+ return false;
+ return key.getPollData() != 0;
+ }
+} // class Keyboard
diff --git a/src/core/net/java/games/input/Mouse.java b/src/core/net/java/games/input/Mouse.java
new file mode 100644
index 0000000..27abad5
--- /dev/null
+++ b/src/core/net/java/games/input/Mouse.java
@@ -0,0 +1,183 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/** ***************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ **************************************************************************** */
+package net.java.games.input;
+
+/**
+ * A Mouse is a type of controller consisting of two child controllers,
+ * a ball and a button pad. This includes devices such as touch pads,
+ * trackballs, and fingersticks.
+ */
+public abstract class Mouse extends AbstractController {
+ protected Mouse(String name, Component[] components, Controller[] children, Rumbler[] rumblers) {
+ super(name, components, children, rumblers);
+ }
+
+ /**
+ * Returns the type of the Controller.
+ */
+ public Type getType() {
+ return Type.MOUSE;
+ }
+
+ /**
+ * Returns the x-axis for the mouse ball, never null.
+ */
+ public Component getX() {
+ return getComponent(Component.Identifier.Axis.X);
+ }
+
+ /**
+ * Returns the y-axis for the mouse ball, never null.
+ */
+ public Component getY() {
+ return getComponent(Component.Identifier.Axis.Y);
+ }
+
+ /**
+ * Returns the mouse wheel, or null if no mouse wheel is present.
+ */
+ public Component getWheel() {
+ return getComponent(Component.Identifier.Axis.Z);
+ }
+
+ /**
+ * Returns the left or primary mouse button, never null.
+ */
+ public Component getPrimaryButton() {
+ Component primaryButton = getComponent(Component.Identifier.Button.LEFT);
+ if (primaryButton == null) {
+ primaryButton = getComponent(Component.Identifier.Button._1);
+ }
+ return primaryButton;
+ }
+
+ /**
+ * Returns the right or secondary mouse button, null if the mouse is
+ * a single-button mouse.
+ */
+ public Component getSecondaryButton() {
+ Component secondaryButton = getComponent(Component.Identifier.Button.RIGHT);
+ if (secondaryButton == null) {
+ secondaryButton = getComponent(Component.Identifier.Button._2);
+ }
+ return secondaryButton;
+ }
+
+ /**
+ * Returns the middle or tertiary mouse button, null if the mouse has
+ * fewer than three buttons.
+ */
+ public Component getTertiaryButton() {
+ Component tertiaryButton = getComponent(Component.Identifier.Button.MIDDLE);
+ if (tertiaryButton == null) {
+ tertiaryButton = getComponent(Component.Identifier.Button._3);
+ }
+ return tertiaryButton;
+ }
+
+ /**
+ * Returns the left mouse button.
+ */
+ public Component getLeft() {
+ return getComponent(Component.Identifier.Button.LEFT);
+ }
+
+ /**
+ * Returns the right, null if the mouse is a single-button mouse.
+ */
+ public Component getRight() {
+ return getComponent(Component.Identifier.Button.RIGHT);
+ }
+
+ /**
+ * Returns the middle, null if the mouse has fewer than three buttons.
+ */
+ public Component getMiddle() {
+ return getComponent(Component.Identifier.Button.MIDDLE);
+ }
+
+ /**
+ * Returns the side or 4th mouse button, null if the mouse has
+ * fewer than 4 buttons.
+ */
+ public Component getSide() {
+ return getComponent(Component.Identifier.Button.SIDE);
+ }
+
+ /**
+ * Returns the extra or 5th mouse button, null if the mouse has
+ * fewer than 5 buttons.
+ */
+ public Component getExtra() {
+ return getComponent(Component.Identifier.Button.EXTRA);
+ }
+
+ /**
+ * Returns the forward mouse button, null if the mouse hasn't
+ * got one.
+ */
+ public Component getForward() {
+ return getComponent(Component.Identifier.Button.FORWARD);
+ }
+
+ /**
+ * Returns the back mouse button, null if the mouse hasn't
+ * got one.
+ */
+ public Component getBack() {
+ return getComponent(Component.Identifier.Button.BACK);
+ }
+
+ /**
+ * Returns forth mouse button, null if the mouse hasn't
+ * got one.
+ */
+ public Component getButton3() {
+ return getComponent(Component.Identifier.Button._3);
+ }
+
+ /**
+ * Returns fifth mouse button, null if the mouse hasn't
+ * got one.
+ */
+ public Component getButton4() {
+ return getComponent(Component.Identifier.Button._4);
+ }
+
+} // class Mouse
diff --git a/src/core/net/java/games/input/PluginClassLoader.java b/src/core/net/java/games/input/PluginClassLoader.java
new file mode 100644
index 0000000..da5eb62
--- /dev/null
+++ b/src/core/net/java/games/input/PluginClassLoader.java
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ */
+package net.java.games.input;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.StringTokenizer;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * Loads all plugins.
+ *
+ * @version %I% %G%
+ * @author Michael Martak
+ */
+class PluginClassLoader extends ClassLoader {
+
+ /**
+ * Location of directory to look for plugins
+ */
+ private static String pluginDirectory;
+
+ /**
+ * File filter for JAR files
+ */
+ private static final FileFilter JAR_FILTER = new JarFileFilter();
+
+ /**
+ * Create a new class loader for loading plugins
+ */
+ public PluginClassLoader() {
+ super(Thread.currentThread().getContextClassLoader());
+ }
+
+ /**
+ * Overrides findClass to first look in the parent class loader,
+ * then try loading the class from the plugin file system.
+ */
+ protected Class> findClass(String name)
+ throws ClassNotFoundException {
+ // Try loading the class from the file system.
+ byte[] b = loadClassData(name);
+ return defineClass(name, b, 0, b.length);
+ }
+
+ /**
+ * Load the class data from the file system
+ */
+ private byte[] loadClassData(String name)
+ throws ClassNotFoundException {
+ if (pluginDirectory == null) {
+ pluginDirectory = DefaultControllerEnvironment.libPath +
+ File.separator + "controller";
+ }
+ try {
+ return loadClassFromDirectory(name);
+ } catch (Exception e) {
+ try {
+ return loadClassFromJAR(name);
+ } catch (IOException e2) {
+ throw new ClassNotFoundException(name, e2);
+ }
+ }
+ }
+
+ /**
+ * Load the class data from the file system based on parsing
+ * the class name (packages).
+ */
+ private byte[] loadClassFromDirectory(String name)
+ throws ClassNotFoundException, IOException {
+ // Parse the class name into package directories.
+ // Look for the class in the plugin directory.
+ StringTokenizer tokenizer = new StringTokenizer(name, ".");
+ StringBuffer path = new StringBuffer(pluginDirectory);
+ while (tokenizer.hasMoreTokens()) {
+ path.append(File.separator);
+ path.append(tokenizer.nextToken());
+ }
+ path.append(".class");
+ File file = new File(path.toString());
+ if (!file.exists()) {
+ throw new ClassNotFoundException(name);
+ }
+ try(FileInputStream fileInputStream = new FileInputStream(file)) {
+ assert file.length() <= Integer.MAX_VALUE;
+ int length = (int) file.length();
+ byte[] bytes = new byte[length];
+ int length2 = fileInputStream.read(bytes);
+ assert length == length2;
+ return bytes;
+ }
+ }
+
+ /**
+ * Scans through the plugin directory for JAR files and
+ * attempts to load the class data from each JAR file.
+ */
+ private byte[] loadClassFromJAR(String name)
+ throws ClassNotFoundException, IOException {
+ File dir = new File(pluginDirectory);
+ File[] jarFiles = dir.listFiles(JAR_FILTER);
+ if (jarFiles == null) {
+ throw new ClassNotFoundException("Could not find class " + name);
+ }
+ for (int i = 0; i < jarFiles.length; i++) {
+ JarFile jarfile = new JarFile(jarFiles[i]);
+ JarEntry jarentry = jarfile.getJarEntry(name + ".class");
+ if (jarentry != null) {
+ try(InputStream jarInputStream = jarfile.getInputStream(jarentry)) {
+ assert jarentry.getSize() <= Integer.MAX_VALUE;
+ int length = (int) jarentry.getSize();
+ assert length >= 0;
+ byte[] bytes = new byte[length];
+ int length2 = jarInputStream.read(bytes);
+ assert length == length2;
+ return bytes;
+ }
+ }
+ }
+ throw new FileNotFoundException(name);
+ }
+
+ /**
+ * Filters out all non-JAR files, based on whether or not they
+ * end in ".JAR" (case-insensitive).
+ */
+ private static class JarFileFilter implements FileFilter {
+ public boolean accept(File file) {
+ return file.getName().toUpperCase().endsWith(".JAR");
+ }
+ }
+}
+
diff --git a/src/core/net/java/games/input/Rumbler.java b/src/core/net/java/games/input/Rumbler.java
new file mode 100644
index 0000000..9d64cf3
--- /dev/null
+++ b/src/core/net/java/games/input/Rumbler.java
@@ -0,0 +1,67 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+/**
+ * A Rumbler is a controller's mechanism for delivering feedback
+ * to the user through the device.
+ */
+public interface Rumbler {
+
+ /**
+ * Rumble with the specified intensity.
+ */
+ public abstract void rumble(float intensity);
+
+ /**
+ * Get the string name of the axis the rumbler is attached to
+ *
+ * @return The axis name
+ */
+ public String getAxisName();
+
+ /**
+ * Get the axis identifier the rumbler is attached to
+ *
+ * @return The axis identifier
+ */
+ public Component.Identifier getAxisIdentifier();
+
+
+} // interface Rumbler
diff --git a/src/core/net/java/games/input/Version.java b/src/core/net/java/games/input/Version.java
new file mode 100644
index 0000000..89092d2
--- /dev/null
+++ b/src/core/net/java/games/input/Version.java
@@ -0,0 +1,101 @@
+/*
+* Copyright (c) 2004 Sun Microsystems, Inc. All Rights Reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* -Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may
+* be used to endorse or promote products derived from this software without
+* specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS
+* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A
+* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
+* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
+* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
+* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
+* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for use in the
+* design, construction, operation or maintenance of any nuclear facility.
+ */
+package net.java.games.input;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.PropertyResourceBundle;
+
+/**
+ * The version and build number of this implementation.
+ * Version numbers for a release are of the form: w.x.y, where:
+ *
+ * -
+ * w - the major version number of the release. This number should
+ * start at 1. Typically, a bump in the major version number
+ * signifies that the release breaks backwards compatibility
+ * with some older release.
+ *
+ * -
+ * x - minor version number. This number starts at 0. A bump in
+ * the minor version number signifies a release that has significant
+ * new functionality.
+ *
+ * -
+ * y - minor-minor version number number. This number starts at 0. A
+ * bump in the minor-minor version number signifies that new bug
+ * fixes have been added to the build.
+ *
+ *
+ *
+ * For example, the following are all valid version strings:
+ *
+ * - 1.1.2
+ * - 1.3.5-SNAPSHOT
+ * - 4.7.1-M2
+ *
+ *
+ * @version 2.10
+ */
+public final class Version {
+
+ /**
+ * Private constructor - no need for user to create
+ * an instance of this class.
+ */
+ private Version() {
+ }
+
+ public static void main(String[] args) {
+ String version = getVersion();
+ System.out.println("jinput version " + version);
+ }
+
+ /**
+ * Returns the verison string and build number of
+ * this implementation. See the class descritpion
+ * for the version string format.
+ *
+ * @return The version string of this implementation.
+ */
+ public static String getVersion() {
+ URL url = Version.class.getResource("jinput.properties");
+ try {
+ PropertyResourceBundle prb = new PropertyResourceBundle(url.openStream());
+ String version = prb.getString("version");
+ return version;
+ } catch (IOException ex) {
+ return "Unversioned";
+ }
+ }
+}
diff --git a/src/core/net/java/games/input/jinput.properties b/src/core/net/java/games/input/jinput.properties
new file mode 100644
index 0000000..2b0e575
--- /dev/null
+++ b/src/core/net/java/games/input/jinput.properties
@@ -0,0 +1,2 @@
+version=2.10
+date=13/05/2021
diff --git a/src/core/net/java/games/input/package.html b/src/core/net/java/games/input/package.html
new file mode 100644
index 0000000..58c075f
--- /dev/null
+++ b/src/core/net/java/games/input/package.html
@@ -0,0 +1,14 @@
+
+
+
+
+Top level package for JInput.
+
+Package Specification
+
+Use -Djinput.useDefaultPlugin=false (or net.java.games.input.useDefaultPlugin=false) to disable automatic loading of the default plugin for the platform.
+Use -Djinput.plugins (or net.java.games.input.plugins) and specifiy a list of class name to over ride the plugins system. This will force the classes passed to be loaded first, then plugins will be searched for in the default manner (./controller/*.jar)
+Use -Djinput.controllerPluginPath to change the path the plugins mechanism will use to search for plugin Jars.
+Use -Djinput.loglevel to change the logging level using Java util logging level strings.
+
+
\ No newline at end of file
diff --git a/src/jutils/net/java/games/util/Version.java b/src/jutils/net/java/games/util/Version.java
new file mode 100644
index 0000000..62bd4a1
--- /dev/null
+++ b/src/jutils/net/java/games/util/Version.java
@@ -0,0 +1,104 @@
+/*
+* Copyright (c) 2004 Sun Microsystems, Inc. All Rights Reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* -Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* -Redistribution 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 Sun Microsystems, Inc. or the names of contributors may
+* be used to endorse or promote products derived from this software without
+* specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS
+* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A
+* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
+* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
+* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
+* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
+* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for use in the
+* design, construction, operation or maintenance of any nuclear facility.
+*/
+
+package net.java.games.util;
+
+/**
+ * The version and build number of this implementation.
+ * Version numbers for a release are of the form: w.x.y[-a]-z, where:
+ *
+ * -
+ * w - the major version number of the release. This number should
+ * start at 1. Typically, a bump in the major version number
+ * signifies that the release breaks backwards compatibility
+ * with some older release.
+ *
+ * -
+ * x - minor version number. This number starts at 0. A bump in
+ * the minor version number signifies a release that has significant
+ * new functionality.
+ *
+ * -
+ * y - minor-minor version number number. This number starts at 0. A
+ * bump in the minor-minor version number signifies that new bug
+ * fixes have been added to the build.
+ *
+ * -
+ * a - an optional build designator followed by a digit. Valid build
+ * designators are:
+ *
+ *
+ * -
+ * z - build number. This is used to specify the build number of the
+ * release. This is usually only important to people that use
+ * the daily build of a project. The format is the lower-case
+ * letter 'b' followed by a two digit number.
+ *
+ *
+ *
+ * For example, the following are all valid version strings:
+ *
+ * - 1.1.2-b02
+ * - 1.3.5-alpha1-b19
+ * - 4.7.1-beta3-b20
+ *
+ *
+ */
+public final class Version {
+
+ /**
+ * Private constructor - no need for user to create
+ * an instance of this class.
+ */
+ private Version() {
+ }
+
+ /**
+ * Version string of this build.
+ */
+ private static final String version = "1.0.0-b01";
+
+ /**
+ * Returns the verison string and build number of
+ * this implementation. See the class descritpion
+ * for the version string format.
+ *
+ * @return The version string of this implementation.
+ */
+ public static String getVersion() {
+ return version;
+ }
+}
diff --git a/src/jutils/net/java/games/util/package.html b/src/jutils/net/java/games/util/package.html
new file mode 100644
index 0000000..62832a4
--- /dev/null
+++ b/src/jutils/net/java/games/util/package.html
@@ -0,0 +1,7 @@
+
+
+
+
+Utility package for JInput. See https://github.com/jinput/jutils.
+
+
\ No newline at end of file
diff --git a/src/jutils/net/java/games/util/plugins/Plugin.java b/src/jutils/net/java/games/util/plugins/Plugin.java
new file mode 100644
index 0000000..cfb533b
--- /dev/null
+++ b/src/jutils/net/java/games/util/plugins/Plugin.java
@@ -0,0 +1,60 @@
+/*
+ * Plugin.java
+ *
+ * Created on April 18, 2003, 11:29 AM
+ */
+
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+
+package net.java.games.util.plugins;
+
+/** This is a marker interface used to mark plugins in a Jar file
+ * for retrieval by the Plugins class. In order for a class to be
+ * treated as a Plugin the following must be true:
+ *
+ * (1) The name of the class must end with "Plugin".
+ * (ie MedianCutFilterPlugin, DirectInput EnvrionmentPlugin)
+ *
+ * (2) The class must implement the Plugin interface. It can do
+ * so directly, through inheritence of either a superclass
+ * that implements this interface, or through the implementation
+ * of an interface that extends this interface.
+ *
+ *
+ * @author Jeffrey P. Kesselman
+ *
+ */
+public interface Plugin {
+
+}
diff --git a/src/jutils/net/java/games/util/plugins/PluginLoader.java b/src/jutils/net/java/games/util/plugins/PluginLoader.java
new file mode 100644
index 0000000..00545eb
--- /dev/null
+++ b/src/jutils/net/java/games/util/plugins/PluginLoader.java
@@ -0,0 +1,169 @@
+/*
+ * PluginLodaer.java
+ *
+ * Created on April 18, 2003, 11:32 AM
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.util.plugins;
+
+/**
+ *
+ * @author jeff
+ */
+import java.io.*;
+import java.net.*;
+
+/** This class is used internally by the Plugin system.
+ * End users of the system are unlikely to need to be aware
+ * of it.
+ *
+ *
+ * This is the class loader used to keep the namespaces of
+ * different plugins isolated from each other and from the
+ * main app code. One plugin loader is created per Jar
+ * file in the sub-directory tree of the plugin directory.
+ *
+ * In addition to isolating java classes this loader also isolates
+ * DLLs such that plugins with conflicting DLL names may be
+ * used by simply placing the plugin and its associated DLL
+ * in a sub-folder of its own.
+ *
+ * This class also currently implements methods for testing
+ * classes for inheritance of superclasses or interfaces.
+ * This code is genericly useful and should really be moved
+ * to a seperate ClassUtils class.
+ * @author Jeffrey Kesselman
+ */
+public class PluginLoader extends URLClassLoader {
+ static final boolean DEBUG = false;
+ File parentDir;
+ boolean localDLLs = true;
+ /** Creates a new instance of PluginLodaer
+ * If the system property "net.java.games.util.plugins.nolocalnative" is
+ * not set then the laoder will look for requried native libs in the
+ * same directory as the plugin jar. (Useful for handling name
+ * collision between plugins). If it IS set however, then it will
+ * fall back to the default way of loading natives. (Necessary for
+ * Java Web Start.)
+ * @param jf The JarFile to load the Plugins from.
+ * @throws MalformedURLException Will throw this exception if jf does not refer to a
+ * legitimate Jar file.
+ */
+ public PluginLoader(File jf) throws MalformedURLException {
+ super(new URL[] {jf.toURL()},
+ Thread.currentThread().getContextClassLoader());
+ parentDir = jf.getParentFile();
+ if (System.getProperty("net.java.games.util.plugins.nolocalnative")
+ !=null){
+ localDLLs = false;
+ }
+ }
+
+ /** This method is queried by the System.loadLibrary()
+ * code to find the actual native name and path to the
+ * native library to load.
+ *
+ * This subclass implementation of this method ensures that
+ * the native library will be loaded from, and only from,
+ * the parent directory of the Jar file this loader was
+ * created to support. This allows different Plugins
+ * with supporting DLLs of the same name to co-exist, each
+ * in their own subdirectory.
+ *
+ * Setting the global "localDLLs" by setting the property
+ * net.java.games.util.plugins.nolocalnative defeats this behavior.
+ * This is necessary for Java Web Start apps which have strong
+ * restrictions on where and how native libs can be loaded.
+ *
+ * @param libname The JNI name of the native library to locate.
+ * @return Returns a string describing the actual loation of the
+ * native library in the native file system.
+ */
+ protected String findLibrary(String libname){
+ if (localDLLs) {
+ String libpath = parentDir.getPath() + File.separator +
+ System.mapLibraryName(libname);
+ if (DEBUG) {
+ System.out.println("Returning libname of: " + libpath);
+ }
+ return libpath;
+ } else {
+ return super.findLibrary(libname);
+ }
+ }
+
+ /** This function is called as part of scanning the Jar for
+ * plugins. It checks to make sure the class passed in is
+ * a legitimate plugin, which is to say that it meets
+ * the following criteria:
+ *
+ * (1) Is not itself an interface
+ * (2) Implements the Plugin marker interface either directly
+ * or through inheritance.
+ *
+ * interface, either
+ * @param pc The potential plug-in class to vette.
+ * @return Returns true if the class meets the criteria for a
+ * plugin. Otherwise returns false.
+ */
+ public boolean attemptPluginDefine(Class pc){
+ return ((!pc.isInterface()) && classImplementsPlugin(pc));
+ }
+
+ private boolean classImplementsPlugin(Class testClass){
+ if (testClass == null) return false; // end of tree
+ if (DEBUG) {
+ System.out.println("testing class "+testClass.getName());
+ }
+ Class[] implementedInterfaces = testClass.getInterfaces();
+ for(int i=0;iany of the passed in set of
+ * Interfaces (either directly or through inheritance.)
+ * @param interfaces A set of interfaces to match against the interfaces
+ * implemented by the plugin classes.
+ * @return The list of plugin classes that implement at least
+ * one member of the passed in set of interfaces.
+ */
+ public Class[] getImplementsAny(Class[] interfaces){
+ List matchList = new ArrayList(pluginList.size());
+ Set interfaceSet = new HashSet();
+ for(int i=0;iall of the passed in set of
+ * Interfaces (either directly or through inheritance.)
+ * @param interfaces A set of interfaces to match against the interfaces
+ * implemented by the plugin classes.
+ * @return The list of plugin classes that implement at least
+ * one member of the passed in set of interfaces.
+ */
+ public Class[] getImplementsAll(Class[] interfaces){
+ List matchList = new ArrayList(pluginList.size());
+ Set interfaceSet = new HashSet();
+ for(int i=0;i
+
+
+
+Utility package for JInput Plugins.
+
+
\ No newline at end of file
diff --git a/src/manifest.mf b/src/manifest.mf
new file mode 100644
index 0000000..2552295
--- /dev/null
+++ b/src/manifest.mf
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: net.java.games.input.Version
+Automatic-Module-Name: net.java.games.jinput
diff --git a/src/native/common/util.c b/src/native/common/util.c
new file mode 100644
index 0000000..089ba17
--- /dev/null
+++ b/src/native/common/util.c
@@ -0,0 +1,118 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+
+#include
+#include
+#include
+#include "util.h"
+
+static jstring sprintfJavaString(JNIEnv *env, const char *format, va_list ap) {
+#define BUFFER_SIZE 4000
+ char buffer[BUFFER_SIZE];
+ jstring str;
+#ifdef _MSC_VER
+ vsnprintf_s(buffer, BUFFER_SIZE, _TRUNCATE, format, ap);
+#else
+ vsnprintf(buffer, BUFFER_SIZE, format, ap);
+#endif
+ buffer[BUFFER_SIZE - 1] = '\0';
+ str = (*env)->NewStringUTF(env, buffer);
+ return str;
+}
+
+void printfJava(JNIEnv *env, const char *format, ...) {
+ jstring str;
+ jclass org_lwjgl_LWJGLUtil_class;
+ jmethodID log_method;
+ va_list ap;
+ va_start(ap, format);
+ str = sprintfJavaString(env, format, ap);
+ va_end(ap);
+ org_lwjgl_LWJGLUtil_class = (*env)->FindClass(env, "net/java/games/input/ControllerEnvironment");
+ if (org_lwjgl_LWJGLUtil_class == NULL)
+ return;
+ log_method = (*env)->GetStaticMethodID(env, org_lwjgl_LWJGLUtil_class, "log", "(Ljava/lang/String;)V");
+ if (log_method == NULL)
+ return;
+ (*env)->CallStaticVoidMethod(env, org_lwjgl_LWJGLUtil_class, log_method, str);
+}
+
+static void throwException(JNIEnv * env, const char *exception_name, const char *format, va_list ap) {
+ jstring str;
+ jobject exception;
+
+ if ((*env)->ExceptionCheck(env) == JNI_TRUE)
+ return; // The JVM crashes if we try to throw two exceptions from one native call
+ str = sprintfJavaString(env, format, ap);
+ exception = newJObject(env, exception_name, "(Ljava/lang/String;)V", str);
+ (*env)->Throw(env, exception);
+}
+
+void throwRuntimeException(JNIEnv * env, const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ throwException(env, "java/lang/RuntimeException", format, ap);
+ va_end(ap);
+}
+
+void throwIOException(JNIEnv * env, const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ throwException(env, "java/io/IOException", format, ap);
+ va_end(ap);
+}
+
+jobject newJObject(JNIEnv * env, const char *class_name, const char *constructor_signature, ...) {
+ va_list ap;
+ jclass clazz;
+ jmethodID constructor;
+ jobject obj;
+
+ clazz = (*env)->FindClass(env, class_name);
+ if (clazz == NULL)
+ return NULL;
+ constructor = (*env)->GetMethodID(env, clazz, "", constructor_signature);
+ if (constructor == NULL)
+ return NULL;
+ va_start(ap, constructor_signature);
+ obj = (*env)->NewObjectV(env, clazz, constructor, ap);
+ va_end(ap);
+ return obj;
+}
+
diff --git a/src/native/common/util.h b/src/native/common/util.h
new file mode 100644
index 0000000..657a93d
--- /dev/null
+++ b/src/native/common/util.h
@@ -0,0 +1,53 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+
+#include
+#include
+#include
+#ifdef _MSC_VER
+#include
+#else
+#include
+#endif
+
+extern void printfJava(JNIEnv *env, const char *format, ...);
+extern void throwRuntimeException(JNIEnv * env, const char *format, ...);
+extern void throwIOException(JNIEnv * env, const char *format, ...);
+extern jobject newJObject(JNIEnv * env, const char *class_name, const char *constructor_signature, ...);
+
diff --git a/src/native/linux/build.xml b/src/native/linux/build.xml
new file mode 100644
index 0000000..ccdc209
--- /dev/null
+++ b/src/native/linux/build.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/native/linux/getDefinitions b/src/native/linux/getDefinitions
new file mode 100644
index 0000000..e5d127d
--- /dev/null
+++ b/src/native/linux/getDefinitions
@@ -0,0 +1,60 @@
+#!/bin/gawk -f
+
+# Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
+#
+# 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.
+# The name of the author may not be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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
+
+NR == 1 {
+ FILENAME == ARGV[1];
+ printf("package net.java.games.input;\n\n")
+ printf("\n");
+ printf("/**\n * This file is generated from %s please do not edit\n */\n", FILENAME);
+ printf("class NativeDefinitions {\n")
+}
+/#define ABS_/ {
+ printf(" public static final int %s = %s;\n", $2, $3)
+}
+/#define REL_/ {
+ printf(" public static final int %s = %s;\n", $2, $3)
+}
+/#define BTN_/ {
+ printf(" public static final int %s = %s;\n", $2, $3)
+}
+/#define KEY_/ {
+ printf(" public static final int %s = %s;\n", $2, $3)
+}
+/#define BUS_/ {
+ printf(" public static final int %s = %s;\n", $2, $3)
+}
+/#define EV_/ {
+ printf(" public static final int %s = %s;\n", $2, $3)
+}
+/#define FF_/ {
+ printf(" public static final int %s = %s;\n", $2, $3)
+}
+/#define USAGE_/ {
+ printf(" public static final int %s = %s;\n", $2, $3)
+}
+END {
+ printf("}\n");
+}
diff --git a/src/native/linux/net_java_games_input_LinuxEventDevice.c b/src/native/linux/net_java_games_input_LinuxEventDevice.c
new file mode 100644
index 0000000..18913c2
--- /dev/null
+++ b/src/native/linux/net_java_games_input_LinuxEventDevice.c
@@ -0,0 +1,243 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "util.h"
+#include "net_java_games_input_LinuxEventDevice.h"
+
+JNIEXPORT jlong JNICALL Java_net_java_games_input_LinuxEventDevice_nOpen(JNIEnv *env, jclass unused, jstring path, jboolean rw_flag) {
+ const char *path_str = (*env)->GetStringUTFChars(env, path, NULL);
+ if (path_str == NULL)
+ return -1;
+ int flags = rw_flag == JNI_TRUE ? O_RDWR : O_RDONLY;
+ flags = flags | O_NONBLOCK;
+ int fd = open(path_str, flags);
+ if (fd == -1)
+ throwIOException(env, "Failed to open device %s (%d)\n", path_str, errno);
+ (*env)->ReleaseStringUTFChars(env, path, path_str);
+ return fd;
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nClose(JNIEnv *env, jclass unused, jlong fd_address) {
+ int fd = (int)fd_address;
+ int result = close(fd);
+ if (result == -1)
+ throwIOException(env, "Failed to close device (%d)\n", errno);
+}
+
+JNIEXPORT jstring JNICALL Java_net_java_games_input_LinuxEventDevice_nGetName(JNIEnv *env, jclass unused, jlong fd_address) {
+#define BUFFER_SIZE 1024
+ int fd = (int)fd_address;
+ char device_name[BUFFER_SIZE];
+
+ if (ioctl(fd, EVIOCGNAME(BUFFER_SIZE), device_name) == -1) {
+ throwIOException(env, "Failed to get device name (%d)\n", errno);
+ return NULL;
+ }
+ jstring jstr = (*env)->NewStringUTF(env, device_name);
+ return jstr;
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nGetKeyStates(JNIEnv *env, jclass unused, jlong fd_address, jbyteArray bits_array) {
+ int fd = (int)fd_address;
+ jsize len = (*env)->GetArrayLength(env, bits_array);
+ jbyte *bits = (*env)->GetByteArrayElements(env, bits_array, NULL);
+ if (bits == NULL)
+ return;
+ int res = ioctl(fd, EVIOCGKEY(len), bits);
+ (*env)->ReleaseByteArrayElements(env, bits_array, bits, 0);
+ if (res == -1)
+ throwIOException(env, "Failed to get device key states (%d)\n", errno);
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nGetVersion(JNIEnv *env, jclass unused, jlong fd_address) {
+ int fd = (int)fd_address;
+ int version;
+ if (ioctl(fd, EVIOCGVERSION, &version) == -1) {
+ throwIOException(env, "Failed to get device version (%d)\n", errno);
+ return -1;
+ }
+ return version;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nGetNumEffects(JNIEnv *env, jclass unused, jlong fd_address) {
+ int fd = (int)fd_address;
+ int num_effects;
+ if (ioctl(fd, EVIOCGEFFECTS, &num_effects) == -1) {
+ throwIOException(env, "Failed to get number of device effects (%d)\n", errno);
+ return -1;
+ }
+ return num_effects;
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nGetBits(JNIEnv *env, jclass unused, jlong fd_address, jint evtype, jbyteArray bits_array) {
+ int fd = (int)fd_address;
+ jsize len = (*env)->GetArrayLength(env, bits_array);
+ jbyte *bits = (*env)->GetByteArrayElements(env, bits_array, NULL);
+ if (bits == NULL)
+ return;
+ int res = ioctl(fd, EVIOCGBIT(evtype, len), bits);
+ (*env)->ReleaseByteArrayElements(env, bits_array, bits, 0);
+ if (res == -1)
+ throwIOException(env, "Failed to get device bits (%d)\n", errno);
+}
+
+JNIEXPORT jobject JNICALL Java_net_java_games_input_LinuxEventDevice_nGetInputID(JNIEnv *env, jclass unused, jlong fd_address) {
+ int fd = (int)fd_address;
+ jclass input_id_class = (*env)->FindClass(env, "net/java/games/input/LinuxInputID");
+ if (input_id_class == NULL)
+ return NULL;
+ jmethodID input_id_constructor = (*env)->GetMethodID(env, input_id_class, "", "(IIII)V");
+ if (input_id_constructor == NULL)
+ return NULL;
+ struct input_id id;
+ int result = ioctl(fd, EVIOCGID, &id);
+ if (result == -1) {
+ throwIOException(env, "Failed to get input id for device (%d)\n", errno);
+ return NULL;
+ }
+ return (*env)->NewObject(env, input_id_class, input_id_constructor, (jint)id.bustype, (jint)id.vendor, (jint)id.product, (jint)id.version);
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nGetAbsInfo(JNIEnv *env, jclass unused, jlong fd_address, jint abs_axis, jobject abs_info_return) {
+ int fd = (int)fd_address;
+ jclass abs_info_class = (*env)->GetObjectClass(env, abs_info_return);
+ if (abs_info_class == NULL)
+ return;
+ jmethodID abs_info_set = (*env)->GetMethodID(env, abs_info_class, "set", "(IIIII)V");
+ if (abs_info_set == NULL)
+ return;
+ struct input_absinfo abs_info;
+ int result = ioctl(fd, EVIOCGABS(abs_axis), &abs_info);
+ if (result == -1) {
+ throwIOException(env, "Failed to get abs info for axis (%d)\n", errno);
+ return;
+ }
+ (*env)->CallVoidMethod(env, abs_info_return, abs_info_set, (jint)abs_info.value, (jint)abs_info.minimum, (jint)abs_info.maximum, (jint)abs_info.fuzz, (jint)abs_info.flat);
+}
+
+JNIEXPORT jboolean JNICALL Java_net_java_games_input_LinuxEventDevice_nGetNextEvent(JNIEnv *env, jclass unused, jlong fd_address, jobject linux_event_return) {
+ int fd = (int)fd_address;
+ jclass linux_event_class = (*env)->GetObjectClass(env, linux_event_return);
+ if (linux_event_class == NULL)
+ return JNI_FALSE;
+ jmethodID linux_event_set = (*env)->GetMethodID(env, linux_event_class, "set", "(JJIII)V");
+ if (linux_event_set == NULL)
+ return JNI_FALSE;
+ struct input_event event;
+ if (read(fd, &event, sizeof(struct input_event)) == -1) {
+ if (errno == EAGAIN)
+ return JNI_FALSE;
+ throwIOException(env, "Failed to read next device event (%d)\n", errno);
+ return JNI_FALSE;
+ }
+ (*env)->CallVoidMethod(env, linux_event_return, linux_event_set, (jlong)event.time.tv_sec, (jlong)event.time.tv_usec, (jint)event.type, (jint)event.code, (jint)event.value);
+ return JNI_TRUE;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nUploadRumbleEffect(JNIEnv *env, jclass unused, jlong fd_address, jint id, jint direction, jint trigger_button, jint trigger_interval, jint replay_length, jint replay_delay, jint strong_magnitude, jint weak_magnitude) {
+ int fd = (int)fd_address;
+ struct ff_effect effect;
+
+ effect.type = FF_RUMBLE;
+ effect.id = id;
+ effect.trigger.button = trigger_button;
+ effect.trigger.interval = trigger_interval;
+ effect.replay.length = replay_length;
+ effect.replay.delay = replay_delay;
+ effect.direction = direction;
+ effect.u.rumble.strong_magnitude = strong_magnitude;
+ effect.u.rumble.weak_magnitude = weak_magnitude;
+
+ if (ioctl(fd, EVIOCSFF, &effect) == -1) {
+ throwIOException(env, "Failed to upload effect (%d)\n", errno);
+ return -1;
+ }
+ return effect.id;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nUploadConstantEffect(JNIEnv *env, jclass unused, jlong fd_address, jint id, jint direction, jint trigger_button, jint trigger_interval, jint replay_length, jint replay_delay, jint constant_level, jint constant_env_attack_length, jint constant_env_attack_level, jint constant_env_fade_length, jint constant_env_fade_level) {
+ int fd = (int)fd_address;
+ struct ff_effect effect;
+
+ effect.type = FF_CONSTANT;
+ effect.id = id;
+ effect.trigger.button = trigger_button;
+ effect.trigger.interval = trigger_interval;
+ effect.replay.length = replay_length;
+ effect.replay.delay = replay_delay;
+ effect.direction = direction;
+ effect.u.constant.level = constant_level;
+ effect.u.constant.envelope.attack_length = constant_env_attack_length;
+ effect.u.constant.envelope.attack_level = constant_env_attack_level;
+ effect.u.constant.envelope.fade_length = constant_env_fade_length;
+ effect.u.constant.envelope.fade_level = constant_env_fade_level;
+
+ if (ioctl(fd, EVIOCSFF, &effect) == -1) {
+ throwIOException(env, "Failed to upload effect (%d)\n", errno);
+ return -1;
+ }
+ return effect.id;
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nWriteEvent(JNIEnv *env, jclass unused, jlong fd_address, jint type, jint code, jint value) {
+ int fd = (int)fd_address;
+ struct input_event event;
+ event.type = type;
+ event.code = code;
+ event.value = value;
+
+ if (write(fd, &event, sizeof(event)) == -1) {
+ throwIOException(env, "Failed to write to device (%d)\n", errno);
+ }
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nEraseEffect(JNIEnv *env, jclass unused, jlong fd_address, jint ff_id) {
+ int fd = (int)fd_address;
+ int ff_id_int = ff_id;
+
+ if (ioctl(fd, EVIOCRMFF, &ff_id_int) == -1)
+ throwIOException(env, "Failed to erase effect (%d)\n", errno);
+}
diff --git a/src/native/linux/net_java_games_input_LinuxJoystickDevice.c b/src/native/linux/net_java_games_input_LinuxJoystickDevice.c
new file mode 100644
index 0000000..718bef3
--- /dev/null
+++ b/src/native/linux/net_java_games_input_LinuxJoystickDevice.c
@@ -0,0 +1,158 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "util.h"
+#include "net_java_games_input_LinuxJoystickDevice.h"
+
+JNIEXPORT jlong JNICALL Java_net_java_games_input_LinuxJoystickDevice_nOpen(JNIEnv *env, jclass unused, jstring path) {
+ const char *path_str = (*env)->GetStringUTFChars(env, path, NULL);
+ if (path_str == NULL)
+ return -1;
+ int fd = open(path_str, O_RDONLY | O_NONBLOCK);
+ if (fd == -1)
+ throwIOException(env, "Failed to open device %s (%d)\n", path_str, errno);
+ (*env)->ReleaseStringUTFChars(env, path, path_str);
+ return fd;
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_LinuxJoystickDevice_nClose(JNIEnv *env, jclass unused, jlong fd_address) {
+ int fd = (int)fd_address;
+ int result = close(fd);
+ if (result == -1)
+ throwIOException(env, "Failed to close device (%d)\n", errno);
+}
+
+JNIEXPORT jstring JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetName(JNIEnv *env, jclass unused, jlong fd_address) {
+#define BUFFER_SIZE 1024
+ int fd = (int)fd_address;
+ char device_name[BUFFER_SIZE];
+
+ if (ioctl(fd, JSIOCGNAME(BUFFER_SIZE), device_name) == -1) {
+ throwIOException(env, "Failed to get device name (%d)\n", errno);
+ return NULL;
+ }
+ jstring jstr = (*env)->NewStringUTF(env, device_name);
+ return jstr;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetVersion(JNIEnv *env, jclass unused, jlong fd_address) {
+ int fd = (int)fd_address;
+ __u32 version;
+ if (ioctl(fd, JSIOCGVERSION, &version) == -1) {
+ throwIOException(env, "Failed to get device version (%d)\n", errno);
+ return -1;
+ }
+ return version;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetNumButtons(JNIEnv *env, jclass unused, jlong fd_address) {
+ int fd = (int)fd_address;
+ __u8 num_buttons;
+ if (ioctl(fd, JSIOCGBUTTONS, &num_buttons) == -1) {
+ throwIOException(env, "Failed to get number of buttons (%d)\n", errno);
+ return -1;
+ }
+ return num_buttons;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetNumAxes(JNIEnv *env, jclass unused, jlong fd_address) {
+ int fd = (int)fd_address;
+ __u8 num_axes;
+ if (ioctl(fd, JSIOCGAXES, &num_axes) == -1) {
+ throwIOException(env, "Failed to get number of buttons (%d)\n", errno);
+ return -1;
+ }
+ return num_axes;
+}
+
+JNIEXPORT jbyteArray JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetAxisMap(JNIEnv *env, jclass unused, jlong fd_address) {
+ int fd = (int)fd_address;
+ __u8 axis_map[ABS_MAX + 1];
+ if (ioctl(fd, JSIOCGAXMAP, axis_map) == -1) {
+ throwIOException(env, "Failed to get axis map (%d)\n", errno);
+ return NULL;
+ }
+
+ jbyteArray axis_map_array = (*env)->NewByteArray(env, (ABS_MAX + 1));
+ if (axis_map_array == NULL)
+ return NULL;
+ (*env)->SetByteArrayRegion(env, axis_map_array, 0, (ABS_MAX + 1), (jbyte *)axis_map);
+ return axis_map_array;
+}
+
+JNIEXPORT jcharArray JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetButtonMap(JNIEnv *env, jclass unused, jlong fd_address) {
+ int fd = (int)fd_address;
+ __u16 button_map[KEY_MAX - BTN_MISC + 1];
+ if (ioctl(fd, JSIOCGBTNMAP, button_map) == -1) {
+ throwIOException(env, "Failed to get button map (%d)\n", errno);
+ return NULL;
+ }
+
+ jcharArray button_map_array = (*env)->NewCharArray(env, (KEY_MAX - BTN_MISC + 1));
+ if (button_map_array == NULL)
+ return NULL;
+ (*env)->SetCharArrayRegion(env, button_map_array, 0, (KEY_MAX - BTN_MISC + 1), (jchar *)button_map);
+ return button_map_array;
+}
+
+JNIEXPORT jboolean JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetNextEvent(JNIEnv *env, jclass unused, jlong fd_address, jobject event_return) {
+ int fd = (int)fd_address;
+ jclass event_class = (*env)->GetObjectClass(env, event_return);
+ if (event_class == NULL)
+ return JNI_FALSE;
+ jmethodID event_set = (*env)->GetMethodID(env, event_class, "set", "(JIII)V");
+ if (event_set == NULL)
+ return JNI_FALSE;
+ struct js_event event;
+ if (read(fd, &event, sizeof(event)) == -1) {
+ if (errno == EAGAIN)
+ return JNI_FALSE;
+ throwIOException(env, "Failed to read next device event (%d)\n", errno);
+ return JNI_FALSE;
+ }
+ (*env)->CallVoidMethod(env, event_return, event_set, (jlong)event.time, (jint)event.value, (jint)event.type, (jint)event.number);
+ return JNI_TRUE;
+}
diff --git a/src/native/osx/build.xml b/src/native/osx/build.xml
new file mode 100644
index 0000000..05bda4b
--- /dev/null
+++ b/src/native/osx/build.xml
@@ -0,0 +1,52 @@
+
+
+ OSX JInput Native Plugin
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/native/osx/macosxutil.c b/src/native/osx/macosxutil.c
new file mode 100644
index 0000000..81b5cc6
--- /dev/null
+++ b/src/native/osx/macosxutil.c
@@ -0,0 +1,197 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+
+#include
+#include
+#include
+#include
+#include
+#include "util.h"
+#include "macosxutil.h"
+
+typedef struct {
+ JNIEnv *env;
+ jobject map;
+} dict_context_t;
+
+typedef struct {
+ JNIEnv *env;
+ jobjectArray array;
+ jsize index;
+} array_context_t;
+
+static jobject createObjectFromCFObject(JNIEnv *env, CFTypeRef cfobject);
+
+static jstring createStringFromCFString(JNIEnv *env, CFStringRef cfstring) {
+ CFIndex unicode_length = CFStringGetLength(cfstring);
+ CFIndex utf8_length = CFStringGetMaximumSizeForEncoding(unicode_length, kCFStringEncodingUTF8);
+ // Allocate buffer large enough, plus \0 terminator
+ char *buffer = (char *)malloc(utf8_length + 1);
+ if (buffer == NULL)
+ return NULL;
+ Boolean result = CFStringGetCString(cfstring, buffer, utf8_length + 1, kCFStringEncodingUTF8);
+ if (!result) {
+ free(buffer);
+ return NULL;
+ }
+ jstring str = (*env)->NewStringUTF(env, buffer);
+ free(buffer);
+ return str;
+}
+
+static jobject createDoubleObjectFromCFNumber(JNIEnv *env, CFNumberRef cfnumber) {
+ double value;
+ Boolean result = CFNumberGetValue(cfnumber, kCFNumberDoubleType, &value);
+ if (!result)
+ return NULL;
+ return newJObject(env, "java/lang/Double", "(D)V", (jdouble)value);
+}
+
+static jobject createLongObjectFromCFNumber(JNIEnv *env, CFNumberRef cfnumber) {
+ SInt64 value;
+ Boolean result = CFNumberGetValue(cfnumber, kCFNumberSInt64Type, &value);
+ if (!result)
+ return NULL;
+ return newJObject(env, "java/lang/Long", "(J)V", (jlong)value);
+}
+
+static jobject createNumberFromCFNumber(JNIEnv *env, CFNumberRef cfnumber) {
+ CFNumberType number_type = CFNumberGetType(cfnumber);
+ switch (number_type) {
+ case kCFNumberSInt8Type:
+ case kCFNumberSInt16Type:
+ case kCFNumberSInt32Type:
+ case kCFNumberSInt64Type:
+ case kCFNumberCharType:
+ case kCFNumberShortType:
+ case kCFNumberIntType:
+ case kCFNumberLongType:
+ case kCFNumberLongLongType:
+ case kCFNumberCFIndexType:
+ return createLongObjectFromCFNumber(env, cfnumber);
+ case kCFNumberFloat32Type:
+ case kCFNumberFloat64Type:
+ case kCFNumberFloatType:
+ case kCFNumberDoubleType:
+ return createDoubleObjectFromCFNumber(env, cfnumber);
+ default:
+ return NULL;
+ }
+}
+
+static void createArrayEntries(const void *value, void *context) {
+ array_context_t *array_context = (array_context_t *)context;
+ jobject jval = createObjectFromCFObject(array_context->env, value);
+ (*array_context->env)->SetObjectArrayElement(array_context->env, array_context->array, array_context->index++, jval);
+ (*array_context->env)->DeleteLocalRef(array_context->env, jval);
+}
+
+static jobject createArrayFromCFArray(JNIEnv *env, CFArrayRef cfarray) {
+ jclass Object_class = (*env)->FindClass(env, "java/lang/Object");
+ if (Object_class == NULL)
+ return NULL;
+ CFIndex size = CFArrayGetCount(cfarray);
+ CFRange range = {0, size};
+ jobjectArray array = (*env)->NewObjectArray(env, size, Object_class, NULL);
+ array_context_t array_context;
+ array_context.env = env;
+ array_context.array = array;
+ array_context.index = 0;
+ CFArrayApplyFunction(cfarray, range, createArrayEntries, &array_context);
+ return array;
+}
+
+static jobject createObjectFromCFObject(JNIEnv *env, CFTypeRef cfobject) {
+ CFTypeID type_id = CFGetTypeID(cfobject);
+ if (type_id == CFDictionaryGetTypeID()) {
+ return createMapFromCFDictionary(env, cfobject);
+ } else if (type_id == CFArrayGetTypeID()) {
+ return createArrayFromCFArray(env, cfobject);
+ } else if (type_id == CFStringGetTypeID()) {
+ return createStringFromCFString(env, cfobject);
+ } else if (type_id == CFNumberGetTypeID()) {
+ return createNumberFromCFNumber(env, cfobject);
+ } else {
+ return NULL;
+ }
+}
+
+static void createMapKeys(const void *key, const void *value, void *context) {
+ dict_context_t *dict_context = (dict_context_t *)context;
+
+ jclass Map_class = (*dict_context->env)->GetObjectClass(dict_context->env, dict_context->map);
+ if (Map_class == NULL)
+ return;
+ jmethodID map_put = (*dict_context->env)->GetMethodID(dict_context->env, Map_class, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
+ if (map_put == NULL)
+ return;
+ jobject jkey = createObjectFromCFObject(dict_context->env, key);
+ jobject jvalue = createObjectFromCFObject(dict_context->env, value);
+ if (jkey == NULL || jvalue == NULL)
+ return;
+ (*dict_context->env)->CallObjectMethod(dict_context->env, dict_context->map, map_put, jkey, jvalue);
+ (*dict_context->env)->DeleteLocalRef(dict_context->env, jkey);
+ (*dict_context->env)->DeleteLocalRef(dict_context->env, jvalue);
+}
+
+jobject createMapFromCFDictionary(JNIEnv *env, CFDictionaryRef dict) {
+ jobject map = newJObject(env, "java/util/HashMap", "()V");
+ if (map == NULL)
+ return NULL;
+ dict_context_t dict_context;
+ dict_context.env = env;
+ dict_context.map = map;
+ CFDictionaryApplyFunction(dict, createMapKeys, &dict_context);
+ return map;
+}
+
+void copyEvent(JNIEnv *env, IOHIDEventStruct *event, jobject event_return) {
+ jclass OSXEvent_class = (*env)->GetObjectClass(env, event_return);
+ if (OSXEvent_class == NULL) {
+ return;
+ }
+
+ jmethodID OSXEvent_set = (*env)->GetMethodID(env, OSXEvent_class, "set", "(JJIJ)V");
+ if (OSXEvent_set == NULL) {
+ return;
+ }
+ Nanoseconds nanos = AbsoluteToNanoseconds(event->timestamp);
+ uint64_t nanos64= *((uint64_t *)&nanos);
+ (*env)->CallVoidMethod(env, event_return, OSXEvent_set, (jlong)event->type, (jlong)(intptr_t)event->elementCookie, (jint)event->value, (jlong)nanos64);
+}
diff --git a/src/native/osx/macosxutil.h b/src/native/osx/macosxutil.h
new file mode 100644
index 0000000..ed2722c
--- /dev/null
+++ b/src/native/osx/macosxutil.h
@@ -0,0 +1,48 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+extern jobject createMapFromCFDictionary(JNIEnv *env, CFDictionaryRef dict);
+extern void copyEvent(JNIEnv *env, IOHIDEventStruct *event, jobject event_return);
diff --git a/src/native/osx/net_java_games_input_OSXHIDDevice.c b/src/native/osx/net_java_games_input_OSXHIDDevice.c
new file mode 100644
index 0000000..cef6701
--- /dev/null
+++ b/src/native/osx/net_java_games_input_OSXHIDDevice.c
@@ -0,0 +1,118 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include "net_java_games_input_OSXHIDDevice.h"
+#include "util.h"
+#include "macosxutil.h"
+
+JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDDevice_nReleaseDevice(JNIEnv *env, jclass unused, jlong device_address, jlong interface_address) {
+ io_object_t hidDevice = (io_object_t)device_address;
+ IOHIDDeviceInterface **device_interface = (IOHIDDeviceInterface **)(intptr_t)interface_address;;
+ (*device_interface)->Release(device_interface);
+ IOObjectRelease(hidDevice);
+}
+
+JNIEXPORT jobject JNICALL Java_net_java_games_input_OSXHIDDevice_nGetDeviceProperties(JNIEnv *env, jclass unused, jlong device_address) {
+ io_object_t hidDevice = (io_object_t)device_address;
+ CFMutableDictionaryRef properties;
+
+ kern_return_t result = IORegistryEntryCreateCFProperties(hidDevice,
+ &properties,
+ kCFAllocatorDefault,
+ kNilOptions);
+ if (result != KERN_SUCCESS) {
+ throwIOException(env, "Failed to create properties for device (%ld)", result);
+ return NULL;
+ }
+ jobject map = createMapFromCFDictionary(env, properties);
+ CFRelease(properties);
+ return map;
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDDevice_nOpen
+ (JNIEnv * env, jclass unused, jlong lpDevice) {
+ IOHIDDeviceInterface **hidDeviceInterface = (IOHIDDeviceInterface **)(intptr_t)lpDevice;
+ IOReturn ioReturnValue = (*hidDeviceInterface)->open(hidDeviceInterface, 0);
+ if (ioReturnValue != kIOReturnSuccess) {
+ throwIOException(env, "Device open failed: %d", ioReturnValue);
+ }
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDDevice_nClose
+ (JNIEnv * env, jclass unused, jlong lpDevice) {
+ IOHIDDeviceInterface **hidDeviceInterface = (IOHIDDeviceInterface **)(intptr_t)lpDevice;
+ IOReturn ioReturnValue = (*hidDeviceInterface)->close(hidDeviceInterface);
+ if (ioReturnValue != kIOReturnSuccess) {
+ throwIOException(env, "Device close failed: %d", ioReturnValue);
+ }
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDDevice_nGetElementValue
+ (JNIEnv * env, jclass unused, jlong lpDevice, jlong hidCookie, jobject event_return) {
+ IOHIDDeviceInterface **hidDeviceInterface = (IOHIDDeviceInterface **)(intptr_t)lpDevice;
+ IOHIDElementCookie cookie = (IOHIDElementCookie)(intptr_t)hidCookie;
+ IOHIDEventStruct event;
+
+ IOReturn ioReturnValue = (*hidDeviceInterface)->getElementValue(hidDeviceInterface, cookie, &event);
+ if (ioReturnValue != kIOReturnSuccess) {
+ throwIOException(env, "Device getElementValue failed: %d", ioReturnValue);
+ return;
+ }
+ copyEvent(env, &event, event_return);
+ if (event.longValue != NULL) {
+ free(event.longValue);
+ }
+}
+
+JNIEXPORT jlong JNICALL Java_net_java_games_input_OSXHIDDevice_nCreateQueue(JNIEnv *env, jclass unused, jlong device_address) {
+ IOHIDDeviceInterface **hidDeviceInterface = (IOHIDDeviceInterface **)(intptr_t)device_address;
+ IOHIDQueueInterface **queue = (*hidDeviceInterface)->allocQueue(hidDeviceInterface);
+
+ if (queue == NULL) {
+ throwIOException(env, "Could not allocate queue");
+ return 0;
+ }
+ return (jlong)(intptr_t)queue;
+}
diff --git a/src/native/osx/net_java_games_input_OSXHIDDeviceIterator.c b/src/native/osx/net_java_games_input_OSXHIDDeviceIterator.c
new file mode 100644
index 0000000..e76363f
--- /dev/null
+++ b/src/native/osx/net_java_games_input_OSXHIDDeviceIterator.c
@@ -0,0 +1,143 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include "net_java_games_input_OSXHIDDeviceIterator.h"
+#include "util.h"
+
+JNIEXPORT jlong JNICALL Java_net_java_games_input_OSXHIDDeviceIterator_nCreateIterator(JNIEnv *env, jclass unused) {
+ io_iterator_t hidObjectIterator;
+ // Set up a matching dictionary to search the I/O Registry by class
+ // name for all HID class devices
+ //
+ CFMutableDictionaryRef hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
+
+ // Now search I/O Registry for matching devices.
+ // IOServiceGetMatchingServices consumes a reference to the dictionary so we don't have to release it
+ IOReturn ioReturnValue = IOServiceGetMatchingServices(kIOMasterPortDefault, hidMatchDictionary, &hidObjectIterator);
+
+ if (ioReturnValue != kIOReturnSuccess) {
+ throwIOException(env, "Failed to create iterator (%ld)\n", ioReturnValue);
+ return 0;
+ }
+
+ if (hidObjectIterator == IO_OBJECT_NULL) {
+ throwIOException(env, "Failed to create iterator\n");
+ return 0;
+ }
+ return (jlong)hidObjectIterator;
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDDeviceIterator_nReleaseIterator(JNIEnv *env, jclass unused, jlong address) {
+ io_iterator_t iterator = (io_iterator_t)address;
+ IOObjectRelease(iterator);
+}
+
+static IOHIDDeviceInterface **createHIDDevice(JNIEnv *env, io_object_t hidDevice) {
+// io_name_t className;
+ IOHIDDeviceInterface **hidDeviceInterface;
+ IOCFPlugInInterface **plugInInterface;
+ SInt32 score;
+
+/* ioReturnValue = IOObjectGetClass(hidDevice, className);
+ if (ioReturnValue != kIOReturnSuccess) {
+ printfJava(env, "Failed to get IOObject class name.");
+ }
+
+ printfJava(env, "Found device type [%s]\n", className);
+ */
+ IOReturn ioReturnValue = IOCreatePlugInInterfaceForService(hidDevice,
+ kIOHIDDeviceUserClientTypeID,
+ kIOCFPlugInInterfaceID,
+ &plugInInterface,
+ &score);
+
+ if (ioReturnValue != kIOReturnSuccess) {
+ throwIOException(env, "Couldn't create plugin for device interface (%ld)\n", ioReturnValue);
+ return NULL;
+ }
+ //Call a method of the intermediate plug-in to create the device
+ //interface
+ //
+ HRESULT plugInResult = (*plugInInterface)->QueryInterface(plugInInterface,
+ CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
+ (LPVOID)&hidDeviceInterface);
+ (*plugInInterface)->Release(plugInInterface);
+ if (plugInResult != S_OK) {
+ throwIOException(env, "Couldn't create HID class device interface (%ld)\n", plugInResult);
+ return NULL;
+ }
+ return hidDeviceInterface;
+}
+
+JNIEXPORT jobject JNICALL Java_net_java_games_input_OSXHIDDeviceIterator_nNext(JNIEnv *env, jclass unused, jlong address) {
+ io_iterator_t iterator = (io_iterator_t)address;
+ io_object_t hidDevice;
+// io_string_t path;
+// kern_return_t result;
+
+ hidDevice = IOIteratorNext(iterator);
+ if (hidDevice == MACH_PORT_NULL)
+ return NULL;
+/* IOResult result = IORegistryEntryGetPath(hidDevice, kIOServicePlane, path);
+
+ if (result != KERN_SUCCESS) {
+ IOObjectRelease(hidDevice);
+ throwIOException("Failed to get device path (%ld)\n", result);
+ return NULL;
+ }
+*/
+ IOHIDDeviceInterface **device_interface = createHIDDevice(env, hidDevice);
+ if (device_interface == NULL) {
+ IOObjectRelease(hidDevice);
+ return NULL;
+ }
+ jobject device_object = newJObject(env, "net/java/games/input/OSXHIDDevice", "(JJ)V", (jlong)hidDevice, (jlong)(intptr_t)device_interface);
+ if (device_object == NULL) {
+ (*device_interface)->Release(device_interface);
+ IOObjectRelease(hidDevice);
+ return NULL;
+ }
+ return device_object;
+}
diff --git a/src/native/osx/net_java_games_input_OSXHIDQueue.c b/src/native/osx/net_java_games_input_OSXHIDQueue.c
new file mode 100644
index 0000000..12dbd0a
--- /dev/null
+++ b/src/native/osx/net_java_games_input_OSXHIDQueue.c
@@ -0,0 +1,135 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include "net_java_games_input_OSXHIDQueue.h"
+#include "util.h"
+#include "macosxutil.h"
+
+JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nOpen(JNIEnv *env, jclass unused, jlong address, jint queue_depth) {
+ IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
+ IOReturn ioReturnValue = (*queue)->create(queue, 0, queue_depth);
+ if (ioReturnValue != kIOReturnSuccess) {
+ throwIOException(env, "Queue open failed: %d\n", ioReturnValue);
+ return;
+ }
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nStart(JNIEnv *env, jclass unused, jlong address) {
+ IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
+ IOReturn ioReturnValue = (*queue)->start(queue);
+ if (ioReturnValue != kIOReturnSuccess) {
+ throwIOException(env, "Queue start failed: %d\n", ioReturnValue);
+ return;
+ }
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nStop(JNIEnv *env, jclass unused, jlong address) {
+ IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
+ IOReturn ioReturnValue = (*queue)->stop(queue);
+ if (ioReturnValue != kIOReturnSuccess) {
+ throwIOException(env, "Queue stop failed: %d\n", ioReturnValue);
+ return;
+ }
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nClose(JNIEnv *env, jclass unused, jlong address) {
+ IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
+ IOReturn ioReturnValue = (*queue)->dispose(queue);
+ if (ioReturnValue != kIOReturnSuccess) {
+ throwIOException(env, "Queue dispose failed: %d\n", ioReturnValue);
+ return;
+ }
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nReleaseQueue(JNIEnv *env, jclass unused, jlong address) {
+ IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
+ IOReturn ioReturnValue = (*queue)->Release(queue);
+ if (ioReturnValue != kIOReturnSuccess) {
+ throwIOException(env, "Queue Release failed: %d\n", ioReturnValue);
+ return;
+ }
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nAddElement(JNIEnv *env, jclass unused, jlong address, jlong cookie_address) {
+ IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
+ IOHIDElementCookie cookie = (IOHIDElementCookie)(intptr_t)cookie_address;
+
+ IOReturn ioReturnValue = (*queue)->addElement(queue, cookie, 0);
+ if (ioReturnValue != kIOReturnSuccess) {
+ throwIOException(env, "Queue addElement failed: %d\n", ioReturnValue);
+ return;
+ }
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nRemoveElement(JNIEnv *env, jclass unused, jlong address, jlong cookie_address) {
+ IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
+ IOHIDElementCookie cookie = (IOHIDElementCookie)(intptr_t)cookie_address;
+
+ IOReturn ioReturnValue = (*queue)->removeElement(queue, cookie);
+ if (ioReturnValue != kIOReturnSuccess) {
+ throwIOException(env, "Queue removeElement failed: %d\n", ioReturnValue);
+ return;
+ }
+}
+
+
+JNIEXPORT jboolean JNICALL Java_net_java_games_input_OSXHIDQueue_nGetNextEvent(JNIEnv *env, jclass unused, jlong address, jobject event_return) {
+ IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
+ IOHIDEventStruct event;
+
+ AbsoluteTime zeroTime = {0, 0};
+ IOReturn ioReturnValue = (*queue)->getNextEvent(queue, &event, zeroTime, 0);
+ if (ioReturnValue == kIOReturnUnderrun) {
+ return JNI_FALSE;
+ } else if (ioReturnValue != kIOReturnSuccess) {
+ throwIOException(env, "Queue getNextEvent failed: %d\n", ioReturnValue);
+ return JNI_FALSE;
+ }
+ copyEvent(env, &event, event_return);
+ if (event.longValue != NULL) {
+ free(event.longValue);
+ }
+ return JNI_TRUE;
+}
diff --git a/src/native/windows/build.xml b/src/native/windows/build.xml
new file mode 100644
index 0000000..412a9b7
--- /dev/null
+++ b/src/native/windows/build.xml
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/native/windows/dx8/dxversion.h b/src/native/windows/dx8/dxversion.h
new file mode 100644
index 0000000..396c7f7
--- /dev/null
+++ b/src/native/windows/dx8/dxversion.h
@@ -0,0 +1,13 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+
+#ifndef DXVERSION_H
+#define DXVERSION_H
+
+#define DIRECTINPUT_VERSION 0x0800
+
+#endif
diff --git a/src/native/windows/dx8/net_java_games_input_IDirectInput.c b/src/native/windows/dx8/net_java_games_input_IDirectInput.c
new file mode 100644
index 0000000..2a8df2b
--- /dev/null
+++ b/src/native/windows/dx8/net_java_games_input_IDirectInput.c
@@ -0,0 +1,103 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+
+#include
+#include
+#include "dxversion.h"
+#include
+#include "net_java_games_input_IDirectInput.h"
+#include "util.h"
+#include "winutil.h"
+
+typedef struct {
+ LPDIRECTINPUT8 lpDirectInput;
+ JNIEnv *env;
+ jobject obj;
+} enum_context_t;
+
+JNIEXPORT jlong JNICALL Java_net_java_games_input_IDirectInput_createIDirectInput(JNIEnv *env, jclass unused) {
+ LPDIRECTINPUT8 lpDirectInput;
+ HRESULT res = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION,
+ &IID_IDirectInput8, (void *)&lpDirectInput, NULL);
+ if (FAILED(res)) {
+ throwIOException(env, "Failed to create IDirectInput8 (%d)\n", res);
+ return 0;
+ }
+ return (jlong)(INT_PTR)lpDirectInput;
+}
+
+static BOOL CALLBACK enumerateDevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID context) {
+ enum_context_t *enum_context = (enum_context_t *)context;
+// LPCDIDATAFORMAT lpDataFormat;
+ LPDIRECTINPUTDEVICE8 lpDevice;
+ DWORD device_type;
+ DWORD device_subtype;
+ HRESULT res;
+ jclass obj_class;
+ jmethodID IDirectInput_addDevice;
+ jstring instance_name;
+ jstring product_name;
+ jbyteArray instance_guid;
+ jbyteArray product_guid;
+
+ instance_guid = wrapGUID(enum_context->env, &(lpddi->guidInstance));
+ if (instance_guid == NULL)
+ return DIENUM_STOP;
+ product_guid = wrapGUID(enum_context->env, &(lpddi->guidProduct));
+ if (product_guid == NULL)
+ return DIENUM_STOP;
+ instance_name = (*enum_context->env)->NewStringUTF(enum_context->env, lpddi->tszInstanceName);
+ if (instance_name == NULL)
+ return DIENUM_STOP;
+ product_name = (*enum_context->env)->NewStringUTF(enum_context->env, lpddi->tszProductName);
+ if (product_name == NULL)
+ return DIENUM_STOP;
+
+ obj_class = (*enum_context->env)->GetObjectClass(enum_context->env, enum_context->obj);
+ if (obj_class == NULL)
+ return DIENUM_STOP;
+
+ IDirectInput_addDevice = (*enum_context->env)->GetMethodID(enum_context->env, obj_class, "addDevice", "(J[B[BIILjava/lang/String;Ljava/lang/String;)V");
+ if (IDirectInput_addDevice == NULL)
+ return DIENUM_STOP;
+
+ res = IDirectInput8_CreateDevice(enum_context->lpDirectInput, &(lpddi->guidInstance), &lpDevice, NULL);
+ if (FAILED(res)) {
+ throwIOException(enum_context->env, "Failed to create device (%d)\n", res);
+ return DIENUM_STOP;
+ }
+
+ device_type = GET_DIDEVICE_TYPE(lpddi->dwDevType);
+ device_subtype = GET_DIDEVICE_SUBTYPE(lpddi->dwDevType);
+
+ (*enum_context->env)->CallVoidMethod(enum_context->env, enum_context->obj, IDirectInput_addDevice, (jlong)(INT_PTR)lpDevice, instance_guid, product_guid, (jint)device_type, (jint)device_subtype, instance_name, product_name);
+ if ((*enum_context->env)->ExceptionOccurred(enum_context->env) != NULL) {
+ IDirectInputDevice8_Release(lpDevice);
+ return DIENUM_STOP;
+ }
+
+ return DIENUM_CONTINUE;
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_IDirectInput_nEnumDevices(JNIEnv *env, jobject obj, jlong address) {
+ LPDIRECTINPUT8 lpDirectInput = (LPDIRECTINPUT8)(INT_PTR)address;
+ HRESULT res;
+
+ enum_context_t enum_context;
+ enum_context.lpDirectInput = lpDirectInput;
+ enum_context.env = env;
+ enum_context.obj = obj;
+ res = IDirectInput8_EnumDevices(lpDirectInput, DI8DEVCLASS_ALL, enumerateDevicesCallback, &enum_context, DIEDFL_ATTACHEDONLY);
+ if (FAILED(res)) {
+ throwIOException(env, "Failed to enumerate devices (%d)\n", res);
+ }
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_IDirectInput_nRelease(JNIEnv *env, jclass unused, jlong address) {
+ LPDIRECTINPUT8 lpDirectInput = (LPDIRECTINPUT8)(INT_PTR)address;
+ IDirectInput8_Release(lpDirectInput);
+}
diff --git a/src/native/windows/dx8/net_java_games_input_IDirectInputDevice.c b/src/native/windows/dx8/net_java_games_input_IDirectInputDevice.c
new file mode 100644
index 0000000..9f29191
--- /dev/null
+++ b/src/native/windows/dx8/net_java_games_input_IDirectInputDevice.c
@@ -0,0 +1,502 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+
+#include
+#include "dxversion.h"
+#include
+#include
+#include "net_java_games_input_IDirectInputDevice.h"
+#include "util.h"
+#include "winutil.h"
+
+typedef struct {
+ JNIEnv *env;
+ jobject device_obj;
+} enum_context_t;
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_IDirectInputDevice_nSetBufferSize(JNIEnv *env, jclass unused, jlong address, jint size) {
+ LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address;
+ DIPROPDWORD dipropdw;
+ HRESULT res;
+
+ dipropdw.diph.dwSize = sizeof(DIPROPDWORD);
+ dipropdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+ dipropdw.diph.dwObj = 0;
+ dipropdw.diph.dwHow = DIPH_DEVICE;
+ dipropdw.dwData = size;
+ res = IDirectInputDevice8_SetProperty(lpDevice, DIPROP_BUFFERSIZE, &dipropdw.diph);
+ return res;
+}
+
+static jint mapGUIDType(const GUID *guid) {
+ if (IsEqualGUID(guid, &GUID_XAxis)) {
+ return net_java_games_input_IDirectInputDevice_GUID_XAxis;
+ } else if (IsEqualGUID(guid, &GUID_YAxis)) {
+ return net_java_games_input_IDirectInputDevice_GUID_YAxis;
+ } else if (IsEqualGUID(guid, &GUID_ZAxis)) {
+ return net_java_games_input_IDirectInputDevice_GUID_ZAxis;
+ } else if (IsEqualGUID(guid, &GUID_RxAxis)) {
+ return net_java_games_input_IDirectInputDevice_GUID_RxAxis;
+ } else if (IsEqualGUID(guid, &GUID_RyAxis)) {
+ return net_java_games_input_IDirectInputDevice_GUID_RyAxis;
+ } else if (IsEqualGUID(guid, &GUID_RzAxis)) {
+ return net_java_games_input_IDirectInputDevice_GUID_RzAxis;
+ } else if (IsEqualGUID(guid, &GUID_Slider)) {
+ return net_java_games_input_IDirectInputDevice_GUID_Slider;
+ } else if (IsEqualGUID(guid, &GUID_Button)) {
+ return net_java_games_input_IDirectInputDevice_GUID_Button;
+ } else if (IsEqualGUID(guid, &GUID_Key)) {
+ return net_java_games_input_IDirectInputDevice_GUID_Key;
+ } else if (IsEqualGUID(guid, &GUID_POV)) {
+ return net_java_games_input_IDirectInputDevice_GUID_POV;
+ } else if (IsEqualGUID(guid, &GUID_ConstantForce)) {
+ return net_java_games_input_IDirectInputDevice_GUID_ConstantForce;
+ } else if (IsEqualGUID(guid, &GUID_RampForce)) {
+ return net_java_games_input_IDirectInputDevice_GUID_RampForce;
+ } else if (IsEqualGUID(guid, &GUID_Square)) {
+ return net_java_games_input_IDirectInputDevice_GUID_Square;
+ } else if (IsEqualGUID(guid, &GUID_Sine)) {
+ return net_java_games_input_IDirectInputDevice_GUID_Sine;
+ } else if (IsEqualGUID(guid, &GUID_Triangle)) {
+ return net_java_games_input_IDirectInputDevice_GUID_Triangle;
+ } else if (IsEqualGUID(guid, &GUID_SawtoothUp)) {
+ return net_java_games_input_IDirectInputDevice_GUID_SawtoothUp;
+ } else if (IsEqualGUID(guid, &GUID_SawtoothDown)) {
+ return net_java_games_input_IDirectInputDevice_GUID_SawtoothDown;
+ } else if (IsEqualGUID(guid, &GUID_Spring)) {
+ return net_java_games_input_IDirectInputDevice_GUID_Spring;
+ } else if (IsEqualGUID(guid, &GUID_Damper)) {
+ return net_java_games_input_IDirectInputDevice_GUID_Damper;
+ } else if (IsEqualGUID(guid, &GUID_Inertia)) {
+ return net_java_games_input_IDirectInputDevice_GUID_Inertia;
+ } else if (IsEqualGUID(guid, &GUID_Friction)) {
+ return net_java_games_input_IDirectInputDevice_GUID_Friction;
+ } else if (IsEqualGUID(guid, &GUID_CustomForce)) {
+ return net_java_games_input_IDirectInputDevice_GUID_CustomForce;
+ } else
+ return net_java_games_input_IDirectInputDevice_GUID_Unknown;
+}
+
+static BOOL CALLBACK enumEffectsCallback(LPCDIEFFECTINFO pdei, LPVOID pvRef) {
+ enum_context_t *enum_context = (enum_context_t *)pvRef;
+ jmethodID add_method;
+ jstring name;
+ jbyteArray guid;
+ JNIEnv *env = enum_context->env;
+ jobject device_obj = enum_context->device_obj;
+ jint guid_id;
+ jclass obj_class = (*env)->GetObjectClass(env, device_obj);
+
+
+ if (obj_class == NULL)
+ return DIENUM_STOP;
+ guid = wrapGUID(env, &(pdei->guid));
+ if (guid == NULL)
+ return DIENUM_STOP;
+ add_method = (*env)->GetMethodID(env, obj_class, "addEffect", "([BIIIILjava/lang/String;)V");
+ if (add_method == NULL)
+ return DIENUM_STOP;
+ name = (*env)->NewStringUTF(env, pdei->tszName);
+ if (name == NULL)
+ return DIENUM_STOP;
+ guid_id = mapGUIDType(&(pdei->guid));
+ (*env)->CallBooleanMethod(env, device_obj, add_method, guid, guid_id, (jint)pdei->dwEffType, (jint)pdei->dwStaticParams, (jint)pdei->dwDynamicParams, name);
+ if ((*env)->ExceptionOccurred(env)) {
+ return DIENUM_STOP;
+ }
+ return DIENUM_CONTINUE;
+}
+
+static BOOL CALLBACK enumObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) {
+ enum_context_t *enum_context = (enum_context_t *)pvRef;
+ jmethodID add_method;
+ jstring name;
+ DWORD instance;
+ DWORD type;
+ jint guid_type;
+ jbyteArray guid;
+ JNIEnv *env = enum_context->env;
+ jobject device_obj = enum_context->device_obj;
+ jclass obj_class = (*env)->GetObjectClass(env, device_obj);
+
+ if (obj_class == NULL)
+ return DIENUM_STOP;
+ guid = wrapGUID(env, &(lpddoi->guidType));
+ if (guid == NULL)
+ return DIENUM_STOP;
+ add_method = (*env)->GetMethodID(env, obj_class, "addObject", "([BIIIIILjava/lang/String;)V");
+ if (add_method == NULL)
+ return DIENUM_STOP;
+ name = (*env)->NewStringUTF(env, lpddoi->tszName);
+ if (name == NULL)
+ return DIENUM_STOP;
+ instance = DIDFT_GETINSTANCE(lpddoi->dwType);
+ type = DIDFT_GETTYPE(lpddoi->dwType);
+ guid_type = mapGUIDType(&(lpddoi->guidType));
+//printfJava(env, "name %s guid_type %d id %d\n", lpddoi->tszName, guid_type, lpddoi->dwType);
+ (*env)->CallBooleanMethod(env, device_obj, add_method, guid, (jint)guid_type, (jint)lpddoi->dwType, (jint)type, (jint)instance, (jint)lpddoi->dwFlags, name);
+ if ((*env)->ExceptionOccurred(env)) {
+ return DIENUM_STOP;
+ }
+ return DIENUM_CONTINUE;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_IDirectInputDevice_nGetRangeProperty(JNIEnv *env, jclass unused, jlong address, jint object_id, jlongArray range_array_obj) {
+ LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address;
+ DIPROPRANGE range;
+ HRESULT res;
+ jlong range_array[2];
+
+ range.diph.dwSize = sizeof(DIPROPRANGE);
+ range.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+ range.diph.dwObj = object_id;
+ range.diph.dwHow = DIPH_BYID;
+ res = IDirectInputDevice8_GetProperty(lpDevice, DIPROP_RANGE, &(range.diph));
+ range_array[0] = range.lMin;
+ range_array[1] = range.lMax;
+ (*env)->SetLongArrayRegion(env, range_array_obj, 0, 2, range_array);
+ return res;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_IDirectInputDevice_nGetDeadzoneProperty(JNIEnv *env, jclass unused, jlong address, jint object_id) {
+ LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address;
+ DIPROPDWORD deadzone;
+ HRESULT res;
+
+ deadzone.diph.dwSize = sizeof(deadzone);
+ deadzone.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+ deadzone.diph.dwObj = object_id;
+ deadzone.diph.dwHow = DIPH_BYID;
+ res = IDirectInputDevice8_GetProperty(lpDevice, DIPROP_DEADZONE, &(deadzone.diph));
+ if (res != DI_OK && res != S_FALSE)
+ throwIOException(env, "Failed to get deadzone property (%x)\n", res);
+ return deadzone.dwData;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_IDirectInputDevice_nSetDataFormat(JNIEnv *env, jclass unused, jlong address, jint flags, jobjectArray objects) {
+ LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address;
+ DIDATAFORMAT data_format;
+ jsize num_objects = (*env)->GetArrayLength(env, objects);
+ /*
+ * Data size must be a multiple of 4, but since sizeof(jint) is
+ * 4, we're safe
+ */
+ DWORD data_size = num_objects*sizeof(jint);
+ GUID *guids;
+ DIOBJECTDATAFORMAT *object_formats;
+ int i;
+ HRESULT res;
+ jclass clazz;
+ jmethodID getGUID_method;
+ jmethodID getFlags_method;
+ jmethodID getType_method;
+ jmethodID getInstance_method;
+ jobject object;
+ jint type;
+ jint object_flags;
+ jint instance;
+ jobject guid_array;
+ DWORD composite_type;
+ DWORD flags_masked;
+ LPDIOBJECTDATAFORMAT object_format;
+
+ data_format.dwSize = sizeof(DIDATAFORMAT);
+ data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT);
+ data_format.dwFlags = flags;
+ data_format.dwDataSize = data_size;
+ data_format.dwNumObjs = num_objects;
+
+ clazz = (*env)->FindClass(env, "net/java/games/input/DIDeviceObject");
+ if (clazz == NULL)
+ return -1;
+ getGUID_method = (*env)->GetMethodID(env, clazz, "getGUID", "()[B");
+ if (getGUID_method == NULL)
+ return -1;
+ getFlags_method = (*env)->GetMethodID(env, clazz, "getFlags", "()I");
+ if (getFlags_method == NULL)
+ return -1;
+ getType_method = (*env)->GetMethodID(env, clazz, "getType", "()I");
+ if (getType_method == NULL)
+ return -1;
+ getInstance_method = (*env)->GetMethodID(env, clazz, "getInstance", "()I");
+ if (getInstance_method == NULL)
+ return -1;
+
+ guids = (GUID *)malloc(num_objects*sizeof(GUID));
+ if (guids == NULL) {
+ throwIOException(env, "Failed to allocate GUIDs");
+ return -1;
+ }
+ object_formats = (DIOBJECTDATAFORMAT *)malloc(num_objects*sizeof(DIOBJECTDATAFORMAT));
+ if (object_formats == NULL) {
+ free(guids);
+ throwIOException(env, "Failed to allocate data format");
+ return -1;
+ }
+ for (i = 0; i < num_objects; i++) {
+ object = (*env)->GetObjectArrayElement(env, objects, i);
+ if ((*env)->ExceptionOccurred(env)) {
+ free(guids);
+ free(object_formats);
+ return -1;
+ }
+ guid_array = (*env)->CallObjectMethod(env, object, getGUID_method);
+ if ((*env)->ExceptionOccurred(env)) {
+ free(guids);
+ free(object_formats);
+ return -1;
+ }
+ unwrapGUID(env, guid_array, guids + i);
+ if ((*env)->ExceptionOccurred(env)) {
+ free(guids);
+ free(object_formats);
+ return -1;
+ }
+ type = (*env)->CallIntMethod(env, object, getType_method);
+ if ((*env)->ExceptionOccurred(env)) {
+ free(guids);
+ free(object_formats);
+ return -1;
+ }
+ object_flags = (*env)->CallIntMethod(env, object, getFlags_method);
+ if ((*env)->ExceptionOccurred(env)) {
+ free(guids);
+ free(object_formats);
+ return -1;
+ }
+ instance = (*env)->CallIntMethod(env, object, getInstance_method);
+ if ((*env)->ExceptionOccurred(env)) {
+ free(guids);
+ free(object_formats);
+ return -1;
+ }
+ (*env)->DeleteLocalRef(env, object);
+ composite_type = type | DIDFT_MAKEINSTANCE(instance);
+ flags_masked = flags & (DIDOI_ASPECTACCEL | DIDOI_ASPECTFORCE | DIDOI_ASPECTPOSITION | DIDOI_ASPECTVELOCITY);
+ object_format = object_formats + i;
+ object_format->pguid = guids + i;
+ object_format->dwType = composite_type;
+ object_format->dwFlags = flags_masked;
+ // dwOfs must be multiple of 4, but sizeof(jint) is 4, so we're safe
+ object_format->dwOfs = i*sizeof(jint);
+ }
+ data_format.rgodf = object_formats;
+ res = IDirectInputDevice8_SetDataFormat(lpDevice, &data_format);
+ free(guids);
+ free(object_formats);
+ return res;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_IDirectInputDevice_nAcquire(JNIEnv *env, jclass unused, jlong address) {
+ LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address;
+
+ HRESULT res = IDirectInputDevice8_Acquire(lpDevice);
+ return res;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_IDirectInputDevice_nUnacquire(JNIEnv *env, jclass unused, jlong address) {
+ LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address;
+
+ HRESULT res = IDirectInputDevice8_Unacquire(lpDevice);
+ return res;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_IDirectInputDevice_nPoll(JNIEnv *env, jclass unused, jlong address) {
+ LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address;
+
+ HRESULT res = IDirectInputDevice8_Poll(lpDevice);
+ return res;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_IDirectInputDevice_nGetDeviceState(JNIEnv *env, jclass unused, jlong address, jintArray device_state_array) {
+ LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address;
+ jsize state_length = (*env)->GetArrayLength(env, device_state_array);
+ DWORD state_size = state_length*sizeof(jint);
+ HRESULT res;
+ jint *device_state = (*env)->GetIntArrayElements(env, device_state_array, NULL);
+ if (device_state == NULL)
+ return -1;
+
+ res = IDirectInputDevice8_GetDeviceState(lpDevice, state_size, device_state);
+ (*env)->ReleaseIntArrayElements(env, device_state_array, device_state, 0);
+ return res;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_IDirectInputDevice_nGetDeviceData(JNIEnv *env, jclass unused, jlong address, jint flags, jobject queue, jobject queue_array, jint position, jint remaining) {
+ LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address;
+ DWORD num_events = remaining;
+ DIDEVICEOBJECTDATA *data;
+ DIDEVICEOBJECTDATA *data_element;
+ jmethodID set_method;
+ HRESULT res;
+ int i;
+ jclass data_class;
+ jclass queue_class;
+ jmethodID position_method;
+
+ data_class = (*env)->FindClass(env, "net/java/games/input/DIDeviceObjectData");
+ if (data_class == NULL)
+ return -1;
+ set_method = (*env)->GetMethodID(env, data_class, "set", "(IIII)V");
+ if (set_method == NULL)
+ return -1;
+ queue_class = (*env)->GetObjectClass(env, queue);
+ if (queue_class == NULL)
+ return -1;
+ position_method = (*env)->GetMethodID(env, queue_class, "position", "(I)V");
+ if (position_method == NULL)
+ return -1;
+
+ data = (DIDEVICEOBJECTDATA *)malloc(num_events*sizeof(DIDEVICEOBJECTDATA));
+ if (data == NULL)
+ return -1;
+
+ res = IDirectInputDevice8_GetDeviceData(lpDevice, sizeof(DIDEVICEOBJECTDATA), data, &num_events, flags);
+ if (res == DI_OK || res == DI_BUFFEROVERFLOW) {
+ for (i = 0; i < num_events; i++) {
+ jobject queue_element = (*env)->GetObjectArrayElement(env, queue_array, position + i);
+ if (queue_element == NULL) {
+ free(data);
+ return -1;
+ }
+ data_element = data + i;
+ (*env)->CallVoidMethod(env, queue_element, set_method, (jint)data_element->dwOfs, (jint)data_element->dwData, (jint)data_element->dwTimeStamp, (jint)data_element->dwSequence);
+ if ((*env)->ExceptionOccurred(env)) {
+ free(data);
+ return -1;
+ }
+ }
+ (*env)->CallVoidMethod(env, queue, position_method, position + num_events);
+ }
+ free(data);
+ return res;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_IDirectInputDevice_nEnumEffects(JNIEnv *env, jobject device_obj, jlong address, jint flags) {
+ LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address;
+ HRESULT res;
+ enum_context_t enum_context;
+
+ enum_context.env = env;
+ enum_context.device_obj = device_obj;
+ res = IDirectInputDevice8_EnumEffects(lpDevice, enumEffectsCallback, &enum_context, flags);
+ return res;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_IDirectInputDevice_nEnumObjects(JNIEnv *env, jobject device_obj, jlong address, jint flags) {
+ LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address;
+ HRESULT res;
+ enum_context_t enum_context;
+
+ enum_context.env = env;
+ enum_context.device_obj = device_obj;
+ res = IDirectInputDevice8_EnumObjects(lpDevice, enumObjectsCallback, &enum_context, flags);
+ return res;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_IDirectInputDevice_nSetCooperativeLevel(JNIEnv *env, jclass unused, jlong address, jlong hwnd_address, jint flags) {
+ LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address;
+ HWND hwnd = (HWND)(INT_PTR)hwnd_address;
+
+ HRESULT res = IDirectInputDevice8_SetCooperativeLevel(lpDevice, hwnd, flags);
+ return res;
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_IDirectInputDevice_nRelease(JNIEnv *env, jclass unused, jlong address) {
+ LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address;
+
+ IDirectInputDevice8_Release(lpDevice);
+}
+
+JNIEXPORT jlong JNICALL Java_net_java_games_input_IDirectInputDevice_nCreatePeriodicEffect(JNIEnv *env, jclass unused, jlong address, jbyteArray effect_guid_array, jint flags, jint duration, jint sample_period, jint gain, jint trigger_button, jint trigger_repeat_interval, jintArray axis_ids_array, jlongArray directions_array, jint envelope_attack_level, jint envelope_attack_time, jint envelope_fade_level, jint envelope_fade_time, jint periodic_magnitude, jint periodic_offset, jint periodic_phase, jint periodic_period, jint start_delay) {
+ LPDIRECTINPUTDEVICE8 lpDevice = (LPDIRECTINPUTDEVICE8)(INT_PTR)address;
+ LPDIRECTINPUTEFFECT lpdiEffect;
+ DIEFFECT effect;
+ GUID effect_guid;
+ jint *axis_ids;
+ jlong *directions;
+ jsize num_axes;
+ jsize num_directions;
+ LONG *directions_long;
+ DWORD *axis_ids_dword;
+ HRESULT res;
+ DIPERIODIC periodic;
+ DIENVELOPE envelope;
+ int i;
+
+ num_axes = (*env)->GetArrayLength(env, axis_ids_array);
+ num_directions = (*env)->GetArrayLength(env, directions_array);
+
+ if (num_axes != num_directions) {
+ throwIOException(env, "axis_ids.length != directions.length\n");
+ return 0;
+ }
+
+ unwrapGUID(env, effect_guid_array, &effect_guid);
+ if ((*env)->ExceptionOccurred(env))
+ return 0;
+ axis_ids = (*env)->GetIntArrayElements(env, axis_ids_array, NULL);
+ if (axis_ids == NULL)
+ return 0;
+ directions = (*env)->GetLongArrayElements(env, directions_array, NULL);
+ if (axis_ids == NULL)
+ return 0;
+ axis_ids_dword = (DWORD *)malloc(sizeof(DWORD)*num_axes);
+ if (axis_ids_dword == NULL) {
+ throwIOException(env, "Failed to allocate axes array\n");
+ return 0;
+ }
+ directions_long = (LONG *)malloc(sizeof(LONG)*num_directions);
+ if (directions_long == NULL) {
+ free(axis_ids_dword);
+ throwIOException(env, "Failed to allocate directions array\n");
+ return 0;
+ }
+ for (i = 0; i < num_axes; i++) {
+ axis_ids_dword[i] = axis_ids[i];
+ }
+ for (i = 0; i < num_directions; i++) {
+ directions_long[i] = directions[i];
+ }
+
+ envelope.dwSize = sizeof(DIENVELOPE);
+ envelope.dwAttackLevel = envelope_attack_level;
+ envelope.dwAttackTime = envelope_attack_time;
+ envelope.dwFadeLevel = envelope_fade_level;
+ envelope.dwFadeTime = envelope_fade_time;
+
+ periodic.dwMagnitude = periodic_magnitude;
+ periodic.lOffset = periodic_offset;
+ periodic.dwPhase = periodic_phase;
+ periodic.dwPeriod = periodic_period;
+
+ effect.dwSize = sizeof(DIEFFECT);
+ effect.dwFlags = flags;
+ effect.dwDuration = duration;
+ effect.dwSamplePeriod = sample_period;
+ effect.dwGain = gain;
+ effect.dwTriggerButton = trigger_button;
+ effect.dwTriggerRepeatInterval = trigger_repeat_interval;
+ effect.cAxes = num_axes;
+ effect.rgdwAxes = axis_ids_dword;
+ effect.rglDirection = directions_long;
+ effect.lpEnvelope = &envelope;
+ effect.cbTypeSpecificParams = sizeof(periodic);
+ effect.lpvTypeSpecificParams = &periodic;
+ effect.dwStartDelay = start_delay;
+
+ res = IDirectInputDevice8_CreateEffect(lpDevice, &effect_guid, &effect, &lpdiEffect, NULL);
+ (*env)->ReleaseIntArrayElements(env, axis_ids_array, axis_ids, 0);
+ (*env)->ReleaseLongArrayElements(env, directions_array, directions, 0);
+ free(axis_ids_dword);
+ free(directions_long);
+ if (res != DI_OK) {
+ throwIOException(env, "Failed to create effect (0x%x)\n", res);
+ return 0;
+ }
+ return (jlong)(INT_PTR)lpdiEffect;
+}
diff --git a/src/native/windows/dx8/net_java_games_input_IDirectInputEffect.c b/src/native/windows/dx8/net_java_games_input_IDirectInputEffect.c
new file mode 100644
index 0000000..4553817
--- /dev/null
+++ b/src/native/windows/dx8/net_java_games_input_IDirectInputEffect.c
@@ -0,0 +1,42 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+
+#include
+#include "dxversion.h"
+#include
+#include
+#include "net_java_games_input_IDirectInputEffect.h"
+#include "util.h"
+
+JNIEXPORT void JNICALL Java_net_java_games_input_IDirectInputEffect_nRelease(JNIEnv *env, jclass unused, jlong address) {
+ LPDIRECTINPUTEFFECT ppdeff = (LPDIRECTINPUTEFFECT)(INT_PTR)address;
+
+ IDirectInputEffect_Release(ppdeff);
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_IDirectInputEffect_nSetGain(JNIEnv *env, jclass unused, jlong address, jint gain) {
+ LPDIRECTINPUTEFFECT ppdeff = (LPDIRECTINPUTEFFECT)(INT_PTR)address;
+ DIEFFECT params;
+
+ ZeroMemory(¶ms, sizeof(params));
+ params.dwSize = sizeof(params);
+ params.dwGain = gain;
+
+ return IDirectInputEffect_SetParameters(ppdeff, ¶ms, DIEP_GAIN);
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_IDirectInputEffect_nStart(JNIEnv *env, jclass unused, jlong address, jint iterations, jint flags) {
+ LPDIRECTINPUTEFFECT ppdeff = (LPDIRECTINPUTEFFECT)(INT_PTR)address;
+
+ return IDirectInputEffect_Start(ppdeff, iterations, flags);
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_IDirectInputEffect_nStop(JNIEnv *env, jclass unused, jlong address) {
+ LPDIRECTINPUTEFFECT ppdeff = (LPDIRECTINPUTEFFECT)(INT_PTR)address;
+
+ return IDirectInputEffect_Stop(ppdeff);
+}
diff --git a/src/native/windows/net_java_games_input_DummyWindow.c b/src/native/windows/net_java_games_input_DummyWindow.c
new file mode 100644
index 0000000..1aa1832
--- /dev/null
+++ b/src/native/windows/net_java_games_input_DummyWindow.c
@@ -0,0 +1,71 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+
+#include
+#include
+#include "net_java_games_input_DummyWindow.h"
+#include "util.h"
+
+static const TCHAR* DUMMY_WINDOW_NAME = "JInputControllerWindow";
+
+static LRESULT CALLBACK DummyWndProc(
+ HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
+ return DefWindowProc(hWnd, message, wParam, lParam);
+}
+
+static BOOL RegisterDummyWindow(HINSTANCE hInstance)
+{
+ WNDCLASSEX wcex;
+ wcex.cbSize = sizeof(WNDCLASSEX);
+ wcex.style = CS_HREDRAW | CS_VREDRAW;
+ wcex.lpfnWndProc = (WNDPROC)DummyWndProc;
+ wcex.cbClsExtra = 0;
+ wcex.cbWndExtra = 0;
+ wcex.hInstance = hInstance;
+ wcex.hIcon = NULL;
+ wcex.hCursor = NULL;
+ wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
+ wcex.lpszMenuName = (LPCSTR)NULL;
+ wcex.lpszClassName = DUMMY_WINDOW_NAME;
+ wcex.hIconSm = NULL;
+ return RegisterClassEx(&wcex);
+}
+
+JNIEXPORT jlong JNICALL Java_net_java_games_input_DummyWindow_createWindow(JNIEnv *env, jclass unused) {
+ HINSTANCE hInst = GetModuleHandle(NULL);
+ HWND hwndDummy;
+ WNDCLASSEX class_info;
+ class_info.cbSize = sizeof(WNDCLASSEX);
+ class_info.cbClsExtra = 0;
+ class_info.cbWndExtra = 0;
+
+ if (!GetClassInfoEx(hInst, DUMMY_WINDOW_NAME, &class_info)) {
+ // Register the dummy input window
+ if (!RegisterDummyWindow(hInst)) {
+ throwIOException(env, "Failed to register window class (%d)\n", GetLastError());
+ return 0;
+ }
+ }
+
+ // Create the dummy input window
+ hwndDummy = CreateWindow(DUMMY_WINDOW_NAME, NULL,
+ WS_POPUP | WS_ICONIC,
+ 0, 0, 0, 0, NULL, NULL, hInst, NULL);
+ if (hwndDummy == NULL) {
+ throwIOException(env, "Failed to create window (%d)\n", GetLastError());
+ return 0;
+ }
+ return (jlong)(intptr_t)hwndDummy;
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_DummyWindow_nDestroy(JNIEnv *env, jclass unused, jlong hwnd_address) {
+ HWND hwndDummy = (HWND)(INT_PTR)hwnd_address;
+ BOOL result = DestroyWindow(hwndDummy);
+ if (!result) {
+ throwIOException(env, "Failed to destroy window (%d)\n", GetLastError());
+ }
+}
diff --git a/src/native/windows/raw/net_java_games_input_RawDevice.c b/src/native/windows/raw/net_java_games_input_RawDevice.c
new file mode 100644
index 0000000..5a031c7
--- /dev/null
+++ b/src/native/windows/raw/net_java_games_input_RawDevice.c
@@ -0,0 +1,70 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+
+#include "rawwinver.h"
+#include
+#include
+#include
+#include "net_java_games_input_RawDevice.h"
+#include "util.h"
+
+JNIEXPORT jstring JNICALL Java_net_java_games_input_RawDevice_nGetName(JNIEnv *env, jclass unused, jlong handle_addr) {
+ HANDLE handle = (HANDLE)(INT_PTR)handle_addr;
+ UINT res;
+ UINT name_length;
+ char *name;
+ jstring name_str;
+
+ res = GetRawInputDeviceInfo(handle, RIDI_DEVICENAME, NULL, &name_length);
+ name = (char *)malloc(name_length*sizeof(char));
+ res = GetRawInputDeviceInfo(handle, RIDI_DEVICENAME, name, &name_length);
+ if ((UINT)-1 == res) {
+ free(name);
+ throwIOException(env, "Failed to get device name (%d)\n", GetLastError());
+ return NULL;
+ }
+ name_str = (*env)->NewStringUTF(env, name);
+ free(name);
+ return name_str;
+}
+
+static jobject createKeyboardInfo(JNIEnv *env, jobject device_obj, RID_DEVICE_INFO_KEYBOARD *device_info) {
+ return newJObject(env, "net/java/games/input/RawKeyboardInfo", "(Lnet/java/games/input/RawDevice;IIIIII)V", device_obj, (jint)device_info->dwType, (jint)device_info->dwSubType, (jint)device_info->dwKeyboardMode, (jint)device_info->dwNumberOfFunctionKeys, (jint)device_info->dwNumberOfIndicators, (jint)device_info->dwNumberOfKeysTotal);
+}
+
+static jobject createMouseInfo(JNIEnv *env, jobject device_obj, RID_DEVICE_INFO_MOUSE *device_info) {
+ return newJObject(env, "net/java/games/input/RawMouseInfo", "(Lnet/java/games/input/RawDevice;III)V", device_obj, (jint)device_info->dwId, (jint)device_info->dwNumberOfButtons, (jint)device_info->dwSampleRate);
+}
+
+static jobject createHIDInfo(JNIEnv *env, jobject device_obj, RID_DEVICE_INFO_HID *device_info) {
+ return newJObject(env, "net/java/games/input/RawHIDInfo", "(Lnet/java/games/input/RawDevice;IIIII)V", device_obj, (jint)device_info->dwVendorId, (jint)device_info->dwProductId, (jint)device_info->dwVersionNumber, (jint)device_info->usUsagePage, (jint)device_info->usUsage);
+}
+
+JNIEXPORT jobject JNICALL Java_net_java_games_input_RawDevice_nGetInfo(JNIEnv *env, jclass unused, jobject device_obj, jlong handle_addr) {
+ HANDLE handle = (HANDLE)(INT_PTR)handle_addr;
+ RID_DEVICE_INFO device_info;
+ UINT size = sizeof(RID_DEVICE_INFO);
+ UINT res;
+
+ device_info.cbSize = sizeof(RID_DEVICE_INFO);
+ res = GetRawInputDeviceInfo(handle, RIDI_DEVICEINFO, &device_info, &size);
+ if ((UINT)-1 == res) {
+ throwIOException(env, "Failed to get device info (%d)\n", GetLastError());
+ return NULL;
+ }
+ switch (device_info.dwType) {
+ case RIM_TYPEHID:
+ return createHIDInfo(env, device_obj,&(device_info.hid));
+ case RIM_TYPEKEYBOARD:
+ return createKeyboardInfo(env, device_obj, &(device_info.keyboard));
+ case RIM_TYPEMOUSE:
+ return createMouseInfo(env, device_obj, &(device_info.mouse));
+ default:
+ throwIOException(env, "Unknown device type: %d\n", device_info.dwType);
+ return NULL;
+ }
+}
diff --git a/src/native/windows/raw/net_java_games_input_RawInputEnvironmentPlugin.c b/src/native/windows/raw/net_java_games_input_RawInputEnvironmentPlugin.c
new file mode 100644
index 0000000..9814b7d
--- /dev/null
+++ b/src/native/windows/raw/net_java_games_input_RawInputEnvironmentPlugin.c
@@ -0,0 +1,166 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+
+#include "rawwinver.h"
+#include
+#include
+#include
+#include
+#include
+#include "net_java_games_input_RawInputEnvironmentPlugin.h"
+#include "util.h"
+#include "winutil.h"
+
+JNIEXPORT jbyteArray JNICALL Java_net_java_games_input_RawInputEnvironmentPlugin_getKeyboardClassGUID(JNIEnv *env, jclass unused) {
+ return wrapGUID(env, &GUID_DEVCLASS_KEYBOARD);
+}
+
+JNIEXPORT jbyteArray JNICALL Java_net_java_games_input_RawInputEnvironmentPlugin_getMouseClassGUID(JNIEnv *env, jclass unused) {
+ return wrapGUID(env, &GUID_DEVCLASS_MOUSE);
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_RawInputEnvironmentPlugin_nEnumSetupAPIDevices(JNIEnv *env, jclass unused, jbyteArray guid_array, jobject device_list) {
+ jclass list_class;
+ jmethodID add_method;
+ HDEVINFO hDevInfo;
+ SP_DEVINFO_DATA DeviceInfoData;
+ int i;
+ GUID setup_class_guid;
+ jstring device_name;
+ jstring device_instance_id;
+ jobject setup_api_device;
+
+ list_class = (*env)->GetObjectClass(env, device_list);
+ if (list_class == NULL)
+ return;
+ add_method = (*env)->GetMethodID(env, list_class, "add", "(Ljava/lang/Object;)Z");
+ if (add_method == NULL)
+ return;
+ unwrapGUID(env, guid_array, &setup_class_guid);
+ if ((*env)->ExceptionOccurred(env))
+ return;
+
+ hDevInfo = SetupDiGetClassDevs(&setup_class_guid,
+ NULL,
+ NULL,
+ DIGCF_PRESENT);
+
+ if (hDevInfo == INVALID_HANDLE_VALUE) {
+ throwIOException(env, "Failed to create device enumerator (%d)\n", GetLastError());
+ return;
+ }
+
+
+ DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
+ for (i = 0; SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData); i++) {
+ DWORD DataT;
+ LPTSTR buffer = NULL;
+ DWORD buffersize = 0;
+
+
+ while (!SetupDiGetDeviceRegistryProperty(
+ hDevInfo,
+ &DeviceInfoData,
+ SPDRP_DEVICEDESC,
+ &DataT,
+ (PBYTE)buffer,
+ buffersize,
+ &buffersize)) {
+ if (buffer != NULL)
+ free(buffer);
+ if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+ buffer = malloc(buffersize);
+ } else {
+ throwIOException(env, "Failed to get device description (%x)\n", GetLastError());
+ SetupDiDestroyDeviceInfoList(hDevInfo);
+ return;
+ }
+ }
+
+ device_name = (*env)->NewStringUTF(env, buffer);
+ if (device_name == NULL) {
+ free(buffer);
+ SetupDiDestroyDeviceInfoList(hDevInfo);
+ return;
+ }
+
+ while (!SetupDiGetDeviceInstanceId(
+ hDevInfo,
+ &DeviceInfoData,
+ buffer,
+ buffersize,
+ &buffersize))
+ {
+ if (buffer != NULL)
+ free(buffer);
+ if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+ buffer = malloc(buffersize);
+ } else {
+ throwIOException(env, "Failed to get device instance id (%x)\n", GetLastError());
+ SetupDiDestroyDeviceInfoList(hDevInfo);
+ return;
+ }
+ }
+
+ device_instance_id = (*env)->NewStringUTF(env, buffer);
+ if (buffer != NULL)
+ free(buffer);
+ if (device_instance_id == NULL) {
+ SetupDiDestroyDeviceInfoList(hDevInfo);
+ return;
+ }
+ setup_api_device = newJObject(env, "net/java/games/input/SetupAPIDevice", "(Ljava/lang/String;Ljava/lang/String;)V", device_instance_id, device_name);
+ if (setup_api_device == NULL) {
+ SetupDiDestroyDeviceInfoList(hDevInfo);
+ return;
+ }
+ (*env)->CallBooleanMethod(env, device_list, add_method, setup_api_device);
+ if ((*env)->ExceptionOccurred(env)) {
+ SetupDiDestroyDeviceInfoList(hDevInfo);
+ return;
+ }
+ }
+ SetupDiDestroyDeviceInfoList(hDevInfo);
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_RawInputEnvironmentPlugin_enumerateDevices(JNIEnv *env, jclass unused, jobject queue, jobject device_list) {
+ UINT num_devices;
+ UINT res;
+ RAWINPUTDEVICELIST *devices;
+ RAWINPUTDEVICELIST *device;
+ jobject device_object;
+ jclass list_class;
+ jmethodID add_method;
+ int i;
+
+ list_class = (*env)->GetObjectClass(env, device_list);
+ if (list_class == NULL)
+ return;
+ add_method = (*env)->GetMethodID(env, list_class, "add", "(Ljava/lang/Object;)Z");
+ if (add_method == NULL)
+ return;
+
+ res = GetRawInputDeviceList(NULL, &num_devices, sizeof(RAWINPUTDEVICELIST));
+ if ((UINT)-1 == res) {
+ throwIOException(env, "Failed to get number of devices (%d)\n", GetLastError());
+ return;
+ }
+ devices = (RAWINPUTDEVICELIST *)malloc(num_devices*sizeof(RAWINPUTDEVICELIST));
+ GetRawInputDeviceList(devices, &num_devices, sizeof(RAWINPUTDEVICELIST));
+ for (i = 0; i < num_devices; i++) {
+ device = devices + i;
+ device_object = newJObject(env, "net/java/games/input/RawDevice", "(Lnet/java/games/input/RawInputEventQueue;JI)V", queue, (jlong)(INT_PTR)device->hDevice, (jint)device->dwType);
+ if (device_object == NULL) {
+ free(devices);
+ return;
+ }
+ (*env)->CallBooleanMethod(env, device_list, add_method, device_object);
+ (*env)->DeleteLocalRef(env, device_object);
+ }
+ free(devices);
+}
+
diff --git a/src/native/windows/raw/net_java_games_input_RawInputEventQueue.c b/src/native/windows/raw/net_java_games_input_RawInputEventQueue.c
new file mode 100644
index 0000000..d0a1564
--- /dev/null
+++ b/src/native/windows/raw/net_java_games_input_RawInputEventQueue.c
@@ -0,0 +1,171 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+
+#include "rawwinver.h"
+#include
+#include
+#include "net_java_games_input_RawInputEventQueue.h"
+#include "util.h"
+
+static void handleMouseEvent(JNIEnv *env, jobject self, jmethodID add_method, LONG time, RAWINPUT *data) {
+ (*env)->CallVoidMethod(env, self, add_method,
+ (jlong)(INT_PTR)data->header.hDevice,
+ (jlong)time,
+ (jint)data->data.mouse.usFlags,
+ (jint)data->data.mouse.usButtonFlags,
+ /*
+ * The Raw Input spec says that the usButtonData
+ * is a signed value, if RI_MOUSE_WHEEL
+ * is set in usFlags. However, usButtonData
+ * is an unsigned value, for unknown reasons,
+ * and since its only known use is the wheel
+ * delta, we'll convert it to a signed value here
+ */
+ (jint)(SHORT)data->data.mouse.usButtonData,
+ (jlong)data->data.mouse.ulRawButtons,
+ (jlong)data->data.mouse.lLastX,
+ (jlong)data->data.mouse.lLastY,
+ (jlong)data->data.mouse.ulExtraInformation
+ );
+}
+
+static void handleKeyboardEvent(JNIEnv *env, jobject self, jmethodID add_method, LONG time, RAWINPUT *data) {
+ (*env)->CallVoidMethod(env, self, add_method,
+ (jlong)(INT_PTR)data->header.hDevice,
+ (jlong)time,
+ (jint)data->data.keyboard.MakeCode,
+ (jint)data->data.keyboard.Flags,
+ (jint)data->data.keyboard.VKey,
+ (jint)data->data.keyboard.Message,
+ (jlong)data->data.keyboard.ExtraInformation
+ );
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_RawInputEventQueue_nRegisterDevices(JNIEnv *env, jclass unused, jint flags, jlong hwnd_addr, jobjectArray device_infos) {
+ BOOL res;
+ jclass device_info_class;
+ jmethodID getUsage_method;
+ jmethodID getUsagePage_method;
+ RAWINPUTDEVICE *devices;
+ RAWINPUTDEVICE *device;
+ jsize num_devices = (*env)->GetArrayLength(env, device_infos);
+ USHORT usage;
+ USHORT usage_page;
+ int i;
+ HWND hwnd = (HWND)(INT_PTR)hwnd_addr;
+
+/* res = GetRegisteredRawInputDevices(NULL, &num_devices, sizeof(RAWINPUTDEVICE));
+ if (num_devices > 0) {
+ devices = (RAWINPUTDEVICE *)malloc(num_devices*sizeof(RAWINPUTDEVICE));
+ res = GetRegisteredRawInputDevices(devices, &num_devices, sizeof(RAWINPUTDEVICE));
+ if (res == -1) {
+ throwIOException(env, "Failed to get registered raw devices (%d)\n", GetLastError());
+ return;
+ }
+ for (i = 0; i < num_devices; i++) {
+ printfJava(env, "from windows: registered: %d %d %p (of %d)\n", devices[i].usUsagePage, devices[i].usUsage, devices[i].hwndTarget, num_devices);
+ }
+ free(devices);
+ }*/
+ device_info_class = (*env)->FindClass(env, "net/java/games/input/RawDeviceInfo");
+ if (device_info_class == NULL)
+ return;
+ getUsage_method = (*env)->GetMethodID(env, device_info_class, "getUsage", "()I");
+ if (getUsage_method == NULL)
+ return;
+ getUsagePage_method = (*env)->GetMethodID(env, device_info_class, "getUsagePage", "()I");
+ if (getUsagePage_method == NULL)
+ return;
+ devices = (RAWINPUTDEVICE *)malloc(num_devices*sizeof(RAWINPUTDEVICE));
+ if (devices == NULL) {
+ throwIOException(env, "Failed to allocate device structs\n");
+ return;
+ }
+ for (i = 0; i < num_devices; i++) {
+ jobject device_obj = (*env)->GetObjectArrayElement(env, device_infos, i);
+ if (device_obj == NULL) {
+ free(devices);
+ return;
+ }
+ usage = (*env)->CallIntMethod(env, device_obj, getUsage_method);
+ if ((*env)->ExceptionOccurred(env)) {
+ free(devices);
+ return;
+ }
+ usage_page = (*env)->CallIntMethod(env, device_obj, getUsagePage_method);
+ if ((*env)->ExceptionOccurred(env)) {
+ free(devices);
+ return;
+ }
+ device = devices + i;
+ device->usUsagePage = usage_page;
+ device->usUsage = usage;
+ device->dwFlags = flags;
+ device->hwndTarget = hwnd;
+ }
+ res = RegisterRawInputDevices(devices, num_devices, sizeof(RAWINPUTDEVICE));
+ free(devices);
+ if (!res)
+ throwIOException(env, "Failed to register raw devices (%d)\n", GetLastError());
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_RawInputEventQueue_nPoll(JNIEnv *env, jobject self, jlong hwnd_handle) {
+ MSG msg;
+ HWND hwnd = (HWND)(INT_PTR)hwnd_handle;
+ jmethodID addMouseEvent_method;
+ jmethodID addKeyboardEvent_method;
+ UINT input_size;
+ RAWINPUT *input_data;
+ LONG time;
+ jclass self_class = (*env)->GetObjectClass(env, self);
+
+ if (self_class == NULL)
+ return;
+ addMouseEvent_method = (*env)->GetMethodID(env, self_class, "addMouseEvent", "(JJIIIJJJJ)V");
+ if (addMouseEvent_method == NULL)
+ return;
+ addKeyboardEvent_method = (*env)->GetMethodID(env, self_class, "addKeyboardEvent", "(JJIIIIJ)V");
+ if (addKeyboardEvent_method == NULL)
+ return;
+ if (GetMessage(&msg, hwnd, 0, 0) != 0) {
+ if (msg.message != WM_INPUT) {
+ DefWindowProc(hwnd, msg.message, msg.wParam, msg.lParam);
+ return; // ignore it
+ }
+ time = msg.time;
+ if (GetRawInputData((HRAWINPUT)msg.lParam, RID_INPUT, NULL, &input_size, sizeof(RAWINPUTHEADER)) == (UINT)-1) {
+ throwIOException(env, "Failed to get raw input data size (%d)\n", GetLastError());
+ DefWindowProc(hwnd, msg.message, msg.wParam, msg.lParam);
+ return;
+ }
+ input_data = (RAWINPUT *)malloc(input_size);
+ if (input_data == NULL) {
+ throwIOException(env, "Failed to allocate input data buffer\n");
+ DefWindowProc(hwnd, msg.message, msg.wParam, msg.lParam);
+ return;
+ }
+ if (GetRawInputData((HRAWINPUT)msg.lParam, RID_INPUT, input_data, &input_size, sizeof(RAWINPUTHEADER)) == (UINT)-1) {
+ free(input_data);
+ throwIOException(env, "Failed to get raw input data (%d)\n", GetLastError());
+ DefWindowProc(hwnd, msg.message, msg.wParam, msg.lParam);
+ return;
+ }
+ switch (input_data->header.dwType) {
+ case RIM_TYPEMOUSE:
+ handleMouseEvent(env, self, addMouseEvent_method, time, input_data);
+ break;
+ case RIM_TYPEKEYBOARD:
+ handleKeyboardEvent(env, self, addKeyboardEvent_method, time, input_data);
+ break;
+ default:
+ /* ignore other types of message */
+ break;
+ }
+ free(input_data);
+ DefWindowProc(hwnd, msg.message, msg.wParam, msg.lParam);
+ }
+}
diff --git a/src/native/windows/raw/rawwinver.h b/src/native/windows/raw/rawwinver.h
new file mode 100644
index 0000000..882341a
--- /dev/null
+++ b/src/native/windows/raw/rawwinver.h
@@ -0,0 +1,14 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+
+#ifndef RAWWINVER_H
+#define RAWWINVER_H
+
+#define _WIN32_WINNT 0x0501
+#define WINVER 0x0501
+
+#endif
diff --git a/src/native/windows/winutil.c b/src/native/windows/winutil.c
new file mode 100644
index 0000000..93606dd
--- /dev/null
+++ b/src/native/windows/winutil.c
@@ -0,0 +1,21 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+
+#include "winutil.h"
+
+jbyteArray wrapGUID(JNIEnv *env, const GUID *guid) {
+ jbyteArray guid_array = (*env)->NewByteArray(env, sizeof(GUID));
+ if (guid_array == NULL)
+ return NULL;
+ (*env)->SetByteArrayRegion(env, guid_array, 0, sizeof(GUID), (jbyte *)guid);
+ return guid_array;
+}
+
+void unwrapGUID(JNIEnv *env, const jobjectArray byte_array, GUID *guid) {
+ (*env)->GetByteArrayRegion(env, byte_array, 0, sizeof(GUID), (jbyte *)guid);
+}
+
diff --git a/src/native/windows/winutil.h b/src/native/windows/winutil.h
new file mode 100644
index 0000000..169280e
--- /dev/null
+++ b/src/native/windows/winutil.h
@@ -0,0 +1,17 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+
+#ifndef _WINUTIL_H
+#define _WINUTIL_H
+
+#include
+#include
+
+extern jbyteArray wrapGUID(JNIEnv *env, const GUID *guid);
+extern void unwrapGUID(JNIEnv *env, const jobjectArray byte_array, GUID *guid);
+
+#endif
diff --git a/src/native/wintab/WinTabUtils.c b/src/native/wintab/WinTabUtils.c
new file mode 100644
index 0000000..3c9d709
--- /dev/null
+++ b/src/native/wintab/WinTabUtils.c
@@ -0,0 +1,167 @@
+/*----------------------------------------------------------------------------
+
+ NAME
+ Utils.c
+
+ PURPOSE
+ Some general-purpose functions for the WinTab demos.
+
+ COPYRIGHT
+ Copyright (c) Wacom Company, Ltd. 2014 All Rights Reserved
+ All rights reserved.
+
+ The text and information contained in this file may be freely used,
+ copied, or distributed without compensation or licensing restrictions.
+
+---------------------------------------------------------------------------- */
+
+#include "WinTabUtils.h"
+
+#ifdef WACOM_DEBUG
+
+void WacomTrace( char *lpszFormat, ...);
+
+#define WACOM_ASSERT( x ) assert( x )
+#define WACOM_TRACE(...) WacomTrace(__VA_ARGS__)
+#else
+#define WACOM_TRACE(...)
+#define WACOM_ASSERT( x )
+
+#endif // WACOM_DEBUG
+
+//////////////////////////////////////////////////////////////////////////////
+HINSTANCE ghWintab = NULL;
+
+WTINFOA gpWTInfoA = NULL;
+WTOPENA gpWTOpenA = NULL;
+WTGETA gpWTGetA = NULL;
+WTSETA gpWTSetA = NULL;
+WTCLOSE gpWTClose = NULL;
+WTPACKET gpWTPacket = NULL;
+WTENABLE gpWTEnable = NULL;
+WTOVERLAP gpWTOverlap = NULL;
+WTSAVE gpWTSave = NULL;
+WTCONFIG gpWTConfig = NULL;
+WTRESTORE gpWTRestore = NULL;
+WTEXTSET gpWTExtSet = NULL;
+WTEXTGET gpWTExtGet = NULL;
+WTQUEUESIZESET gpWTQueueSizeSet = NULL;
+WTDATAPEEK gpWTDataPeek = NULL;
+WTPACKETSGET gpWTPacketsGet = NULL;
+
+// TODO - add more wintab32 function pointers as needed
+
+#define GETPROCADDRESS(type, func) \
+ gp##func = (type)GetProcAddress(ghWintab, #func); \
+ if (!gp##func){ WACOM_ASSERT(FALSE); UnloadWintab(); return FALSE; }
+
+//////////////////////////////////////////////////////////////////////////////
+// Purpose
+// Find wintab32.dll and load it.
+// Find the exported functions we need from it.
+//
+// Returns
+// TRUE on success.
+// FALSE on failure.
+//
+BOOL LoadWintab( void )
+{
+ ghWintab = LoadLibraryA( "Wintab32.dll" );
+ if ( !ghWintab )
+ {
+ DWORD err = GetLastError();
+ WACOM_TRACE("LoadLibrary error: %i\n", err);
+ return FALSE;
+ }
+
+ // Explicitly find the exported Wintab functions in which we are interested.
+ // We are using the ASCII, not unicode versions (where applicable).
+ GETPROCADDRESS( WTOPENA, WTOpenA );
+ GETPROCADDRESS( WTINFOA, WTInfoA );
+ GETPROCADDRESS( WTGETA, WTGetA );
+ GETPROCADDRESS( WTSETA, WTSetA );
+ GETPROCADDRESS( WTPACKET, WTPacket );
+ GETPROCADDRESS( WTCLOSE, WTClose );
+ GETPROCADDRESS( WTENABLE, WTEnable );
+ GETPROCADDRESS( WTOVERLAP, WTOverlap );
+ GETPROCADDRESS( WTSAVE, WTSave );
+ GETPROCADDRESS( WTCONFIG, WTConfig );
+ GETPROCADDRESS( WTRESTORE, WTRestore );
+ GETPROCADDRESS( WTEXTSET, WTExtSet );
+ GETPROCADDRESS( WTEXTGET, WTExtGet );
+ GETPROCADDRESS( WTQUEUESIZESET, WTQueueSizeSet );
+ GETPROCADDRESS( WTDATAPEEK, WTDataPeek );
+ GETPROCADDRESS( WTPACKETSGET, WTPacketsGet );
+
+
+ // TODO - don't forget to NULL out pointers in UnloadWintab().
+ return TRUE;
+}
+
+
+
+//////////////////////////////////////////////////////////////////////////////
+// Purpose
+// Uninitializes use of wintab32.dll
+//
+// Returns
+// Nothing.
+//
+void UnloadWintab( void )
+{
+ WACOM_TRACE( "UnloadWintab()\n" );
+
+ if ( ghWintab )
+ {
+ FreeLibrary( ghWintab );
+ ghWintab = NULL;
+ }
+
+ gpWTOpenA = NULL;
+ gpWTClose = NULL;
+ gpWTInfoA = NULL;
+ gpWTPacket = NULL;
+ gpWTEnable = NULL;
+ gpWTOverlap = NULL;
+ gpWTSave = NULL;
+ gpWTConfig = NULL;
+ gpWTGetA = NULL;
+ gpWTSetA = NULL;
+ gpWTRestore = NULL;
+ gpWTExtSet = NULL;
+ gpWTExtGet = NULL;
+ gpWTQueueSizeSet = NULL;
+ gpWTDataPeek = NULL;
+ gpWTPacketsGet = NULL;
+}
+
+
+
+#ifdef WACOM_DEBUG
+
+//////////////////////////////////////////////////////////////////////////////
+
+void WacomTrace( char *lpszFormat, ...)
+{
+ char szTraceMessage[ 128 ];
+
+ int nBytesWritten;
+
+ va_list args;
+
+ WACOM_ASSERT( lpszFormat );
+
+ va_start( args, lpszFormat );
+
+ nBytesWritten = _vsnprintf( szTraceMessage, sizeof( szTraceMessage ) - 1,
+ lpszFormat, args );
+
+ if ( nBytesWritten > 0 )
+ {
+ OutputDebugStringA( szTraceMessage );
+ }
+
+ va_end( args );
+}
+
+#endif // WACOM_DEBUG
diff --git a/src/native/wintab/WinTabUtils.h b/src/native/wintab/WinTabUtils.h
new file mode 100644
index 0000000..89b31a3
--- /dev/null
+++ b/src/native/wintab/WinTabUtils.h
@@ -0,0 +1,92 @@
+/*----------------------------------------------------------------------------
+
+ NAME
+ Utils.h
+
+ PURPOSE
+ Defines for the general-purpose functions for the WinTab demos.
+
+ COPYRIGHT
+ Copyright (c) Wacom Company, Ltd. 2014 All Rights Reserved
+ All rights reserved.
+
+ The text and information contained in this file may be freely used,
+ copied, or distributed without compensation or licensing restrictions.
+
+---------------------------------------------------------------------------- */
+#pragma once
+
+#include
+#include
+#include
+#include
+
+#include "wintab.h" // NOTE: get from wactab header package
+
+
+//////////////////////////////////////////////////////////////////////////////
+#define WACOM_DEBUG
+
+// Ignore warnings about using unsafe string functions.
+#pragma warning( disable : 4996 )
+
+//////////////////////////////////////////////////////////////////////////////
+// Function pointers to Wintab functions exported from wintab32.dll.
+typedef UINT ( API * WTINFOA ) ( UINT, UINT, LPVOID );
+typedef HCTX ( API * WTOPENA )( HWND, LPLOGCONTEXTA, BOOL );
+typedef BOOL ( API * WTGETA ) ( HCTX, LPLOGCONTEXT );
+typedef BOOL ( API * WTSETA ) ( HCTX, LPLOGCONTEXT );
+typedef BOOL ( API * WTCLOSE ) ( HCTX );
+typedef BOOL ( API * WTENABLE ) ( HCTX, BOOL );
+typedef BOOL ( API * WTPACKET ) ( HCTX, UINT, LPVOID );
+typedef BOOL ( API * WTOVERLAP ) ( HCTX, BOOL );
+typedef BOOL ( API * WTSAVE ) ( HCTX, LPVOID );
+typedef BOOL ( API * WTCONFIG ) ( HCTX, HWND );
+typedef HCTX ( API * WTRESTORE ) ( HWND, LPVOID, BOOL );
+typedef BOOL ( API * WTEXTSET ) ( HCTX, UINT, LPVOID );
+typedef BOOL ( API * WTEXTGET ) ( HCTX, UINT, LPVOID );
+typedef BOOL ( API * WTQUEUESIZESET ) ( HCTX, int );
+typedef int ( API * WTDATAPEEK ) ( HCTX, UINT, UINT, int, LPVOID, LPINT);
+typedef int ( API * WTPACKETSGET ) (HCTX, int, LPVOID);
+
+// TODO - add more wintab32 function defs as needed
+
+// Loaded Wintab32 API functions.
+extern HINSTANCE ghWintab;
+
+extern WTINFOA gpWTInfoA;
+extern WTOPENA gpWTOpenA;
+extern WTGETA gpWTGetA;
+extern WTSETA gpWTSetA;
+extern WTCLOSE gpWTClose;
+extern WTPACKET gpWTPacket;
+extern WTENABLE gpWTEnable;
+extern WTOVERLAP gpWTOverlap;
+extern WTSAVE gpWTSave;
+extern WTCONFIG gpWTConfig;
+extern WTRESTORE gpWTRestore;
+extern WTEXTSET gpWTExtSet;
+extern WTEXTGET gpWTExtGet;
+extern WTQUEUESIZESET gpWTQueueSizeSet;
+extern WTDATAPEEK gpWTDataPeek;
+extern WTPACKETSGET gpWTPacketsGet;
+
+// TODO - add more wintab32 function pointers as needed
+
+//////////////////////////////////////////////////////////////////////////////
+BOOL LoadWintab( void );
+void UnloadWintab( void );
+
+//////////////////////////////////////////////////////////////////////////////
+#ifdef WACOM_DEBUG
+
+void WacomTrace( char *lpszFormat, ...);
+
+#define WACOM_ASSERT( x ) assert( x )
+#define WACOM_TRACE(...) WacomTrace(__VA_ARGS__)
+#else
+#define WACOM_TRACE(...)
+#define WACOM_ASSERT( x )
+
+#endif // WACOM_DEBUG
+
diff --git a/src/native/wintab/build.xml b/src/native/wintab/build.xml
new file mode 100644
index 0000000..8de51f9
--- /dev/null
+++ b/src/native/wintab/build.xml
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/native/wintab/net_java_games_input_WinTabContext.c b/src/native/wintab/net_java_games_input_WinTabContext.c
new file mode 100644
index 0000000..d455197
--- /dev/null
+++ b/src/native/wintab/net_java_games_input_WinTabContext.c
@@ -0,0 +1,106 @@
+#include
+#include
+
+#include
+#include "net_java_games_input_WinTabContext.h"
+#include "wintabutils.h"
+#include
+//#define PACKETDATA ( PK_X | PK_Y | PK_Z | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ROTATION | PK_ORIENTATION | PK_CURSOR )
+#define PACKETDATA ( PK_TIME | PK_X | PK_Y | PK_Z | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_CURSOR )
+#define PACKETMODE 0
+#include
+#include
+
+#define MAX_PACKETS 20
+
+JNIEXPORT jlong JNICALL Java_net_java_games_input_WinTabContext_nOpen(JNIEnv *env, jclass unused, jlong hWnd_long) {
+ LOGCONTEXT context;
+ HWND hWnd = (HWND)(INT_PTR)hWnd_long;
+ HCTX hCtx = NULL;
+
+ jclass booleanClass = (*env)->FindClass(env, "java/lang/Boolean");
+ jstring propertyName = (*env)->NewStringUTF(env, "jinput.wintab.detachcursor");
+ jmethodID getBooleanMethod = (*env)->GetStaticMethodID(env, booleanClass, "getBoolean", "(Ljava/lang/String;)Z");
+ jboolean detachCursor = (*env)->CallStaticBooleanMethod(env, booleanClass, getBooleanMethod, propertyName);
+
+ if(!LoadWintab()) {
+ throwIOException(env, "Failed to load wintab (%d)\n", GetLastError());
+ } else {
+ printfJava(env, "Wintab dll loaded\n");
+ }
+
+ if (!gpWTInfoA(0, 0, NULL)) {
+ throwIOException(env, "Wintab is not available (%d)\n", GetLastError());
+ } else {
+ printfJava(env, "Wintab is available\n");
+ }
+
+ gpWTInfoA(WTI_DEFCONTEXT, 0, &context);
+
+ wsprintf(context.lcName, "JInput Digitizing");
+ context.lcPktData = PACKETDATA;
+ context.lcPktMode = PACKETMODE;
+ context.lcMoveMask = PACKETDATA;
+ context.lcBtnUpMask = context.lcBtnDnMask;
+ if(!detachCursor) {
+ context.lcOptions |= CXO_SYSTEM;
+ }
+
+ /* open the region */
+ hCtx = gpWTOpenA(hWnd, &context, TRUE);
+
+ return (jlong)(intptr_t)hCtx;
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_WinTabContext_nClose(JNIEnv *env, jclass unused, jlong hCtx_long) {
+ gpWTClose((HCTX)(INT_PTR)hCtx_long);
+ UnloadWintab();
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_WinTabContext_nGetNumberOfSupportedDevices(JNIEnv *env, jclass unused) {
+ int numDevices;
+ gpWTInfoA(WTI_INTERFACE, IFC_NDEVICES, &numDevices);
+ return numDevices;
+}
+
+JNIEXPORT jobjectArray JNICALL Java_net_java_games_input_WinTabContext_nGetPackets(JNIEnv *env, jclass unused, jlong hCtx_long) {
+
+ jobjectArray retval;
+ int i=0;
+ PACKET packets[MAX_PACKETS];
+ int numberRead = gpWTPacketsGet((HCTX)(INT_PTR)hCtx_long, MAX_PACKETS, packets);
+ jclass winTabPacketClass = (*env)->FindClass(env, "net/java/games/input/WinTabPacket");
+ jfieldID packetTimeField = (*env)->GetFieldID(env, winTabPacketClass, "PK_TIME", "J");
+ jfieldID packetXAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_X", "I");
+ jfieldID packetYAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_Y", "I");
+ jfieldID packetZAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_Z", "I");
+ jfieldID packetButtonsField = (*env)->GetFieldID(env, winTabPacketClass, "PK_BUTTONS", "I");
+ jfieldID packetNPressureAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_NORMAL_PRESSURE", "I");
+ jfieldID packetTPressureAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_TANGENT_PRESSURE", "I");
+ jfieldID packetCursorField = (*env)->GetFieldID(env, winTabPacketClass, "PK_CURSOR", "I");
+ jfieldID packetOrientationAltAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_ORIENTATION_ALT", "I");
+ jfieldID packetOrientationAzAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_ORIENTATION_AZ", "I");
+ jfieldID packetOrientationTwistAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_ORIENTATION_TWIST", "I");
+ jobject prototypePacket = newJObject(env, "net/java/games/input/WinTabPacket", "()V");
+
+ retval = (*env)->NewObjectArray(env, numberRead, winTabPacketClass, NULL);
+ for(i=0;iSetLongField(env, tempPacket, packetTimeField, packets[i].pkTime);
+ (*env)->SetIntField(env, tempPacket, packetXAxisField, packets[i].pkX);
+ (*env)->SetIntField(env, tempPacket, packetYAxisField, packets[i].pkY);
+ (*env)->SetIntField(env, tempPacket, packetZAxisField, packets[i].pkZ);
+ (*env)->SetIntField(env, tempPacket, packetButtonsField, packets[i].pkButtons);
+ (*env)->SetIntField(env, tempPacket, packetNPressureAxisField, packets[i].pkNormalPressure);
+ (*env)->SetIntField(env, tempPacket, packetTPressureAxisField, packets[i].pkTangentPressure);
+ (*env)->SetIntField(env, tempPacket, packetCursorField, packets[i].pkCursor);
+ (*env)->SetIntField(env, tempPacket, packetOrientationAltAxisField, packets[i].pkOrientation.orAzimuth);
+ (*env)->SetIntField(env, tempPacket, packetOrientationAzAxisField, packets[i].pkOrientation.orAltitude);
+ (*env)->SetIntField(env, tempPacket, packetOrientationTwistAxisField, packets[i].pkOrientation.orTwist);
+
+ (*env)->SetObjectArrayElement(env, retval, i, tempPacket);
+ }
+
+ return retval;
+}
diff --git a/src/native/wintab/net_java_games_input_WinTabDevice.c b/src/native/wintab/net_java_games_input_WinTabDevice.c
new file mode 100644
index 0000000..45af0c1
--- /dev/null
+++ b/src/native/wintab/net_java_games_input_WinTabDevice.c
@@ -0,0 +1,107 @@
+#include
+#include
+
+#include
+#include "net_java_games_input_WinTabDevice.h"
+#include "util.h"
+#include "wintabutils.h"
+#include
+#include
+#define PACKETDATA ( PK_X | PK_Y | PK_Z | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_ORIENTATION | PK_CURSOR )
+#define PACKETMODE 0
+#include
+
+JNIEXPORT jstring JNICALL Java_net_java_games_input_WinTabDevice_nGetName(JNIEnv *env, jclass unused, jint deviceIndex) {
+ char name[50];
+ gpWTInfoA(WTI_DEVICES + deviceIndex, DVC_NAME, name);
+ return (*env)->NewStringUTF(env, name);
+}
+
+JNIEXPORT jintArray JNICALL Java_net_java_games_input_WinTabDevice_nGetAxisDetails(JNIEnv *env, jclass unused, jint deviceIndex, jint axisId) {
+ UINT type;
+ AXIS threeAxisArray[3];
+ AXIS axis;
+ long threeAxisData[6];
+ long axisData[2];
+ int res;
+ jintArray retVal = NULL;
+
+ if(axisId==net_java_games_input_WinTabDevice_XAxis) type = DVC_X;
+ else if(axisId==net_java_games_input_WinTabDevice_YAxis) type = DVC_Y;
+ else if(axisId==net_java_games_input_WinTabDevice_ZAxis) type = DVC_Z;
+ else if(axisId==net_java_games_input_WinTabDevice_NPressureAxis) type = DVC_NPRESSURE;
+ else if(axisId==net_java_games_input_WinTabDevice_TPressureAxis) type = DVC_TPRESSURE;
+ else if(axisId==net_java_games_input_WinTabDevice_OrientationAxis) type = DVC_ORIENTATION;
+ else if(axisId==net_java_games_input_WinTabDevice_RotationAxis) type = DVC_ROTATION;
+
+ if(axisId==net_java_games_input_WinTabDevice_RotationAxis || axisId==net_java_games_input_WinTabDevice_OrientationAxis) {
+ res = gpWTInfoA(WTI_DEVICES + deviceIndex, type, &threeAxisArray);
+ if(res!=0) {
+ threeAxisData[0] = threeAxisArray[0].axMin;
+ threeAxisData[1] = threeAxisArray[0].axMax;
+ threeAxisData[2] = threeAxisArray[1].axMin;
+ threeAxisData[3] = threeAxisArray[1].axMax;
+ threeAxisData[4] = threeAxisArray[2].axMin;
+ threeAxisData[5] = threeAxisArray[2].axMax;
+ retVal = (*env)->NewIntArray(env, 6);
+ (*env)->SetIntArrayRegion(env, retVal, 0, 6, threeAxisData);
+ }
+ } else {
+ res = gpWTInfoA(WTI_DEVICES + deviceIndex, type, &axis);
+ if(res!=0) {
+ axisData[0] = axis.axMin;
+ axisData[1] = axis.axMax;
+ retVal = (*env)->NewIntArray(env, 2);
+ (*env)->SetIntArrayRegion(env, retVal, 0, 2, axisData);
+ }
+ }
+
+ if(retVal==NULL) {
+ retVal = (*env)->NewIntArray(env, 0);
+ }
+
+ return retVal;
+}
+
+JNIEXPORT jobjectArray JNICALL Java_net_java_games_input_WinTabDevice_nGetCursorNames(JNIEnv *env, jclass unused, jint deviceId) {
+ int numberCursorTypes;
+ int firstCursorType;
+ char name[50];
+ int i;
+ jclass stringClass = (*env)->FindClass(env, "java/lang/String");
+ jstring nameString;
+ jobjectArray retval;
+
+ gpWTInfoA(WTI_DEVICES + deviceId, DVC_NCSRTYPES, &numberCursorTypes);
+ gpWTInfoA(WTI_DEVICES + deviceId, DVC_FIRSTCSR, &firstCursorType);
+
+ retval = (*env)->NewObjectArray(env, numberCursorTypes, stringClass, NULL);
+
+ for(i=0;iNewStringUTF(env, name);
+ (*env)->SetObjectArrayElement(env, retval, i-firstCursorType, nameString);
+ }
+
+ return retval;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_WinTabDevice_nGetMaxButtonCount(JNIEnv *env, jclass unused, jint deviceId) {
+ int numberCursorTypes;
+ int firstCursorType;
+ byte buttonCount;
+ int i;
+ byte retval=0;
+
+ gpWTInfoA(WTI_DEVICES + deviceId, DVC_NCSRTYPES, &numberCursorTypes);
+ gpWTInfoA(WTI_DEVICES + deviceId, DVC_FIRSTCSR, &firstCursorType);
+
+ for(i=0;iretval) {
+ retval = buttonCount;
+ }
+ }
+
+ return (jint)retval;
+}
diff --git a/src/overview.html b/src/overview.html
new file mode 100644
index 0000000..9290060
--- /dev/null
+++ b/src/overview.html
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+ This is a fork of the jinput project. The fork is at https://github.com/hervegirod/jinput2.
+
+
+ The original jinput project is at https://github.com/jinput/jinput
+
+
diff --git a/src/plugins/awt/net/java/games/input/AWTEnvironmentPlugin.java b/src/plugins/awt/net/java/games/input/AWTEnvironmentPlugin.java
new file mode 100644
index 0000000..b6b062a
--- /dev/null
+++ b/src/plugins/awt/net/java/games/input/AWTEnvironmentPlugin.java
@@ -0,0 +1,51 @@
+/**
+ * Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+import net.java.games.input.Controller;
+import net.java.games.input.ControllerEnvironment;
+import net.java.games.util.plugins.Plugin;
+
+/**
+ * @author Jeremy
+ * @author elias
+ */
+public class AWTEnvironmentPlugin extends ControllerEnvironment implements Plugin {
+
+ private final Controller[] controllers;
+
+ public AWTEnvironmentPlugin() {
+ this.controllers = new Controller[]{new AWTKeyboard(), new AWTMouse()};
+ }
+
+ public Controller[] getControllers() {
+ return controllers;
+ }
+
+ public boolean isSupported() {
+ return true;
+ }
+}
diff --git a/src/plugins/awt/net/java/games/input/AWTKeyMap.java b/src/plugins/awt/net/java/games/input/AWTKeyMap.java
new file mode 100644
index 0000000..cb0c548
--- /dev/null
+++ b/src/plugins/awt/net/java/games/input/AWTKeyMap.java
@@ -0,0 +1,289 @@
+/**
+ * Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+import java.awt.event.KeyEvent;
+
+/**
+ * @author Jeremy
+ * @author elias
+ */
+final class AWTKeyMap {
+ public final static Component.Identifier.Key mapKeyCode(int key_code) {
+ switch (key_code) {
+ case KeyEvent.VK_0:
+ return Component.Identifier.Key._0;
+ case KeyEvent.VK_1:
+ return Component.Identifier.Key._1;
+ case KeyEvent.VK_2:
+ return Component.Identifier.Key._2;
+ case KeyEvent.VK_3:
+ return Component.Identifier.Key._3;
+ case KeyEvent.VK_4:
+ return Component.Identifier.Key._4;
+ case KeyEvent.VK_5:
+ return Component.Identifier.Key._5;
+ case KeyEvent.VK_6:
+ return Component.Identifier.Key._6;
+ case KeyEvent.VK_7:
+ return Component.Identifier.Key._7;
+ case KeyEvent.VK_8:
+ return Component.Identifier.Key._8;
+ case KeyEvent.VK_9:
+ return Component.Identifier.Key._9;
+
+ case KeyEvent.VK_Q:
+ return Component.Identifier.Key.Q;
+ case KeyEvent.VK_W:
+ return Component.Identifier.Key.W;
+ case KeyEvent.VK_E:
+ return Component.Identifier.Key.E;
+ case KeyEvent.VK_R:
+ return Component.Identifier.Key.R;
+ case KeyEvent.VK_T:
+ return Component.Identifier.Key.T;
+ case KeyEvent.VK_Y:
+ return Component.Identifier.Key.Y;
+ case KeyEvent.VK_U:
+ return Component.Identifier.Key.U;
+ case KeyEvent.VK_I:
+ return Component.Identifier.Key.I;
+ case KeyEvent.VK_O:
+ return Component.Identifier.Key.O;
+ case KeyEvent.VK_P:
+ return Component.Identifier.Key.P;
+ case KeyEvent.VK_A:
+ return Component.Identifier.Key.A;
+ case KeyEvent.VK_S:
+ return Component.Identifier.Key.S;
+ case KeyEvent.VK_D:
+ return Component.Identifier.Key.D;
+ case KeyEvent.VK_F:
+ return Component.Identifier.Key.F;
+ case KeyEvent.VK_G:
+ return Component.Identifier.Key.G;
+ case KeyEvent.VK_H:
+ return Component.Identifier.Key.H;
+ case KeyEvent.VK_J:
+ return Component.Identifier.Key.J;
+ case KeyEvent.VK_K:
+ return Component.Identifier.Key.K;
+ case KeyEvent.VK_L:
+ return Component.Identifier.Key.L;
+ case KeyEvent.VK_Z:
+ return Component.Identifier.Key.Z;
+ case KeyEvent.VK_X:
+ return Component.Identifier.Key.X;
+ case KeyEvent.VK_C:
+ return Component.Identifier.Key.C;
+ case KeyEvent.VK_V:
+ return Component.Identifier.Key.V;
+ case KeyEvent.VK_B:
+ return Component.Identifier.Key.B;
+ case KeyEvent.VK_N:
+ return Component.Identifier.Key.N;
+ case KeyEvent.VK_M:
+ return Component.Identifier.Key.M;
+
+ case KeyEvent.VK_F1:
+ return Component.Identifier.Key.F1;
+ case KeyEvent.VK_F2:
+ return Component.Identifier.Key.F2;
+ case KeyEvent.VK_F3:
+ return Component.Identifier.Key.F3;
+ case KeyEvent.VK_F4:
+ return Component.Identifier.Key.F4;
+ case KeyEvent.VK_F5:
+ return Component.Identifier.Key.F5;
+ case KeyEvent.VK_F6:
+ return Component.Identifier.Key.F6;
+ case KeyEvent.VK_F7:
+ return Component.Identifier.Key.F7;
+ case KeyEvent.VK_F8:
+ return Component.Identifier.Key.F8;
+ case KeyEvent.VK_F9:
+ return Component.Identifier.Key.F9;
+ case KeyEvent.VK_F10:
+ return Component.Identifier.Key.F10;
+ case KeyEvent.VK_F11:
+ return Component.Identifier.Key.F11;
+ case KeyEvent.VK_F12:
+ return Component.Identifier.Key.F12;
+
+ case KeyEvent.VK_ESCAPE:
+ return Component.Identifier.Key.ESCAPE;
+ case KeyEvent.VK_MINUS:
+ return Component.Identifier.Key.MINUS;
+ case KeyEvent.VK_EQUALS:
+ return Component.Identifier.Key.EQUALS;
+ case KeyEvent.VK_BACK_SPACE:
+ return Component.Identifier.Key.BACKSLASH;
+ case KeyEvent.VK_TAB:
+ return Component.Identifier.Key.TAB;
+ case KeyEvent.VK_OPEN_BRACKET:
+ return Component.Identifier.Key.LBRACKET;
+ case KeyEvent.VK_CLOSE_BRACKET:
+ return Component.Identifier.Key.RBRACKET;
+ case KeyEvent.VK_SEMICOLON:
+ return Component.Identifier.Key.SEMICOLON;
+ case KeyEvent.VK_QUOTE:
+ return Component.Identifier.Key.APOSTROPHE;
+ case KeyEvent.VK_NUMBER_SIGN:
+ return Component.Identifier.Key.GRAVE;
+ case KeyEvent.VK_BACK_SLASH:
+ return Component.Identifier.Key.BACKSLASH;
+ case KeyEvent.VK_PERIOD:
+ return Component.Identifier.Key.PERIOD;
+ case KeyEvent.VK_SLASH:
+ return Component.Identifier.Key.SLASH;
+ case KeyEvent.VK_MULTIPLY:
+ return Component.Identifier.Key.MULTIPLY;
+ case KeyEvent.VK_SPACE:
+ return Component.Identifier.Key.SPACE;
+ case KeyEvent.VK_CAPS_LOCK:
+ return Component.Identifier.Key.CAPITAL;
+ case KeyEvent.VK_NUM_LOCK:
+ return Component.Identifier.Key.NUMLOCK;
+ case KeyEvent.VK_SCROLL_LOCK:
+ return Component.Identifier.Key.SCROLL;
+ case KeyEvent.VK_NUMPAD7:
+ return Component.Identifier.Key.NUMPAD7;
+ case KeyEvent.VK_NUMPAD8:
+ return Component.Identifier.Key.NUMPAD8;
+ case KeyEvent.VK_NUMPAD9:
+ return Component.Identifier.Key.NUMPAD9;
+ case KeyEvent.VK_SUBTRACT:
+ return Component.Identifier.Key.SUBTRACT;
+ case KeyEvent.VK_NUMPAD4:
+ return Component.Identifier.Key.NUMPAD4;
+ case KeyEvent.VK_NUMPAD5:
+ return Component.Identifier.Key.NUMPAD5;
+ case KeyEvent.VK_NUMPAD6:
+ return Component.Identifier.Key.NUMPAD6;
+ case KeyEvent.VK_ADD:
+ return Component.Identifier.Key.ADD;
+ case KeyEvent.VK_NUMPAD1:
+ return Component.Identifier.Key.NUMPAD1;
+ case KeyEvent.VK_NUMPAD2:
+ return Component.Identifier.Key.NUMPAD2;
+ case KeyEvent.VK_NUMPAD3:
+ return Component.Identifier.Key.NUMPAD3;
+ case KeyEvent.VK_NUMPAD0:
+ return Component.Identifier.Key.NUMPAD0;
+ case KeyEvent.VK_DECIMAL:
+ return Component.Identifier.Key.DECIMAL;
+
+ case KeyEvent.VK_KANA:
+ return Component.Identifier.Key.KANA;
+ case KeyEvent.VK_CONVERT:
+ return Component.Identifier.Key.CONVERT;
+ case KeyEvent.VK_NONCONVERT:
+ return Component.Identifier.Key.NOCONVERT;
+
+ case KeyEvent.VK_CIRCUMFLEX:
+ return Component.Identifier.Key.CIRCUMFLEX;
+ case KeyEvent.VK_AT:
+ return Component.Identifier.Key.AT;
+ case KeyEvent.VK_COLON:
+ return Component.Identifier.Key.COLON;
+ case KeyEvent.VK_UNDERSCORE:
+ return Component.Identifier.Key.UNDERLINE;
+ case KeyEvent.VK_KANJI:
+ return Component.Identifier.Key.KANJI;
+
+ case KeyEvent.VK_STOP:
+ return Component.Identifier.Key.STOP;
+
+ case KeyEvent.VK_DIVIDE:
+ return Component.Identifier.Key.DIVIDE;
+
+ case KeyEvent.VK_PAUSE:
+ return Component.Identifier.Key.PAUSE;
+ case KeyEvent.VK_HOME:
+ return Component.Identifier.Key.HOME;
+ case KeyEvent.VK_UP:
+ return Component.Identifier.Key.UP;
+ case KeyEvent.VK_PAGE_UP:
+ return Component.Identifier.Key.PAGEUP;
+ case KeyEvent.VK_LEFT:
+ return Component.Identifier.Key.LEFT;
+ case KeyEvent.VK_RIGHT:
+ return Component.Identifier.Key.RIGHT;
+ case KeyEvent.VK_END:
+ return Component.Identifier.Key.END;
+ case KeyEvent.VK_DOWN:
+ return Component.Identifier.Key.DOWN;
+ case KeyEvent.VK_PAGE_DOWN:
+ return Component.Identifier.Key.PAGEDOWN;
+ case KeyEvent.VK_INSERT:
+ return Component.Identifier.Key.INSERT;
+ case KeyEvent.VK_DELETE:
+ return Component.Identifier.Key.DELETE;
+ default:
+ return Component.Identifier.Key.UNKNOWN;
+ }
+ }
+
+ public final static Component.Identifier.Key map(KeyEvent event) {
+ int key_code = event.getKeyCode();
+ int key_location = event.getKeyLocation();
+ switch (key_code) {
+ case KeyEvent.VK_CONTROL:
+ if (key_location == KeyEvent.KEY_LOCATION_RIGHT)
+ return Component.Identifier.Key.RCONTROL;
+ else
+ return Component.Identifier.Key.LCONTROL;
+ case KeyEvent.VK_SHIFT:
+ if (key_location == KeyEvent.KEY_LOCATION_RIGHT)
+ return Component.Identifier.Key.RSHIFT;
+ else
+ return Component.Identifier.Key.LSHIFT;
+ case KeyEvent.VK_ALT:
+ if (key_location == KeyEvent.KEY_LOCATION_RIGHT)
+ return Component.Identifier.Key.RALT;
+ else
+ return Component.Identifier.Key.LALT;
+ //this is 1.5 only
+/* case KeyEvent.VK_WINDOWS:
+ if (key_location == KeyEvent.KEY_LOCATION_RIGHT)
+ return Component.Identifier.Key.RWIN;
+ else
+ return Component.Identifier.Key.LWIN;*/
+ case KeyEvent.VK_ENTER:
+ if (key_location == KeyEvent.KEY_LOCATION_NUMPAD)
+ return Component.Identifier.Key.NUMPADENTER;
+ else
+ return Component.Identifier.Key.RETURN;
+ case KeyEvent.VK_COMMA:
+ if (key_location == KeyEvent.KEY_LOCATION_NUMPAD)
+ return Component.Identifier.Key.NUMPADCOMMA;
+ else
+ return Component.Identifier.Key.COMMA;
+ default:
+ return mapKeyCode(key_code);
+ }
+ }
+}
diff --git a/src/plugins/awt/net/java/games/input/AWTKeyboard.java b/src/plugins/awt/net/java/games/input/AWTKeyboard.java
new file mode 100644
index 0000000..b30a39d
--- /dev/null
+++ b/src/plugins/awt/net/java/games/input/AWTKeyboard.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+import java.awt.AWTEvent;
+import java.awt.Toolkit;
+import java.awt.event.AWTEventListener;
+import java.awt.event.KeyEvent;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import java.io.IOException;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+/**
+ * @author Jeremy
+ * @author elias
+ */
+final class AWTKeyboard extends Keyboard implements AWTEventListener {
+ private final List awt_events = new ArrayList<>();
+ private Event[] processed_events;
+ private int processed_events_index;
+
+ protected AWTKeyboard() {
+ super("AWTKeyboard", createComponents(), new Controller[]{}, new Rumbler[]{});
+ Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
+ resizeEventQueue(EVENT_QUEUE_DEPTH);
+ }
+
+ private final static Component[] createComponents() {
+ List components = new ArrayList<>();
+ Field[] vkey_fields = KeyEvent.class.getFields();
+ for (int i = 0; i < vkey_fields.length; i++) {
+ Field vkey_field = vkey_fields[i];
+ try {
+ if (Modifier.isStatic(vkey_field.getModifiers()) && vkey_field.getType() == int.class &&
+ vkey_field.getName().startsWith("VK_")) {
+ int vkey_code = vkey_field.getInt(null);
+ Component.Identifier.Key key_id = AWTKeyMap.mapKeyCode(vkey_code);
+ if (key_id != Component.Identifier.Key.UNKNOWN)
+ components.add(new Key(key_id));
+ }
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ components.add(new Key(Component.Identifier.Key.RCONTROL));
+ components.add(new Key(Component.Identifier.Key.LCONTROL));
+ components.add(new Key(Component.Identifier.Key.RSHIFT));
+ components.add(new Key(Component.Identifier.Key.LSHIFT));
+ components.add(new Key(Component.Identifier.Key.RALT));
+ components.add(new Key(Component.Identifier.Key.LALT));
+ components.add(new Key(Component.Identifier.Key.NUMPADENTER));
+ components.add(new Key(Component.Identifier.Key.RETURN));
+ components.add(new Key(Component.Identifier.Key.NUMPADCOMMA));
+ components.add(new Key(Component.Identifier.Key.COMMA));
+ return components.toArray(new Component[]{});
+ }
+
+ private final void resizeEventQueue(int size) {
+ processed_events = new Event[size];
+ for (int i = 0; i < processed_events.length; i++)
+ processed_events[i] = new Event();
+ processed_events_index = 0;
+ }
+
+ protected final void setDeviceEventQueueSize(int size) throws IOException {
+ resizeEventQueue(size);
+ }
+
+ public final synchronized void eventDispatched(AWTEvent event) {
+ if (event instanceof KeyEvent)
+ awt_events.add((KeyEvent)event);
+ }
+
+ public final synchronized void pollDevice() throws IOException {
+ for (int i = 0; i < awt_events.size(); i++) {
+ processEvent(awt_events.get(i));
+ }
+ awt_events.clear();
+ }
+
+ private final void processEvent(KeyEvent event) {
+ Component.Identifier.Key key_id = AWTKeyMap.map(event);
+ if (key_id == null)
+ return;
+ Key key = (Key)getComponent(key_id);
+ if (key == null)
+ return;
+ long nanos = event.getWhen()*1000000L;
+ if (event.getID() == KeyEvent.KEY_PRESSED) {
+ //the key was pressed
+ addEvent(key, 1, nanos);
+ } else if (event.getID() == KeyEvent.KEY_RELEASED) {
+ KeyEvent nextPress = (KeyEvent)Toolkit.getDefaultToolkit().getSystemEventQueue().peekEvent(KeyEvent.KEY_PRESSED);
+ if ((nextPress == null) || (nextPress.getWhen() != event.getWhen())) {
+ //the key came really came up
+ addEvent(key, 0, nanos);
+ }
+ }
+ }
+
+ private final void addEvent(Key key, float value, long nanos) {
+ key.setValue(value);
+ if (processed_events_index < processed_events.length)
+ processed_events[processed_events_index++].set(key, value, nanos);
+ }
+
+ protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException {
+ if (processed_events_index == 0)
+ return false;
+ processed_events_index--;
+ event.set(processed_events[0]);
+ Event tmp = processed_events[0];
+ processed_events[0] = processed_events[processed_events_index];
+ processed_events[processed_events_index] = tmp;
+ return true;
+ }
+
+
+ private final static class Key extends AbstractComponent {
+ private float value;
+
+ public Key(Component.Identifier.Key key_id) {
+ super(key_id.getName(), key_id);
+ }
+
+ public final void setValue(float value) {
+ this.value = value;
+ }
+
+ protected final float poll() {
+ return value;
+ }
+
+ public final boolean isAnalog() {
+ return false;
+ }
+
+ public final boolean isRelative() {
+ return false;
+ }
+ }
+}
diff --git a/src/plugins/awt/net/java/games/input/AWTMouse.java b/src/plugins/awt/net/java/games/input/AWTMouse.java
new file mode 100644
index 0000000..8f8cb06
--- /dev/null
+++ b/src/plugins/awt/net/java/games/input/AWTMouse.java
@@ -0,0 +1,221 @@
+/*
+ * Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+import java.awt.AWTEvent;
+import java.awt.Toolkit;
+import java.awt.event.AWTEventListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseWheelEvent;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import java.io.IOException;
+
+/**
+ * @author Jeremy
+ * @author elias
+ */
+final class AWTMouse extends Mouse implements AWTEventListener {
+ private final static int EVENT_X = 1;
+ private final static int EVENT_Y = 2;
+ private final static int EVENT_BUTTON = 4;
+
+ private final List awt_events = new ArrayList<>();
+ private final List processed_awt_events = new ArrayList<>();
+
+ private int event_state = EVENT_X;
+
+ protected AWTMouse() {
+ super("AWTMouse", createComponents(), new Controller[]{}, new Rumbler[]{});
+ Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK);
+ }
+
+ private final static Component[] createComponents() {
+ return new Component[]{new Axis(Component.Identifier.Axis.X),
+ new Axis(Component.Identifier.Axis.Y),
+ new Axis(Component.Identifier.Axis.Z),
+ new Button(Component.Identifier.Button.LEFT),
+ new Button(Component.Identifier.Button.MIDDLE),
+ new Button(Component.Identifier.Button.RIGHT)};
+ }
+
+ private final void processButtons(int button_enum, float value) {
+ Button button = getButton(button_enum);
+ if (button != null)
+ button.setValue(value);
+ }
+
+ private final Button getButton(int button_enum) {
+ switch (button_enum) {
+ case MouseEvent.BUTTON1:
+ return (Button)getLeft();
+ case MouseEvent.BUTTON2:
+ return (Button)getMiddle();
+ case MouseEvent.BUTTON3:
+ return (Button)getRight();
+ case MouseEvent.NOBUTTON:
+ default:
+ // Unknown button
+ return null;
+ }
+ }
+
+ private final void processEvent(AWTEvent event) throws IOException {
+ if (event instanceof MouseWheelEvent) {
+ MouseWheelEvent mwe = (MouseWheelEvent)event;
+ Axis wheel = (Axis)getWheel();
+ wheel.setValue(wheel.poll() + mwe.getWheelRotation());
+ } else if (event instanceof MouseEvent) {
+ MouseEvent me = (MouseEvent)event;
+ Axis x = (Axis)getX();
+ Axis y = (Axis)getY();
+ x.setValue(me.getX());
+ y.setValue(me.getY());
+ switch (me.getID()) {
+ case MouseEvent.MOUSE_PRESSED:
+ processButtons(me.getButton(), 1f);
+ break;
+ case MouseEvent.MOUSE_RELEASED:
+ processButtons(me.getButton(), 0f);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ public final synchronized void pollDevice() throws IOException {
+ Axis wheel = (Axis)getWheel();
+ wheel.setValue(0);
+ for (int i = 0; i < awt_events.size(); i++) {
+ AWTEvent event = awt_events.get(i);
+ processEvent(event);
+ processed_awt_events.add(event);
+ }
+ awt_events.clear();
+ }
+
+ protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException {
+ while (true) {
+ if (processed_awt_events.isEmpty())
+ return false;
+ AWTEvent awt_event = processed_awt_events.get(0);
+ if (awt_event instanceof MouseWheelEvent) {
+ MouseWheelEvent awt_wheel_event = (MouseWheelEvent)awt_event;
+ long nanos = awt_wheel_event.getWhen()*1000000L;
+ event.set(getWheel(), awt_wheel_event.getWheelRotation(), nanos);
+ processed_awt_events.remove(0);
+ } else if (awt_event instanceof MouseEvent) {
+ MouseEvent mouse_event = (MouseEvent)awt_event;
+ long nanos = mouse_event.getWhen()*1000000L;
+ switch (event_state) {
+ case EVENT_X:
+ event_state = EVENT_Y;
+ event.set(getX(), mouse_event.getX(), nanos);
+ return true;
+ case EVENT_Y:
+ event_state = EVENT_BUTTON;
+ event.set(getY(), mouse_event.getY(), nanos);
+ return true;
+ case EVENT_BUTTON:
+ processed_awt_events.remove(0);
+ event_state = EVENT_X;
+ Button button = getButton(mouse_event.getButton());
+ if (button != null) {
+ switch (mouse_event.getID()) {
+ case MouseEvent.MOUSE_PRESSED:
+ event.set(button, 1f, nanos);
+ return true;
+ case MouseEvent.MOUSE_RELEASED:
+ event.set(button, 0f, nanos);
+ return true;
+ default:
+ break;
+ }
+ }
+ break;
+ default:
+ throw new RuntimeException("Unknown event state: " + event_state);
+ }
+ }
+ }
+ }
+
+ public final synchronized void eventDispatched(AWTEvent event) {
+ awt_events.add(event);
+ }
+
+ final static class Axis extends AbstractComponent {
+ private float value;
+
+ public Axis(Component.Identifier.Axis axis_id) {
+ super(axis_id.getName(), axis_id);
+ }
+
+ public final boolean isRelative() {
+ return false;
+ }
+
+ public final boolean isAnalog() {
+ return true;
+ }
+
+ protected final void setValue(float value) {
+ this.value = value;
+ }
+
+ protected final float poll() throws IOException {
+ return value;
+ }
+ }
+
+ final static class Button extends AbstractComponent {
+ private float value;
+
+ public Button(Component.Identifier.Button button_id) {
+ super(button_id.getName(), button_id);
+ }
+
+ protected final void setValue(float value) {
+ this.value = value;
+ }
+
+ protected final float poll() throws IOException {
+ return value;
+ }
+
+ public final boolean isAnalog() {
+ return false;
+ }
+
+ public final boolean isRelative() {
+ return false;
+ }
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxAbsInfo.java b/src/plugins/linux/net/java/games/input/LinuxAbsInfo.java
new file mode 100644
index 0000000..a2b9456
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxAbsInfo.java
@@ -0,0 +1,69 @@
+/**
+ * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+/**
+ * @author elias
+ */
+final class LinuxAbsInfo {
+ private int value;
+ private int minimum;
+ private int maximum;
+ private int fuzz;
+ private int flat;
+
+ public final void set(int value, int min, int max, int fuzz, int flat) {
+ this.value = value;
+ this.minimum = min;
+ this.maximum = max;
+ this.fuzz = fuzz;
+ this.flat = flat;
+ }
+
+ public final String toString() {
+ return "AbsInfo: value = " + value + " | min = " + minimum + " | max = " + maximum + " | fuzz = " + fuzz + " | flat = " + flat;
+ }
+
+ public final int getValue() {
+ return value;
+ }
+
+ final int getMax() {
+ return maximum;
+ }
+
+ final int getMin() {
+ return minimum;
+ }
+
+ final int getFlat() {
+ return flat;
+ }
+
+ final int getFuzz() {
+ return fuzz;
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxAbstractController.java b/src/plugins/linux/net/java/games/input/LinuxAbstractController.java
new file mode 100644
index 0000000..7efbfb1
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxAbstractController.java
@@ -0,0 +1,74 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Represents a Linux controller
+* @author elias
+* @version 1.0
+*/
+final class LinuxAbstractController extends AbstractController {
+ private final PortType port;
+ private final LinuxEventDevice device;
+ private final Type type;
+
+ protected LinuxAbstractController(LinuxEventDevice device, Component[] components, Controller[] children, Rumbler[] rumblers, Type type) throws IOException {
+ super(device.getName(), components, children, rumblers);
+ this.device = device;
+ this.port = device.getPortType();
+ this.type = type;
+ }
+
+ public final PortType getPortType() {
+ return port;
+ }
+
+ public final void pollDevice() throws IOException {
+ device.pollKeyStates();
+ }
+
+ protected final boolean getNextDeviceEvent(Event event) throws IOException {
+ return LinuxControllers.getNextDeviceEvent(event, device);
+ }
+
+ public Type getType() {
+ return type;
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxAxisDescriptor.java b/src/plugins/linux/net/java/games/input/LinuxAxisDescriptor.java
new file mode 100644
index 0000000..d2e476d
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxAxisDescriptor.java
@@ -0,0 +1,62 @@
+/**
+ * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+/**
+ * @author elias
+ */
+final class LinuxAxisDescriptor {
+ private int type;
+ private int code;
+
+ public final void set(int type, int code) {
+ this.type = type;
+ this.code = code;
+ }
+
+ public final int getType() {
+ return type;
+ }
+
+ public final int getCode() {
+ return code;
+ }
+
+ public final int hashCode() {
+ return type ^ code;
+ }
+
+ public final boolean equals(Object other) {
+ if (!(other instanceof LinuxAxisDescriptor))
+ return false;
+ LinuxAxisDescriptor descriptor = (LinuxAxisDescriptor)other;
+ return descriptor.type == type && descriptor.code == code;
+ }
+
+ public final String toString() {
+ return "LinuxAxis: type = 0x" + Integer.toHexString(type) + ", code = 0x" + Integer.toHexString(code);
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxCombinedController.java b/src/plugins/linux/net/java/games/input/LinuxCombinedController.java
new file mode 100644
index 0000000..a88c7c9
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxCombinedController.java
@@ -0,0 +1,32 @@
+package net.java.games.input;
+
+import java.io.IOException;
+
+public class LinuxCombinedController extends AbstractController {
+
+ private LinuxAbstractController eventController;
+ private LinuxJoystickAbstractController joystickController;
+
+ LinuxCombinedController(LinuxAbstractController eventController, LinuxJoystickAbstractController joystickController) {
+ super(eventController.getName(), joystickController.getComponents(), eventController.getControllers(), eventController.getRumblers());
+ this.eventController = eventController;
+ this.joystickController = joystickController;
+ }
+
+ protected boolean getNextDeviceEvent(Event event) throws IOException {
+ return joystickController.getNextDeviceEvent(event);
+ }
+
+ public final PortType getPortType() {
+ return eventController.getPortType();
+ }
+
+ public final void pollDevice() throws IOException {
+ eventController.pollDevice();
+ joystickController.pollDevice();
+ }
+
+ public Type getType() {
+ return eventController.getType();
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxComponent.java b/src/plugins/linux/net/java/games/input/LinuxComponent.java
new file mode 100644
index 0000000..8016deb
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxComponent.java
@@ -0,0 +1,78 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Represents a linux Axis
+* @author elias
+* @version 1.0
+*/
+class LinuxComponent extends AbstractComponent {
+ private final LinuxEventComponent component;
+
+ public LinuxComponent(LinuxEventComponent component) {
+ super(component.getIdentifier().getName(), component.getIdentifier());
+ this.component = component;
+ }
+
+ public final boolean isRelative() {
+ return component.isRelative();
+ }
+
+ public final boolean isAnalog() {
+ return component.isAnalog();
+ }
+
+ protected float poll() throws IOException {
+ return convertValue(LinuxControllers.poll(component), component.getDescriptor());
+ }
+
+ float convertValue(float value, LinuxAxisDescriptor descriptor) {
+ return getComponent().convertValue(value);
+ }
+
+ public final float getDeadZone() {
+ return component.getDeadZone();
+ }
+
+ public final LinuxEventComponent getComponent() {
+ return component;
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxConstantFF.java b/src/plugins/linux/net/java/games/input/LinuxConstantFF.java
new file mode 100644
index 0000000..6610c5a
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxConstantFF.java
@@ -0,0 +1,42 @@
+/**
+ * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+import java.io.IOException;
+
+/**
+ * @author elias
+ */
+final class LinuxConstantFF extends LinuxForceFeedbackEffect {
+ public LinuxConstantFF(LinuxEventDevice device) throws IOException {
+ super(device);
+ }
+
+ protected final int upload(int id, float intensity) throws IOException {
+ int scaled_intensity = Math.round(intensity*0x7fff);
+ return getDevice().uploadConstantEffect(id, 0, 0, 0, 0, 0, scaled_intensity, 0, 0, 0, 0);
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxControllers.java b/src/plugins/linux/net/java/games/input/LinuxControllers.java
new file mode 100644
index 0000000..e5edf81
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxControllers.java
@@ -0,0 +1,81 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** helper methods for Linux specific Controllers
+* @author elias
+* @version 1.0
+*/
+final class LinuxControllers {
+ private final static LinuxEvent linux_event = new LinuxEvent();
+
+ /* Declared synchronized to protect linux_event */
+ public final static synchronized boolean getNextDeviceEvent(Event event, LinuxEventDevice device) throws IOException {
+ while (device.getNextEvent(linux_event)) {
+ LinuxAxisDescriptor descriptor = linux_event.getDescriptor();
+ LinuxComponent component = device.mapDescriptor(descriptor);
+ if (component != null) {
+ float value = component.convertValue(linux_event.getValue(), descriptor);
+ event.set(component, value, linux_event.getNanos());
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private final static LinuxAbsInfo abs_info = new LinuxAbsInfo();
+
+ /* Declared synchronized to protect abs_info */
+ public final static synchronized float poll(LinuxEventComponent event_component) throws IOException {
+ int native_type = event_component.getDescriptor().getType();
+ switch (native_type) {
+ case NativeDefinitions.EV_KEY:
+ int native_code = event_component.getDescriptor().getCode();
+ float state = event_component.getDevice().isKeySet(native_code) ? 1f : 0f;
+ return state;
+ case NativeDefinitions.EV_ABS:
+ event_component.getAbsInfo(abs_info);
+ return abs_info.getValue();
+ default:
+ throw new RuntimeException("Unkown native_type: " + native_type);
+ }
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxDevice.java b/src/plugins/linux/net/java/games/input/LinuxDevice.java
new file mode 100644
index 0000000..2f26a68
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxDevice.java
@@ -0,0 +1,39 @@
+/**
+ * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author elias
+ */
+interface LinuxDevice {
+ void close() throws IOException;
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxDeviceTask.java b/src/plugins/linux/net/java/games/input/LinuxDeviceTask.java
new file mode 100644
index 0000000..3dbdeda
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxDeviceTask.java
@@ -0,0 +1,62 @@
+/**
+ * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+import java.io.IOException;
+
+abstract class LinuxDeviceTask {
+ public final static int INPROGRESS = 1;
+ public final static int COMPLETED = 2;
+ public final static int FAILED = 3;
+
+ private Object result;
+ private IOException exception;
+ private int state = INPROGRESS;
+
+ public final void doExecute() {
+ try {
+ result = execute();
+ state = COMPLETED;
+ } catch (IOException e) {
+ exception = e;
+ state = FAILED;
+ }
+ }
+
+ public final IOException getException() {
+ return exception;
+ }
+
+ public final Object getResult() {
+ return result;
+ }
+
+ public final int getState() {
+ return state;
+ }
+
+ protected abstract Object execute() throws IOException;
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxDeviceThread.java b/src/plugins/linux/net/java/games/input/LinuxDeviceThread.java
new file mode 100644
index 0000000..f550c24
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxDeviceThread.java
@@ -0,0 +1,91 @@
+/**
+ * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Linux doesn't have proper support for force feedback
+ * from different threads since it relies on PIDs
+ * to determine ownership of a particular effect slot.
+ * Therefore we have to hack around this by
+ * making sure everything related to FF
+ * (including the final device close that performs
+ * and implicit deletion of all the process' effects)
+ * is run on a single thread.
+ */
+final class LinuxDeviceThread extends Thread {
+ private final List tasks = new ArrayList<>();
+
+ public LinuxDeviceThread() {
+ setDaemon(true);
+ start();
+ }
+
+ public synchronized final void run() {
+ while (true) {
+ if (!tasks.isEmpty()) {
+ LinuxDeviceTask task = tasks.remove(0);
+ task.doExecute();
+ synchronized (task) {
+ task.notify();
+ }
+ } else {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ }
+ }
+ }
+
+ public final Object execute(LinuxDeviceTask task) throws IOException {
+ synchronized (this) {
+ tasks.add(task);
+ notify();
+ }
+ synchronized (task) {
+ while (task.getState() == LinuxDeviceTask.INPROGRESS) {
+ try {
+ task.wait();
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ }
+ }
+ switch (task.getState()) {
+ case LinuxDeviceTask.COMPLETED:
+ return task.getResult();
+ case LinuxDeviceTask.FAILED:
+ throw task.getException();
+ default:
+ throw new RuntimeException("Invalid task state: " + task.getState());
+ }
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxEnvironmentPlugin.java b/src/plugins/linux/net/java/games/input/LinuxEnvironmentPlugin.java
new file mode 100644
index 0000000..035b8f7
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxEnvironmentPlugin.java
@@ -0,0 +1,477 @@
+/*
+ * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+import net.java.games.util.plugins.Plugin;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.ArrayList;
+import java.io.IOException;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/** Environment plugin for linux
+ * @author elias
+ * @author Jeremy Booth (jeremy@newdawnsoftware.com)
+ */
+public final class LinuxEnvironmentPlugin extends ControllerEnvironment implements Plugin {
+ private final static String LIBNAME = "jinput-linux";
+ private final static String POSTFIX64BIT = "64";
+ private static boolean supported = false;
+
+ private final Controller[] controllers;
+ private final List devices = new ArrayList();
+ private final static LinuxDeviceThread device_thread = new LinuxDeviceThread();
+
+ /**
+ * Static utility method for loading native libraries.
+ * It will try to load from either the path given by
+ * the net.java.games.input.librarypath property
+ * or through System.loadLibrary().
+ *
+ */
+ static void loadLibrary(final String lib_name) {
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ String lib_path = System.getProperty("net.java.games.input.librarypath");
+ try {
+ if(lib_path != null)
+ System.load(lib_path + File.separator + System.mapLibraryName(lib_name));
+ else
+ System.loadLibrary(lib_name);
+ } catch(UnsatisfiedLinkError e) {
+ log("Failed to load library: " + e.getMessage());
+ e.printStackTrace();
+ supported = false;
+ }
+ return null;
+ });
+ }
+
+ static String getPrivilegedProperty(final String property) {
+ return AccessController.doPrivileged((PrivilegedAction)() -> System.getProperty(property));
+ }
+
+
+ static String getPrivilegedProperty(final String property, final String default_value) {
+ return AccessController.doPrivileged((PrivilegedAction)() -> System.getProperty(property, default_value));
+ }
+
+ static {
+ String osName = getPrivilegedProperty("os.name", "").trim();
+ if(osName.equals("Linux")) {
+ supported = true;
+ if("i386".equals(getPrivilegedProperty("os.arch"))) {
+ loadLibrary(LIBNAME);
+ } else {
+ loadLibrary(LIBNAME + POSTFIX64BIT);
+ }
+ }
+ }
+
+ public final static Object execute(LinuxDeviceTask task) throws IOException {
+ return device_thread.execute(task);
+ }
+
+ public LinuxEnvironmentPlugin() {
+ if(isSupported()) {
+ this.controllers = enumerateControllers();
+ log("Linux plugin claims to have found " + controllers.length + " controllers");
+ AccessController.doPrivileged((PrivilegedAction)() -> {
+ Runtime.getRuntime().addShutdownHook(new ShutdownHook());
+ return null;
+ });
+ } else {
+ controllers = new Controller[0];
+ }
+ }
+
+ /** Returns a list of all controllers available to this environment,
+ * or an empty array if there are no controllers in this environment.
+ * @return Returns a list of all controllers available to this environment,
+ * or an empty array if there are no controllers in this environment.
+ */
+ public final Controller[] getControllers() {
+ return controllers;
+ }
+
+ private final static Component[] createComponents(List event_components, LinuxEventDevice device) {
+ LinuxEventComponent[][] povs = new LinuxEventComponent[4][2];
+ List components = new ArrayList<>();
+ for(int i = 0; i < event_components.size(); i++) {
+ LinuxEventComponent event_component = event_components.get(i);
+ Component.Identifier identifier = event_component.getIdentifier();
+
+ if(identifier == Component.Identifier.Axis.POV) {
+ int native_code = event_component.getDescriptor().getCode();
+ switch(native_code) {
+ case NativeDefinitions.ABS_HAT0X:
+ povs[0][0] = event_component;
+ break;
+ case NativeDefinitions.ABS_HAT0Y:
+ povs[0][1] = event_component;
+ break;
+ case NativeDefinitions.ABS_HAT1X:
+ povs[1][0] = event_component;
+ break;
+ case NativeDefinitions.ABS_HAT1Y:
+ povs[1][1] = event_component;
+ break;
+ case NativeDefinitions.ABS_HAT2X:
+ povs[2][0] = event_component;
+ break;
+ case NativeDefinitions.ABS_HAT2Y:
+ povs[2][1] = event_component;
+ break;
+ case NativeDefinitions.ABS_HAT3X:
+ povs[3][0] = event_component;
+ break;
+ case NativeDefinitions.ABS_HAT3Y:
+ povs[3][1] = event_component;
+ break;
+ default:
+ log("Unknown POV instance: " + native_code);
+ break;
+ }
+ } else if(identifier != null) {
+ LinuxComponent component = new LinuxComponent(event_component);
+ components.add(component);
+ device.registerComponent(event_component.getDescriptor(), component);
+ }
+ }
+ for(int i = 0; i < povs.length; i++) {
+ LinuxEventComponent x = povs[i][0];
+ LinuxEventComponent y = povs[i][1];
+ if(x != null && y != null) {
+ LinuxComponent controller_component = new LinuxPOV(x, y);
+ components.add(controller_component);
+ device.registerComponent(x.getDescriptor(), controller_component);
+ device.registerComponent(y.getDescriptor(), controller_component);
+ }
+ }
+ Component[] components_array = new Component[components.size()];
+ components.toArray(components_array);
+ return components_array;
+ }
+
+ private final static Mouse createMouseFromDevice(LinuxEventDevice device, Component[] components) throws IOException {
+ Mouse mouse = new LinuxMouse(device, components, new Controller[]{}, device.getRumblers());
+ if(mouse.getX() != null && mouse.getY() != null && mouse.getPrimaryButton() != null)
+ return mouse;
+ else
+ return null;
+ }
+
+ private final static Keyboard createKeyboardFromDevice(LinuxEventDevice device, Component[] components) throws IOException {
+ Keyboard keyboard = new LinuxKeyboard(device, components, new Controller[]{}, device.getRumblers());
+ return keyboard;
+ }
+
+ private final static Controller createJoystickFromDevice(LinuxEventDevice device, Component[] components, Controller.Type type) throws IOException {
+ Controller joystick = new LinuxAbstractController(device, components, new Controller[]{}, device.getRumblers(), type);
+ return joystick;
+ }
+
+ private final static Controller createControllerFromDevice(LinuxEventDevice device) throws IOException {
+ List event_components = device.getComponents();
+ Component[] components = createComponents(event_components, device);
+ Controller.Type type = device.getType();
+
+ if(type == Controller.Type.MOUSE) {
+ return createMouseFromDevice(device, components);
+ } else if(type == Controller.Type.KEYBOARD) {
+ return createKeyboardFromDevice(device, components);
+ } else if(type == Controller.Type.STICK || type == Controller.Type.GAMEPAD) {
+ return createJoystickFromDevice(device, components, type);
+ } else
+ return null;
+ }
+
+ private final Controller[] enumerateControllers() {
+ List controllers = new ArrayList<>();
+ List eventControllers = new ArrayList<>();
+ List jsControllers = new ArrayList<>();
+ enumerateEventControllers(eventControllers);
+ enumerateJoystickControllers(jsControllers);
+
+ for(int i = 0; i < eventControllers.size(); i++) {
+ for(int j = 0; j < jsControllers.size(); j++) {
+ Controller evController = eventControllers.get(i);
+ Controller jsController = jsControllers.get(j);
+
+ // compare
+ // Check if the nodes have the same name
+ if(evController.getName().equals(jsController.getName())) {
+ // Check they have the same component count
+ Component[] evComponents = evController.getComponents();
+ Component[] jsComponents = jsController.getComponents();
+ if(evComponents.length == jsComponents.length) {
+ boolean foundADifference = false;
+ // check the component pairs are of the same type
+ for(int k = 0; k < evComponents.length; k++) {
+ // Check the type of the component is the same
+ if(!(evComponents[k].getIdentifier() == jsComponents[k].getIdentifier())) {
+ foundADifference = true;
+ }
+ }
+
+ if(!foundADifference) {
+ controllers.add(new LinuxCombinedController((LinuxAbstractController) eventControllers.remove(i), (LinuxJoystickAbstractController) jsControllers.remove(j)));
+ i--;
+ j--;
+ break;
+ }
+ }
+ }
+ }
+ }
+ controllers.addAll(eventControllers);
+ controllers.addAll(jsControllers);
+
+ Controller[] controllers_array = new Controller[controllers.size()];
+ controllers.toArray(controllers_array);
+ return controllers_array;
+ }
+
+ private final static Component.Identifier.Button getButtonIdentifier(int index) {
+ switch(index) {
+ case 0:
+ return Component.Identifier.Button._0;
+ case 1:
+ return Component.Identifier.Button._1;
+ case 2:
+ return Component.Identifier.Button._2;
+ case 3:
+ return Component.Identifier.Button._3;
+ case 4:
+ return Component.Identifier.Button._4;
+ case 5:
+ return Component.Identifier.Button._5;
+ case 6:
+ return Component.Identifier.Button._6;
+ case 7:
+ return Component.Identifier.Button._7;
+ case 8:
+ return Component.Identifier.Button._8;
+ case 9:
+ return Component.Identifier.Button._9;
+ case 10:
+ return Component.Identifier.Button._10;
+ case 11:
+ return Component.Identifier.Button._11;
+ case 12:
+ return Component.Identifier.Button._12;
+ case 13:
+ return Component.Identifier.Button._13;
+ case 14:
+ return Component.Identifier.Button._14;
+ case 15:
+ return Component.Identifier.Button._15;
+ case 16:
+ return Component.Identifier.Button._16;
+ case 17:
+ return Component.Identifier.Button._17;
+ case 18:
+ return Component.Identifier.Button._18;
+ case 19:
+ return Component.Identifier.Button._19;
+ case 20:
+ return Component.Identifier.Button._20;
+ case 21:
+ return Component.Identifier.Button._21;
+ case 22:
+ return Component.Identifier.Button._22;
+ case 23:
+ return Component.Identifier.Button._23;
+ case 24:
+ return Component.Identifier.Button._24;
+ case 25:
+ return Component.Identifier.Button._25;
+ case 26:
+ return Component.Identifier.Button._26;
+ case 27:
+ return Component.Identifier.Button._27;
+ case 28:
+ return Component.Identifier.Button._28;
+ case 29:
+ return Component.Identifier.Button._29;
+ case 30:
+ return Component.Identifier.Button._30;
+ case 31:
+ return Component.Identifier.Button._31;
+ default:
+ return null;
+ }
+ }
+
+ private final static Controller createJoystickFromJoystickDevice(LinuxJoystickDevice device) {
+ List components = new ArrayList<>();
+ byte[] axisMap = device.getAxisMap();
+ char[] buttonMap = device.getButtonMap();
+ LinuxJoystickAxis[] hatBits = new LinuxJoystickAxis[6];
+
+ for(int i = 0; i < device.getNumButtons(); i++) {
+ Component.Identifier button_id = LinuxNativeTypesMap.getButtonID(buttonMap[i]);
+ if(button_id != null) {
+ LinuxJoystickButton button = new LinuxJoystickButton(button_id);
+ device.registerButton(i, button);
+ components.add(button);
+ }
+ }
+ for(int i = 0; i < device.getNumAxes(); i++) {
+ Component.Identifier.Axis axis_id;
+ axis_id = (Component.Identifier.Axis) LinuxNativeTypesMap.getAbsAxisID(axisMap[i]);
+ LinuxJoystickAxis axis = new LinuxJoystickAxis(axis_id);
+
+ device.registerAxis(i, axis);
+
+ if(axisMap[i] == NativeDefinitions.ABS_HAT0X) {
+ hatBits[0] = axis;
+ } else if(axisMap[i] == NativeDefinitions.ABS_HAT0Y) {
+ hatBits[1] = axis;
+ axis = new LinuxJoystickPOV(Component.Identifier.Axis.POV, hatBits[0], hatBits[1]);
+ device.registerPOV((LinuxJoystickPOV) axis);
+ components.add(axis);
+ } else if(axisMap[i] == NativeDefinitions.ABS_HAT1X) {
+ hatBits[2] = axis;
+ } else if(axisMap[i] == NativeDefinitions.ABS_HAT1Y) {
+ hatBits[3] = axis;
+ axis = new LinuxJoystickPOV(Component.Identifier.Axis.POV, hatBits[2], hatBits[3]);
+ device.registerPOV((LinuxJoystickPOV) axis);
+ components.add(axis);
+ } else if(axisMap[i] == NativeDefinitions.ABS_HAT2X) {
+ hatBits[4] = axis;
+ } else if(axisMap[i] == NativeDefinitions.ABS_HAT2Y) {
+ hatBits[5] = axis;
+ axis = new LinuxJoystickPOV(Component.Identifier.Axis.POV, hatBits[4], hatBits[5]);
+ device.registerPOV((LinuxJoystickPOV) axis);
+ components.add(axis);
+ } else {
+ components.add(axis);
+ }
+ }
+
+ return new LinuxJoystickAbstractController(device, components.toArray(new Component[]{}), new Controller[]{}, new Rumbler[]{});
+ }
+
+ private final void enumerateJoystickControllers(List controllers) {
+ File[] joystick_device_files = enumerateJoystickDeviceFiles("/dev/input");
+ if(joystick_device_files == null || joystick_device_files.length == 0) {
+ joystick_device_files = enumerateJoystickDeviceFiles("/dev");
+ if(joystick_device_files == null)
+ return;
+ }
+ for(int i = 0; i < joystick_device_files.length; i++) {
+ File event_file = joystick_device_files[i];
+ try {
+ String path = getAbsolutePathPrivileged(event_file);
+ LinuxJoystickDevice device = new LinuxJoystickDevice(path);
+ Controller controller = createJoystickFromJoystickDevice(device);
+ if(controller != null) {
+ controllers.add(controller);
+ devices.add(device);
+ } else
+ device.close();
+ } catch(IOException e) {
+ log("Failed to open device (" + event_file + "): " + e.getMessage());
+ }
+ }
+ }
+
+ private final static File[] enumerateJoystickDeviceFiles(final String dev_path) {
+ final File dev = new File(dev_path);
+ return listFilesPrivileged(dev, new FilenameFilter() {
+ public final boolean accept(File dir, String name) {
+ return name.startsWith("js");
+ }
+ });
+ }
+
+ private static String getAbsolutePathPrivileged(final File file) {
+ return AccessController.doPrivileged((PrivilegedAction) () -> file.getAbsolutePath());
+ }
+
+ private static File[] listFilesPrivileged(final File dir, final FilenameFilter filter) {
+ return AccessController.doPrivileged((PrivilegedAction) () -> {
+ File[] files = dir.listFiles(filter);
+ if(files == null) {
+ log("dir " + dir.getName() + " exists: " + dir.exists() + ", is writable: " + dir.isDirectory());
+ files = new File[]{};
+ } else {
+ Arrays.sort(files, Comparator.comparing(File::getName));
+ }
+ return files;
+ });
+ }
+
+ private final void enumerateEventControllers(List controllers) {
+ final File dev = new File("/dev/input");
+ File[] event_device_files = listFilesPrivileged(dev, (File dir, String name) -> name.startsWith("event"));
+
+ if(event_device_files == null)
+ return;
+ for(int i = 0; i < event_device_files.length; i++) {
+ File event_file = event_device_files[i];
+ try {
+ String path = getAbsolutePathPrivileged(event_file);
+ LinuxEventDevice device = new LinuxEventDevice(path);
+ try {
+ Controller controller = createControllerFromDevice(device);
+ if(controller != null) {
+ controllers.add(controller);
+ devices.add(device);
+ } else
+ device.close();
+ } catch(IOException e) {
+ log("Failed to create Controller: " + e.getMessage());
+ device.close();
+ }
+ } catch(IOException e) {
+ log("Failed to open device (" + event_file + "): " + e.getMessage());
+ }
+ }
+ }
+
+ private final class ShutdownHook extends Thread {
+ public final void run() {
+ for(int i = 0; i < devices.size(); i++) {
+ try {
+ LinuxDevice device = devices.get(i);
+ device.close();
+ } catch(IOException e) {
+ log("Failed to close device: " + e.getMessage());
+ }
+ }
+ }
+ }
+
+ public boolean isSupported() {
+ return supported;
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxEvent.java b/src/plugins/linux/net/java/games/input/LinuxEvent.java
new file mode 100644
index 0000000..de2959c
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxEvent.java
@@ -0,0 +1,53 @@
+/**
+ * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+/**
+ * @author elias
+ */
+final class LinuxEvent {
+ private long nanos;
+ private final LinuxAxisDescriptor descriptor = new LinuxAxisDescriptor();
+ private int value;
+
+ public final void set(long seconds, long microseconds, int type, int code, int value) {
+ this.nanos = (seconds*1000000 + microseconds)*1000;
+ this.descriptor.set(type, code);
+ this.value = value;
+ }
+
+ public final int getValue() {
+ return value;
+ }
+
+ public final LinuxAxisDescriptor getDescriptor() {
+ return descriptor;
+ }
+
+ public final long getNanos() {
+ return nanos;
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxEventComponent.java b/src/plugins/linux/net/java/games/input/LinuxEventComponent.java
new file mode 100644
index 0000000..b2ad562
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxEventComponent.java
@@ -0,0 +1,115 @@
+/**
+ * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+import java.io.IOException;
+
+/**
+ * @author elias
+ * @author Jeremy Booth (jeremy@newdawnsoftware.com)
+ */
+final class LinuxEventComponent {
+ private final LinuxEventDevice device;
+ private final Component.Identifier identifier;
+ private final Controller.Type button_trait;
+ private final boolean is_relative;
+ private final LinuxAxisDescriptor descriptor;
+ private final int min;
+ private final int max;
+ private final int flat;
+
+
+ public LinuxEventComponent(LinuxEventDevice device, Component.Identifier identifier, boolean is_relative, int native_type, int native_code) throws IOException {
+ this.device = device;
+ this.identifier = identifier;
+ if (native_type == NativeDefinitions.EV_KEY)
+ this.button_trait = LinuxNativeTypesMap.guessButtonTrait(native_code);
+ else
+ this.button_trait = Controller.Type.UNKNOWN;
+ this.is_relative = is_relative;
+ this.descriptor = new LinuxAxisDescriptor();
+ descriptor.set(native_type, native_code);
+ if (native_type == NativeDefinitions.EV_ABS) {
+ LinuxAbsInfo abs_info = new LinuxAbsInfo();
+ getAbsInfo(abs_info);
+ this.min = abs_info.getMin();
+ this.max = abs_info.getMax();
+ this.flat = abs_info.getFlat();
+ } else {
+ this.min = Integer.MIN_VALUE;
+ this.max = Integer.MAX_VALUE;
+ this.flat = 0;
+ }
+ }
+
+ public final LinuxEventDevice getDevice() {
+ return device;
+ }
+
+ public final void getAbsInfo(LinuxAbsInfo abs_info) throws IOException {
+ assert descriptor.getType() == NativeDefinitions.EV_ABS;
+ device.getAbsInfo(descriptor.getCode(), abs_info);
+ }
+
+ public final Controller.Type getButtonTrait() {
+ return button_trait;
+ }
+
+ public final Component.Identifier getIdentifier() {
+ return identifier;
+ }
+
+ public final LinuxAxisDescriptor getDescriptor() {
+ return descriptor;
+ }
+
+ public final boolean isRelative() {
+ return is_relative;
+ }
+
+ public final boolean isAnalog() {
+ return identifier instanceof Component.Identifier.Axis && identifier != Component.Identifier.Axis.POV;
+ }
+
+ final float convertValue(float value) {
+ if (identifier instanceof Component.Identifier.Axis && !is_relative) {
+ // Some axes have min = max = 0
+ if (min == max)
+ return 0;
+ if (value > max)
+ value = max;
+ else if (value < min)
+ value = min;
+ return 2*(value - min)/(max - min) - 1;
+ } else {
+ return value;
+ }
+ }
+
+ final float getDeadZone() {
+ return flat/(2f*(max - min));
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxEventDevice.java b/src/plugins/linux/net/java/games/input/LinuxEventDevice.java
new file mode 100644
index 0000000..a69f9e8
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxEventDevice.java
@@ -0,0 +1,367 @@
+/*
+ * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author elias
+ */
+final class LinuxEventDevice implements LinuxDevice {
+ private final Map component_map = new HashMap<>();
+ private final Rumbler[] rumblers;
+ private final long fd;
+ private final String name;
+ private final LinuxInputID input_id;
+ private final List components;
+ private final Controller.Type type;
+
+ /* Closed state variable that protects the validity of the file descriptor.
+ * Access to the closed state must be synchronized
+ */
+ private boolean closed;
+
+ /* Access to the key_states array could be synchronized, but
+ * it doesn't hurt to have multiple threads read/write from/to it
+ */
+ private final byte[] key_states = new byte[NativeDefinitions.KEY_MAX/8 + 1];
+
+ public LinuxEventDevice(String filename) throws IOException {
+ long fd;
+ boolean detect_rumblers = true;
+ try {
+ fd = nOpen(filename, true);
+ } catch (IOException e) {
+ fd = nOpen(filename, false);
+ detect_rumblers = false;
+ }
+ this.fd = fd;
+ try {
+ this.name = getDeviceName();
+ this.input_id = getDeviceInputID();
+ this.components = getDeviceComponents();
+ if (detect_rumblers)
+ this.rumblers = enumerateRumblers();
+ else
+ this.rumblers = new Rumbler[]{};
+ this.type = guessType();
+ } catch (IOException e) {
+ close();
+ throw e;
+ }
+ }
+ private final static native long nOpen(String filename, boolean rw) throws IOException;
+
+ public final Controller.Type getType() {
+ return type;
+ }
+
+ private final static int countComponents(List components, Class> id_type, boolean relative) {
+ int count = 0;
+ for (int i = 0; i < components.size(); i++) {
+ LinuxEventComponent component = components.get(i);
+ if (id_type.isInstance(component.getIdentifier()) && relative == component.isRelative())
+ count++;
+ }
+ return count;
+ }
+
+ private final Controller.Type guessType() throws IOException {
+ List components = getComponents();
+ if (components.size() == 0)
+ return Controller.Type.UNKNOWN;
+ int num_rel_axes = countComponents(components, Component.Identifier.Axis.class, true);
+ int num_abs_axes = countComponents(components, Component.Identifier.Axis.class, false);
+ int num_keys = countComponents(components, Component.Identifier.Key.class, false);
+ int mouse_traits = 0;
+ int keyboard_traits = 0;
+ int joystick_traits = 0;
+ int gamepad_traits = 0;
+ if (name.toLowerCase().indexOf("mouse") != -1)
+ mouse_traits++;
+ if (name.toLowerCase().indexOf("keyboard") != -1)
+ keyboard_traits++;
+ if (name.toLowerCase().indexOf("joystick") != -1)
+ joystick_traits++;
+ if (name.toLowerCase().indexOf("gamepad") != -1)
+ gamepad_traits++;
+ int num_keyboard_button_traits = 0;
+ int num_mouse_button_traits = 0;
+ int num_joystick_button_traits = 0;
+ int num_gamepad_button_traits = 0;
+ // count button traits
+ for (int i = 0; i < components.size(); i++) {
+ LinuxEventComponent component = components.get(i);
+ if (component.getButtonTrait() == Controller.Type.MOUSE)
+ num_mouse_button_traits++;
+ else if (component.getButtonTrait() == Controller.Type.KEYBOARD)
+ num_keyboard_button_traits++;
+ else if (component.getButtonTrait() == Controller.Type.GAMEPAD)
+ num_gamepad_button_traits++;
+ else if (component.getButtonTrait() == Controller.Type.STICK)
+ num_joystick_button_traits++;
+ }
+ if ((num_mouse_button_traits >= num_keyboard_button_traits) && (num_mouse_button_traits >= num_joystick_button_traits) && (num_mouse_button_traits >= num_gamepad_button_traits)) {
+ mouse_traits++;
+ } else if ((num_keyboard_button_traits >= num_mouse_button_traits) && (num_keyboard_button_traits >= num_joystick_button_traits) && (num_keyboard_button_traits >= num_gamepad_button_traits)) {
+ keyboard_traits++;
+ } else if ((num_joystick_button_traits >= num_keyboard_button_traits) && (num_joystick_button_traits >= num_mouse_button_traits) && (num_joystick_button_traits >= num_gamepad_button_traits)) {
+ joystick_traits++;
+ } else if ((num_gamepad_button_traits >= num_keyboard_button_traits) && (num_gamepad_button_traits >= num_mouse_button_traits) && (num_gamepad_button_traits >= num_joystick_button_traits)) {
+ gamepad_traits++;
+ }
+ if (num_rel_axes >= 2) {
+ mouse_traits++;
+ }
+ if (num_abs_axes >= 2) {
+ joystick_traits++;
+ gamepad_traits++;
+ }
+
+ if ((mouse_traits >= keyboard_traits) && (mouse_traits >= joystick_traits) && (mouse_traits >= gamepad_traits)) {
+ return Controller.Type.MOUSE;
+ } else if ((keyboard_traits >= mouse_traits) && (keyboard_traits >= joystick_traits) && (keyboard_traits >= gamepad_traits)) {
+ return Controller.Type.KEYBOARD;
+ } else if ((joystick_traits >= mouse_traits) && (joystick_traits >= keyboard_traits) && (joystick_traits >= gamepad_traits)) {
+ return Controller.Type.STICK;
+ } else if ((gamepad_traits >= mouse_traits) && (gamepad_traits >= keyboard_traits) && (gamepad_traits >= joystick_traits)) {
+ return Controller.Type.GAMEPAD;
+ } else
+ return null;
+ }
+
+ private final Rumbler[] enumerateRumblers() {
+ List rumblers = new ArrayList<>();
+ try {
+ int num_effects = getNumEffects();
+ if (num_effects <= 0)
+ return rumblers.toArray(new Rumbler[]{});
+ byte[] ff_bits = getForceFeedbackBits();
+ if (isBitSet(ff_bits, NativeDefinitions.FF_RUMBLE) && num_effects > rumblers.size()) {
+ rumblers.add(new LinuxRumbleFF(this));
+ }
+ } catch (IOException e) {
+ LinuxEnvironmentPlugin.log("Failed to enumerate rumblers: " + e.getMessage());
+ }
+ return rumblers.toArray(new Rumbler[]{});
+ }
+
+ public final Rumbler[] getRumblers() {
+ return rumblers;
+ }
+
+ public final synchronized int uploadRumbleEffect(int id, int trigger_button, int direction, int trigger_interval, int replay_length, int replay_delay, int strong_magnitude, int weak_magnitude) throws IOException {
+ checkClosed();
+ return nUploadRumbleEffect(fd, id, direction, trigger_button, trigger_interval, replay_length, replay_delay, strong_magnitude, weak_magnitude);
+ }
+ private final static native int nUploadRumbleEffect(long fd, int id, int direction, int trigger_button, int trigger_interval, int replay_length, int replay_delay, int strong_magnitude, int weak_magnitude) throws IOException;
+
+ public final synchronized int uploadConstantEffect(int id, int trigger_button, int direction, int trigger_interval, int replay_length, int replay_delay, int constant_level, int constant_env_attack_length, int constant_env_attack_level, int constant_env_fade_length, int constant_env_fade_level) throws IOException {
+ checkClosed();
+ return nUploadConstantEffect(fd, id, direction, trigger_button, trigger_interval, replay_length, replay_delay, constant_level, constant_env_attack_length, constant_env_attack_level, constant_env_fade_length, constant_env_fade_level);
+ }
+ private final static native int nUploadConstantEffect(long fd, int id, int direction, int trigger_button, int trigger_interval, int replay_length, int replay_delay, int constant_level, int constant_env_attack_length, int constant_env_attack_level, int constant_env_fade_length, int constant_env_fade_level) throws IOException;
+
+ final void eraseEffect(int id) throws IOException {
+ nEraseEffect(fd, id);
+ }
+ private final static native void nEraseEffect(long fd, int ff_id) throws IOException;
+
+ public final synchronized void writeEvent(int type, int code, int value) throws IOException {
+ checkClosed();
+ nWriteEvent(fd, type, code, value);
+ }
+ private final static native void nWriteEvent(long fd, int type, int code, int value) throws IOException;
+
+ public final void registerComponent(LinuxAxisDescriptor desc, LinuxComponent component) {
+ component_map.put(desc, component);
+ }
+
+ public final LinuxComponent mapDescriptor(LinuxAxisDescriptor desc) {
+ return component_map.get(desc);
+ }
+
+ public final Controller.PortType getPortType() throws IOException {
+ return input_id.getPortType();
+ }
+
+ public final LinuxInputID getInputID() {
+ return input_id;
+ }
+
+ private final LinuxInputID getDeviceInputID() throws IOException {
+ return nGetInputID(fd);
+ }
+ private final static native LinuxInputID nGetInputID(long fd) throws IOException;
+
+ public final int getNumEffects() throws IOException {
+ return nGetNumEffects(fd);
+ }
+ private final static native int nGetNumEffects(long fd) throws IOException;
+
+ private final int getVersion() throws IOException {
+ return nGetVersion(fd);
+ }
+ private final static native int nGetVersion(long fd) throws IOException;
+
+ public final synchronized boolean getNextEvent(LinuxEvent linux_event) throws IOException {
+ checkClosed();
+ return nGetNextEvent(fd, linux_event);
+ }
+ private final static native boolean nGetNextEvent(long fd, LinuxEvent linux_event) throws IOException;
+
+ public final synchronized void getAbsInfo(int abs_axis, LinuxAbsInfo abs_info) throws IOException {
+ checkClosed();
+ nGetAbsInfo(fd, abs_axis, abs_info);
+ }
+ private final static native void nGetAbsInfo(long fd, int abs_axis, LinuxAbsInfo abs_info) throws IOException;
+
+ private final void addKeys(List components) throws IOException {
+ byte[] bits = getKeysBits();
+ for (int i = 0; i < bits.length*8; i++) {
+ if (isBitSet(bits, i)) {
+ Component.Identifier id = LinuxNativeTypesMap.getButtonID(i);
+ components.add(new LinuxEventComponent(this, id, false, NativeDefinitions.EV_KEY, i));
+ }
+ }
+ }
+
+ private final void addAbsoluteAxes(List components) throws IOException {
+ byte[] bits = getAbsoluteAxesBits();
+ for (int i = 0; i < bits.length*8; i++) {
+ if (isBitSet(bits, i)) {
+ Component.Identifier id = LinuxNativeTypesMap.getAbsAxisID(i);
+ components.add(new LinuxEventComponent(this, id, false, NativeDefinitions.EV_ABS, i));
+ }
+ }
+ }
+
+ private final void addRelativeAxes(List components) throws IOException {
+ byte[] bits = getRelativeAxesBits();
+ for (int i = 0; i < bits.length*8; i++) {
+ if (isBitSet(bits, i)) {
+ Component.Identifier id = LinuxNativeTypesMap.getRelAxisID(i);
+ components.add(new LinuxEventComponent(this, id, true, NativeDefinitions.EV_REL, i));
+ }
+ }
+ }
+
+ public final List getComponents() {
+ return components;
+ }
+
+ private final List getDeviceComponents() throws IOException {
+ List components = new ArrayList<>();
+ byte[] evtype_bits = getEventTypeBits();
+ if (isBitSet(evtype_bits, NativeDefinitions.EV_KEY))
+ addKeys(components);
+ if (isBitSet(evtype_bits, NativeDefinitions.EV_ABS))
+ addAbsoluteAxes(components);
+ if (isBitSet(evtype_bits, NativeDefinitions.EV_REL))
+ addRelativeAxes(components);
+ return components;
+ }
+
+ private final byte[] getForceFeedbackBits() throws IOException {
+ byte[] bits = new byte[NativeDefinitions.FF_MAX/8 + 1];
+ nGetBits(fd, NativeDefinitions.EV_FF, bits);
+ return bits;
+ }
+
+ private final byte[] getKeysBits() throws IOException {
+ byte[] bits = new byte[NativeDefinitions.KEY_MAX/8 + 1];
+ nGetBits(fd, NativeDefinitions.EV_KEY, bits);
+ return bits;
+ }
+
+ private final byte[] getAbsoluteAxesBits() throws IOException {
+ byte[] bits = new byte[NativeDefinitions.ABS_MAX/8 + 1];
+ nGetBits(fd, NativeDefinitions.EV_ABS, bits);
+ return bits;
+ }
+
+ private final byte[] getRelativeAxesBits() throws IOException {
+ byte[] bits = new byte[NativeDefinitions.REL_MAX/8 + 1];
+ nGetBits(fd, NativeDefinitions.EV_REL, bits);
+ return bits;
+ }
+
+ private final byte[] getEventTypeBits() throws IOException {
+ byte[] bits = new byte[NativeDefinitions.EV_MAX/8 + 1];
+ nGetBits(fd, 0, bits);
+ return bits;
+ }
+ private final static native void nGetBits(long fd, int ev_type, byte[] evtype_bits) throws IOException;
+
+ public final synchronized void pollKeyStates() throws IOException {
+ nGetKeyStates(fd, key_states);
+ }
+ private final static native void nGetKeyStates(long fd, byte[] states) throws IOException;
+
+ public final boolean isKeySet(int bit) {
+ return isBitSet(key_states, bit);
+ }
+
+ public final static boolean isBitSet(byte[] bits, int bit) {
+ return (bits[bit/8] & (1<<(bit%8))) != 0;
+ }
+
+ public final String getName() {
+ return name;
+ }
+
+ private final String getDeviceName() throws IOException {
+ return nGetName(fd);
+ }
+ private final static native String nGetName(long fd) throws IOException;
+
+ public synchronized final void close() throws IOException {
+ if (closed)
+ return;
+ closed = true;
+ LinuxEnvironmentPlugin.execute(new LinuxDeviceTask() {
+ protected final Object execute() throws IOException {
+ nClose(fd);
+ return null;
+ }
+ });
+ }
+ private final static native void nClose(long fd) throws IOException;
+
+ private final void checkClosed() throws IOException {
+ if (closed)
+ throw new IOException("Device is closed");
+ }
+
+ @SuppressWarnings("deprecation")
+ protected void finalize() throws IOException {
+ close();
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxForceFeedbackEffect.java b/src/plugins/linux/net/java/games/input/LinuxForceFeedbackEffect.java
new file mode 100644
index 0000000..3d134ba
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxForceFeedbackEffect.java
@@ -0,0 +1,110 @@
+/**
+ * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+import java.io.IOException;
+
+/**
+ * @author elias
+ */
+abstract class LinuxForceFeedbackEffect implements Rumbler {
+ private final LinuxEventDevice device;
+ private final int ff_id;
+ private final WriteTask write_task = new WriteTask();
+ private final UploadTask upload_task = new UploadTask();
+
+ public LinuxForceFeedbackEffect(LinuxEventDevice device) throws IOException {
+ this.device = device;
+ this.ff_id = upload_task.doUpload(-1, 0);
+ }
+
+ protected abstract int upload(int id, float intensity) throws IOException;
+
+ protected final LinuxEventDevice getDevice() {
+ return device;
+ }
+
+ public synchronized final void rumble(float intensity) {
+ try {
+ if (intensity > 0) {
+ upload_task.doUpload(ff_id, intensity);
+ write_task.write(1);
+ } else {
+ write_task.write(0);
+ }
+ } catch (IOException e) {
+ LinuxEnvironmentPlugin.log("Failed to rumble: " + e);
+ }
+ }
+
+ /*
+ * Erase doesn't seem to be implemented on Logitech joysticks,
+ * so we'll rely on the kernel cleaning up on device close
+ */
+/*
+ public final void erase() throws IOException {
+ device.eraseEffect(ff_id);
+ }
+*/
+ public final String getAxisName() {
+ return null;
+ }
+
+ public final Component.Identifier getAxisIdentifier() {
+ return null;
+ }
+
+ private final class UploadTask extends LinuxDeviceTask {
+ private int id;
+ private float intensity;
+
+ public final int doUpload(int id, float intensity) throws IOException {
+ this.id = id;
+ this.intensity = intensity;
+ LinuxEnvironmentPlugin.execute(this);
+ return this.id;
+ }
+
+ protected final Object execute() throws IOException {
+ this.id = upload(id, intensity);
+ return null;
+ }
+ }
+
+ private final class WriteTask extends LinuxDeviceTask {
+ private int value;
+
+ public final void write(int value) throws IOException {
+ this.value = value;
+ LinuxEnvironmentPlugin.execute(this);
+ }
+
+ protected final Object execute() throws IOException {
+ device.writeEvent(NativeDefinitions.EV_FF, ff_id, value);
+ return null;
+ }
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxInputID.java b/src/plugins/linux/net/java/games/input/LinuxInputID.java
new file mode 100644
index 0000000..bed8fd3
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxInputID.java
@@ -0,0 +1,52 @@
+/**
+ * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+/**
+ * @author elias
+ */
+final class LinuxInputID {
+ private final int bustype;
+ private final int vendor;
+ private final int product;
+ private final int version;
+
+ public LinuxInputID(int bustype, int vendor, int product, int version) {
+ this.bustype = bustype;
+ this.vendor = vendor;
+ this.product = product;
+ this.version = version;
+ }
+
+ public final Controller.PortType getPortType() {
+ return LinuxNativeTypesMap.getPortType(bustype);
+ }
+
+ public final String toString() {
+ return "LinuxInputID: bustype = 0x" + Integer.toHexString(bustype) + " | vendor = 0x" + Integer.toHexString(vendor) +
+ " | product = 0x" + Integer.toHexString(product) + " | version = 0x" + Integer.toHexString(version);
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxJoystickAbstractController.java b/src/plugins/linux/net/java/games/input/LinuxJoystickAbstractController.java
new file mode 100644
index 0000000..36633ad
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxJoystickAbstractController.java
@@ -0,0 +1,70 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Represents a Linux controller
+* @author elias
+* @version 1.0
+*/
+final class LinuxJoystickAbstractController extends AbstractController {
+ private final LinuxJoystickDevice device;
+
+ protected LinuxJoystickAbstractController(LinuxJoystickDevice device, Component[] components, Controller[] children, Rumbler[] rumblers) {
+ super(device.getName(), components, children, rumblers);
+ this.device = device;
+ }
+
+ protected final void setDeviceEventQueueSize(int size) throws IOException {
+ device.setBufferSize(size);
+ }
+
+ public final void pollDevice() throws IOException {
+ device.poll();
+ }
+
+ protected final boolean getNextDeviceEvent(Event event) throws IOException {
+ return device.getNextEvent(event);
+ }
+
+ public Type getType() {
+ return Controller.Type.STICK;
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxJoystickAxis.java b/src/plugins/linux/net/java/games/input/LinuxJoystickAxis.java
new file mode 100644
index 0000000..47adc99
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxJoystickAxis.java
@@ -0,0 +1,76 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Represents a linux Axis
+* @author elias
+* @version 1.0
+*/
+class LinuxJoystickAxis extends AbstractComponent {
+ private float value;
+ private boolean analog;
+
+ public LinuxJoystickAxis(Component.Identifier.Axis axis_id) {
+ this(axis_id, true);
+ }
+
+ public LinuxJoystickAxis(Component.Identifier.Axis axis_id, boolean analog) {
+ super(axis_id.getName(), axis_id);
+ this.analog = analog;
+ }
+
+ public final boolean isRelative() {
+ return false;
+ }
+
+ public final boolean isAnalog() {
+ return analog;
+ }
+
+ final void setValue(float value) {
+ this.value = value;
+ resetHasPolled();
+ }
+
+ protected final float poll() throws IOException {
+ return value;
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxJoystickButton.java b/src/plugins/linux/net/java/games/input/LinuxJoystickButton.java
new file mode 100644
index 0000000..e0a3b3d
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxJoystickButton.java
@@ -0,0 +1,65 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Represents a linux button from the joystick interface
+* @author elias
+* @version 1.0
+*/
+final class LinuxJoystickButton extends AbstractComponent {
+ private float value;
+
+ public LinuxJoystickButton(Component.Identifier button_id) {
+ super(button_id.getName(), button_id);
+ }
+
+ public final boolean isRelative() {
+ return false;
+ }
+
+ final void setValue(float value) {
+ this.value = value;
+ }
+
+ protected final float poll() throws IOException {
+ return value;
+ }
+}
diff --git a/src/plugins/linux/net/java/games/input/LinuxJoystickDevice.java b/src/plugins/linux/net/java/games/input/LinuxJoystickDevice.java
new file mode 100644
index 0000000..c749684
--- /dev/null
+++ b/src/plugins/linux/net/java/games/input/LinuxJoystickDevice.java
@@ -0,0 +1,238 @@
+/*
+ * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author elias
+ */
+final class LinuxJoystickDevice implements LinuxDevice {
+ public final static int JS_EVENT_BUTTON = 0x01; /* button pressed/released */
+ public final static int JS_EVENT_AXIS = 0x02; /* joystick moved */
+ public final static int JS_EVENT_INIT = 0x80; /* initial state of device */
+
+ public final static int AXIS_MAX_VALUE = 32767;
+
+ private final long fd;
+ private final String name;
+
+ private final LinuxJoystickEvent joystick_event = new LinuxJoystickEvent();
+ private final Event event = new Event();
+ private final LinuxJoystickButton[] buttons;
+ private final LinuxJoystickAxis[] axes;
+ private final Map povXs = new HashMap<>();
+ private final Map povYs = new HashMap<>();
+ private final byte[] axisMap;
+ private final char[] buttonMap;
+
+ private EventQueue event_queue;
+
+ /* Closed state variable that protects the validity of the file descriptor.
+ * Access to the closed state must be synchronized
+ */
+ private boolean closed;
+
+ public LinuxJoystickDevice(String filename) throws IOException {
+ this.fd = nOpen(filename);
+ try {
+ this.name = getDeviceName();
+ setBufferSize(AbstractController.EVENT_QUEUE_DEPTH);
+ buttons = new LinuxJoystickButton[getNumDeviceButtons()];
+ axes = new LinuxJoystickAxis[getNumDeviceAxes()];
+ axisMap = getDeviceAxisMap();
+ buttonMap = getDeviceButtonMap();
+ } catch (IOException e) {
+ close();
+ throw e;
+ }
+ }
+ private final static native long nOpen(String filename) throws IOException;
+
+ public final synchronized void setBufferSize(int size) {
+ event_queue = new EventQueue(size);
+ }
+
+ private final void processEvent(LinuxJoystickEvent joystick_event) {
+ int index = joystick_event.getNumber();
+ // Filter synthetic init event flag
+ int type = joystick_event.getType() & ~JS_EVENT_INIT;
+ switch (type) {
+ case JS_EVENT_BUTTON:
+ if (index < getNumButtons()) {
+ LinuxJoystickButton button = buttons[index];
+ if (button != null) {
+ float value = joystick_event.getValue();
+ button.setValue(value);
+ event.set(button, value, joystick_event.getNanos());
+ break;
+ }
+ }
+ return;
+ case JS_EVENT_AXIS:
+ if (index < getNumAxes()) {
+ LinuxJoystickAxis axis = axes[index];
+ if (axis != null) {
+ float value = (float)joystick_event.getValue()/AXIS_MAX_VALUE;
+ axis.setValue(value);
+ if(povXs.containsKey(index)) {
+ LinuxJoystickPOV pov = povXs.get(index);
+ pov.updateValue();
+ event.set(pov, pov.getPollData(), joystick_event.getNanos());
+ } else if(povYs.containsKey(index)) {
+ LinuxJoystickPOV pov = povYs.get(index);
+ pov.updateValue();
+ event.set(pov, pov.getPollData(), joystick_event.getNanos());
+ } else {
+ event.set(axis, value, joystick_event.getNanos());
+ }
+ break;
+ }
+ }
+ return;
+ default:
+ // Unknown component type
+ return;
+ }
+ if (!event_queue.isFull()) {
+ event_queue.add(event);
+ }
+ }
+
+ public final void registerAxis(int index, LinuxJoystickAxis axis) {
+ axes[index] = axis;
+ }
+
+ public final void registerButton(int index, LinuxJoystickButton button) {
+ buttons[index] = button;
+ }
+
+ public final void registerPOV(LinuxJoystickPOV pov) {
+ // The x and y on a joystick device are not the same as on an event device
+ LinuxJoystickAxis xAxis = pov.getYAxis();
+ LinuxJoystickAxis yAxis = pov.getXAxis();
+ int xIndex;
+ int yIndex;
+ for(xIndex=0;xIndex map = new HashMap<>();
+
+ private final int button_id;
+
+ public final static ButtonUsage map(int button_id) {
+ Integer button_id_obj = button_id;
+ ButtonUsage existing = map.get(button_id_obj);
+ if (existing != null)
+ return existing;
+ ButtonUsage new_button = new ButtonUsage(button_id);
+ map.put(button_id_obj, new_button);
+ return new_button;
+ }
+
+ private ButtonUsage(int button_id) {
+ this.button_id = button_id;
+ }
+
+ public final Component.Identifier.Button getIdentifier() {
+ switch (button_id) {
+ case 1:
+ return Component.Identifier.Button._0;
+ case 2:
+ return Component.Identifier.Button._1;
+ case 3:
+ return Component.Identifier.Button._2;
+ case 4:
+ return Component.Identifier.Button._3;
+ case 5:
+ return Component.Identifier.Button._4;
+ case 6:
+ return Component.Identifier.Button._5;
+ case 7:
+ return Component.Identifier.Button._6;
+ case 8:
+ return Component.Identifier.Button._7;
+ case 9:
+ return Component.Identifier.Button._8;
+ case 10:
+ return Component.Identifier.Button._9;
+ case 11:
+ return Component.Identifier.Button._10;
+ case 12:
+ return Component.Identifier.Button._11;
+ case 13:
+ return Component.Identifier.Button._12;
+ case 14:
+ return Component.Identifier.Button._13;
+ case 15:
+ return Component.Identifier.Button._14;
+ case 16:
+ return Component.Identifier.Button._15;
+ case 17:
+ return Component.Identifier.Button._16;
+ case 18:
+ return Component.Identifier.Button._17;
+ case 19:
+ return Component.Identifier.Button._18;
+ case 20:
+ return Component.Identifier.Button._19;
+ case 21:
+ return Component.Identifier.Button._20;
+ case 22:
+ return Component.Identifier.Button._21;
+ case 23:
+ return Component.Identifier.Button._22;
+ case 24:
+ return Component.Identifier.Button._23;
+ case 25:
+ return Component.Identifier.Button._24;
+ case 26:
+ return Component.Identifier.Button._25;
+ case 27:
+ return Component.Identifier.Button._26;
+ case 28:
+ return Component.Identifier.Button._27;
+ case 29:
+ return Component.Identifier.Button._28;
+ case 30:
+ return Component.Identifier.Button._29;
+ case 31:
+ return Component.Identifier.Button._30;
+ case 32:
+ return Component.Identifier.Button._31;
+ default:
+ return null;
+ }
+ }
+
+ public final String toString() {
+ return "ButtonUsage (" + button_id + ")";
+ }
+}
diff --git a/src/plugins/osx/net/java/games/input/ElementType.java b/src/plugins/osx/net/java/games/input/ElementType.java
new file mode 100644
index 0000000..efc303f
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/ElementType.java
@@ -0,0 +1,74 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.lang.reflect.Method;
+
+/** HID Element types
+* @author elias
+* @version 1.0
+*/
+final class ElementType {
+ private final static ElementType[] map = new ElementType[514];
+
+ public final static ElementType INPUT_MISC = new ElementType(1);
+ public final static ElementType INPUT_BUTTON = new ElementType(2);
+ public final static ElementType INPUT_AXIS = new ElementType(3);
+ public final static ElementType INPUT_SCANCODES = new ElementType(4);
+ public final static ElementType OUTPUT = new ElementType(129);
+ public final static ElementType FEATURE = new ElementType(257);
+ public final static ElementType COLLECTION = new ElementType(513);
+
+ private final int type_id;
+
+ public final static ElementType map(int type_id) {
+ if (type_id < 0 || type_id >= map.length)
+ return null;
+ return map[type_id];
+ }
+
+ private ElementType(int type_id) {
+ map[type_id] = this;
+ this.type_id = type_id;
+ }
+
+ public final String toString() {
+ return "ElementType (0x" + Integer.toHexString(type_id) + ")";
+ }
+}
diff --git a/src/plugins/osx/net/java/games/input/GenericDesktopUsage.java b/src/plugins/osx/net/java/games/input/GenericDesktopUsage.java
new file mode 100644
index 0000000..4049d68
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/GenericDesktopUsage.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ */
+package net.java.games.input;
+
+/** Generic Desktop Usages
+* @author elias
+* @version 1.0
+*/
+final class GenericDesktopUsage implements Usage {
+ private final static GenericDesktopUsage[] map = new GenericDesktopUsage[0xFF];
+
+ public final static GenericDesktopUsage POINTER = new GenericDesktopUsage(0x01); /* Physical Collection */
+ public final static GenericDesktopUsage MOUSE = new GenericDesktopUsage(0x02); /* Application Collection */
+ /* 0x03 Reserved */
+ public final static GenericDesktopUsage JOYSTICK = new GenericDesktopUsage(0x04); /* Application Collection */
+ public final static GenericDesktopUsage GAME_PAD = new GenericDesktopUsage(0x05); /* Application Collection */
+ public final static GenericDesktopUsage KEYBOARD = new GenericDesktopUsage(0x06); /* Application Collection */
+ public final static GenericDesktopUsage KEYPAD = new GenericDesktopUsage(0x07); /* Application Collection */
+ public final static GenericDesktopUsage MULTI_AXIS_CONTROLLER = new GenericDesktopUsage(0x08); /* Application Collection */
+ /* 0x09 - 0x2F Reserved */
+ public final static GenericDesktopUsage X = new GenericDesktopUsage(0x30); /* Dynamic Value */
+ public final static GenericDesktopUsage Y = new GenericDesktopUsage(0x31); /* Dynamic Value */
+ public final static GenericDesktopUsage Z = new GenericDesktopUsage(0x32); /* Dynamic Value */
+ public final static GenericDesktopUsage RX = new GenericDesktopUsage(0x33); /* Dynamic Value */
+ public final static GenericDesktopUsage RY = new GenericDesktopUsage(0x34); /* Dynamic Value */
+ public final static GenericDesktopUsage RZ = new GenericDesktopUsage(0x35); /* Dynamic Value */
+ public final static GenericDesktopUsage SLIDER = new GenericDesktopUsage(0x36); /* Dynamic Value */
+ public final static GenericDesktopUsage DIAL = new GenericDesktopUsage(0x37); /* Dynamic Value */
+ public final static GenericDesktopUsage WHEEL = new GenericDesktopUsage(0x38); /* Dynamic Value */
+ public final static GenericDesktopUsage HATSWITCH = new GenericDesktopUsage(0x39); /* Dynamic Value */
+ public final static GenericDesktopUsage COUNTED_BUFFER = new GenericDesktopUsage(0x3A); /* Logical Collection */
+ public final static GenericDesktopUsage BYTE_COUNT = new GenericDesktopUsage(0x3B); /* Dynamic Value */
+ public final static GenericDesktopUsage MOTION_WAKEUP = new GenericDesktopUsage(0x3C); /* One-Shot Control */
+ public final static GenericDesktopUsage START = new GenericDesktopUsage(0x3D); /* On/Off Control */
+ public final static GenericDesktopUsage SELECT = new GenericDesktopUsage(0x3E); /* On/Off Control */
+ /* 0x3F Reserved */
+ public final static GenericDesktopUsage VX = new GenericDesktopUsage(0x40); /* Dynamic Value */
+ public final static GenericDesktopUsage VY = new GenericDesktopUsage(0x41); /* Dynamic Value */
+ public final static GenericDesktopUsage VZ = new GenericDesktopUsage(0x42); /* Dynamic Value */
+ public final static GenericDesktopUsage VBRX = new GenericDesktopUsage(0x43); /* Dynamic Value */
+ public final static GenericDesktopUsage VBRY = new GenericDesktopUsage(0x44); /* Dynamic Value */
+ public final static GenericDesktopUsage VBRZ = new GenericDesktopUsage(0x45); /* Dynamic Value */
+ public final static GenericDesktopUsage VNO = new GenericDesktopUsage(0x46); /* Dynamic Value */
+ /* 0x47 - 0x7F Reserved */
+ public final static GenericDesktopUsage SYSTEM_CONTROL = new GenericDesktopUsage(0x80); /* Application Collection */
+ public final static GenericDesktopUsage SYSTEM_POWER_DOWN = new GenericDesktopUsage(0x81); /* One-Shot Control */
+ public final static GenericDesktopUsage SYSTEM_SLEEP = new GenericDesktopUsage(0x82); /* One-Shot Control */
+ public final static GenericDesktopUsage SYSTEM_WAKE_UP = new GenericDesktopUsage(0x83); /* One-Shot Control */
+ public final static GenericDesktopUsage SYSTEM_CONTEXT_MENU = new GenericDesktopUsage(0x84); /* One-Shot Control */
+ public final static GenericDesktopUsage SYSTEM_MAIN_MENU = new GenericDesktopUsage(0x85); /* One-Shot Control */
+ public final static GenericDesktopUsage SYSTEM_APP_MENU = new GenericDesktopUsage(0x86); /* One-Shot Control */
+ public final static GenericDesktopUsage SYSTEM_MENU_HELP = new GenericDesktopUsage(0x87); /* One-Shot Control */
+ public final static GenericDesktopUsage SYSTEM_MENU_EXIT = new GenericDesktopUsage(0x88); /* One-Shot Control */
+ public final static GenericDesktopUsage SYSTEM_MENU = new GenericDesktopUsage(0x89); /* Selector */
+ public final static GenericDesktopUsage SYSTEM_MENU_RIGHT = new GenericDesktopUsage(0x8A); /* Re-Trigger Control */
+ public final static GenericDesktopUsage SYSTEM_MENU_LEFT = new GenericDesktopUsage(0x8B); /* Re-Trigger Control */
+ public final static GenericDesktopUsage SYSTEM_MENU_UP = new GenericDesktopUsage(0x8C); /* Re-Trigger Control */
+ public final static GenericDesktopUsage SYSTEM_MENU_DOWN = new GenericDesktopUsage(0x8D); /* Re-Trigger Control */
+ /* 0x8E - 0x8F Reserved */
+ public final static GenericDesktopUsage DPAD_UP = new GenericDesktopUsage(0x90); /* On/Off Control */
+ public final static GenericDesktopUsage DPAD_DOWN = new GenericDesktopUsage(0x91); /* On/Off Control */
+ public final static GenericDesktopUsage DPAD_RIGHT = new GenericDesktopUsage(0x92); /* On/Off Control */
+ public final static GenericDesktopUsage DPAD_LEFT = new GenericDesktopUsage(0x93); /* On/Off Control */
+ /* 0x94 - 0xFFFF Reserved */
+
+ private final int usage_id;
+
+ public final static GenericDesktopUsage map(int usage_id) {
+ if (usage_id < 0 || usage_id >= map.length)
+ return null;
+ return map[usage_id];
+ }
+
+ private GenericDesktopUsage(int usage_id) {
+ map[usage_id] = this;
+ this.usage_id = usage_id;
+ }
+
+ public final String toString() {
+ return "GenericDesktopUsage (0x" + Integer.toHexString(usage_id) + ")";
+ }
+
+ public final Component.Identifier getIdentifier() {
+ if (this == GenericDesktopUsage.X) {
+ return Component.Identifier.Axis.X;
+ } else if (this == GenericDesktopUsage.Y) {
+ return Component.Identifier.Axis.Y;
+ } else if (this == GenericDesktopUsage.Z || this == GenericDesktopUsage.WHEEL) {
+ return Component.Identifier.Axis.Z;
+ } else if (this == GenericDesktopUsage.RX) {
+ return Component.Identifier.Axis.RX;
+ } else if (this == GenericDesktopUsage.RY) {
+ return Component.Identifier.Axis.RY;
+ } else if (this == GenericDesktopUsage.RZ) {
+ return Component.Identifier.Axis.RZ;
+ } else if (this == GenericDesktopUsage.SLIDER) {
+ return Component.Identifier.Axis.SLIDER;
+ } else if (this == GenericDesktopUsage.HATSWITCH) {
+ return Component.Identifier.Axis.POV;
+ } else if (this == GenericDesktopUsage.SELECT) {
+ return Component.Identifier.Button.SELECT;
+ } else
+ return null;
+ }
+
+}
diff --git a/src/plugins/osx/net/java/games/input/KeyboardUsage.java b/src/plugins/osx/net/java/games/input/KeyboardUsage.java
new file mode 100644
index 0000000..30f2383
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/KeyboardUsage.java
@@ -0,0 +1,242 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ */
+package net.java.games.input;
+
+/** Mapping from Keyboard HID usages to Component.Identifier.Key
+* @author elias
+* @version 1.0
+*/
+final class KeyboardUsage implements Usage {
+ private final static KeyboardUsage[] map = new KeyboardUsage[0xFF];
+
+ public static final KeyboardUsage ERRORROLLOVER = new KeyboardUsage(0x01); /* ErrorRollOver */
+ public static final KeyboardUsage POSTFAIL = new KeyboardUsage(0x02); /* POSTFail */
+ public static final KeyboardUsage ERRORUNDEFINED = new KeyboardUsage(0x03); /* ErrorUndefined */
+ public static final KeyboardUsage A = new KeyboardUsage(Component.Identifier.Key.A, 0x04); /* a or A */
+ public static final KeyboardUsage B = new KeyboardUsage(Component.Identifier.Key.B, 0x05); /* b or B */
+ public static final KeyboardUsage C = new KeyboardUsage(Component.Identifier.Key.C, 0x06); /* c or C */
+ public static final KeyboardUsage D = new KeyboardUsage(Component.Identifier.Key.D, 0x07); /* d or D */
+ public static final KeyboardUsage E = new KeyboardUsage(Component.Identifier.Key.E, 0x08); /* e or E */
+ public static final KeyboardUsage F = new KeyboardUsage(Component.Identifier.Key.F, 0x09); /* f or F */
+ public static final KeyboardUsage G = new KeyboardUsage(Component.Identifier.Key.G, 0x0A); /* g or G */
+ public static final KeyboardUsage H = new KeyboardUsage(Component.Identifier.Key.H, 0x0B); /* h or H */
+ public static final KeyboardUsage I = new KeyboardUsage(Component.Identifier.Key.I, 0x0C); /* i or I */
+ public static final KeyboardUsage J = new KeyboardUsage(Component.Identifier.Key.J, 0x0D); /* j or J */
+ public static final KeyboardUsage K = new KeyboardUsage(Component.Identifier.Key.K, 0x0E); /* k or K */
+ public static final KeyboardUsage L = new KeyboardUsage(Component.Identifier.Key.L, 0x0F); /* l or L */
+ public static final KeyboardUsage M = new KeyboardUsage(Component.Identifier.Key.M, 0x10); /* m or M */
+ public static final KeyboardUsage N = new KeyboardUsage(Component.Identifier.Key.N, 0x11); /* n or N */
+ public static final KeyboardUsage O = new KeyboardUsage(Component.Identifier.Key.O, 0x12); /* o or O */
+ public static final KeyboardUsage P = new KeyboardUsage(Component.Identifier.Key.P, 0x13); /* p or P */
+ public static final KeyboardUsage Q = new KeyboardUsage(Component.Identifier.Key.Q, 0x14); /* q or Q */
+ public static final KeyboardUsage R = new KeyboardUsage(Component.Identifier.Key.R, 0x15); /* r or R */
+ public static final KeyboardUsage S = new KeyboardUsage(Component.Identifier.Key.S, 0x16); /* s or S */
+ public static final KeyboardUsage T = new KeyboardUsage(Component.Identifier.Key.T, 0x17); /* t or T */
+ public static final KeyboardUsage U = new KeyboardUsage(Component.Identifier.Key.U, 0x18); /* u or U */
+ public static final KeyboardUsage V = new KeyboardUsage(Component.Identifier.Key.V, 0x19); /* v or V */
+ public static final KeyboardUsage W = new KeyboardUsage(Component.Identifier.Key.W, 0x1A); /* w or W */
+ public static final KeyboardUsage X = new KeyboardUsage(Component.Identifier.Key.X, 0x1B); /* x or X */
+ public static final KeyboardUsage Y = new KeyboardUsage(Component.Identifier.Key.Y, 0x1C); /* y or Y */
+ public static final KeyboardUsage Z = new KeyboardUsage(Component.Identifier.Key.Z, 0x1D); /* z or Z */
+ public static final KeyboardUsage _1 = new KeyboardUsage(Component.Identifier.Key._1, 0x1E); /* 1 or ! */
+ public static final KeyboardUsage _2 = new KeyboardUsage(Component.Identifier.Key._2, 0x1F); /* 2 or @ */
+ public static final KeyboardUsage _3 = new KeyboardUsage(Component.Identifier.Key._3, 0x20); /* 3 or # */
+ public static final KeyboardUsage _4 = new KeyboardUsage(Component.Identifier.Key._4, 0x21); /* 4 or $ */
+ public static final KeyboardUsage _5 = new KeyboardUsage(Component.Identifier.Key._5, 0x22); /* 5 or % */
+ public static final KeyboardUsage _6 = new KeyboardUsage(Component.Identifier.Key._6, 0x23); /* 6 or ^ */
+ public static final KeyboardUsage _7 = new KeyboardUsage(Component.Identifier.Key._7, 0x24); /* 7 or & */
+ public static final KeyboardUsage _8 = new KeyboardUsage(Component.Identifier.Key._8, 0x25); /* 8 or * */
+ public static final KeyboardUsage _9 = new KeyboardUsage(Component.Identifier.Key._9, 0x26); /* 9 or ( */
+ public static final KeyboardUsage _0 = new KeyboardUsage(Component.Identifier.Key._0, 0x27); /* 0 or ) */
+ public static final KeyboardUsage ENTER = new KeyboardUsage(Component.Identifier.Key.RETURN, 0x28); /* Return (Enter) */
+ public static final KeyboardUsage ESCAPE = new KeyboardUsage(Component.Identifier.Key.ESCAPE, 0x29); /* Escape */
+ public static final KeyboardUsage BACKSPACE = new KeyboardUsage(Component.Identifier.Key.BACK, 0x2A); /* Delete (Backspace) */
+ public static final KeyboardUsage TAB = new KeyboardUsage(Component.Identifier.Key.TAB, 0x2B); /* Tab */
+ public static final KeyboardUsage SPACEBAR = new KeyboardUsage(Component.Identifier.Key.SPACE, 0x2C); /* Spacebar */
+ public static final KeyboardUsage HYPHEN = new KeyboardUsage(Component.Identifier.Key.MINUS, 0x2D); /* - or _ */
+ public static final KeyboardUsage EQUALSIGN = new KeyboardUsage(Component.Identifier.Key.EQUALS, 0x2E); /* = or + */
+ public static final KeyboardUsage OPENBRACKET = new KeyboardUsage(Component.Identifier.Key.LBRACKET, 0x2F); /* [ or { */
+ public static final KeyboardUsage CLOSEBRACKET = new KeyboardUsage(Component.Identifier.Key.RBRACKET, 0x30); /* ] or } */
+ public static final KeyboardUsage BACKSLASH = new KeyboardUsage(Component.Identifier.Key.BACKSLASH, 0x31); /* \ or | */
+ public static final KeyboardUsage NONUSPOUNT = new KeyboardUsage(Component.Identifier.Key.PERIOD, 0x32); /* Non-US # or _ */
+ public static final KeyboardUsage SEMICOLON = new KeyboardUsage(Component.Identifier.Key.SEMICOLON, 0x33); /* ; or : */
+ public static final KeyboardUsage QUOTE = new KeyboardUsage(Component.Identifier.Key.APOSTROPHE, 0x34); /* ' or " */
+ public static final KeyboardUsage TILDE = new KeyboardUsage(Component.Identifier.Key.GRAVE, 0x35); /* Grave Accent and Tilde */
+ public static final KeyboardUsage COMMA = new KeyboardUsage(Component.Identifier.Key.COMMA, 0x36); /* , or < */
+ public static final KeyboardUsage PERIOD = new KeyboardUsage(Component.Identifier.Key.PERIOD, 0x37); /* . or > */
+ public static final KeyboardUsage SLASH = new KeyboardUsage(Component.Identifier.Key.SLASH, 0x38); /* / or ? */
+ public static final KeyboardUsage CAPSLOCK = new KeyboardUsage(Component.Identifier.Key.CAPITAL, 0x39); /* Caps Lock */
+ public static final KeyboardUsage F1 = new KeyboardUsage(Component.Identifier.Key.F1, 0x3A); /* F1 */
+ public static final KeyboardUsage F2 = new KeyboardUsage(Component.Identifier.Key.F2, 0x3B); /* F2 */
+ public static final KeyboardUsage F3 = new KeyboardUsage(Component.Identifier.Key.F3, 0x3C); /* F3 */
+ public static final KeyboardUsage F4 = new KeyboardUsage(Component.Identifier.Key.F4, 0x3D); /* F4 */
+ public static final KeyboardUsage F5 = new KeyboardUsage(Component.Identifier.Key.F5, 0x3E); /* F5 */
+ public static final KeyboardUsage F6 = new KeyboardUsage(Component.Identifier.Key.F6, 0x3F); /* F6 */
+ public static final KeyboardUsage F7 = new KeyboardUsage(Component.Identifier.Key.F7, 0x40); /* F7 */
+ public static final KeyboardUsage F8 = new KeyboardUsage(Component.Identifier.Key.F8, 0x41); /* F8 */
+ public static final KeyboardUsage F9 = new KeyboardUsage(Component.Identifier.Key.F9, 0x42); /* F9 */
+ public static final KeyboardUsage F10 = new KeyboardUsage(Component.Identifier.Key.F10, 0x43); /* F10 */
+ public static final KeyboardUsage F11 = new KeyboardUsage(Component.Identifier.Key.F11, 0x44); /* F11 */
+ public static final KeyboardUsage F12 = new KeyboardUsage(Component.Identifier.Key.F12, 0x45); /* F12 */
+ public static final KeyboardUsage PRINTSCREEN = new KeyboardUsage(Component.Identifier.Key.SYSRQ, 0x46); /* PrintScreen */
+ public static final KeyboardUsage SCROLLLOCK = new KeyboardUsage(Component.Identifier.Key.SCROLL, 0x47); /* Scroll Lock */
+ public static final KeyboardUsage PAUSE = new KeyboardUsage(Component.Identifier.Key.PAUSE, 0x48); /* Pause */
+ public static final KeyboardUsage INSERT = new KeyboardUsage(Component.Identifier.Key.INSERT, 0x49); /* Insert */
+ public static final KeyboardUsage HOME = new KeyboardUsage(Component.Identifier.Key.HOME, 0x4A); /* Home */
+ public static final KeyboardUsage PAGEUP = new KeyboardUsage(Component.Identifier.Key.PAGEUP, 0x4B); /* Page Up */
+ public static final KeyboardUsage DELETE = new KeyboardUsage(Component.Identifier.Key.DELETE, 0x4C); /* Delete Forward */
+ public static final KeyboardUsage END = new KeyboardUsage(Component.Identifier.Key.END, 0x4D); /* End */
+ public static final KeyboardUsage PAGEDOWN = new KeyboardUsage(Component.Identifier.Key.PAGEDOWN, 0x4E); /* Page Down */
+ public static final KeyboardUsage RIGHTARROW = new KeyboardUsage(Component.Identifier.Key.RIGHT, 0x4F); /* Right Arrow */
+ public static final KeyboardUsage LEFTARROW = new KeyboardUsage(Component.Identifier.Key.LEFT, 0x50); /* Left Arrow */
+ public static final KeyboardUsage DOWNARROW = new KeyboardUsage(Component.Identifier.Key.DOWN, 0x51); /* Down Arrow */
+ public static final KeyboardUsage UPARROW = new KeyboardUsage(Component.Identifier.Key.UP, 0x52); /* Up Arrow */
+ public static final KeyboardUsage KEYPAD_NUMLOCK = new KeyboardUsage(Component.Identifier.Key.NUMLOCK, 0x53); /* Keypad NumLock or Clear */
+ public static final KeyboardUsage KEYPAD_SLASH = new KeyboardUsage(Component.Identifier.Key.DIVIDE, 0x54); /* Keypad / */
+ public static final KeyboardUsage KEYPAD_ASTERICK = new KeyboardUsage(0x55); /* Keypad * */
+ public static final KeyboardUsage KEYPAD_HYPHEN = new KeyboardUsage(Component.Identifier.Key.SUBTRACT, 0x56); /* Keypad - */
+ public static final KeyboardUsage KEYPAD_PLUS = new KeyboardUsage(Component.Identifier.Key.ADD, 0x57); /* Keypad + */
+ public static final KeyboardUsage KEYPAD_ENTER = new KeyboardUsage(Component.Identifier.Key.NUMPADENTER, 0x58); /* Keypad Enter */
+ public static final KeyboardUsage KEYPAD_1 = new KeyboardUsage(Component.Identifier.Key.NUMPAD1, 0x59); /* Keypad 1 or End */
+ public static final KeyboardUsage KEYPAD_2 = new KeyboardUsage(Component.Identifier.Key.NUMPAD2, 0x5A); /* Keypad 2 or Down Arrow */
+ public static final KeyboardUsage KEYPAD_3 = new KeyboardUsage(Component.Identifier.Key.NUMPAD3, 0x5B); /* Keypad 3 or Page Down */
+ public static final KeyboardUsage KEYPAD_4 = new KeyboardUsage(Component.Identifier.Key.NUMPAD4, 0x5C); /* Keypad 4 or Left Arrow */
+ public static final KeyboardUsage KEYPAD_5 = new KeyboardUsage(Component.Identifier.Key.NUMPAD5, 0x5D); /* Keypad 5 */
+ public static final KeyboardUsage KEYPAD_6 = new KeyboardUsage(Component.Identifier.Key.NUMPAD6, 0x5E); /* Keypad 6 or Right Arrow */
+ public static final KeyboardUsage KEYPAD_7 = new KeyboardUsage(Component.Identifier.Key.NUMPAD7, 0x5F); /* Keypad 7 or Home */
+ public static final KeyboardUsage KEYPAD_8 = new KeyboardUsage(Component.Identifier.Key.NUMPAD8, 0x60); /* Keypad 8 or Up Arrow */
+ public static final KeyboardUsage KEYPAD_9 = new KeyboardUsage(Component.Identifier.Key.NUMPAD9, 0x61); /* Keypad 9 or Page Up */
+ public static final KeyboardUsage KEYPAD_0 = new KeyboardUsage(Component.Identifier.Key.NUMPAD0, 0x62); /* Keypad 0 or Insert */
+ public static final KeyboardUsage KEYPAD_PERIOD = new KeyboardUsage(Component.Identifier.Key.DECIMAL, 0x63); /* Keypad . or Delete */
+ public static final KeyboardUsage NONUSBACKSLASH = new KeyboardUsage(Component.Identifier.Key.BACKSLASH, 0x64); /* Non-US \ or | */
+ public static final KeyboardUsage APPLICATION = new KeyboardUsage(Component.Identifier.Key.APPS, 0x65); /* Application */
+ public static final KeyboardUsage POWER = new KeyboardUsage(Component.Identifier.Key.POWER, 0x66); /* Power */
+ public static final KeyboardUsage KEYPAD_EQUALSIGN = new KeyboardUsage(Component.Identifier.Key.NUMPADEQUAL, 0x67); /* Keypad = */
+ public static final KeyboardUsage F13 = new KeyboardUsage(Component.Identifier.Key.F13, 0x68); /* F13 */
+ public static final KeyboardUsage F14 = new KeyboardUsage(Component.Identifier.Key.F14, 0x69); /* F14 */
+ public static final KeyboardUsage F15 = new KeyboardUsage(Component.Identifier.Key.F15, 0x6A); /* F15 */
+ public static final KeyboardUsage F16 = new KeyboardUsage(0x6B); /* F16 */
+ public static final KeyboardUsage F17 = new KeyboardUsage(0x6C); /* F17 */
+ public static final KeyboardUsage F18 = new KeyboardUsage(0x6D); /* F18 */
+ public static final KeyboardUsage F19 = new KeyboardUsage(0x6E); /* F19 */
+ public static final KeyboardUsage F20 = new KeyboardUsage(0x6F); /* F20 */
+ public static final KeyboardUsage F21 = new KeyboardUsage(0x70); /* F21 */
+ public static final KeyboardUsage F22 = new KeyboardUsage(0x71); /* F22 */
+ public static final KeyboardUsage F23 = new KeyboardUsage(0x72); /* F23 */
+ public static final KeyboardUsage F24 = new KeyboardUsage(0x73); /* F24 */
+ public static final KeyboardUsage EXECUTE = new KeyboardUsage(0x74); /* Execute */
+ public static final KeyboardUsage HELP = new KeyboardUsage(0x75); /* Help */
+ public static final KeyboardUsage MENU = new KeyboardUsage(0x76); /* Menu */
+ public static final KeyboardUsage SELECT = new KeyboardUsage(0x77); /* Select */
+ public static final KeyboardUsage STOP = new KeyboardUsage(Component.Identifier.Key.STOP, 0x78); /* Stop */
+ public static final KeyboardUsage AGAIN = new KeyboardUsage(0x79); /* Again */
+ public static final KeyboardUsage UNDO = new KeyboardUsage(0x7A); /* Undo */
+ public static final KeyboardUsage CUT = new KeyboardUsage(0x7B); /* Cut */
+ public static final KeyboardUsage COPY = new KeyboardUsage(0x7C); /* Copy */
+ public static final KeyboardUsage PASTE = new KeyboardUsage(0x7D); /* Paste */
+ public static final KeyboardUsage FIND = new KeyboardUsage(0x7E); /* Find */
+ public static final KeyboardUsage MUTE = new KeyboardUsage(0x7F); /* Mute */
+ public static final KeyboardUsage VOLUMEUP = new KeyboardUsage(0x80); /* Volume Up */
+ public static final KeyboardUsage VOLUMEDOWN = new KeyboardUsage(0x81); /* Volume Down */
+ public static final KeyboardUsage LOCKINGCAPSLOCK = new KeyboardUsage(Component.Identifier.Key.CAPITAL, 0x82); /* Locking Caps Lock */
+ public static final KeyboardUsage LOCKINGNUMLOCK = new KeyboardUsage(Component.Identifier.Key.NUMLOCK, 0x83); /* Locking Num Lock */
+ public static final KeyboardUsage LOCKINGSCROLLLOCK = new KeyboardUsage(Component.Identifier.Key.SCROLL, 0x84); /* Locking Scroll Lock */
+ public static final KeyboardUsage KEYPAD_COMMA = new KeyboardUsage(Component.Identifier.Key.COMMA, 0x85); /* Keypad Comma */
+ public static final KeyboardUsage KEYPAD_EQUALSSIGNAS400 = new KeyboardUsage(0x86); /* Keypad Equal Sign for AS/400 */
+ public static final KeyboardUsage INTERNATIONAL1 = new KeyboardUsage(0x87); /* International1 */
+ public static final KeyboardUsage INTERNATIONAL2 = new KeyboardUsage(0x88); /* International2 */
+ public static final KeyboardUsage INTERNATIONAL3 = new KeyboardUsage(0x89); /* International3 */
+ public static final KeyboardUsage INTERNATIONAL4 = new KeyboardUsage(0x8A); /* International4 */
+ public static final KeyboardUsage INTERNATIONAL5 = new KeyboardUsage(0x8B); /* International5 */
+ public static final KeyboardUsage INTERNATIONAL6 = new KeyboardUsage(0x8C); /* International6 */
+ public static final KeyboardUsage INTERNATIONAL7 = new KeyboardUsage(0x8D); /* International7 */
+ public static final KeyboardUsage INTERNATIONAL8 = new KeyboardUsage(0x8E); /* International8 */
+ public static final KeyboardUsage INTERNATIONAL9 = new KeyboardUsage(0x8F); /* International9 */
+ public static final KeyboardUsage LANG1 = new KeyboardUsage(0x90); /* LANG1 */
+ public static final KeyboardUsage LANG2 = new KeyboardUsage(0x91); /* LANG2 */
+ public static final KeyboardUsage LANG3 = new KeyboardUsage(0x92); /* LANG3 */
+ public static final KeyboardUsage LANG4 = new KeyboardUsage(0x93); /* LANG4 */
+ public static final KeyboardUsage LANG5 = new KeyboardUsage(0x94); /* LANG5 */
+ public static final KeyboardUsage LANG6 = new KeyboardUsage(0x95); /* LANG6 */
+ public static final KeyboardUsage LANG7 = new KeyboardUsage(0x96); /* LANG7 */
+ public static final KeyboardUsage LANG8 = new KeyboardUsage(0x97); /* LANG8 */
+ public static final KeyboardUsage LANG9 = new KeyboardUsage(0x98); /* LANG9 */
+ public static final KeyboardUsage ALTERNATEERASE = new KeyboardUsage(0x99); /* AlternateErase */
+ public static final KeyboardUsage SYSREQORATTENTION = new KeyboardUsage(Component.Identifier.Key.SYSRQ, 0x9A); /* SysReq/Attention */
+ public static final KeyboardUsage CANCEL = new KeyboardUsage(0x9B); /* Cancel */
+ public static final KeyboardUsage CLEAR = new KeyboardUsage(0x9C); /* Clear */
+ public static final KeyboardUsage PRIOR = new KeyboardUsage(Component.Identifier.Key.PAGEUP, 0x9D); /* Prior */
+ public static final KeyboardUsage RETURN = new KeyboardUsage(Component.Identifier.Key.RETURN, 0x9E); /* Return */
+ public static final KeyboardUsage SEPARATOR = new KeyboardUsage(0x9F); /* Separator */
+ public static final KeyboardUsage OUT = new KeyboardUsage(0xA0); /* Out */
+ public static final KeyboardUsage OPER = new KeyboardUsage(0xA1); /* Oper */
+ public static final KeyboardUsage CLEARORAGAIN = new KeyboardUsage(0xA2); /* Clear/Again */
+ public static final KeyboardUsage CRSELORPROPS = new KeyboardUsage(0xA3); /* CrSel/Props */
+ public static final KeyboardUsage EXSEL = new KeyboardUsage(0xA4); /* ExSel */
+ /* 0xA5-0xDF Reserved */
+ public static final KeyboardUsage LEFTCONTROL = new KeyboardUsage(Component.Identifier.Key.LCONTROL, 0xE0); /* Left Control */
+ public static final KeyboardUsage LEFTSHIFT = new KeyboardUsage(Component.Identifier.Key.LSHIFT, 0xE1); /* Left Shift */
+ public static final KeyboardUsage LEFTALT = new KeyboardUsage(Component.Identifier.Key.LALT, 0xE2); /* Left Alt */
+ public static final KeyboardUsage LEFTGUI = new KeyboardUsage(Component.Identifier.Key.LWIN, 0xE3); /* Left GUI */
+ public static final KeyboardUsage RIGHTCONTROL = new KeyboardUsage(Component.Identifier.Key.RCONTROL, 0xE4); /* Right Control */
+ public static final KeyboardUsage RIGHTSHIFT = new KeyboardUsage(Component.Identifier.Key.RSHIFT, 0xE5); /* Right Shift */
+ public static final KeyboardUsage RIGHTALT = new KeyboardUsage(Component.Identifier.Key.RALT, 0xE6); /* Right Alt */
+ public static final KeyboardUsage RIGHTGUI = new KeyboardUsage(Component.Identifier.Key.RWIN, 0xE7); /* Right GUI */
+
+ private final int usage;
+ private final Component.Identifier.Key identifier;
+
+ public final Component.Identifier.Key getIdentifier() {
+ return identifier;
+ }
+
+ public final static KeyboardUsage map(int usage) {
+ if (usage < 0 || usage >= map.length)
+ return null;
+ return map[usage];
+ }
+
+ private KeyboardUsage(int usage) {
+ this(Component.Identifier.Key.UNKNOWN, usage);
+ }
+
+ private KeyboardUsage(Component.Identifier.Key id, int usage) {
+ this.identifier = id;
+ this.usage = usage;
+ map[usage] = this;
+ }
+
+ public final String toString() {
+ return "KeyboardUsage (0x" + Integer.toHexString(usage) + ")";
+ }
+}
diff --git a/src/plugins/osx/net/java/games/input/OSXAbstractController.java b/src/plugins/osx/net/java/games/input/OSXAbstractController.java
new file mode 100644
index 0000000..4248c88
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/OSXAbstractController.java
@@ -0,0 +1,74 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Represents an OSX AbstractController
+* @author elias
+* @version 1.0
+*/
+final class OSXAbstractController extends AbstractController {
+ private final PortType port;
+ private final OSXHIDQueue queue;
+ private final Type type;
+
+ protected OSXAbstractController(OSXHIDDevice device, OSXHIDQueue queue, Component[] components, Controller[] children, Rumbler[] rumblers, Type type) {
+ super(device.getProductName(), components, children, rumblers);
+ this.queue = queue;
+ this.type = type;
+ this.port = device.getPortType();
+ }
+
+ protected final boolean getNextDeviceEvent(Event event) throws IOException {
+ return OSXControllers.getNextDeviceEvent(event, queue);
+ }
+
+ protected final void setDeviceEventQueueSize(int size) throws IOException {
+ queue.setQueueDepth(size);
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public final PortType getPortType() {
+ return port;
+ }
+}
diff --git a/src/plugins/osx/net/java/games/input/OSXComponent.java b/src/plugins/osx/net/java/games/input/OSXComponent.java
new file mode 100644
index 0000000..6533a79
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/OSXComponent.java
@@ -0,0 +1,70 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Represents an OSX Component
+* @author elias
+* @version 1.0
+*/
+class OSXComponent extends AbstractComponent {
+ private final OSXHIDElement element;
+
+ public OSXComponent(Component.Identifier id, OSXHIDElement element) {
+ super(id.getName(), id);
+ this.element = element;
+ }
+
+ public final boolean isRelative() {
+ return element.isRelative();
+ }
+
+ public boolean isAnalog() {
+ return element.isAnalog();
+ }
+
+ public final OSXHIDElement getElement() {
+ return element;
+ }
+
+ protected float poll() throws IOException {
+ return OSXControllers.poll(element);
+ }
+}
diff --git a/src/plugins/osx/net/java/games/input/OSXControllers.java b/src/plugins/osx/net/java/games/input/OSXControllers.java
new file mode 100644
index 0000000..704ccc5
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/OSXControllers.java
@@ -0,0 +1,64 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** helper methods for OSX specific Controllers
+* @author elias
+* @version 1.0
+*/
+final class OSXControllers {
+ private final static OSXEvent osx_event = new OSXEvent();
+
+ public final static synchronized float poll(OSXHIDElement element) throws IOException {
+ element.getElementValue(osx_event);
+ return element.convertValue(osx_event.getValue());
+ }
+
+ /* synchronized to protect osx_event */
+ public final static synchronized boolean getNextDeviceEvent(Event event, OSXHIDQueue queue) throws IOException {
+ if (queue.getNextEvent(osx_event)) {
+ OSXComponent component = queue.mapEvent(osx_event);
+ event.set(component, component.getElement().convertValue(osx_event.getValue()), osx_event.getNanos());
+ return true;
+ } else
+ return false;
+ }
+}
diff --git a/src/plugins/osx/net/java/games/input/OSXEnvironmentPlugin.java b/src/plugins/osx/net/java/games/input/OSXEnvironmentPlugin.java
new file mode 100644
index 0000000..2278313
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/OSXEnvironmentPlugin.java
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ */
+package net.java.games.input;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+import net.java.games.util.plugins.Plugin;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/** OSX HIDManager implementation
+* @author elias
+* @author gregorypierce
+* @version 1.0
+*/
+public final class OSXEnvironmentPlugin extends ControllerEnvironment implements Plugin {
+
+ private static boolean supported = false;
+
+ /**
+ * Static utility method for loading native libraries.
+ * It will try to load from either the path given by
+ * the net.java.games.input.librarypath property
+ * or through System.loadLibrary().
+ *
+ */
+ static void loadLibrary(final String lib_name) {
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ try {
+ String lib_path = System.getProperty("net.java.games.input.librarypath");
+ if (lib_path != null)
+ System.load(lib_path + File.separator + System.mapLibraryName(lib_name));
+ else
+ System.loadLibrary(lib_name);
+ } catch (UnsatisfiedLinkError e) {
+ e.printStackTrace();
+ supported = false;
+ }
+ return null;
+ });
+ }
+
+ static String getPrivilegedProperty(final String property) {
+ return AccessController.doPrivileged((PrivilegedAction)() -> System.getProperty(property));
+ }
+
+
+ static String getPrivilegedProperty(final String property, final String default_value) {
+ return AccessController.doPrivileged((PrivilegedAction)() -> System.getProperty(property, default_value));
+ }
+
+ static {
+ String osName = getPrivilegedProperty("os.name", "").trim();
+ if(osName.equals("Mac OS X")) {
+ // Could check isMacOSXEqualsOrBetterThan in here too.
+ supported = true;
+ loadLibrary("jinput-osx");
+ }
+ }
+
+ private final static boolean isMacOSXEqualsOrBetterThan(int major_required, int minor_required) {
+ String os_version = System.getProperty("os.version");
+ StringTokenizer version_tokenizer = new StringTokenizer(os_version, ".");
+ int major;
+ int minor;
+ try {
+ String major_str = version_tokenizer.nextToken();
+ String minor_str = version_tokenizer.nextToken();
+ major = Integer.parseInt(major_str);
+ minor = Integer.parseInt(minor_str);
+ } catch (Exception e) {
+ log("Exception occurred while trying to determine OS version: " + e);
+ // Best guess, no
+ return false;
+ }
+ return major > major_required || (major == major_required && minor >= minor_required);
+ }
+
+ private final Controller[] controllers;
+
+ public OSXEnvironmentPlugin() {
+ if(isSupported()) {
+ this.controllers = enumerateControllers();
+ } else {
+ this.controllers = new Controller[0];
+ }
+ }
+
+ public final Controller[] getControllers() {
+ return controllers;
+ }
+
+ public boolean isSupported() {
+ return supported;
+ }
+
+ private final static void addElements(OSXHIDQueue queue, List elements, List components, boolean map_mouse_buttons) throws IOException {
+ Iterator it = elements.iterator();
+ while (it.hasNext()) {
+ OSXHIDElement element = it.next();
+ Component.Identifier id = element.getIdentifier();
+ if (id == null)
+ continue;
+ if (map_mouse_buttons) {
+ if (id == Component.Identifier.Button._0) {
+ id = Component.Identifier.Button.LEFT;
+ } else if (id == Component.Identifier.Button._1) {
+ id = Component.Identifier.Button.RIGHT;
+ } else if (id == Component.Identifier.Button._2) {
+ id = Component.Identifier.Button.MIDDLE;
+ }
+ }
+ OSXComponent component = new OSXComponent(id, element);
+ components.add(component);
+ queue.addElement(element, component);
+ }
+ }
+
+ private final static Keyboard createKeyboardFromDevice(OSXHIDDevice device, List elements) throws IOException {
+ List components = new ArrayList<>();
+ OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH);
+ try {
+ addElements(queue, elements, components, false);
+ } catch (IOException e) {
+ queue.release();
+ throw e;
+ }
+ Component[] components_array = new Component[components.size()];
+ components.toArray(components_array);
+ return new OSXKeyboard(device, queue, components_array, new Controller[]{}, new Rumbler[]{});
+ }
+
+ private final static Mouse createMouseFromDevice(OSXHIDDevice device, List elements) throws IOException {
+ List components = new ArrayList<>();
+ OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH);
+ try {
+ addElements(queue, elements, components, true);
+ } catch (IOException e) {
+ queue.release();
+ throw e;
+ }
+ Component[] components_array = new Component[components.size()];
+ components.toArray(components_array);
+ Mouse mouse = new OSXMouse(device, queue, components_array, new Controller[]{}, new Rumbler[]{});
+ if (mouse.getPrimaryButton() != null && mouse.getX() != null && mouse.getY() != null) {
+ return mouse;
+ } else {
+ queue.release();
+ return null;
+ }
+ }
+
+ private final static AbstractController createControllerFromDevice(OSXHIDDevice device, List elements, Controller.Type type) throws IOException {
+ List components = new ArrayList<>();
+ OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH);
+ try {
+ addElements(queue, elements, components, false);
+ } catch (IOException e) {
+ queue.release();
+ throw e;
+ }
+ Component[] components_array = new Component[components.size()];
+ components.toArray(components_array);
+ return new OSXAbstractController(device, queue, components_array, new Controller[]{}, new Rumbler[]{}, type);
+ }
+
+ private final static void createControllersFromDevice(OSXHIDDevice device, List controllers) throws IOException {
+ UsagePair usage_pair = device.getUsagePair();
+ if (usage_pair == null)
+ return;
+ List elements = device.getElements();
+ if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && (usage_pair.getUsage() == GenericDesktopUsage.MOUSE ||
+ usage_pair.getUsage() == GenericDesktopUsage.POINTER)) {
+ Controller mouse = createMouseFromDevice(device, elements);
+ if (mouse != null)
+ controllers.add(mouse);
+ } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && (usage_pair.getUsage() == GenericDesktopUsage.KEYBOARD ||
+ usage_pair.getUsage() == GenericDesktopUsage.KEYPAD)) {
+ controllers.add(createKeyboardFromDevice(device, elements));
+ } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.JOYSTICK) {
+ controllers.add(createControllerFromDevice(device, elements, Controller.Type.STICK));
+ } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.MULTI_AXIS_CONTROLLER) {
+ controllers.add(createControllerFromDevice(device, elements, Controller.Type.STICK));
+ } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.GAME_PAD) {
+ controllers.add(createControllerFromDevice(device, elements, Controller.Type.GAMEPAD));
+ }
+ }
+
+ private final static Controller[] enumerateControllers() {
+ List controllers = new ArrayList<>();
+ try {
+ OSXHIDDeviceIterator it = new OSXHIDDeviceIterator();
+ try {
+ while (true) {
+ OSXHIDDevice device;
+ try {
+ device = it.next();
+ if (device == null)
+ break;
+ boolean device_used = false;
+ try {
+ int old_size = controllers.size();
+ createControllersFromDevice(device, controllers);
+ device_used = old_size != controllers.size();
+ } catch (IOException e) {
+ log("Failed to create controllers from device: " + device.getProductName());
+ }
+ if (!device_used)
+ device.release();
+ } catch (IOException e) {
+ log("Failed to enumerate device: " + e.getMessage());
+ }
+ }
+ } finally {
+ it.close();
+ }
+ } catch (IOException e) {
+ log("Failed to enumerate devices: " + e.getMessage());
+ return new Controller[]{};
+ }
+ Controller[] controllers_array = new Controller[controllers.size()];
+ controllers.toArray(controllers_array);
+ return controllers_array;
+ }
+}
diff --git a/src/plugins/osx/net/java/games/input/OSXEvent.java b/src/plugins/osx/net/java/games/input/OSXEvent.java
new file mode 100644
index 0000000..9db46e6
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/OSXEvent.java
@@ -0,0 +1,73 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+/** OSX Event structure corresponding to IOHIDEventStruct
+* @author elias
+* @version 1.0
+*/
+class OSXEvent {
+ private long type;
+ private long cookie;
+ private int value;
+ private long nanos;
+
+ public void set(long type, long cookie, int value, long nanos) {
+ this.type = type;
+ this.cookie = cookie;
+ this.value = value;
+ this.nanos = nanos;
+ }
+
+ public long getType() {
+ return type;
+ }
+
+ public long getCookie() {
+ return cookie;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public long getNanos() {
+ return nanos;
+ }
+}
diff --git a/src/plugins/osx/net/java/games/input/OSXHIDDevice.java b/src/plugins/osx/net/java/games/input/OSXHIDDevice.java
new file mode 100644
index 0000000..7ac4831
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/OSXHIDDevice.java
@@ -0,0 +1,294 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ */
+package net.java.games.input;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Iterator;
+import java.util.logging.Logger;
+
+/** OSX HIDManager implementation
+* @author elias
+* @author gregorypierce
+* @version 1.0
+*/
+final class OSXHIDDevice {
+ private final static Logger log = Logger.getLogger(OSXHIDDevice.class.getName());
+ private final static int AXIS_DEFAULT_MIN_VALUE = 0;
+ private final static int AXIS_DEFAULT_MAX_VALUE = 64*1024;
+
+ private final static String kIOHIDTransportKey = "Transport";
+ private final static String kIOHIDVendorIDKey = "VendorID";
+ private final static String kIOHIDVendorIDSourceKey = "VendorIDSource";
+ private final static String kIOHIDProductIDKey = "ProductID";
+ private final static String kIOHIDVersionNumberKey = "VersionNumber";
+ private final static String kIOHIDManufacturerKey = "Manufacturer";
+ private final static String kIOHIDProductKey = "Product";
+ private final static String kIOHIDSerialNumberKey = "SerialNumber";
+ private final static String kIOHIDCountryCodeKey = "CountryCode";
+ private final static String kIOHIDLocationIDKey = "LocationID";
+ private final static String kIOHIDDeviceUsageKey = "DeviceUsage";
+ private final static String kIOHIDDeviceUsagePageKey = "DeviceUsagePage";
+ private final static String kIOHIDDeviceUsagePairsKey = "DeviceUsagePairs";
+ private final static String kIOHIDPrimaryUsageKey = "PrimaryUsage";
+ private final static String kIOHIDPrimaryUsagePageKey = "PrimaryUsagePage";
+ private final static String kIOHIDMaxInputReportSizeKey = "MaxInputReportSize";
+ private final static String kIOHIDMaxOutputReportSizeKey = "MaxOutputReportSize";
+ private final static String kIOHIDMaxFeatureReportSizeKey = "MaxFeatureReportSize";
+
+ private final static String kIOHIDElementKey = "Elements";
+
+ private final static String kIOHIDElementCookieKey = "ElementCookie";
+ private final static String kIOHIDElementTypeKey = "Type";
+ private final static String kIOHIDElementCollectionTypeKey = "CollectionType";
+ private final static String kIOHIDElementUsageKey = "Usage";
+ private final static String kIOHIDElementUsagePageKey = "UsagePage";
+ private final static String kIOHIDElementMinKey = "Min";
+ private final static String kIOHIDElementMaxKey = "Max";
+ private final static String kIOHIDElementScaledMinKey = "ScaledMin";
+ private final static String kIOHIDElementScaledMaxKey = "ScaledMax";
+ private final static String kIOHIDElementSizeKey = "Size";
+ private final static String kIOHIDElementReportSizeKey = "ReportSize";
+ private final static String kIOHIDElementReportCountKey = "ReportCount";
+ private final static String kIOHIDElementReportIDKey = "ReportID";
+ private final static String kIOHIDElementIsArrayKey = "IsArray";
+ private final static String kIOHIDElementIsRelativeKey = "IsRelative";
+ private final static String kIOHIDElementIsWrappingKey = "IsWrapping";
+ private final static String kIOHIDElementIsNonLinearKey = "IsNonLinear";
+ private final static String kIOHIDElementHasPreferredStateKey = "HasPreferredState";
+ private final static String kIOHIDElementHasNullStateKey = "HasNullState";
+ private final static String kIOHIDElementUnitKey = "Unit";
+ private final static String kIOHIDElementUnitExponentKey = "UnitExponent";
+ private final static String kIOHIDElementNameKey = "Name";
+ private final static String kIOHIDElementValueLocationKey = "ValueLocation";
+ private final static String kIOHIDElementDuplicateIndexKey = "DuplicateIndex";
+ private final static String kIOHIDElementParentCollectionKey = "ParentCollection";
+
+ private final long device_address;
+ private final long device_interface_address;
+ private final Map properties;
+
+ private boolean released;
+
+ public OSXHIDDevice(long device_address, long device_interface_address) throws IOException {
+ this.device_address = device_address;
+ this.device_interface_address = device_interface_address;
+ this.properties = getDeviceProperties();
+ open();
+ }
+
+ public final Controller.PortType getPortType() {
+ String transport = (String)properties.get(kIOHIDTransportKey);
+ if (transport == null)
+ return Controller.PortType.UNKNOWN;
+ if (transport.equals("USB")) {
+ return Controller.PortType.USB;
+ } else {
+ return Controller.PortType.UNKNOWN;
+ }
+ }
+
+ public final String getProductName() {
+ return (String)properties.get(kIOHIDProductKey);
+ }
+
+ private final OSXHIDElement createElementFromElementProperties(Map element_properties) {
+ /* long size = getLongFromProperties(element_properties, kIOHIDElementSizeKey);
+ // ignore elements that can't fit into the 32 bit value field of a hid event
+ if (size > 32)
+ return null;*/
+ long element_cookie = getLongFromProperties(element_properties, kIOHIDElementCookieKey);
+ int element_type_id = getIntFromProperties(element_properties, kIOHIDElementTypeKey);
+ ElementType element_type = ElementType.map(element_type_id);
+ int min = (int)getLongFromProperties(element_properties, kIOHIDElementMinKey, AXIS_DEFAULT_MIN_VALUE);
+ int max = (int)getLongFromProperties(element_properties, kIOHIDElementMaxKey, AXIS_DEFAULT_MAX_VALUE);
+/* long scaled_min = getLongFromProperties(element_properties, kIOHIDElementScaledMinKey, Long.MIN_VALUE);
+ long scaled_max = getLongFromProperties(element_properties, kIOHIDElementScaledMaxKey, Long.MAX_VALUE);*/
+ UsagePair device_usage_pair = getUsagePair();
+ boolean default_relative = device_usage_pair != null && (device_usage_pair.getUsage() == GenericDesktopUsage.POINTER || device_usage_pair.getUsage() == GenericDesktopUsage.MOUSE);
+
+ boolean is_relative = getBooleanFromProperties(element_properties, kIOHIDElementIsRelativeKey, default_relative);
+/* boolean is_wrapping = getBooleanFromProperties(element_properties, kIOHIDElementIsWrappingKey);
+ boolean is_non_linear = getBooleanFromProperties(element_properties, kIOHIDElementIsNonLinearKey);
+ boolean has_preferred_state = getBooleanFromProperties(element_properties, kIOHIDElementHasPreferredStateKey);
+ boolean has_null_state = getBooleanFromProperties(element_properties, kIOHIDElementHasNullStateKey);*/
+ int usage = getIntFromProperties(element_properties, kIOHIDElementUsageKey);
+ int usage_page = getIntFromProperties(element_properties, kIOHIDElementUsagePageKey);
+ UsagePair usage_pair = createUsagePair(usage_page, usage);
+ if (usage_pair == null || (element_type != ElementType.INPUT_MISC && element_type != ElementType.INPUT_BUTTON && element_type != ElementType.INPUT_AXIS)) {
+ //log.info("element_type = 0x" + element_type + " | usage = " + usage + " | usage_page = " + usage_page);
+ return null;
+ } else {
+ return new OSXHIDElement(this, usage_pair, element_cookie, element_type, min, max, is_relative);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private final void addElements(List elements, Map properties) {
+ Object[] elements_properties = (Object[])properties.get(kIOHIDElementKey);
+ if (elements_properties == null)
+ return;
+ for (int i = 0; i < elements_properties.length; i++) {
+ Map element_properties = (Map)elements_properties[i];
+ OSXHIDElement element = createElementFromElementProperties(element_properties);
+ if (element != null) {
+ elements.add(element);
+ }
+ addElements(elements, element_properties);
+ }
+ }
+
+ public final List getElements() {
+ List elements = new ArrayList<>();
+ addElements(elements, properties);
+ return elements;
+ }
+
+ private final static long getLongFromProperties(Map properties, String key, long default_value) {
+ Long long_obj = (Long)properties.get(key);
+ if (long_obj == null)
+ return default_value;
+ return long_obj.longValue();
+ }
+
+ private final static boolean getBooleanFromProperties(Map properties, String key, boolean default_value) {
+ return getLongFromProperties(properties, key, default_value ? 1 : 0) != 0;
+ }
+
+ private final static int getIntFromProperties(Map properties, String key) {
+ return (int)getLongFromProperties(properties, key);
+ }
+
+ private final static long getLongFromProperties(Map properties, String key) {
+ Long long_obj = (Long)properties.get(key);
+ return long_obj.longValue();
+ }
+
+ private final static UsagePair createUsagePair(int usage_page_id, int usage_id) {
+ UsagePage usage_page = UsagePage.map(usage_page_id);
+ if (usage_page != null) {
+ Usage usage = usage_page.mapUsage(usage_id);
+ if (usage != null)
+ return new UsagePair(usage_page, usage);
+ }
+ return null;
+ }
+
+ public final UsagePair getUsagePair() {
+ int usage_page_id = getIntFromProperties(properties, kIOHIDPrimaryUsagePageKey);
+ int usage_id = getIntFromProperties(properties, kIOHIDPrimaryUsageKey);
+ return createUsagePair(usage_page_id, usage_id);
+ }
+
+ private final void dumpProperties() {
+ log.info(toString());
+ dumpMap("", properties);
+ }
+
+ private final static void dumpArray(String prefix, Object[] array) {
+ log.info(prefix + "{");
+ for (int i = 0; i < array.length; i++) {
+ dumpObject(prefix + "\t", array[i]);
+ log.info(prefix + ",");
+ }
+ log.info(prefix + "}");
+ }
+
+ private final static void dumpMap(String prefix, Map map) {
+ Iterator keys = map.keySet().iterator();
+ while (keys.hasNext()) {
+ Object key = keys.next();
+ Object value = map.get(key);
+ dumpObject(prefix, key);
+ dumpObject(prefix + "\t", value);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private final static void dumpObject(String prefix, Object obj) {
+ if (obj instanceof Long) {
+ Long l = (Long)obj;
+ log.info(prefix + "0x" + Long.toHexString(l.longValue()));
+ } else if (obj instanceof Map)
+ dumpMap(prefix, (Map)obj);
+ else if (obj.getClass().isArray())
+ dumpArray(prefix, (Object[])obj);
+ else
+ log.info(prefix + obj);
+ }
+
+ private final Map getDeviceProperties() throws IOException {
+ return nGetDeviceProperties(device_address);
+ }
+ private final static native Map nGetDeviceProperties(long device_address) throws IOException;
+
+ public final synchronized void release() throws IOException {
+ try {
+ close();
+ } finally {
+ released = true;
+ nReleaseDevice(device_address, device_interface_address);
+ }
+ }
+ private final static native void nReleaseDevice(long device_address, long device_interface_address);
+
+ public final synchronized void getElementValue(long element_cookie, OSXEvent event) throws IOException {
+ checkReleased();
+ nGetElementValue(device_interface_address, element_cookie, event);
+ }
+ private final static native void nGetElementValue(long device_interface_address, long element_cookie, OSXEvent event) throws IOException;
+
+ public final synchronized OSXHIDQueue createQueue(int queue_depth) throws IOException {
+ checkReleased();
+ long queue_address = nCreateQueue(device_interface_address);
+ return new OSXHIDQueue(queue_address, queue_depth);
+ }
+ private final static native long nCreateQueue(long device_interface_address) throws IOException;
+
+ private final void open() throws IOException {
+ nOpen(device_interface_address);
+ }
+ private final static native void nOpen(long device_interface_address) throws IOException;
+
+ private final void close() throws IOException {
+ nClose(device_interface_address);
+ }
+ private final static native void nClose(long device_interface_address) throws IOException;
+
+ private final void checkReleased() throws IOException {
+ if (released)
+ throw new IOException();
+ }
+}
diff --git a/src/plugins/osx/net/java/games/input/OSXHIDDeviceIterator.java b/src/plugins/osx/net/java/games/input/OSXHIDDeviceIterator.java
new file mode 100644
index 0000000..1070c58
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/OSXHIDDeviceIterator.java
@@ -0,0 +1,65 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** OSX HIDManager implementation
+* @author elias
+* @author gregorypierce
+* @version 1.0
+*/
+final class OSXHIDDeviceIterator {
+ private final long iterator_address;
+
+ public OSXHIDDeviceIterator() throws IOException {
+ this.iterator_address = nCreateIterator();
+ }
+ private final static native long nCreateIterator();
+
+ public final void close(){
+ nReleaseIterator(iterator_address);
+ }
+ private final static native void nReleaseIterator(long iterator_address);
+
+ public final OSXHIDDevice next() throws IOException {
+ return nNext(iterator_address);
+ }
+ private final static native OSXHIDDevice nNext(long iterator_address) throws IOException;
+}
diff --git a/src/plugins/osx/net/java/games/input/OSXHIDElement.java b/src/plugins/osx/net/java/games/input/OSXHIDElement.java
new file mode 100644
index 0000000..a8c0907
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/OSXHIDElement.java
@@ -0,0 +1,143 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Represents an OSX HID Element
+* @author elias
+* @author gregorypierce
+* @version 1.0
+*/
+final class OSXHIDElement {
+ private final OSXHIDDevice device;
+ private final UsagePair usage_pair;
+ private final long element_cookie;
+ private final ElementType element_type;
+ private final int min;
+ private final int max;
+ private final Component.Identifier identifier;
+ private final boolean is_relative;
+
+ public OSXHIDElement(OSXHIDDevice device, UsagePair usage_pair, long element_cookie, ElementType element_type, int min, int max, boolean is_relative) {
+ this.device = device;
+ this.usage_pair = usage_pair;
+ this.element_cookie = element_cookie;
+ this.element_type = element_type;
+ this.min = min;
+ this.max = max;
+ this.identifier = computeIdentifier();
+ this.is_relative = is_relative;
+ }
+
+ private final Component.Identifier computeIdentifier() {
+ if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP) {
+ return ((GenericDesktopUsage)usage_pair.getUsage()).getIdentifier();
+ } else if (usage_pair.getUsagePage() == UsagePage.BUTTON) {
+ return ((ButtonUsage)usage_pair.getUsage()).getIdentifier();
+ } else if (usage_pair.getUsagePage() == UsagePage.KEYBOARD_OR_KEYPAD) {
+ return ((KeyboardUsage)usage_pair.getUsage()).getIdentifier();
+ } else
+ return null;
+ }
+
+ final Component.Identifier getIdentifier() {
+ return identifier;
+ }
+
+ final long getCookie() {
+ return element_cookie;
+ }
+
+ final ElementType getType() {
+ return element_type;
+ }
+
+ final boolean isRelative() {
+ return is_relative && identifier instanceof Component.Identifier.Axis;
+ }
+
+ final boolean isAnalog() {
+ return identifier instanceof Component.Identifier.Axis && identifier != Component.Identifier.Axis.POV;
+ }
+
+ private UsagePair getUsagePair() {
+ return usage_pair;
+ }
+
+ final void getElementValue(OSXEvent event) throws IOException {
+ device.getElementValue(element_cookie, event);
+ }
+
+ final float convertValue(float value) {
+ if (identifier == Component.Identifier.Axis.POV) {
+ switch ((int)value) {
+ case 0:
+ return Component.POV.UP;
+ case 1:
+ return Component.POV.UP_RIGHT;
+ case 2:
+ return Component.POV.RIGHT;
+ case 3:
+ return Component.POV.DOWN_RIGHT;
+ case 4:
+ return Component.POV.DOWN;
+ case 5:
+ return Component.POV.DOWN_LEFT;
+ case 6:
+ return Component.POV.LEFT;
+ case 7:
+ return Component.POV.UP_LEFT;
+ case 8:
+ return Component.POV.OFF;
+ default:
+ return Component.POV.OFF;
+ }
+ } else if (identifier instanceof Component.Identifier.Axis && !is_relative) {
+ if (min == max)
+ return 0;
+ else if (value > max)
+ value = max;
+ else if (value < min)
+ value = min;
+ return 2*(value - min)/(max - min) - 1;
+ } else
+ return value;
+ }
+}
diff --git a/src/plugins/osx/net/java/games/input/OSXHIDQueue.java b/src/plugins/osx/net/java/games/input/OSXHIDQueue.java
new file mode 100644
index 0000000..f97cf6a
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/OSXHIDQueue.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ */
+package net.java.games.input;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+* @author elias
+* @version 1.0
+*/
+final class OSXHIDQueue {
+ private final Map map = new HashMap<>();
+ private final long queue_address;
+
+ private boolean released;
+
+ public OSXHIDQueue(long address, int queue_depth) throws IOException {
+ this.queue_address = address;
+ try {
+ createQueue(queue_depth);
+ } catch (IOException e) {
+ release();
+ throw e;
+ }
+ }
+
+ public final synchronized void setQueueDepth(int queue_depth) throws IOException {
+ checkReleased();
+ stop();
+ close();
+ createQueue(queue_depth);
+ }
+
+ private final void createQueue(int queue_depth) throws IOException {
+ open(queue_depth);
+ try {
+ start();
+ } catch (IOException e) {
+ close();
+ throw e;
+ }
+ }
+
+ public final OSXComponent mapEvent(OSXEvent event) {
+ return map.get(event.getCookie());
+ }
+
+ private final void open(int queue_depth) throws IOException {
+ nOpen(queue_address, queue_depth);
+ }
+ private final static native void nOpen(long queue_address, int queue_depth) throws IOException;
+
+ private final void close() throws IOException {
+ nClose(queue_address);
+ }
+ private final static native void nClose(long queue_address) throws IOException;
+
+ private final void start() throws IOException {
+ nStart(queue_address);
+ }
+ private final static native void nStart(long queue_address) throws IOException;
+
+ private final void stop() throws IOException {
+ nStop(queue_address);
+ }
+ private final static native void nStop(long queue_address) throws IOException;
+
+ public final synchronized void release() throws IOException {
+ if (!released) {
+ released = true;
+ try {
+ stop();
+ close();
+ } finally {
+ nReleaseQueue(queue_address);
+ }
+ }
+ }
+ private final static native void nReleaseQueue(long queue_address) throws IOException;
+
+ public final void addElement(OSXHIDElement element, OSXComponent component) throws IOException {
+ nAddElement(queue_address, element.getCookie());
+ map.put(element.getCookie(), component);
+ }
+ private final static native void nAddElement(long queue_address, long cookie) throws IOException;
+
+ public final void removeElement(OSXHIDElement element) throws IOException {
+ nRemoveElement(queue_address, element.getCookie());
+ map.remove(element.getCookie());
+ }
+ private final static native void nRemoveElement(long queue_address, long cookie) throws IOException;
+
+ public final synchronized boolean getNextEvent(OSXEvent event) throws IOException {
+ checkReleased();
+ return nGetNextEvent(queue_address, event);
+ }
+ private final static native boolean nGetNextEvent(long queue_address, OSXEvent event) throws IOException;
+
+ private final void checkReleased() throws IOException {
+ if (released)
+ throw new IOException("Queue is released");
+ }
+}
diff --git a/src/plugins/osx/net/java/games/input/OSXKeyboard.java b/src/plugins/osx/net/java/games/input/OSXKeyboard.java
new file mode 100644
index 0000000..f545264
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/OSXKeyboard.java
@@ -0,0 +1,68 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Represents an OSX Keyboard
+* @author elias
+* @version 1.0
+*/
+final class OSXKeyboard extends Keyboard {
+ private final PortType port;
+ private final OSXHIDQueue queue;
+
+ protected OSXKeyboard(OSXHIDDevice device, OSXHIDQueue queue, Component[] components, Controller[] children, Rumbler[] rumblers) {
+ super(device.getProductName(), components, children, rumblers);
+ this.queue = queue;
+ this.port = device.getPortType();
+ }
+
+ protected final boolean getNextDeviceEvent(Event event) throws IOException {
+ return OSXControllers.getNextDeviceEvent(event, queue);
+ }
+
+ protected final void setDeviceEventQueueSize(int size) throws IOException {
+ queue.setQueueDepth(size);
+ }
+
+ public final PortType getPortType() {
+ return port;
+ }
+}
diff --git a/src/plugins/osx/net/java/games/input/OSXMouse.java b/src/plugins/osx/net/java/games/input/OSXMouse.java
new file mode 100644
index 0000000..8f5244b
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/OSXMouse.java
@@ -0,0 +1,68 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Represents an OSX Mouse
+* @author elias
+* @version 1.0
+*/
+final class OSXMouse extends Mouse {
+ private final PortType port;
+ private final OSXHIDQueue queue;
+
+ protected OSXMouse(OSXHIDDevice device, OSXHIDQueue queue, Component[] components, Controller[] children, Rumbler[] rumblers) {
+ super(device.getProductName(), components, children, rumblers);
+ this.queue = queue;
+ this.port = device.getPortType();
+ }
+
+ protected final boolean getNextDeviceEvent(Event event) throws IOException {
+ return OSXControllers.getNextDeviceEvent(event, queue);
+ }
+
+ protected final void setDeviceEventQueueSize(int size) throws IOException {
+ queue.setQueueDepth(size);
+ }
+
+ public final PortType getPortType() {
+ return port;
+ }
+}
diff --git a/src/plugins/osx/net/java/games/input/Usage.java b/src/plugins/osx/net/java/games/input/Usage.java
new file mode 100644
index 0000000..356ee94
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/Usage.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ */
+package net.java.games.input;
+
+/** Generic Desktop Usages
+* @author elias
+* @version 1.0
+*/
+public interface Usage {
+}
diff --git a/src/plugins/osx/net/java/games/input/UsagePage.java b/src/plugins/osx/net/java/games/input/UsagePage.java
new file mode 100644
index 0000000..59e0b9b
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/UsagePage.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ */
+package net.java.games.input;
+
+import java.lang.reflect.Method;
+
+/** HID Usage pages
+* @author elias
+* @version 1.0
+*/
+final class UsagePage {
+ private final static UsagePage[] map = new UsagePage[0xFF];
+
+ public final static UsagePage UNDEFINED = new UsagePage(0x00);
+ public final static UsagePage GENERIC_DESKTOP = new UsagePage(0x01, GenericDesktopUsage.class);
+ public final static UsagePage SIMULATION = new UsagePage(0x02);
+ public final static UsagePage VR = new UsagePage(0x03);
+ public final static UsagePage SPORT = new UsagePage(0x04);
+ public final static UsagePage GAME = new UsagePage(0x05);
+ /* Reserved 0x06 */
+ public final static UsagePage KEYBOARD_OR_KEYPAD = new UsagePage(0x07, KeyboardUsage.class); /* USB Device Class Definition for Human Interface Devices (HID). Note: the usage type for all key codes is Selector (Sel). */
+ public final static UsagePage LEDS = new UsagePage(0x08);
+ public final static UsagePage BUTTON = new UsagePage(0x09, ButtonUsage.class);
+ public final static UsagePage ORDINAL = new UsagePage(0x0A);
+ public final static UsagePage TELEPHONY = new UsagePage(0x0B);
+ public final static UsagePage CONSUMER = new UsagePage(0x0C);
+ public final static UsagePage DIGITIZER = new UsagePage(0x0D);
+ /* Reserved 0x0E */
+ public final static UsagePage PID = new UsagePage(0x0F); /* USB Physical Interface Device definitions for force feedback and related devices. */
+ public final static UsagePage UNICODE = new UsagePage(0x10);
+ /* Reserved 0x11 - 0x13 */
+ public final static UsagePage ALPHANUMERIC_DISPLAY = new UsagePage(0x14);
+ /* Reserved 0x15 - 0x7F */
+ /* Monitor 0x80 - 0x83 USB Device Class Definition for Monitor Devices */
+ /* Power 0x84 - 0x87 USB Device Class Definition for Power Devices */
+ public final static UsagePage POWER_DEVICE = new UsagePage(0x84); /* Power Device Page */
+ public final static UsagePage BATTERY_SYSTEM = new UsagePage(0x85); /* Battery System Page */
+ /* Reserved 0x88 - 0x8B */
+ public final static UsagePage BAR_CODE_SCANNER = new UsagePage(0x8C); /* (Point of Sale) USB Device Class Definition for Bar Code Scanner Devices */
+ public final static UsagePage SCALE = new UsagePage(0x8D); /* (Point of Sale) USB Device Class Definition for Scale Devices */
+ /* ReservedPointofSalepages 0x8E - 0X8F */
+ public final static UsagePage CAMERACONTROL= new UsagePage(0x90); /* USB Device Class Definition for Image Class Devices */
+ public final static UsagePage ARCADE = new UsagePage(0x91); /* OAAF Definitions for arcade and coinop related Devices */
+ private final Class extends Usage> usage_class;
+ private final int usage_page_id;
+
+ public final static UsagePage map(int page_id) {
+ if (page_id < 0 || page_id >= map.length)
+ return null;
+ return map[page_id];
+ }
+
+ private UsagePage(int page_id, Class extends Usage> usage_class) {
+ map[page_id] = this;
+ this.usage_class = usage_class;
+ this.usage_page_id = page_id;
+ }
+
+ private UsagePage(int page_id) {
+ this(page_id, null);
+ }
+
+ public final String toString() {
+ return "UsagePage (0x" + Integer.toHexString(usage_page_id) + ")";
+ }
+
+ public final Usage mapUsage(int usage_id) {
+ if (usage_class == null)
+ return null;
+ try {
+ Method map_method = usage_class.getMethod("map", int.class);
+ Object result = map_method.invoke(null, usage_id);
+ return (Usage)result;
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
+}
diff --git a/src/plugins/osx/net/java/games/input/UsagePair.java b/src/plugins/osx/net/java/games/input/UsagePair.java
new file mode 100644
index 0000000..8d0b883
--- /dev/null
+++ b/src/plugins/osx/net/java/games/input/UsagePair.java
@@ -0,0 +1,76 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+/** Usage/Page pair
+* @author elias
+* @version 1.0
+*/
+class UsagePair {
+ private final UsagePage usage_page;
+ private final Usage usage;
+
+ public UsagePair(UsagePage usage_page, Usage usage) {
+ this.usage_page = usage_page;
+ this.usage = usage;
+ }
+
+ public final UsagePage getUsagePage() {
+ return usage_page;
+ }
+
+ public final Usage getUsage() {
+ return usage;
+ }
+
+ public final int hashCode() {
+ return usage.hashCode() ^ usage_page.hashCode();
+ }
+
+ public final boolean equals(Object other) {
+ if (!(other instanceof UsagePair))
+ return false;
+ UsagePair other_pair = (UsagePair)other;
+ return other_pair.usage.equals(usage) && other_pair.usage_page.equals(usage_page);
+ }
+
+ public final String toString() {
+ return "UsagePair: (page = " + usage_page + ", usage = " + usage + ")";
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/DIAbstractController.java b/src/plugins/windows/net/java/games/input/DIAbstractController.java
new file mode 100644
index 0000000..ef75400
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/DIAbstractController.java
@@ -0,0 +1,72 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/**
+* @author elias
+* @version 1.0
+*/
+final class DIAbstractController extends AbstractController {
+ private final IDirectInputDevice device;
+ private final Controller.Type type;
+
+ protected DIAbstractController(IDirectInputDevice device, Component[] components, Controller[] children, Rumbler[] rumblers, Controller.Type type) {
+ super(device.getProductName(), components, children, rumblers);
+ this.device = device;
+ this.type = type;
+ }
+
+ public final void pollDevice() throws IOException {
+ device.pollAll();
+ }
+
+ protected final boolean getNextDeviceEvent(Event event) throws IOException {
+ return DIControllers.getNextDeviceEvent(event, device);
+ }
+
+ protected final void setDeviceEventQueueSize(int size) throws IOException {
+ device.setBufferSize(size);
+ }
+
+ public final Controller.Type getType() {
+ return type;
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/DIComponent.java b/src/plugins/windows/net/java/games/input/DIComponent.java
new file mode 100644
index 0000000..715c7fb
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/DIComponent.java
@@ -0,0 +1,74 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/**
+* @author elias
+* @version 1.0
+*/
+final class DIComponent extends AbstractComponent {
+ private final DIDeviceObject object;
+
+ public DIComponent(Component.Identifier identifier, DIDeviceObject object) {
+ super(object.getName(), identifier);
+ this.object = object;
+ }
+
+ public final boolean isRelative() {
+ return object.isRelative();
+ }
+
+ public final boolean isAnalog() {
+ return object.isAnalog();
+ }
+
+ public final float getDeadZone() {
+ return object.getDeadzone();
+ }
+
+ public final DIDeviceObject getDeviceObject() {
+ return object;
+ }
+
+ protected final float poll() throws IOException {
+ return DIControllers.poll(this, object);
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/DIControllers.java b/src/plugins/windows/net/java/games/input/DIControllers.java
new file mode 100644
index 0000000..cb4b2d6
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/DIControllers.java
@@ -0,0 +1,78 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/**
+* @author elias
+* @version 1.0
+*/
+final class DIControllers {
+ private final static DIDeviceObjectData di_event = new DIDeviceObjectData();
+
+ /* synchronized to protect di_event */
+ public final static synchronized boolean getNextDeviceEvent(Event event, IDirectInputDevice device) throws IOException {
+ if (!device.getNextEvent(di_event))
+ return false;
+ DIDeviceObject object = device.mapEvent(di_event);
+ DIComponent component = device.mapObject(object);
+ if (component == null)
+ return false;
+ int event_value;
+ if (object.isRelative()) {
+ event_value = object.getRelativeEventValue(di_event.getData());
+ } else {
+ event_value = di_event.getData();
+ }
+ event.set(component, component.getDeviceObject().convertValue(event_value), di_event.getNanos());
+ return true;
+ }
+
+ public final static float poll(Component component, DIDeviceObject object) throws IOException {
+ int poll_data = object.getDevice().getPollData(object);
+ float result;
+ if (object.isRelative()) {
+ result = object.getRelativePollValue(poll_data);
+ } else {
+ result = poll_data;
+ }
+ return object.convertValue(result);
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/DIDeviceObject.java b/src/plugins/windows/net/java/games/input/DIDeviceObject.java
new file mode 100644
index 0000000..c54cd7a
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/DIDeviceObject.java
@@ -0,0 +1,211 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Java wrapper for DIDEVICEOBJECTINSTANCE
+ * @author elias
+ * @version 1.0
+ */
+final class DIDeviceObject {
+ //DirectInput scales wheel deltas by 120
+ private final static int WHEEL_SCALE = 120;
+
+ private final IDirectInputDevice device;
+ private final byte[] guid;
+ private final int identifier;
+ private final int type;
+ private final int instance;
+ private final int guid_type;
+ private final int flags;
+ private final String name;
+ private final Component.Identifier id;
+ private final int format_offset;
+ private final long min;
+ private final long max;
+ private final int deadzone;
+
+ /* These are used for emulating relative axes */
+ private int last_poll_value;
+ private int last_event_value;
+
+ public DIDeviceObject(IDirectInputDevice device, Component.Identifier id, byte[] guid, int guid_type, int identifier, int type, int instance, int flags, String name, int format_offset) throws IOException {
+ this.device = device;
+ this.id = id;
+ this.guid = guid;
+ this.identifier = identifier;
+ this.type = type;
+ this.instance = instance;
+ this.guid_type = guid_type;
+ this.flags = flags;
+ this.name = name;
+ this.format_offset = format_offset;
+ if (isAxis() && !isRelative()) {
+ long[] range = device.getRangeProperty(identifier);
+ this.min = range[0];
+ this.max = range[1];
+ this.deadzone = device.getDeadzoneProperty(identifier);
+ } else {
+ this.min = IDirectInputDevice.DIPROPRANGE_NOMIN;
+ this.max = IDirectInputDevice.DIPROPRANGE_NOMAX;
+ this.deadzone = 0;
+ }
+ }
+
+ public final synchronized int getRelativePollValue(int current_abs_value) {
+ if (device.areAxesRelative())
+ return current_abs_value;
+ int rel_value = current_abs_value - last_poll_value;
+ last_poll_value = current_abs_value;
+ return rel_value;
+ }
+
+ public final synchronized int getRelativeEventValue(int current_abs_value) {
+ if (device.areAxesRelative())
+ return current_abs_value;
+ int rel_value = current_abs_value - last_event_value;
+ last_event_value = current_abs_value;
+ return rel_value;
+ }
+
+ public final int getGUIDType() {
+ return guid_type;
+ }
+
+ public final int getFormatOffset() {
+ return format_offset;
+ }
+
+ public final IDirectInputDevice getDevice() {
+ return device;
+ }
+
+ public final int getDIIdentifier() {
+ return identifier;
+ }
+
+ public final Component.Identifier getIdentifier() {
+ return id;
+ }
+
+ public final String getName() {
+ return name;
+ }
+
+ public final int getInstance() {
+ return instance;
+ }
+
+ public final int getType() {
+ return type;
+ }
+
+ public final byte[] getGUID() {
+ return guid;
+ }
+
+ public final int getFlags() {
+ return flags;
+ }
+
+ public final long getMin() {
+ return min;
+ }
+
+ public final long getMax() {
+ return max;
+ }
+
+ public final float getDeadzone() {
+ return deadzone;
+ }
+
+ public final boolean isButton() {
+ return (type & IDirectInputDevice.DIDFT_BUTTON) != 0;
+ }
+
+ public final boolean isAxis() {
+ return (type & IDirectInputDevice.DIDFT_AXIS) != 0;
+ }
+
+ public final boolean isRelative() {
+ return isAxis() && (type & IDirectInputDevice.DIDFT_RELAXIS) != 0;
+ }
+
+ public final boolean isAnalog() {
+ return isAxis() && id != Component.Identifier.Axis.POV;
+ }
+
+ public final float convertValue(float value) {
+ if (getDevice().getType() == IDirectInputDevice.DI8DEVTYPE_MOUSE && id == Component.Identifier.Axis.Z) {
+ return value/WHEEL_SCALE;
+ } else if (isButton()) {
+ return (((int)value) & 0x80) != 0 ? 1 : 0;
+ } else if (id == Component.Identifier.Axis.POV) {
+ int int_value = (int)value;
+ if ((int_value & 0xFFFF) == 0xFFFF)
+ return Component.POV.OFF;
+ // DirectInput returns POV directions in hundredths of degree clockwise from north
+ int slice = 360*100/16;
+ if (int_value >= 0 && int_value < slice)
+ return Component.POV.UP;
+ else if (int_value < 3*slice)
+ return Component.POV.UP_RIGHT;
+ else if (int_value < 5*slice)
+ return Component.POV.RIGHT;
+ else if (int_value < 7*slice)
+ return Component.POV.DOWN_RIGHT;
+ else if (int_value < 9*slice)
+ return Component.POV.DOWN;
+ else if (int_value < 11*slice)
+ return Component.POV.DOWN_LEFT;
+ else if (int_value < 13*slice)
+ return Component.POV.LEFT;
+ else if (int_value < 15*slice)
+ return Component.POV.UP_LEFT;
+ else
+ return Component.POV.UP;
+ } else if (isAxis() && !isRelative()) {
+ return 2*(value - min)/(float)(max - min) - 1;
+ } else
+ return value;
+ }
+
+}
diff --git a/src/plugins/windows/net/java/games/input/DIDeviceObjectData.java b/src/plugins/windows/net/java/games/input/DIDeviceObjectData.java
new file mode 100644
index 0000000..fa84a9d
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/DIDeviceObjectData.java
@@ -0,0 +1,73 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+/** Java wrapper for DIDEVICEOBJECTDATA
+ * @author elias
+ * @version 1.0
+ */
+final class DIDeviceObjectData {
+ private int format_offset;
+ private int data;
+ private int millis;
+ private int sequence;
+
+ public final void set(int format_offset, int data, int millis, int sequence) {
+ this.format_offset = format_offset;
+ this.data = data;
+ this.millis = millis;
+ this.sequence = sequence;
+ }
+
+ public final void set(DIDeviceObjectData other) {
+ set(other.format_offset, other.data, other.millis, other.sequence);
+ }
+
+ public final int getData() {
+ return data;
+ }
+
+ public final int getFormatOffset() {
+ return format_offset;
+ }
+
+ public final long getNanos() {
+ return millis*1000000L;
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/DIEffectInfo.java b/src/plugins/windows/net/java/games/input/DIEffectInfo.java
new file mode 100644
index 0000000..5ece8a3
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/DIEffectInfo.java
@@ -0,0 +1,83 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+/** Java wrapper for DIEFFECTINFO
+ * @author elias
+ * @version 1.0
+ */
+final class DIEffectInfo {
+ private final IDirectInputDevice device;
+ private final byte[] guid;
+ private final int guid_id;
+ private final int effect_type;
+ private final int static_params;
+ private final int dynamic_params;
+ private final String name;
+
+ public DIEffectInfo(IDirectInputDevice device, byte[] guid, int guid_id, int effect_type, int static_params, int dynamic_params, String name) {
+ this.device = device;
+ this.guid = guid;
+ this.guid_id = guid_id;
+ this.effect_type = effect_type;
+ this.static_params = static_params;
+ this.dynamic_params = dynamic_params;
+ this.name = name;
+ }
+
+ public final byte[] getGUID() {
+ return guid;
+ }
+
+ public final int getGUIDId() {
+ return guid_id;
+ }
+
+ public final int getDynamicParams() {
+ return dynamic_params;
+ }
+
+ public final int getEffectType() {
+ return effect_type;
+ }
+
+ public final String getName() {
+ return name;
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/DIIdentifierMap.java b/src/plugins/windows/net/java/games/input/DIIdentifierMap.java
new file mode 100644
index 0000000..106d658
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/DIIdentifierMap.java
@@ -0,0 +1,546 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+/**
+ * @author elias
+ * @version 1.0
+ */
+final class DIIdentifierMap {
+ public final static int DIK_ESCAPE = 0x01;
+ public final static int DIK_1 = 0x02;
+ public final static int DIK_2 = 0x03;
+ public final static int DIK_3 = 0x04;
+ public final static int DIK_4 = 0x05;
+ public final static int DIK_5 = 0x06;
+ public final static int DIK_6 = 0x07;
+ public final static int DIK_7 = 0x08;
+ public final static int DIK_8 = 0x09;
+ public final static int DIK_9 = 0x0A;
+ public final static int DIK_0 = 0x0B;
+ public final static int DIK_MINUS = 0x0C; /* - on main keyboard */
+ public final static int DIK_EQUALS = 0x0D;
+ public final static int DIK_BACK = 0x0E; /* backspace */
+ public final static int DIK_TAB = 0x0F;
+ public final static int DIK_Q = 0x10;
+ public final static int DIK_W = 0x11;
+ public final static int DIK_E = 0x12;
+ public final static int DIK_R = 0x13;
+ public final static int DIK_T = 0x14;
+ public final static int DIK_Y = 0x15;
+ public final static int DIK_U = 0x16;
+ public final static int DIK_I = 0x17;
+ public final static int DIK_O = 0x18;
+ public final static int DIK_P = 0x19;
+ public final static int DIK_LBRACKET = 0x1A;
+ public final static int DIK_RBRACKET = 0x1B;
+ public final static int DIK_RETURN = 0x1C; /* Enter on main keyboard */
+ public final static int DIK_LCONTROL = 0x1D;
+ public final static int DIK_A = 0x1E;
+ public final static int DIK_S = 0x1F;
+ public final static int DIK_D = 0x20;
+ public final static int DIK_F = 0x21;
+ public final static int DIK_G = 0x22;
+ public final static int DIK_H = 0x23;
+ public final static int DIK_J = 0x24;
+ public final static int DIK_K = 0x25;
+ public final static int DIK_L = 0x26;
+ public final static int DIK_SEMICOLON = 0x27;
+ public final static int DIK_APOSTROPHE = 0x28;
+ public final static int DIK_GRAVE = 0x29; /* accent grave */
+ public final static int DIK_LSHIFT = 0x2A;
+ public final static int DIK_BACKSLASH = 0x2B;
+ public final static int DIK_Z = 0x2C;
+ public final static int DIK_X = 0x2D;
+ public final static int DIK_C = 0x2E;
+ public final static int DIK_V = 0x2F;
+ public final static int DIK_B = 0x30;
+ public final static int DIK_N = 0x31;
+ public final static int DIK_M = 0x32;
+ public final static int DIK_COMMA = 0x33;
+ public final static int DIK_PERIOD = 0x34; /* . on main keyboard */
+ public final static int DIK_SLASH = 0x35; /* / on main keyboard */
+ public final static int DIK_RSHIFT = 0x36;
+ public final static int DIK_MULTIPLY = 0x37; /* * on numeric keypad */
+ public final static int DIK_LMENU = 0x38; /* left Alt */
+ public final static int DIK_SPACE = 0x39;
+ public final static int DIK_CAPITAL = 0x3A;
+ public final static int DIK_F1 = 0x3B;
+ public final static int DIK_F2 = 0x3C;
+ public final static int DIK_F3 = 0x3D;
+ public final static int DIK_F4 = 0x3E;
+ public final static int DIK_F5 = 0x3F;
+ public final static int DIK_F6 = 0x40;
+ public final static int DIK_F7 = 0x41;
+ public final static int DIK_F8 = 0x42;
+ public final static int DIK_F9 = 0x43;
+ public final static int DIK_F10 = 0x44;
+ public final static int DIK_NUMLOCK = 0x45;
+ public final static int DIK_SCROLL = 0x46; /* Scroll Lock */
+ public final static int DIK_NUMPAD7 = 0x47;
+ public final static int DIK_NUMPAD8 = 0x48;
+ public final static int DIK_NUMPAD9 = 0x49;
+ public final static int DIK_SUBTRACT = 0x4A; /* - on numeric keypad */
+ public final static int DIK_NUMPAD4 = 0x4B;
+ public final static int DIK_NUMPAD5 = 0x4C;
+ public final static int DIK_NUMPAD6 = 0x4D;
+ public final static int DIK_ADD = 0x4E; /* + on numeric keypad */
+ public final static int DIK_NUMPAD1 = 0x4F;
+ public final static int DIK_NUMPAD2 = 0x50;
+ public final static int DIK_NUMPAD3 = 0x51;
+ public final static int DIK_NUMPAD0 = 0x52;
+ public final static int DIK_DECIMAL = 0x53; /* . on numeric keypad */
+ public final static int DIK_OEM_102 = 0x56; /* <> or \| on RT 102-key keyboard (Non-U.S.) */
+ public final static int DIK_F11 = 0x57;
+ public final static int DIK_F12 = 0x58;
+ public final static int DIK_F13 = 0x64; /* (NEC PC98) */
+ public final static int DIK_F14 = 0x65; /* (NEC PC98) */
+ public final static int DIK_F15 = 0x66; /* (NEC PC98) */
+ public final static int DIK_KANA = 0x70; /* (Japanese keyboard) */
+ public final static int DIK_ABNT_C1 = 0x73; /* /? on Brazilian keyboard */
+ public final static int DIK_CONVERT = 0x79; /* (Japanese keyboard) */
+ public final static int DIK_NOCONVERT = 0x7B; /* (Japanese keyboard) */
+ public final static int DIK_YEN = 0x7D; /* (Japanese keyboard) */
+ public final static int DIK_ABNT_C2 = 0x7E; /* Numpad . on Brazilian keyboard */
+ public final static int DIK_NUMPADEQUALS = 0x8D; /* = on numeric keypad (NEC PC98) */
+ public final static int DIK_PREVTRACK = 0x90; /* Previous Track (DIK_CIRCUMFLEX on Japanese keyboard) */
+ public final static int DIK_AT = 0x91; /* (NEC PC98) */
+ public final static int DIK_COLON = 0x92; /* (NEC PC98) */
+ public final static int DIK_UNDERLINE = 0x93; /* (NEC PC98) */
+ public final static int DIK_KANJI = 0x94; /* (Japanese keyboard) */
+ public final static int DIK_STOP = 0x95; /* (NEC PC98) */
+ public final static int DIK_AX = 0x96; /* (Japan AX) */
+ public final static int DIK_UNLABELED = 0x97; /* (J3100) */
+ public final static int DIK_NEXTTRACK = 0x99; /* Next Track */
+ public final static int DIK_NUMPADENTER = 0x9C; /* Enter on numeric keypad */
+ public final static int DIK_RCONTROL = 0x9D;
+ public final static int DIK_MUTE = 0xA0; /* Mute */
+ public final static int DIK_CALCULATOR = 0xA1; /* Calculator */
+ public final static int DIK_PLAYPAUSE = 0xA2; /* Play / Pause */
+ public final static int DIK_MEDIASTOP = 0xA4; /* Media Stop */
+ public final static int DIK_VOLUMEDOWN = 0xAE; /* Volume - */
+ public final static int DIK_VOLUMEUP = 0xB0; /* Volume + */
+ public final static int DIK_WEBHOME = 0xB2; /* Web home */
+ public final static int DIK_NUMPADCOMMA = 0xB3; /* , on numeric keypad (NEC PC98) */
+ public final static int DIK_DIVIDE = 0xB5; /* / on numeric keypad */
+ public final static int DIK_SYSRQ = 0xB7;
+ public final static int DIK_RMENU = 0xB8; /* right Alt */
+ public final static int DIK_PAUSE = 0xC5; /* Pause */
+ public final static int DIK_HOME = 0xC7; /* Home on arrow keypad */
+ public final static int DIK_UP = 0xC8; /* UpArrow on arrow keypad */
+ public final static int DIK_PRIOR = 0xC9; /* PgUp on arrow keypad */
+ public final static int DIK_LEFT = 0xCB; /* LeftArrow on arrow keypad */
+ public final static int DIK_RIGHT = 0xCD; /* RightArrow on arrow keypad */
+ public final static int DIK_END = 0xCF; /* End on arrow keypad */
+ public final static int DIK_DOWN = 0xD0; /* DownArrow on arrow keypad */
+ public final static int DIK_NEXT = 0xD1; /* PgDn on arrow keypad */
+ public final static int DIK_INSERT = 0xD2; /* Insert on arrow keypad */
+ public final static int DIK_DELETE = 0xD3; /* Delete on arrow keypad */
+ public final static int DIK_LWIN = 0xDB; /* Left Windows key */
+ public final static int DIK_RWIN = 0xDC; /* Right Windows key */
+ public final static int DIK_APPS = 0xDD; /* AppMenu key */
+ public final static int DIK_POWER = 0xDE; /* System Power */
+ public final static int DIK_SLEEP = 0xDF; /* System Sleep */
+ public final static int DIK_WAKE = 0xE3; /* System Wake */
+ public final static int DIK_WEBSEARCH = 0xE5; /* Web Search */
+ public final static int DIK_WEBFAVORITES = 0xE6; /* Web Favorites */
+ public final static int DIK_WEBREFRESH = 0xE7; /* Web Refresh */
+ public final static int DIK_WEBSTOP = 0xE8; /* Web Stop */
+ public final static int DIK_WEBFORWARD = 0xE9; /* Web Forward */
+ public final static int DIK_WEBBACK = 0xEA; /* Web Back */
+ public final static int DIK_MYCOMPUTER = 0xEB; /* My Computer */
+ public final static int DIK_MAIL = 0xEC; /* Mail */
+ public final static int DIK_MEDIASELECT = 0xED; /* Media Select */
+
+ public final static Component.Identifier.Key getKeyIdentifier(int key_code) {
+ switch (key_code) {
+ case DIK_ESCAPE:
+ return Component.Identifier.Key.ESCAPE;
+ case DIK_1:
+ return Component.Identifier.Key._1;
+ case DIK_2:
+ return Component.Identifier.Key._2;
+ case DIK_3:
+ return Component.Identifier.Key._3;
+ case DIK_4:
+ return Component.Identifier.Key._4;
+ case DIK_5:
+ return Component.Identifier.Key._5;
+ case DIK_6:
+ return Component.Identifier.Key._6;
+ case DIK_7:
+ return Component.Identifier.Key._7;
+ case DIK_8:
+ return Component.Identifier.Key._8;
+ case DIK_9:
+ return Component.Identifier.Key._9;
+ case DIK_0:
+ return Component.Identifier.Key._0;
+ case DIK_MINUS:
+ return Component.Identifier.Key.MINUS;
+ case DIK_EQUALS:
+ return Component.Identifier.Key.EQUALS;
+ case DIK_BACK:
+ return Component.Identifier.Key.BACK;
+ case DIK_TAB:
+ return Component.Identifier.Key.TAB;
+ case DIK_Q:
+ return Component.Identifier.Key.Q;
+ case DIK_W:
+ return Component.Identifier.Key.W;
+ case DIK_E:
+ return Component.Identifier.Key.E;
+ case DIK_R:
+ return Component.Identifier.Key.R;
+ case DIK_T:
+ return Component.Identifier.Key.T;
+ case DIK_Y:
+ return Component.Identifier.Key.Y;
+ case DIK_U:
+ return Component.Identifier.Key.U;
+ case DIK_I:
+ return Component.Identifier.Key.I;
+ case DIK_O:
+ return Component.Identifier.Key.O;
+ case DIK_P:
+ return Component.Identifier.Key.P;
+ case DIK_LBRACKET:
+ return Component.Identifier.Key.LBRACKET;
+ case DIK_RBRACKET:
+ return Component.Identifier.Key.RBRACKET;
+ case DIK_RETURN:
+ return Component.Identifier.Key.RETURN;
+ case DIK_LCONTROL:
+ return Component.Identifier.Key.LCONTROL;
+ case DIK_A:
+ return Component.Identifier.Key.A;
+ case DIK_S:
+ return Component.Identifier.Key.S;
+ case DIK_D:
+ return Component.Identifier.Key.D;
+ case DIK_F:
+ return Component.Identifier.Key.F;
+ case DIK_G:
+ return Component.Identifier.Key.G;
+ case DIK_H:
+ return Component.Identifier.Key.H;
+ case DIK_J:
+ return Component.Identifier.Key.J;
+ case DIK_K:
+ return Component.Identifier.Key.K;
+ case DIK_L:
+ return Component.Identifier.Key.L;
+ case DIK_SEMICOLON:
+ return Component.Identifier.Key.SEMICOLON;
+ case DIK_APOSTROPHE:
+ return Component.Identifier.Key.APOSTROPHE;
+ case DIK_GRAVE:
+ return Component.Identifier.Key.GRAVE;
+ case DIK_LSHIFT:
+ return Component.Identifier.Key.LSHIFT;
+ case DIK_BACKSLASH:
+ return Component.Identifier.Key.BACKSLASH;
+ case DIK_Z:
+ return Component.Identifier.Key.Z;
+ case DIK_X:
+ return Component.Identifier.Key.X;
+ case DIK_C:
+ return Component.Identifier.Key.C;
+ case DIK_V:
+ return Component.Identifier.Key.V;
+ case DIK_B:
+ return Component.Identifier.Key.B;
+ case DIK_N:
+ return Component.Identifier.Key.N;
+ case DIK_M:
+ return Component.Identifier.Key.M;
+ case DIK_COMMA:
+ return Component.Identifier.Key.COMMA;
+ case DIK_PERIOD:
+ return Component.Identifier.Key.PERIOD;
+ case DIK_SLASH:
+ return Component.Identifier.Key.SLASH;
+ case DIK_RSHIFT:
+ return Component.Identifier.Key.RSHIFT;
+ case DIK_MULTIPLY:
+ return Component.Identifier.Key.MULTIPLY;
+ case DIK_LMENU:
+ return Component.Identifier.Key.LALT;
+ case DIK_SPACE:
+ return Component.Identifier.Key.SPACE;
+ case DIK_CAPITAL:
+ return Component.Identifier.Key.CAPITAL;
+ case DIK_F1:
+ return Component.Identifier.Key.F1;
+ case DIK_F2:
+ return Component.Identifier.Key.F2;
+ case DIK_F3:
+ return Component.Identifier.Key.F3;
+ case DIK_F4:
+ return Component.Identifier.Key.F4;
+ case DIK_F5:
+ return Component.Identifier.Key.F5;
+ case DIK_F6:
+ return Component.Identifier.Key.F6;
+ case DIK_F7:
+ return Component.Identifier.Key.F7;
+ case DIK_F8:
+ return Component.Identifier.Key.F8;
+ case DIK_F9:
+ return Component.Identifier.Key.F9;
+ case DIK_F10:
+ return Component.Identifier.Key.F10;
+ case DIK_NUMLOCK:
+ return Component.Identifier.Key.NUMLOCK;
+ case DIK_SCROLL:
+ return Component.Identifier.Key.SCROLL;
+ case DIK_NUMPAD7:
+ return Component.Identifier.Key.NUMPAD7;
+ case DIK_NUMPAD8:
+ return Component.Identifier.Key.NUMPAD8;
+ case DIK_NUMPAD9:
+ return Component.Identifier.Key.NUMPAD9;
+ case DIK_SUBTRACT:
+ return Component.Identifier.Key.SUBTRACT;
+ case DIK_NUMPAD4:
+ return Component.Identifier.Key.NUMPAD4;
+ case DIK_NUMPAD5:
+ return Component.Identifier.Key.NUMPAD5;
+ case DIK_NUMPAD6:
+ return Component.Identifier.Key.NUMPAD6;
+ case DIK_ADD:
+ return Component.Identifier.Key.ADD;
+ case DIK_NUMPAD1:
+ return Component.Identifier.Key.NUMPAD1;
+ case DIK_NUMPAD2:
+ return Component.Identifier.Key.NUMPAD2;
+ case DIK_NUMPAD3:
+ return Component.Identifier.Key.NUMPAD3;
+ case DIK_NUMPAD0:
+ return Component.Identifier.Key.NUMPAD0;
+ case DIK_DECIMAL:
+ return Component.Identifier.Key.DECIMAL;
+ case DIK_F11:
+ return Component.Identifier.Key.F11;
+ case DIK_F12:
+ return Component.Identifier.Key.F12;
+ case DIK_F13:
+ return Component.Identifier.Key.F13;
+ case DIK_F14:
+ return Component.Identifier.Key.F14;
+ case DIK_F15:
+ return Component.Identifier.Key.F15;
+ case DIK_KANA:
+ return Component.Identifier.Key.KANA;
+ case DIK_CONVERT:
+ return Component.Identifier.Key.CONVERT;
+ case DIK_NOCONVERT:
+ return Component.Identifier.Key.NOCONVERT;
+ case DIK_YEN:
+ return Component.Identifier.Key.YEN;
+ case DIK_NUMPADEQUALS:
+ return Component.Identifier.Key.NUMPADEQUAL;
+ case DIK_AT:
+ return Component.Identifier.Key.AT;
+ case DIK_COLON:
+ return Component.Identifier.Key.COLON;
+ case DIK_UNDERLINE:
+ return Component.Identifier.Key.UNDERLINE;
+ case DIK_KANJI:
+ return Component.Identifier.Key.KANJI;
+ case DIK_STOP:
+ return Component.Identifier.Key.STOP;
+ case DIK_AX:
+ return Component.Identifier.Key.AX;
+ case DIK_UNLABELED:
+ return Component.Identifier.Key.UNLABELED;
+ case DIK_NUMPADENTER:
+ return Component.Identifier.Key.NUMPADENTER;
+ case DIK_RCONTROL:
+ return Component.Identifier.Key.RCONTROL;
+ case DIK_NUMPADCOMMA:
+ return Component.Identifier.Key.NUMPADCOMMA;
+ case DIK_DIVIDE:
+ return Component.Identifier.Key.DIVIDE;
+ case DIK_SYSRQ:
+ return Component.Identifier.Key.SYSRQ;
+ case DIK_RMENU:
+ return Component.Identifier.Key.RALT;
+ case DIK_PAUSE:
+ return Component.Identifier.Key.PAUSE;
+ case DIK_HOME:
+ return Component.Identifier.Key.HOME;
+ case DIK_UP:
+ return Component.Identifier.Key.UP;
+ case DIK_PRIOR:
+ return Component.Identifier.Key.PAGEUP;
+ case DIK_LEFT:
+ return Component.Identifier.Key.LEFT;
+ case DIK_RIGHT:
+ return Component.Identifier.Key.RIGHT;
+ case DIK_END:
+ return Component.Identifier.Key.END;
+ case DIK_DOWN:
+ return Component.Identifier.Key.DOWN;
+ case DIK_NEXT:
+ return Component.Identifier.Key.PAGEDOWN;
+ case DIK_INSERT:
+ return Component.Identifier.Key.INSERT;
+ case DIK_DELETE:
+ return Component.Identifier.Key.DELETE;
+ case DIK_LWIN:
+ return Component.Identifier.Key.LWIN;
+ case DIK_RWIN:
+ return Component.Identifier.Key.RWIN;
+ case DIK_APPS:
+ return Component.Identifier.Key.APPS;
+ case DIK_POWER:
+ return Component.Identifier.Key.POWER;
+ case DIK_SLEEP:
+ return Component.Identifier.Key.SLEEP;
+ /* Unassigned keys */
+ case DIK_ABNT_C1:
+ case DIK_ABNT_C2:
+ case DIK_PREVTRACK:
+ case DIK_PLAYPAUSE:
+ case DIK_NEXTTRACK:
+ case DIK_MUTE:
+ case DIK_CALCULATOR:
+ case DIK_MEDIASTOP:
+ case DIK_VOLUMEDOWN:
+ case DIK_VOLUMEUP:
+ case DIK_WEBHOME:
+ case DIK_WAKE:
+ case DIK_WEBSEARCH:
+ case DIK_WEBFAVORITES:
+ case DIK_WEBREFRESH:
+ case DIK_WEBSTOP:
+ case DIK_WEBFORWARD:
+ case DIK_WEBBACK:
+ case DIK_MYCOMPUTER:
+ case DIK_MAIL:
+ case DIK_MEDIASELECT:
+ case DIK_OEM_102:
+ default:
+ return Component.Identifier.Key.UNKNOWN;
+ }
+ }
+
+ public final static Component.Identifier.Button getButtonIdentifier(int id) {
+ switch (id) {
+ case 0:
+ return Component.Identifier.Button._0;
+ case 1:
+ return Component.Identifier.Button._1;
+ case 2:
+ return Component.Identifier.Button._2;
+ case 3:
+ return Component.Identifier.Button._3;
+ case 4:
+ return Component.Identifier.Button._4;
+ case 5:
+ return Component.Identifier.Button._5;
+ case 6:
+ return Component.Identifier.Button._6;
+ case 7:
+ return Component.Identifier.Button._7;
+ case 8:
+ return Component.Identifier.Button._8;
+ case 9:
+ return Component.Identifier.Button._9;
+ case 10:
+ return Component.Identifier.Button._10;
+ case 11:
+ return Component.Identifier.Button._11;
+ case 12:
+ return Component.Identifier.Button._12;
+ case 13:
+ return Component.Identifier.Button._13;
+ case 14:
+ return Component.Identifier.Button._14;
+ case 15:
+ return Component.Identifier.Button._15;
+ case 16:
+ return Component.Identifier.Button._16;
+ case 17:
+ return Component.Identifier.Button._17;
+ case 18:
+ return Component.Identifier.Button._18;
+ case 19:
+ return Component.Identifier.Button._19;
+ case 20:
+ return Component.Identifier.Button._20;
+ case 21:
+ return Component.Identifier.Button._21;
+ case 22:
+ return Component.Identifier.Button._22;
+ case 23:
+ return Component.Identifier.Button._23;
+ case 24:
+ return Component.Identifier.Button._24;
+ case 25:
+ return Component.Identifier.Button._25;
+ case 26:
+ return Component.Identifier.Button._26;
+ case 27:
+ return Component.Identifier.Button._27;
+ case 28:
+ return Component.Identifier.Button._28;
+ case 29:
+ return Component.Identifier.Button._29;
+ case 30:
+ return Component.Identifier.Button._30;
+ case 31:
+ return Component.Identifier.Button._31;
+ default:
+ return null;
+ }
+ }
+
+ public final static Component.Identifier.Button mapMouseButtonIdentifier(Component.Identifier.Button button_id) {
+ if (button_id == Component.Identifier.Button._0) {
+ return Component.Identifier.Button.LEFT;
+ } else if (button_id == Component.Identifier.Button._1) {
+ return Component.Identifier.Button.RIGHT;
+ } else if (button_id == Component.Identifier.Button._2) {
+ return Component.Identifier.Button.MIDDLE;
+ } else
+ return button_id;
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/DIKeyboard.java b/src/plugins/windows/net/java/games/input/DIKeyboard.java
new file mode 100644
index 0000000..6eec1b7
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/DIKeyboard.java
@@ -0,0 +1,66 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/**
+* @author elias
+* @version 1.0
+*/
+final class DIKeyboard extends Keyboard {
+ private final IDirectInputDevice device;
+
+ protected DIKeyboard(IDirectInputDevice device, Component[] components, Controller[] children, Rumbler[] rumblers) {
+ super(device.getProductName(), components, children, rumblers);
+ this.device = device;
+ }
+
+ protected final boolean getNextDeviceEvent(Event event) throws IOException {
+ return DIControllers.getNextDeviceEvent(event, device);
+ }
+
+ public final void pollDevice() throws IOException {
+ device.pollAll();
+ }
+
+ protected final void setDeviceEventQueueSize(int size) throws IOException {
+ device.setBufferSize(size);
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/DIMouse.java b/src/plugins/windows/net/java/games/input/DIMouse.java
new file mode 100644
index 0000000..e24ff77
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/DIMouse.java
@@ -0,0 +1,67 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/**
+* @author elias
+* @version 1.0
+*/
+final class DIMouse extends Mouse {
+ private final IDirectInputDevice device;
+
+ protected DIMouse(IDirectInputDevice device, Component[] components, Controller[] children, Rumbler[] rumblers) {
+ super(device.getProductName(), components, children, rumblers);
+ this.device = device;
+ }
+
+ public final void pollDevice() throws IOException {
+ device.pollAll();
+ }
+
+ protected final boolean getNextDeviceEvent(Event event) throws IOException {
+ return DIControllers.getNextDeviceEvent(event, device);
+ }
+
+ protected final void setDeviceEventQueueSize(int size) throws IOException {
+ device.setBufferSize(size);
+ }
+
+}
diff --git a/src/plugins/windows/net/java/games/input/DataQueue.java b/src/plugins/windows/net/java/games/input/DataQueue.java
new file mode 100644
index 0000000..a530bc6
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/DataQueue.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * @author elias
+ * @version 1.0
+ */
+final class DataQueue {
+ private final T[] elements;
+ private int position;
+ private int limit;
+
+ @SuppressWarnings("unchecked")
+ public DataQueue(int size, Class element_type) {
+ this.elements= (T[])Array.newInstance(element_type, size);
+ for (int i = 0; i < elements.length; i++) {
+ try {
+ elements[i] = element_type.getDeclaredConstructor().newInstance();
+ } catch (InstantiationException|IllegalAccessException|NoSuchMethodException|InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ clear();
+ }
+
+ public final void clear() {
+ position = 0;
+ limit = elements.length;
+ }
+
+ public final int position() {
+ return position;
+ }
+
+ public final int limit() {
+ return limit;
+ }
+
+ public final T get(int index) {
+ assert index < limit;
+ return elements[index];
+ }
+
+ public final T get() {
+ if (!hasRemaining())
+ return null;
+ return get(position++);
+ }
+
+ public final void compact() {
+ int index = 0;
+ while (hasRemaining()) {
+ swap(position, index);
+ position++;
+ index++;
+ }
+ position = index;
+ limit = elements.length;
+ }
+
+ private final void swap(int index1, int index2) {
+ T temp = elements[index1];
+ elements[index1] = elements[index2];
+ elements[index2] = temp;
+ }
+
+ public final void flip() {
+ limit = position;
+ position = 0;
+ }
+
+ public final boolean hasRemaining() {
+ return remaining() > 0;
+ }
+
+ public final int remaining() {
+ return limit - position;
+ }
+
+ public final void position(int position) {
+ this.position = position;
+ }
+
+ public final T[] getElements() {
+ return elements;
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/DirectAndRawInputEnvironmentPlugin.java b/src/plugins/windows/net/java/games/input/DirectAndRawInputEnvironmentPlugin.java
new file mode 100644
index 0000000..29b6c07
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/DirectAndRawInputEnvironmentPlugin.java
@@ -0,0 +1,94 @@
+/**
+ * Copyright (C) 2007 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Combines the list of seperate keyboards and mice found with the raw plugin,
+ * with the game controllers found with direct input.
+ *
+ * @author Jeremy
+ */
+public class DirectAndRawInputEnvironmentPlugin extends ControllerEnvironment {
+
+ private RawInputEnvironmentPlugin rawPlugin;
+ private DirectInputEnvironmentPlugin dinputPlugin;
+ private Controller[] controllers = null;
+
+ public DirectAndRawInputEnvironmentPlugin() {
+ // These two *must* be loaded in this order for raw devices to work.
+ dinputPlugin = new DirectInputEnvironmentPlugin();
+ rawPlugin = new RawInputEnvironmentPlugin();
+ }
+
+ /**
+ * @see net.java.games.input.ControllerEnvironment#getControllers()
+ */
+ public Controller[] getControllers() {
+ if(controllers == null) {
+ boolean rawKeyboardFound = false;
+ boolean rawMouseFound = false;
+ List tempControllers = new ArrayList<>();
+ Controller[] dinputControllers = dinputPlugin.getControllers();
+ Controller[] rawControllers = rawPlugin.getControllers();
+ for(int i=0;i) () -> {
+ try {
+ String lib_path = System.getProperty("net.java.games.input.librarypath");
+ if (lib_path != null)
+ System.load(lib_path + File.separator + System.mapLibraryName(lib_name));
+ else
+ System.loadLibrary(lib_name);
+ } catch (UnsatisfiedLinkError e) {
+ e.printStackTrace();
+ supported = false;
+ }
+ return null;
+ });
+ }
+
+ static String getPrivilegedProperty(final String property) {
+ return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property));
+ }
+
+
+ static String getPrivilegedProperty(final String property, final String default_value) {
+ return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property, default_value));
+ }
+
+ static {
+ String osName = getPrivilegedProperty("os.name", "").trim();
+ if(osName.startsWith("Windows")) {
+ supported = true;
+ if("x86".equals(getPrivilegedProperty("os.arch"))) {
+ loadLibrary("jinput-dx8");
+ } else {
+ loadLibrary("jinput-dx8_64");
+ }
+ }
+ }
+
+ private final Controller[] controllers;
+ private final List active_devices = new ArrayList<>();
+ private final DummyWindow window;
+
+ /** Creates new DirectInputEnvironment */
+ public DirectInputEnvironmentPlugin() {
+ DummyWindow window = null;
+ Controller[] controllers = new Controller[]{};
+ if(isSupported()) {
+ try {
+ window = new DummyWindow();
+ try {
+ controllers = enumControllers(window);
+ } catch (IOException e) {
+ window.destroy();
+ throw e;
+ }
+ } catch (IOException e) {
+ log("Failed to enumerate devices: " + e.getMessage());
+ }
+ this.window = window;
+ this.controllers = controllers;
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ Runtime.getRuntime().addShutdownHook(new ShutdownHook());
+ return null;
+ });
+ } else {
+ // These are final fields, so can't set them, then over ride
+ // them if we are supported.
+ this.window = null;
+ this.controllers = controllers;
+ }
+ }
+
+ public final Controller[] getControllers() {
+ return controllers;
+ }
+
+ private final Component[] createComponents(IDirectInputDevice device, boolean map_mouse_buttons) {
+ List device_objects = device.getObjects();
+ List controller_components = new ArrayList<>();
+ for (int i = 0; i < device_objects.size(); i++) {
+ DIDeviceObject device_object = device_objects.get(i);
+ Component.Identifier identifier = device_object.getIdentifier();
+ if (identifier == null)
+ continue;
+ if (map_mouse_buttons && identifier instanceof Component.Identifier.Button) {
+ identifier = DIIdentifierMap.mapMouseButtonIdentifier((Component.Identifier.Button)identifier);
+ }
+ DIComponent component = new DIComponent(identifier, device_object);
+ controller_components.add(component);
+ device.registerComponent(device_object, component);
+ }
+ Component[] components = new Component[controller_components.size()];
+ controller_components.toArray(components);
+ return components;
+ }
+
+ private final Mouse createMouseFromDevice(IDirectInputDevice device) {
+ Component[] components = createComponents(device, true);
+ Mouse mouse = new DIMouse(device, components, new Controller[]{}, device.getRumblers());
+ if (mouse.getX() != null && mouse.getY() != null && mouse.getPrimaryButton() != null)
+ return mouse;
+ else
+ return null;
+ }
+
+ private final AbstractController createControllerFromDevice(IDirectInputDevice device, Controller.Type type) {
+ Component[] components = createComponents(device, false);
+ AbstractController controller = new DIAbstractController(device, components, new Controller[]{}, device.getRumblers(), type);
+ return controller;
+ }
+
+ private final Keyboard createKeyboardFromDevice(IDirectInputDevice device) {
+ Component[] components = createComponents(device, false);
+ return new DIKeyboard(device, components, new Controller[]{}, device.getRumblers());
+ }
+
+ private final Controller createControllerFromDevice(IDirectInputDevice device) {
+ switch (device.getType()) {
+ case IDirectInputDevice.DI8DEVTYPE_MOUSE:
+ return createMouseFromDevice(device);
+ case IDirectInputDevice.DI8DEVTYPE_KEYBOARD:
+ return createKeyboardFromDevice(device);
+ case IDirectInputDevice.DI8DEVTYPE_GAMEPAD:
+ return createControllerFromDevice(device, Controller.Type.GAMEPAD);
+ case IDirectInputDevice.DI8DEVTYPE_DRIVING:
+ return createControllerFromDevice(device, Controller.Type.WHEEL);
+ case IDirectInputDevice.DI8DEVTYPE_1STPERSON:
+ /* Fall through */
+ case IDirectInputDevice.DI8DEVTYPE_FLIGHT:
+ /* Fall through */
+ case IDirectInputDevice.DI8DEVTYPE_JOYSTICK:
+ return createControllerFromDevice(device, Controller.Type.STICK);
+ default:
+ return createControllerFromDevice(device, Controller.Type.UNKNOWN);
+ }
+ }
+
+ private final Controller[] enumControllers(DummyWindow window) throws IOException {
+ List controllers = new ArrayList<>();
+ IDirectInput dinput = new IDirectInput(window);
+ try {
+ List devices = dinput.getDevices();
+ for (int i = 0; i < devices.size(); i++) {
+ IDirectInputDevice device = devices.get(i);
+ Controller controller = createControllerFromDevice(device);
+ if (controller != null) {
+ controllers.add(controller);
+ active_devices.add(device);
+ } else
+ device.release();
+ }
+ } finally {
+ dinput.release();
+ }
+ Controller[] controllers_array = new Controller[controllers.size()];
+ controllers.toArray(controllers_array);
+ return controllers_array;
+ }
+
+ private final class ShutdownHook extends Thread {
+ public final void run() {
+ /* Release the devices to kill off active force feedback effects */
+ for (int i = 0; i < active_devices.size(); i++) {
+ IDirectInputDevice device = active_devices.get(i);
+ device.release();
+ }
+ /* We won't release the window since it is
+ * owned by the thread that created the environment.
+ */
+ }
+ }
+
+ public boolean isSupported() {
+ return supported;
+ }
+}
\ No newline at end of file
diff --git a/src/plugins/windows/net/java/games/input/DummyWindow.java b/src/plugins/windows/net/java/games/input/DummyWindow.java
new file mode 100644
index 0000000..5c66d9a
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/DummyWindow.java
@@ -0,0 +1,64 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Java wrapper for a (dummy) window
+ * @author martak
+ * @author elias
+ * @version 1.0
+ */
+final class DummyWindow {
+ private final long hwnd_address;
+
+ public DummyWindow() throws IOException {
+ this.hwnd_address = createWindow();
+ }
+ private final static native long createWindow() throws IOException;
+
+ public final void destroy() throws IOException {
+ nDestroy(hwnd_address);
+ }
+ private final static native void nDestroy(long hwnd_address) throws IOException;
+
+ public final long getHwnd() {
+ return hwnd_address;
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/IDirectInput.java b/src/plugins/windows/net/java/games/input/IDirectInput.java
new file mode 100644
index 0000000..e8c929b
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/IDirectInput.java
@@ -0,0 +1,100 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+
+/** Java wrapper for IDirectInput
+ * @author martak
+ * @author elias
+ * @version 1.0
+ */
+final class IDirectInput {
+ private final List devices = new ArrayList<>();
+ private final long idirectinput_address;
+ private final DummyWindow window;
+
+ public IDirectInput(DummyWindow window) throws IOException {
+ this.window = window;
+ this.idirectinput_address = createIDirectInput();
+ try {
+ enumDevices();
+ } catch (IOException e) {
+ releaseDevices();
+ release();
+ throw e;
+ }
+ }
+ private final static native long createIDirectInput() throws IOException;
+
+ public final List getDevices() {
+ return devices;
+ }
+
+ private final void enumDevices() throws IOException {
+ nEnumDevices(idirectinput_address);
+ }
+ private final native void nEnumDevices(long addr) throws IOException;
+
+ /* This method is called from native code in nEnumDevices
+ * native side will clean up in case of an exception
+ */
+ private final void addDevice(long address, byte[] instance_guid, byte[] product_guid, int dev_type, int dev_subtype, String instance_name, String product_name) throws IOException {
+ try {
+ IDirectInputDevice device = new IDirectInputDevice(window, address, instance_guid, product_guid, dev_type, dev_subtype, instance_name, product_name);
+ devices.add(device);
+ } catch (IOException e) {
+ DirectInputEnvironmentPlugin.log("Failed to initialize device " + product_name + " because of: " + e);
+ }
+ }
+
+ public final void releaseDevices() {
+ for (int i = 0; i < devices.size(); i++) {
+ IDirectInputDevice device = devices.get(i);
+ device.release();
+ }
+ }
+
+ public final void release() {
+ nRelease(idirectinput_address);
+ }
+ private final static native void nRelease(long address);
+}
diff --git a/src/plugins/windows/net/java/games/input/IDirectInputDevice.java b/src/plugins/windows/net/java/games/input/IDirectInputDevice.java
new file mode 100644
index 0000000..3fb29f7
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/IDirectInputDevice.java
@@ -0,0 +1,541 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Arrays;
+
+/** Java wrapper for IDirectInputDevice
+ * @author martak
+ * @author elias
+ * @version 1.0
+ */
+final class IDirectInputDevice {
+ public final static int GUID_XAxis = 1;
+ public final static int GUID_YAxis = 2;
+ public final static int GUID_ZAxis = 3;
+ public final static int GUID_RxAxis = 4;
+ public final static int GUID_RyAxis = 5;
+ public final static int GUID_RzAxis = 6;
+ public final static int GUID_Slider = 7;
+ public final static int GUID_Button = 8;
+ public final static int GUID_Key = 9;
+ public final static int GUID_POV = 10;
+ public final static int GUID_Unknown = 11;
+
+ public final static int GUID_ConstantForce = 12;
+ public final static int GUID_RampForce = 13;
+ public final static int GUID_Square = 14;
+ public final static int GUID_Sine = 15;
+ public final static int GUID_Triangle = 16;
+ public final static int GUID_SawtoothUp = 17;
+ public final static int GUID_SawtoothDown = 18;
+ public final static int GUID_Spring = 19;
+ public final static int GUID_Damper = 20;
+ public final static int GUID_Inertia = 21;
+ public final static int GUID_Friction = 22;
+ public final static int GUID_CustomForce = 23;
+
+ public final static int DI8DEVTYPE_DEVICE = 0x11;
+ public final static int DI8DEVTYPE_MOUSE = 0x12;
+ public final static int DI8DEVTYPE_KEYBOARD = 0x13;
+ public final static int DI8DEVTYPE_JOYSTICK = 0x14;
+ public final static int DI8DEVTYPE_GAMEPAD = 0x15;
+ public final static int DI8DEVTYPE_DRIVING = 0x16;
+ public final static int DI8DEVTYPE_FLIGHT = 0x17;
+ public final static int DI8DEVTYPE_1STPERSON = 0x18;
+ public final static int DI8DEVTYPE_DEVICECTRL = 0x19;
+ public final static int DI8DEVTYPE_SCREENPOINTER = 0x1A;
+ public final static int DI8DEVTYPE_REMOTE = 0x1B;
+ public final static int DI8DEVTYPE_SUPPLEMENTAL = 0x1C;
+
+ public final static int DISCL_EXCLUSIVE = 0x00000001;
+ public final static int DISCL_NONEXCLUSIVE = 0x00000002;
+ public final static int DISCL_FOREGROUND = 0x00000004;
+ public final static int DISCL_BACKGROUND = 0x00000008;
+ public final static int DISCL_NOWINKEY = 0x00000010;
+
+ public final static int DIDFT_ALL = 0x00000000;
+
+ public final static int DIDFT_RELAXIS = 0x00000001;
+ public final static int DIDFT_ABSAXIS = 0x00000002;
+ public final static int DIDFT_AXIS = 0x00000003;
+
+ public final static int DIDFT_PSHBUTTON = 0x00000004;
+ public final static int DIDFT_TGLBUTTON = 0x00000008;
+ public final static int DIDFT_BUTTON = 0x0000000C;
+
+ public final static int DIDFT_POV = 0x00000010;
+ public final static int DIDFT_COLLECTION = 0x00000040;
+ public final static int DIDFT_NODATA = 0x00000080;
+
+ public final static int DIDFT_FFACTUATOR = 0x01000000;
+ public final static int DIDFT_FFEFFECTTRIGGER = 0x02000000;
+ public final static int DIDFT_OUTPUT = 0x10000000;
+ public final static int DIDFT_VENDORDEFINED = 0x04000000;
+ public final static int DIDFT_ALIAS = 0x08000000;
+ public final static int DIDFT_OPTIONAL = 0x80000000;
+
+ public final static int DIDFT_NOCOLLECTION = 0x00FFFF00;
+
+ public final static int DIDF_ABSAXIS = 0x00000001;
+ public final static int DIDF_RELAXIS = 0x00000002;
+
+ public final static int DI_OK = 0x00000000;
+ public final static int DI_NOEFFECT = 0x00000001;
+ public final static int DI_PROPNOEFFECT = 0x00000001;
+ public final static int DI_POLLEDDEVICE = 0x00000002;
+
+ public final static int DI_DOWNLOADSKIPPED = 0x00000003;
+ public final static int DI_EFFECTRESTARTED = 0x00000004;
+ public final static int DI_TRUNCATED = 0x00000008;
+ public final static int DI_SETTINGSNOTSAVED = 0x0000000B;
+ public final static int DI_TRUNCATEDANDRESTARTED = 0x0000000C;
+
+ public final static int DI_BUFFEROVERFLOW = 0x00000001;
+ public final static int DIERR_INPUTLOST = 0x8007001E;
+ public final static int DIERR_NOTACQUIRED = 0x8007001C;
+ public final static int DIERR_OTHERAPPHASPRIO = 0x80070005;
+
+ public final static int DIDOI_FFACTUATOR = 0x00000001;
+ public final static int DIDOI_FFEFFECTTRIGGER = 0x00000002;
+ public final static int DIDOI_POLLED = 0x00008000;
+ public final static int DIDOI_ASPECTPOSITION = 0x00000100;
+ public final static int DIDOI_ASPECTVELOCITY = 0x00000200;
+ public final static int DIDOI_ASPECTACCEL = 0x00000300;
+ public final static int DIDOI_ASPECTFORCE = 0x00000400;
+ public final static int DIDOI_ASPECTMASK = 0x00000F00;
+ public final static int DIDOI_GUIDISUSAGE = 0x00010000;
+
+ public final static int DIEFT_ALL = 0x00000000;
+
+ public final static int DIEFT_CONSTANTFORCE = 0x00000001;
+ public final static int DIEFT_RAMPFORCE = 0x00000002;
+ public final static int DIEFT_PERIODIC = 0x00000003;
+ public final static int DIEFT_CONDITION = 0x00000004;
+ public final static int DIEFT_CUSTOMFORCE = 0x00000005;
+ public final static int DIEFT_HARDWARE = 0x000000FF;
+ public final static int DIEFT_FFATTACK = 0x00000200;
+ public final static int DIEFT_FFFADE = 0x00000400;
+ public final static int DIEFT_SATURATION = 0x00000800;
+ public final static int DIEFT_POSNEGCOEFFICIENTS = 0x00001000;
+ public final static int DIEFT_POSNEGSATURATION = 0x00002000;
+ public final static int DIEFT_DEADBAND = 0x00004000;
+ public final static int DIEFT_STARTDELAY = 0x00008000;
+
+ public final static int DIEFF_OBJECTIDS = 0x00000001;
+ public final static int DIEFF_OBJECTOFFSETS = 0x00000002;
+ public final static int DIEFF_CARTESIAN = 0x00000010;
+ public final static int DIEFF_POLAR = 0x00000020;
+ public final static int DIEFF_SPHERICAL = 0x00000040;
+
+ public final static int DIEP_DURATION = 0x00000001;
+ public final static int DIEP_SAMPLEPERIOD = 0x00000002;
+ public final static int DIEP_GAIN = 0x00000004;
+ public final static int DIEP_TRIGGERBUTTON = 0x00000008;
+ public final static int DIEP_TRIGGERREPEATINTERVAL = 0x00000010;
+ public final static int DIEP_AXES = 0x00000020;
+ public final static int DIEP_DIRECTION = 0x00000040;
+ public final static int DIEP_ENVELOPE = 0x00000080;
+ public final static int DIEP_TYPESPECIFICPARAMS = 0x00000100;
+ public final static int DIEP_STARTDELAY = 0x00000200;
+ public final static int DIEP_ALLPARAMS_DX5 = 0x000001FF;
+ public final static int DIEP_ALLPARAMS = 0x000003FF;
+ public final static int DIEP_START = 0x20000000;
+ public final static int DIEP_NORESTART = 0x40000000;
+ public final static int DIEP_NODOWNLOAD = 0x80000000;
+ public final static int DIEB_NOTRIGGER = 0xFFFFFFFF;
+
+ public final static int INFINITE = 0xFFFFFFFF;
+
+ public final static int DI_DEGREES = 100;
+ public final static int DI_FFNOMINALMAX = 10000;
+ public final static int DI_SECONDS = 1000000;
+
+ public final static int DIPROPRANGE_NOMIN = 0x80000000;
+ public final static int DIPROPRANGE_NOMAX = 0x7FFFFFFF;
+
+ private final DummyWindow window;
+ private final long address;
+ private final int dev_type;
+ private final int dev_subtype;
+ private final String instance_name;
+ private final String product_name;
+ private final List objects = new ArrayList<>();
+ private final List effects = new ArrayList<>();
+ private final List rumblers = new ArrayList<>();
+ private final int[] device_state;
+ private final Map object_to_component = new HashMap<>();
+ private final boolean axes_in_relative_mode;
+
+
+ private boolean released;
+ private DataQueue queue;
+
+ private int button_counter;
+ private int current_format_offset;
+
+ public IDirectInputDevice(DummyWindow window, long address, byte[] instance_guid, byte[] product_guid, int dev_type, int dev_subtype, String instance_name, String product_name) throws IOException {
+ this.window = window;
+ this.address = address;
+ this.product_name = product_name;
+ this.instance_name = instance_name;
+ this.dev_type = dev_type;
+ this.dev_subtype = dev_subtype;
+ // Assume that the caller (native side) releases the device if setup fails
+ enumObjects();
+ try {
+ enumEffects();
+ createRumblers();
+ } catch (IOException e) {
+ DirectInputEnvironmentPlugin.log("Failed to create rumblers: " + e.getMessage());
+ }
+ /* Some DirectInput lamer-designer made the device state
+ * axis mode be per-device not per-axis, so I'll just
+ * get all axes as absolute and compensate for relative axes.
+ *
+ * Unless, of course, all axes are relative like a mouse device,
+ * in which case setting the DIDF_ABSAXIS flag will result in
+ * incorrect axis values returned from GetDeviceData for some
+ * obscure reason.
+ */
+ boolean all_relative = true;
+ boolean has_axis = false;
+ for (int i = 0; i < objects.size(); i++) {
+ DIDeviceObject obj = objects.get(i);
+ if (obj.isAxis()) {
+ has_axis = true;
+ if (!obj.isRelative()) {
+ all_relative = false;
+ break;
+ }
+ }
+ }
+ this.axes_in_relative_mode = all_relative && has_axis;
+ int axis_mode = all_relative ? DIDF_RELAXIS : DIDF_ABSAXIS;
+ setDataFormat(axis_mode);
+ if (rumblers.size() > 0) {
+ try {
+ setCooperativeLevel(DISCL_BACKGROUND | DISCL_EXCLUSIVE);
+ } catch (IOException e) {
+ setCooperativeLevel(DISCL_BACKGROUND | DISCL_NONEXCLUSIVE);
+ }
+ } else
+ setCooperativeLevel(DISCL_BACKGROUND | DISCL_NONEXCLUSIVE);
+ setBufferSize(AbstractController.EVENT_QUEUE_DEPTH);
+ acquire();
+ this.device_state = new int[objects.size()];
+ }
+
+ public final boolean areAxesRelative() {
+ return axes_in_relative_mode;
+ }
+
+ public final Rumbler[] getRumblers() {
+ return rumblers.toArray(new Rumbler[]{});
+ }
+
+ private final List createRumblers() throws IOException {
+ DIDeviceObject x_axis = lookupObjectByGUID(GUID_XAxis);
+// DIDeviceObject y_axis = lookupObjectByGUID(GUID_YAxis);
+ if(x_axis == null/* || y_axis == null*/)
+ return rumblers;
+ DIDeviceObject[] axes = {x_axis/*, y_axis*/};
+ long[] directions = {0/*, 0*/};
+ for (int i = 0; i < effects.size(); i++) {
+ DIEffectInfo info = effects.get(i);
+ if ((info.getEffectType() & 0xff) == DIEFT_PERIODIC &&
+ (info.getDynamicParams() & DIEP_GAIN) != 0) {
+ rumblers.add(createPeriodicRumbler(axes, directions, info));
+ }
+ }
+ return rumblers;
+ }
+
+ private final Rumbler createPeriodicRumbler(DIDeviceObject[] axes, long[] directions, DIEffectInfo info) throws IOException {
+ int[] axis_ids = new int[axes.length];
+ for (int i = 0; i < axis_ids.length; i++) {
+ axis_ids[i] = axes[i].getDIIdentifier();
+ }
+ long effect_address = nCreatePeriodicEffect(address, info.getGUID(), DIEFF_CARTESIAN | DIEFF_OBJECTIDS, INFINITE, 0, DI_FFNOMINALMAX, DIEB_NOTRIGGER, 0, axis_ids, directions, 0, 0, 0, 0, DI_FFNOMINALMAX, 0, 0, 50000, 0);
+ return new IDirectInputEffect(effect_address, info);
+ }
+ private final static native long nCreatePeriodicEffect(long address, byte[] effect_guid, int flags, int duration, int sample_period, int gain, int trigger_button, int trigger_repeat_interval, int[] axis_ids, long[] directions, int envelope_attack_level, int envelope_attack_time, int envelope_fade_level, int envelope_fade_time, int periodic_magnitude, int periodic_offset, int periodic_phase, int periodic_period, int start_delay) throws IOException;
+
+ private final DIDeviceObject lookupObjectByGUID(int guid_id) {
+ for (int i = 0; i < objects.size(); i++) {
+ DIDeviceObject object = objects.get(i);
+ if (guid_id == object.getGUIDType())
+ return object;
+ }
+ return null;
+ }
+
+ public final int getPollData(DIDeviceObject object) {
+ return device_state[object.getFormatOffset()];
+ }
+
+ public final DIDeviceObject mapEvent(DIDeviceObjectData event) {
+ /* Raw event format offsets (dwOfs member) is in bytes,
+ * but we're indexing into ints so we have to compensate
+ * for the int size (4 bytes)
+ */
+ int format_offset = event.getFormatOffset()/4;
+ return objects.get(format_offset);
+ }
+
+ public final DIComponent mapObject(DIDeviceObject object) {
+ return object_to_component.get(object);
+ }
+
+ public final void registerComponent(DIDeviceObject object, DIComponent component) {
+ object_to_component.put(object, component);
+ }
+
+ public final synchronized void pollAll() throws IOException {
+ checkReleased();
+ poll();
+ getDeviceState(device_state);
+ queue.compact();
+ getDeviceData(queue);
+ queue.flip();
+ }
+
+ public synchronized final boolean getNextEvent(DIDeviceObjectData data) {
+ DIDeviceObjectData next_event = queue.get();
+ if (next_event == null)
+ return false;
+ data.set(next_event);
+ return true;
+ }
+
+ private final void poll() throws IOException {
+ int res = nPoll(address);
+ if (res != DI_OK && res != DI_NOEFFECT) {
+ if (res == DIERR_NOTACQUIRED) {
+ acquire();
+ return;
+ }
+ throw new IOException("Failed to poll device (" + Integer.toHexString(res) + ")");
+ }
+ }
+ private final static native int nPoll(long address) throws IOException;
+
+ private final void acquire() throws IOException {
+ int res = nAcquire(address);
+ if (res != DI_OK && res != DIERR_OTHERAPPHASPRIO && res != DI_NOEFFECT)
+ throw new IOException("Failed to acquire device (" + Integer.toHexString(res) + ")");
+ }
+ private final static native int nAcquire(long address);
+
+ private final void unacquire() throws IOException {
+ int res = nUnacquire(address);
+ if (res != DI_OK && res != DI_NOEFFECT)
+ throw new IOException("Failed to unAcquire device (" + Integer.toHexString(res) + ")");
+ }
+ private final static native int nUnacquire(long address);
+
+ private final boolean getDeviceData(DataQueue queue) throws IOException {
+ int res = nGetDeviceData(address, 0, queue, queue.getElements(), queue.position(), queue.remaining());
+ if (res != DI_OK && res != DI_BUFFEROVERFLOW) {
+ if (res == DIERR_NOTACQUIRED) {
+ acquire();
+ return false;
+ }
+ throw new IOException("Failed to get device data (" + Integer.toHexString(res) + ")");
+ }
+ return true;
+ }
+ private final static native int nGetDeviceData(long address, int flags, DataQueue queue, Object[] queue_elements, int position, int remaining);
+
+ private final void getDeviceState(int[] device_state) throws IOException {
+ int res = nGetDeviceState(address, device_state);
+ if (res != DI_OK) {
+ if (res == DIERR_NOTACQUIRED) {
+ Arrays.fill(device_state, 0);
+ acquire();
+ return;
+ }
+ throw new IOException("Failed to get device state (" + Integer.toHexString(res) + ")");
+ }
+ }
+ private final static native int nGetDeviceState(long address, int[] device_state);
+
+ /* Set a custom data format that maps each object's data into an int[]
+ array with the same index as in the objects List */
+ private final void setDataFormat(int flags) throws IOException {
+ DIDeviceObject[] device_objects = new DIDeviceObject[objects.size()];
+ objects.toArray(device_objects);
+ int res = nSetDataFormat(address, flags, device_objects);
+ if (res != DI_OK)
+ throw new IOException("Failed to set data format (" + Integer.toHexString(res) + ")");
+ }
+ private final static native int nSetDataFormat(long address, int flags, DIDeviceObject[] device_objects);
+
+ public final String getProductName() {
+ return product_name;
+ }
+
+ public final int getType() {
+ return dev_type;
+ }
+
+ public final List getObjects() {
+ return objects;
+ }
+
+ private final void enumEffects() throws IOException {
+ int res = nEnumEffects(address, DIEFT_ALL);
+ if (res != DI_OK)
+ throw new IOException("Failed to enumerate effects (" + Integer.toHexString(res) + ")");
+ }
+ private final native int nEnumEffects(long address, int flags);
+
+ /* Called from native side from nEnumEffects */
+ private final void addEffect(byte[] guid, int guid_id, int effect_type, int static_params, int dynamic_params, String name) {
+ effects.add(new DIEffectInfo(this, guid, guid_id, effect_type, static_params, dynamic_params, name));
+ }
+
+ private final void enumObjects() throws IOException {
+ int res = nEnumObjects(address, DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV);
+ if (res != DI_OK)
+ throw new IOException("Failed to enumerate objects (" + Integer.toHexString(res) + ")");
+ }
+ private final native int nEnumObjects(long address, int flags);
+
+ public final synchronized long[] getRangeProperty(int object_identifier) throws IOException {
+ checkReleased();
+ long[] range = new long[2];
+ int res = nGetRangeProperty(address, object_identifier, range);
+ if (res != DI_OK)
+ throw new IOException("Failed to get object range (" + res + ")");
+ return range;
+ }
+ private final static native int nGetRangeProperty(long address, int object_id, long[] range);
+
+ public final synchronized int getDeadzoneProperty(int object_identifier) throws IOException {
+ checkReleased();
+ return nGetDeadzoneProperty(address, object_identifier);
+ }
+ private final static native int nGetDeadzoneProperty(long address, int object_id) throws IOException;
+
+ /* Called from native side from nEnumObjects */
+ private final void addObject(byte[] guid, int guid_type, int identifier, int type, int instance, int flags, String name) throws IOException {
+ Component.Identifier id = getIdentifier(guid_type, type, instance);
+ int format_offset = current_format_offset++;
+ DIDeviceObject obj = new DIDeviceObject(this, id, guid, guid_type, identifier, type, instance, flags, name, format_offset);
+ objects.add(obj);
+ }
+
+ private final static Component.Identifier.Key getKeyIdentifier(int key_instance) {
+ return DIIdentifierMap.getKeyIdentifier(key_instance);
+ }
+
+ private final Component.Identifier.Button getNextButtonIdentifier() {
+ int button_id = button_counter++;
+ return DIIdentifierMap.getButtonIdentifier(button_id);
+ }
+
+ private final Component.Identifier getIdentifier(int guid_type, int type, int instance) {
+ switch (guid_type) {
+ case IDirectInputDevice.GUID_XAxis:
+ return Component.Identifier.Axis.X;
+ case IDirectInputDevice.GUID_YAxis:
+ return Component.Identifier.Axis.Y;
+ case IDirectInputDevice.GUID_ZAxis:
+ return Component.Identifier.Axis.Z;
+ case IDirectInputDevice.GUID_RxAxis:
+ return Component.Identifier.Axis.RX;
+ case IDirectInputDevice.GUID_RyAxis:
+ return Component.Identifier.Axis.RY;
+ case IDirectInputDevice.GUID_RzAxis:
+ return Component.Identifier.Axis.RZ;
+ case IDirectInputDevice.GUID_Slider:
+ return Component.Identifier.Axis.SLIDER;
+ case IDirectInputDevice.GUID_POV:
+ return Component.Identifier.Axis.POV;
+ case IDirectInputDevice.GUID_Key:
+ return getKeyIdentifier(instance);
+ case IDirectInputDevice.GUID_Button:
+ return getNextButtonIdentifier();
+ default:
+ return Component.Identifier.Axis.UNKNOWN;
+ }
+ }
+
+ public final synchronized void setBufferSize(int size) throws IOException {
+ checkReleased();
+ unacquire();
+ int res = nSetBufferSize(address, size);
+ if (res != DI_OK && res != DI_PROPNOEFFECT && res != DI_POLLEDDEVICE)
+ throw new IOException("Failed to set buffer size (" + Integer.toHexString(res) + ")");
+ queue = new DataQueue<>(size, DIDeviceObjectData.class);
+ queue.position(queue.limit());
+ acquire();
+ }
+ private final static native int nSetBufferSize(long address, int size);
+
+ public final synchronized void setCooperativeLevel(int flags) throws IOException {
+ checkReleased();
+ int res = nSetCooperativeLevel(address, window.getHwnd(), flags);
+ if (res != DI_OK)
+ throw new IOException("Failed to set cooperative level (" + Integer.toHexString(res) + ")");
+ }
+ private final static native int nSetCooperativeLevel(long address, long hwnd_address, int flags);
+
+ public synchronized final void release() {
+ if (!released) {
+ released = true;
+ for (int i = 0; i < rumblers.size(); i++) {
+ IDirectInputEffect effect = (IDirectInputEffect)rumblers.get(i);
+ effect.release();
+ }
+ nRelease(address);
+ }
+ }
+ private final static native void nRelease(long address);
+
+ private final void checkReleased() throws IOException {
+ if (released)
+ throw new IOException("Device is released");
+ }
+
+ @SuppressWarnings("deprecation")
+ protected void finalize() {
+ release();
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/IDirectInputEffect.java b/src/plugins/windows/net/java/games/input/IDirectInputEffect.java
new file mode 100644
index 0000000..77de468
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/IDirectInputEffect.java
@@ -0,0 +1,122 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Java wrapper for IDirectInputEffect
+ * @author elias
+ * @version 1.0
+ */
+final class IDirectInputEffect implements Rumbler {
+ private final long address;
+ private final DIEffectInfo info;
+ private boolean released;
+
+ public IDirectInputEffect(long address, DIEffectInfo info) {
+ this.address = address;
+ this.info = info;
+ }
+
+ public final synchronized void rumble(float intensity) {
+ try {
+ checkReleased();
+ if (intensity > 0) {
+ int int_gain = Math.round(intensity*IDirectInputDevice.DI_FFNOMINALMAX);
+ setGain(int_gain);
+ start(1, 0);
+ } else
+ stop();
+ } catch (IOException e) {
+ DirectInputEnvironmentPlugin.log("Failed to set rumbler gain: " + e.getMessage());
+ }
+ }
+
+ public final Component.Identifier getAxisIdentifier() {
+ return null;
+ }
+
+ public final String getAxisName() {
+ return null;
+ }
+
+ public final synchronized void release() {
+ if (!released) {
+ released = true;
+ nRelease(address);
+ }
+ }
+ private final static native void nRelease(long address);
+
+ private final void checkReleased() throws IOException {
+ if (released)
+ throw new IOException();
+ }
+
+ private final void setGain(int gain) throws IOException {
+ int res = nSetGain(address, gain);
+ if (res != IDirectInputDevice.DI_DOWNLOADSKIPPED &&
+ res != IDirectInputDevice.DI_EFFECTRESTARTED &&
+ res != IDirectInputDevice.DI_OK &&
+ res != IDirectInputDevice.DI_TRUNCATED &&
+ res != IDirectInputDevice.DI_TRUNCATEDANDRESTARTED) {
+ throw new IOException("Failed to set effect gain (0x" + Integer.toHexString(res) + ")");
+ }
+ }
+ private final static native int nSetGain(long address, int gain);
+
+ private final void start(int iterations, int flags) throws IOException {
+ int res = nStart(address, iterations, flags);
+ if (res != IDirectInputDevice.DI_OK)
+ throw new IOException("Failed to start effect (0x" + Integer.toHexString(res) + ")");
+ }
+ private final static native int nStart(long address, int iterations, int flags);
+
+ private final void stop() throws IOException {
+ int res = nStop(address);
+ if (res != IDirectInputDevice.DI_OK)
+ throw new IOException("Failed to stop effect (0x" + Integer.toHexString(res) + ")");
+ }
+ private final static native int nStop(long address);
+
+ @SuppressWarnings("deprecation")
+ protected void finalize() {
+ release();
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/RawDevice.java b/src/plugins/windows/net/java/games/input/RawDevice.java
new file mode 100644
index 0000000..c7b0696
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/RawDevice.java
@@ -0,0 +1,310 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Java wrapper of RAWDEVICELIST
+ * @author elias
+ * @version 1.0
+ */
+final class RawDevice {
+ public final static int RI_MOUSE_LEFT_BUTTON_DOWN = 0x0001; // Left Button changed to down.
+ public final static int RI_MOUSE_LEFT_BUTTON_UP = 0x0002; // Left Button changed to up.
+ public final static int RI_MOUSE_RIGHT_BUTTON_DOWN = 0x0004; // Right Button changed to down.
+ public final static int RI_MOUSE_RIGHT_BUTTON_UP = 0x0008; // Right Button changed to up.
+ public final static int RI_MOUSE_MIDDLE_BUTTON_DOWN = 0x0010; // Middle Button changed to down.
+ public final static int RI_MOUSE_MIDDLE_BUTTON_UP = 0x0020; // Middle Button changed to up.
+
+ public final static int RI_MOUSE_BUTTON_1_DOWN = RI_MOUSE_LEFT_BUTTON_DOWN;
+ public final static int RI_MOUSE_BUTTON_1_UP = RI_MOUSE_LEFT_BUTTON_UP;
+ public final static int RI_MOUSE_BUTTON_2_DOWN = RI_MOUSE_RIGHT_BUTTON_DOWN;
+ public final static int RI_MOUSE_BUTTON_2_UP = RI_MOUSE_RIGHT_BUTTON_UP;
+ public final static int RI_MOUSE_BUTTON_3_DOWN = RI_MOUSE_MIDDLE_BUTTON_DOWN;
+ public final static int RI_MOUSE_BUTTON_3_UP = RI_MOUSE_MIDDLE_BUTTON_UP;
+
+ public final static int RI_MOUSE_BUTTON_4_DOWN = 0x0040;
+ public final static int RI_MOUSE_BUTTON_4_UP = 0x0080;
+ public final static int RI_MOUSE_BUTTON_5_DOWN = 0x0100;
+ public final static int RI_MOUSE_BUTTON_5_UP = 0x0200;
+
+ /*
+ * If usButtonFlags has RI_MOUSE_WHEEL, the wheel delta is stored in usButtonData.
+ * Take it as a signed value.
+ */
+ public final static int RI_MOUSE_WHEEL = 0x0400;
+
+ public final static int MOUSE_MOVE_RELATIVE = 0;
+ public final static int MOUSE_MOVE_ABSOLUTE = 1;
+ public final static int MOUSE_VIRTUAL_DESKTOP = 0x02; // the coordinates are mapped to the virtual desktop
+ public final static int MOUSE_ATTRIBUTES_CHANGED = 0x04; // requery for mouse attributes
+
+ public final static int RIM_TYPEHID = 2;
+ public final static int RIM_TYPEKEYBOARD = 1;
+ public final static int RIM_TYPEMOUSE = 0;
+
+ public final static int WM_KEYDOWN = 0x0100;
+ public final static int WM_KEYUP = 0x0101;
+ public final static int WM_SYSKEYDOWN = 0x0104;
+ public final static int WM_SYSKEYUP = 0x0105;
+
+ private final RawInputEventQueue queue;
+ private final long handle;
+ private final int type;
+
+ /* Events from the event queue thread end here */
+ private DataQueue keyboard_events;
+ private DataQueue mouse_events;
+
+ /* After processing in poll*(), the events are placed here */
+ private DataQueue processed_keyboard_events;
+ private DataQueue processed_mouse_events;
+
+ /* mouse state */
+ private final boolean[] button_states = new boolean[5];
+ private int wheel;
+ private int relative_x;
+ private int relative_y;
+ private int last_x;
+ private int last_y;
+
+ // Last x, y for converting absolute events to relative
+ private int event_relative_x;
+ private int event_relative_y;
+ private int event_last_x;
+ private int event_last_y;
+
+ /* keyboard state */
+ private final boolean[] key_states = new boolean[0xFF];
+
+ public RawDevice(RawInputEventQueue queue, long handle, int type) {
+ this.queue = queue;
+ this.handle = handle;
+ this.type = type;
+ setBufferSize(AbstractController.EVENT_QUEUE_DEPTH);
+ }
+
+ /* Careful, this is called from the event queue thread */
+ public final synchronized void addMouseEvent(long millis, int flags, int button_flags, int button_data, long raw_buttons, long last_x, long last_y, long extra_information) {
+ if (mouse_events.hasRemaining()) {
+ RawMouseEvent event = mouse_events.get();
+ event.set(millis, flags, button_flags, button_data, raw_buttons, last_x, last_y, extra_information);
+ }
+ }
+
+ /* Careful, this is called from the event queue thread */
+ public final synchronized void addKeyboardEvent(long millis, int make_code, int flags, int vkey, int message, long extra_information) {
+ if (keyboard_events.hasRemaining()) {
+ RawKeyboardEvent event = keyboard_events.get();
+ event.set(millis, make_code, flags, vkey, message, extra_information);
+ }
+ }
+
+ public final synchronized void pollMouse() {
+ relative_x = relative_y = wheel = 0;
+ mouse_events.flip();
+ while (mouse_events.hasRemaining()) {
+ RawMouseEvent event = mouse_events.get();
+ boolean has_update = processMouseEvent(event);
+ if (has_update && processed_mouse_events.hasRemaining()) {
+ RawMouseEvent processed_event = processed_mouse_events.get();
+ processed_event.set(event);
+ }
+ }
+ mouse_events.compact();
+ }
+
+ public final synchronized void pollKeyboard() {
+ keyboard_events.flip();
+ while (keyboard_events.hasRemaining()) {
+ RawKeyboardEvent event = keyboard_events.get();
+ boolean has_update = processKeyboardEvent(event);
+ if (has_update && processed_keyboard_events.hasRemaining()) {
+ RawKeyboardEvent processed_event = processed_keyboard_events.get();
+ processed_event.set(event);
+ }
+ }
+ keyboard_events.compact();
+ }
+
+ private final boolean updateButtonState(int button_id, int button_flags, int down_flag, int up_flag) {
+ if (button_id >= button_states.length)
+ return false;
+ if ((button_flags & down_flag) != 0) {
+ button_states[button_id] = true;
+ return true;
+ } else if ((button_flags & up_flag) != 0) {
+ button_states[button_id] = false;
+ return true;
+ } else
+ return false;
+ }
+
+ private final boolean processKeyboardEvent(RawKeyboardEvent event) {
+ int message = event.getMessage();
+ int vkey = event.getVKey();
+ if (vkey >= key_states.length)
+ return false;
+ if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN) {
+ key_states[vkey] = true;
+ return true;
+ } else if (message == WM_KEYUP || message == WM_SYSKEYUP) {
+ key_states[vkey] = false;
+ return true;
+ } else
+ return false;
+ }
+
+ public final boolean isKeyDown(int vkey) {
+ return key_states[vkey];
+ }
+
+ private final boolean processMouseEvent(RawMouseEvent event) {
+ boolean has_update = false;
+ int button_flags = event.getButtonFlags();
+ has_update = updateButtonState(0, button_flags, RI_MOUSE_BUTTON_1_DOWN, RI_MOUSE_BUTTON_1_UP) || has_update;
+ has_update = updateButtonState(1, button_flags, RI_MOUSE_BUTTON_2_DOWN, RI_MOUSE_BUTTON_2_UP) || has_update;
+ has_update = updateButtonState(2, button_flags, RI_MOUSE_BUTTON_3_DOWN, RI_MOUSE_BUTTON_3_UP) || has_update;
+ has_update = updateButtonState(3, button_flags, RI_MOUSE_BUTTON_4_DOWN, RI_MOUSE_BUTTON_4_UP) || has_update;
+ has_update = updateButtonState(4, button_flags, RI_MOUSE_BUTTON_5_DOWN, RI_MOUSE_BUTTON_5_UP) || has_update;
+ int dx;
+ int dy;
+ if ((event.getFlags() & MOUSE_MOVE_ABSOLUTE) != 0) {
+ dx = event.getLastX() - last_x;
+ dy = event.getLastY() - last_y;
+ last_x = event.getLastX();
+ last_y = event.getLastY();
+ } else {
+ dx = event.getLastX();
+ dy = event.getLastY();
+ }
+ int dwheel = 0;
+ if ((button_flags & RI_MOUSE_WHEEL) != 0)
+ dwheel = event.getWheelDelta();
+ relative_x += dx;
+ relative_y += dy;
+ wheel += dwheel;
+ has_update = dx != 0 || dy != 0 || dwheel != 0 || has_update;
+ return has_update;
+ }
+
+ public final int getWheel() {
+ return wheel;
+ }
+
+ public final int getEventRelativeX() {
+ return event_relative_x;
+ }
+
+ public final int getEventRelativeY() {
+ return event_relative_y;
+ }
+
+ public final int getRelativeX() {
+ return relative_x;
+ }
+
+ public final int getRelativeY() {
+ return relative_y;
+ }
+
+ public final synchronized boolean getNextKeyboardEvent(RawKeyboardEvent event) {
+ processed_keyboard_events.flip();
+ if (!processed_keyboard_events.hasRemaining()) {
+ processed_keyboard_events.compact();
+ return false;
+ }
+ RawKeyboardEvent next_event = processed_keyboard_events.get();
+ event.set(next_event);
+ processed_keyboard_events.compact();
+ return true;
+ }
+
+ public final synchronized boolean getNextMouseEvent(RawMouseEvent event) {
+ processed_mouse_events.flip();
+ if (!processed_mouse_events.hasRemaining()) {
+ processed_mouse_events.compact();
+ return false;
+ }
+ RawMouseEvent next_event = processed_mouse_events.get();
+ if ((next_event.getFlags() & MOUSE_MOVE_ABSOLUTE) != 0) {
+ event_relative_x = next_event.getLastX() - event_last_x;
+ event_relative_y = next_event.getLastY() - event_last_y;
+ event_last_x = next_event.getLastX();
+ event_last_y = next_event.getLastY();
+ } else {
+ event_relative_x = next_event.getLastX();
+ event_relative_y = next_event.getLastY();
+ }
+ event.set(next_event);
+ processed_mouse_events.compact();
+ return true;
+ }
+
+ public final boolean getButtonState(int button_id) {
+ if (button_id >= button_states.length)
+ return false;
+ return button_states[button_id];
+ }
+
+ public final void setBufferSize(int size) {
+ keyboard_events = new DataQueue<>(size, RawKeyboardEvent.class);
+ mouse_events = new DataQueue<>(size, RawMouseEvent.class);
+ processed_keyboard_events = new DataQueue<>(size, RawKeyboardEvent.class);
+ processed_mouse_events = new DataQueue<>(size, RawMouseEvent.class);
+ }
+
+ public final int getType() {
+ return type;
+ }
+
+ public final long getHandle() {
+ return handle;
+ }
+
+ public final String getName() throws IOException {
+ return nGetName(handle);
+ }
+ private final static native String nGetName(long handle) throws IOException;
+
+ public final RawDeviceInfo getInfo() throws IOException {
+ return nGetInfo(this, handle);
+ }
+ private final static native RawDeviceInfo nGetInfo(RawDevice device, long handle) throws IOException;
+}
diff --git a/src/plugins/windows/net/java/games/input/RawDeviceInfo.java b/src/plugins/windows/net/java/games/input/RawDeviceInfo.java
new file mode 100644
index 0000000..7e6228f
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/RawDeviceInfo.java
@@ -0,0 +1,67 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Java wrapper of RID_DEVICE_INFO
+ * @author elias
+ * @version 1.0
+ */
+abstract class RawDeviceInfo {
+ public abstract Controller createControllerFromDevice(RawDevice device, SetupAPIDevice setupapi_device) throws IOException;
+
+ public abstract int getUsage();
+
+ public abstract int getUsagePage();
+
+ public abstract long getHandle();
+
+ public final boolean equals(Object other) {
+ if (!(other instanceof RawDeviceInfo))
+ return false;
+ RawDeviceInfo other_info = (RawDeviceInfo)other;
+ return other_info.getUsage() == getUsage() &&
+ other_info.getUsagePage() == getUsagePage();
+ }
+
+ public final int hashCode() {
+ return getUsage() ^ getUsagePage();
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/RawHIDInfo.java b/src/plugins/windows/net/java/games/input/RawHIDInfo.java
new file mode 100644
index 0000000..6465bb4
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/RawHIDInfo.java
@@ -0,0 +1,80 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Java wrapper of RID_DEVICE_INFO_HID
+ * @author elias
+ * @version 1.0
+ */
+class RawHIDInfo extends RawDeviceInfo {
+ private final RawDevice device;
+
+ private final int vendor_id;
+ private final int product_id;
+ private final int version;
+ private final int page;
+ private final int usage;
+
+ public RawHIDInfo(RawDevice device, int vendor_id, int product_id, int version, int page, int usage) {
+ this.device = device;
+ this.vendor_id = vendor_id;
+ this.product_id = product_id;
+ this.version = version;
+ this.page = page;
+ this.usage = usage;
+ }
+
+ public final int getUsage() {
+ return usage;
+ }
+
+ public final int getUsagePage() {
+ return page;
+ }
+
+ public final long getHandle() {
+ return device.getHandle();
+ }
+
+ public final Controller createControllerFromDevice(RawDevice device, SetupAPIDevice setupapi_device) throws IOException {
+ return null;
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/RawIdentifierMap.java b/src/plugins/windows/net/java/games/input/RawIdentifierMap.java
new file mode 100644
index 0000000..662a183
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/RawIdentifierMap.java
@@ -0,0 +1,553 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+/**
+ * @author elias
+ * @version 1.0
+ */
+final class RawIdentifierMap {
+ public final static int VK_LBUTTON = 0x01;
+ public final static int VK_RBUTTON = 0x02;
+ public final static int VK_CANCEL = 0x03;
+ public final static int VK_MBUTTON = 0x04; /* NOT contiguous with L & RBUTTON */
+
+ public final static int VK_XBUTTON1 = 0x05; /* NOT contiguous with L & RBUTTON */
+ public final static int VK_XBUTTON2 = 0x06; /* NOT contiguous with L & RBUTTON */
+
+/*
+ * 0x07 : unassigned
+ */
+
+ public final static int VK_BACK = 0x08;
+ public final static int VK_TAB = 0x09;
+
+/*
+ * 0x0A - 0x0B : reserved
+ */
+
+ public final static int VK_CLEAR = 0x0C;
+ public final static int VK_RETURN = 0x0D;
+
+ public final static int VK_SHIFT = 0x10;
+ public final static int VK_CONTROL = 0x11;
+ public final static int VK_MENU = 0x12;
+ public final static int VK_PAUSE = 0x13;
+ public final static int VK_CAPITAL = 0x14;
+
+ public final static int VK_KANA = 0x15;
+ public final static int VK_HANGEUL = 0x15; /* old name - should be here for compatibility */
+ public final static int VK_HANGUL = 0x15;
+ public final static int VK_JUNJA = 0x17;
+ public final static int VK_FINAL = 0x18;
+ public final static int VK_HANJA = 0x19;
+ public final static int VK_KANJI = 0x19;
+
+ public final static int VK_ESCAPE = 0x1B;
+
+ public final static int VK_CONVERT = 0x1C;
+ public final static int VK_NONCONVERT = 0x1D;
+ public final static int VK_ACCEPT = 0x1E;
+ public final static int VK_MODECHANGE = 0x1F;
+
+ public final static int VK_SPACE = 0x20;
+ public final static int VK_PRIOR = 0x21;
+ public final static int VK_NEXT = 0x22;
+ public final static int VK_END = 0x23;
+ public final static int VK_HOME = 0x24;
+ public final static int VK_LEFT = 0x25;
+ public final static int VK_UP = 0x26;
+ public final static int VK_RIGHT = 0x27;
+ public final static int VK_DOWN = 0x28;
+ public final static int VK_SELECT = 0x29;
+ public final static int VK_PRINT = 0x2A;
+ public final static int VK_EXECUTE = 0x2B;
+ public final static int VK_SNAPSHOT = 0x2C;
+ public final static int VK_INSERT = 0x2D;
+ public final static int VK_DELETE = 0x2E;
+ public final static int VK_HELP = 0x2F;
+/*
+ * VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39)
+ * 0x40 : unassigned
+ * VK_A - VK_Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A)
+ */
+ public final static int VK_0 = 0x30;
+ public final static int VK_1 = 0x31;
+ public final static int VK_2 = 0x32;
+ public final static int VK_3 = 0x33;
+ public final static int VK_4 = 0x34;
+ public final static int VK_5 = 0x35;
+ public final static int VK_6 = 0x36;
+ public final static int VK_7 = 0x37;
+ public final static int VK_8 = 0x38;
+ public final static int VK_9 = 0x39;
+
+ public final static int VK_A = 0x41;
+ public final static int VK_B = 0x42;
+ public final static int VK_C = 0x43;
+ public final static int VK_D = 0x44;
+ public final static int VK_E = 0x45;
+ public final static int VK_F = 0x46;
+ public final static int VK_G = 0x47;
+ public final static int VK_H = 0x48;
+ public final static int VK_I = 0x49;
+ public final static int VK_J = 0x4A;
+ public final static int VK_K = 0x4B;
+ public final static int VK_L = 0x4C;
+ public final static int VK_M = 0x4D;
+ public final static int VK_N = 0x4E;
+ public final static int VK_O = 0x4F;
+ public final static int VK_P = 0x50;
+ public final static int VK_Q = 0x51;
+ public final static int VK_R = 0x52;
+ public final static int VK_S = 0x53;
+ public final static int VK_T = 0x54;
+ public final static int VK_U = 0x55;
+ public final static int VK_V = 0x56;
+ public final static int VK_W = 0x57;
+ public final static int VK_X = 0x58;
+ public final static int VK_Y = 0x59;
+ public final static int VK_Z = 0x5A;
+
+ public final static int VK_LWIN = 0x5B;
+ public final static int VK_RWIN = 0x5C;
+ public final static int VK_APPS = 0x5D;
+/*
+ * 0x5E : reserved;
+ */
+
+ public final static int VK_SLEEP = 0x5F;
+
+ public final static int VK_NUMPAD0 = 0x60;
+ public final static int VK_NUMPAD1 = 0x61;
+ public final static int VK_NUMPAD2 = 0x62;
+ public final static int VK_NUMPAD3 = 0x63;
+ public final static int VK_NUMPAD4 = 0x64;
+ public final static int VK_NUMPAD5 = 0x65;
+ public final static int VK_NUMPAD6 = 0x66;
+ public final static int VK_NUMPAD7 = 0x67;
+ public final static int VK_NUMPAD8 = 0x68;
+ public final static int VK_NUMPAD9 = 0x69;
+ public final static int VK_MULTIPLY = 0x6A;
+ public final static int VK_ADD = 0x6B;
+ public final static int VK_SEPARATOR = 0x6C;
+ public final static int VK_SUBTRACT = 0x6D;
+ public final static int VK_DECIMAL = 0x6E;
+ public final static int VK_DIVIDE = 0x6F;
+ public final static int VK_F1 = 0x70;
+ public final static int VK_F2 = 0x71;
+ public final static int VK_F3 = 0x72;
+ public final static int VK_F4 = 0x73;
+ public final static int VK_F5 = 0x74;
+ public final static int VK_F6 = 0x75;
+ public final static int VK_F7 = 0x76;
+ public final static int VK_F8 = 0x77;
+ public final static int VK_F9 = 0x78;
+ public final static int VK_F10 = 0x79;
+ public final static int VK_F11 = 0x7A;
+ public final static int VK_F12 = 0x7B;
+ public final static int VK_F13 = 0x7C;
+ public final static int VK_F14 = 0x7D;
+ public final static int VK_F15 = 0x7E;
+ public final static int VK_F16 = 0x7F;
+ public final static int VK_F17 = 0x80;
+ public final static int VK_F18 = 0x81;
+ public final static int VK_F19 = 0x82;
+ public final static int VK_F20 = 0x83;
+ public final static int VK_F21 = 0x84;
+ public final static int VK_F22 = 0x85;
+ public final static int VK_F23 = 0x86;
+ public final static int VK_F24 = 0x87;
+
+/*
+ * 0x88 - 0x8F : unassigned;
+ */
+
+ public final static int VK_NUMLOCK = 0x90;
+ public final static int VK_SCROLL = 0x91;
+
+/*
+ * NEC PC-9800 kbd definitions
+ */
+ public final static int VK_OEM_NEC_EQUAL = 0x92; // '=' key on numpad
+/*
+ * Fujitsu/OASYS kbd definitions
+ */
+ public final static int VK_OEM_FJ_JISHO = 0x92; // 'Dictionary' key
+ public final static int VK_OEM_FJ_MASSHOU = 0x93; // 'Unregister word' key
+ public final static int VK_OEM_FJ_TOUROKU = 0x94; // 'Register word' key
+ public final static int VK_OEM_FJ_LOYA = 0x95; // 'Left OYAYUBI' key
+ public final static int VK_OEM_FJ_ROYA = 0x96; // 'Right OYAYUBI' key
+
+/*
+ * 0x97 - 0x9F : unassigned
+ */
+
+/*
+ * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
+ * Used only as parameters to GetAsyncKeyState() and GetKeyState().
+ * No other API or message will distinguish left and right keys in this way.
+ */
+ public final static int VK_LSHIFT = 0xA0;
+ public final static int VK_RSHIFT = 0xA1;
+ public final static int VK_LCONTROL = 0xA2;
+ public final static int VK_RCONTROL = 0xA3;
+ public final static int VK_LMENU = 0xA4;
+ public final static int VK_RMENU = 0xA5;
+
+ public final static int VK_BROWSER_BACK = 0xA6;
+ public final static int VK_BROWSER_FORWARD = 0xA7;
+ public final static int VK_BROWSER_REFRESH = 0xA8;
+ public final static int VK_BROWSER_STOP = 0xA9;
+ public final static int VK_BROWSER_SEARCH = 0xAA;
+ public final static int VK_BROWSER_FAVORITES = 0xAB;
+ public final static int VK_BROWSER_HOME = 0xAC;
+
+ public final static int VK_VOLUME_MUTE = 0xAD;
+ public final static int VK_VOLUME_DOWN = 0xAE;
+ public final static int VK_VOLUME_UP = 0xAF;
+ public final static int VK_MEDIA_NEXT_TRACK = 0xB0;
+ public final static int VK_MEDIA_PREV_TRACK = 0xB1;
+ public final static int VK_MEDIA_STOP = 0xB2;
+ public final static int VK_MEDIA_PLAY_PAUSE = 0xB3;
+ public final static int VK_LAUNCH_MAIL = 0xB4;
+ public final static int VK_LAUNCH_MEDIA_SELECT = 0xB5;
+ public final static int VK_LAUNCH_APP1 = 0xB6;
+ public final static int VK_LAUNCH_APP2 = 0xB7;
+
+/*
+ * 0xB8 - 0xB9 : reserved
+ */
+
+ public final static int VK_OEM_1 = 0xBA; // ';:' for US
+ public final static int VK_OEM_PLUS = 0xBB; // '+' any country
+ public final static int VK_OEM_COMMA = 0xBC; // ',' any country
+ public final static int VK_OEM_MINUS = 0xBD; // '-' any country
+ public final static int VK_OEM_PERIOD = 0xBE; // '.' any country
+ public final static int VK_OEM_2 = 0xBF; // '/?' for US
+ public final static int VK_OEM_3 = 0xC0; // '`~' for US
+
+/*
+ * 0xC1 - 0xD7 : reserved
+ */
+
+/*
+ * 0xD8 - 0xDA : unassigned
+ */
+
+ public final static int VK_OEM_4 = 0xDB; // '[{' for US
+ public final static int VK_OEM_5 = 0xDC; // '\|' for US
+ public final static int VK_OEM_6 = 0xDD; // ']}' for US
+ public final static int VK_OEM_7 = 0xDE; // ''"' for US
+ public final static int VK_OEM_8 = 0xDF;
+
+/*
+ * 0xE0 : reserved
+ */
+
+/*
+ * Various extended or enhanced keyboards
+ */
+ public final static int VK_OEM_AX = 0xE1; // 'AX' key on Japanese AX kbd
+ public final static int VK_OEM_102 = 0xE2; // "<>" or "\|" on RT 102-key kbd.
+ public final static int VK_ICO_HELP = 0xE3; // Help key on ICO
+ public final static int VK_ICO_00 = 0xE4; // 00 key on ICO
+
+ public final static int VK_PROCESSKEY = 0xE5;
+
+ public final static int VK_ICO_CLEAR = 0xE6;
+
+
+ public final static int VK_PACKET = 0xE7;
+
+/*
+ * 0xE8 : unassigned
+ */
+
+/*
+ * Nokia/Ericsson definitions
+ */
+ public final static int VK_OEM_RESET = 0xE9;
+ public final static int VK_OEM_JUMP = 0xEA;
+ public final static int VK_OEM_PA1 = 0xEB;
+ public final static int VK_OEM_PA2 = 0xEC;
+ public final static int VK_OEM_PA3 = 0xED;
+ public final static int VK_OEM_WSCTRL = 0xEE;
+ public final static int VK_OEM_CUSEL = 0xEF;
+ public final static int VK_OEM_ATTN = 0xF0;
+ public final static int VK_OEM_FINISH = 0xF1;
+ public final static int VK_OEM_COPY = 0xF2;
+ public final static int VK_OEM_AUTO = 0xF3;
+ public final static int VK_OEM_ENLW = 0xF4;
+ public final static int VK_OEM_BACKTAB = 0xF5;
+
+ public final static int VK_ATTN = 0xF6;
+ public final static int VK_CRSEL = 0xF7;
+ public final static int VK_EXSEL = 0xF8;
+ public final static int VK_EREOF = 0xF9;
+ public final static int VK_PLAY = 0xFA;
+ public final static int VK_ZOOM = 0xFB;
+ public final static int VK_NONAME = 0xFC;
+ public final static int VK_PA1 = 0xFD;
+ public final static int VK_OEM_CLEAR = 0xFE;
+
+ public final static Component.Identifier.Key mapVKey(int vkey) {
+ switch (vkey) {
+ case VK_ESCAPE:
+ return Component.Identifier.Key.ESCAPE;
+ case VK_1:
+ return Component.Identifier.Key._1;
+ case VK_2:
+ return Component.Identifier.Key._2;
+ case VK_3:
+ return Component.Identifier.Key._3;
+ case VK_4:
+ return Component.Identifier.Key._4;
+ case VK_5:
+ return Component.Identifier.Key._5;
+ case VK_6:
+ return Component.Identifier.Key._6;
+ case VK_7:
+ return Component.Identifier.Key._7;
+ case VK_8:
+ return Component.Identifier.Key._8;
+ case VK_9:
+ return Component.Identifier.Key._9;
+ case VK_0:
+ return Component.Identifier.Key._0;
+ case VK_OEM_NEC_EQUAL:
+ return Component.Identifier.Key.NUMPADEQUAL;
+ case VK_BACK:
+ return Component.Identifier.Key.BACK;
+ case VK_TAB:
+ return Component.Identifier.Key.TAB;
+ case VK_Q:
+ return Component.Identifier.Key.Q;
+ case VK_W:
+ return Component.Identifier.Key.W;
+ case VK_E:
+ return Component.Identifier.Key.E;
+ case VK_R:
+ return Component.Identifier.Key.R;
+ case VK_T:
+ return Component.Identifier.Key.T;
+ case VK_Y:
+ return Component.Identifier.Key.Y;
+ case VK_U:
+ return Component.Identifier.Key.U;
+ case VK_I:
+ return Component.Identifier.Key.I;
+ case VK_O:
+ return Component.Identifier.Key.O;
+ case VK_P:
+ return Component.Identifier.Key.P;
+ case VK_OEM_4:
+ return Component.Identifier.Key.LBRACKET;
+ case VK_OEM_6:
+ return Component.Identifier.Key.RBRACKET;
+ case VK_RETURN:
+ return Component.Identifier.Key.RETURN;
+ case VK_CONTROL:
+ case VK_LCONTROL:
+ return Component.Identifier.Key.LCONTROL;
+ case VK_A:
+ return Component.Identifier.Key.A;
+ case VK_S:
+ return Component.Identifier.Key.S;
+ case VK_D:
+ return Component.Identifier.Key.D;
+ case VK_F:
+ return Component.Identifier.Key.F;
+ case VK_G:
+ return Component.Identifier.Key.G;
+ case VK_H:
+ return Component.Identifier.Key.H;
+ case VK_J:
+ return Component.Identifier.Key.J;
+ case VK_K:
+ return Component.Identifier.Key.K;
+ case VK_L:
+ return Component.Identifier.Key.L;
+ case VK_OEM_3:
+ return Component.Identifier.Key.GRAVE;
+ case VK_SHIFT:
+ case VK_LSHIFT:
+ return Component.Identifier.Key.LSHIFT;
+ case VK_Z:
+ return Component.Identifier.Key.Z;
+ case VK_X:
+ return Component.Identifier.Key.X;
+ case VK_C:
+ return Component.Identifier.Key.C;
+ case VK_V:
+ return Component.Identifier.Key.V;
+ case VK_B:
+ return Component.Identifier.Key.B;
+ case VK_N:
+ return Component.Identifier.Key.N;
+ case VK_M:
+ return Component.Identifier.Key.M;
+ case VK_OEM_COMMA:
+ return Component.Identifier.Key.COMMA;
+ case VK_OEM_PERIOD:
+ return Component.Identifier.Key.PERIOD;
+ case VK_RSHIFT:
+ return Component.Identifier.Key.RSHIFT;
+ case VK_MULTIPLY:
+ return Component.Identifier.Key.MULTIPLY;
+ case VK_MENU:
+ case VK_LMENU:
+ return Component.Identifier.Key.LALT;
+ case VK_SPACE:
+ return Component.Identifier.Key.SPACE;
+ case VK_CAPITAL:
+ return Component.Identifier.Key.CAPITAL;
+ case VK_F1:
+ return Component.Identifier.Key.F1;
+ case VK_F2:
+ return Component.Identifier.Key.F2;
+ case VK_F3:
+ return Component.Identifier.Key.F3;
+ case VK_F4:
+ return Component.Identifier.Key.F4;
+ case VK_F5:
+ return Component.Identifier.Key.F5;
+ case VK_F6:
+ return Component.Identifier.Key.F6;
+ case VK_F7:
+ return Component.Identifier.Key.F7;
+ case VK_F8:
+ return Component.Identifier.Key.F8;
+ case VK_F9:
+ return Component.Identifier.Key.F9;
+ case VK_F10:
+ return Component.Identifier.Key.F10;
+ case VK_NUMLOCK:
+ return Component.Identifier.Key.NUMLOCK;
+ case VK_SCROLL:
+ return Component.Identifier.Key.SCROLL;
+ case VK_NUMPAD7:
+ return Component.Identifier.Key.NUMPAD7;
+ case VK_NUMPAD8:
+ return Component.Identifier.Key.NUMPAD8;
+ case VK_NUMPAD9:
+ return Component.Identifier.Key.NUMPAD9;
+ case VK_SUBTRACT:
+ return Component.Identifier.Key.SUBTRACT;
+ case VK_NUMPAD4:
+ return Component.Identifier.Key.NUMPAD4;
+ case VK_NUMPAD5:
+ return Component.Identifier.Key.NUMPAD5;
+ case VK_NUMPAD6:
+ return Component.Identifier.Key.NUMPAD6;
+ case VK_ADD:
+ return Component.Identifier.Key.ADD;
+ case VK_NUMPAD1:
+ return Component.Identifier.Key.NUMPAD1;
+ case VK_NUMPAD2:
+ return Component.Identifier.Key.NUMPAD2;
+ case VK_NUMPAD3:
+ return Component.Identifier.Key.NUMPAD3;
+ case VK_NUMPAD0:
+ return Component.Identifier.Key.NUMPAD0;
+ case VK_DECIMAL:
+ return Component.Identifier.Key.DECIMAL;
+ case VK_F11:
+ return Component.Identifier.Key.F11;
+ case VK_F12:
+ return Component.Identifier.Key.F12;
+ case VK_F13:
+ return Component.Identifier.Key.F13;
+ case VK_F14:
+ return Component.Identifier.Key.F14;
+ case VK_F15:
+ return Component.Identifier.Key.F15;
+ case VK_KANA:
+ return Component.Identifier.Key.KANA;
+ case VK_CONVERT:
+ return Component.Identifier.Key.CONVERT;
+ case VK_KANJI:
+ return Component.Identifier.Key.KANJI;
+ case VK_OEM_AX:
+ return Component.Identifier.Key.AX;
+ case VK_RCONTROL:
+ return Component.Identifier.Key.RCONTROL;
+ case VK_SEPARATOR:
+ return Component.Identifier.Key.NUMPADCOMMA;
+ case VK_DIVIDE:
+ return Component.Identifier.Key.DIVIDE;
+ case VK_SNAPSHOT:
+ return Component.Identifier.Key.SYSRQ;
+ case VK_RMENU:
+ return Component.Identifier.Key.RALT;
+ case VK_PAUSE:
+ return Component.Identifier.Key.PAUSE;
+ case VK_HOME:
+ return Component.Identifier.Key.HOME;
+ case VK_UP:
+ return Component.Identifier.Key.UP;
+ case VK_PRIOR:
+ return Component.Identifier.Key.PAGEUP;
+ case VK_LEFT:
+ return Component.Identifier.Key.LEFT;
+ case VK_RIGHT:
+ return Component.Identifier.Key.RIGHT;
+ case VK_END:
+ return Component.Identifier.Key.END;
+ case VK_DOWN:
+ return Component.Identifier.Key.DOWN;
+ case VK_NEXT:
+ return Component.Identifier.Key.PAGEDOWN;
+ case VK_INSERT:
+ return Component.Identifier.Key.INSERT;
+ case VK_DELETE:
+ return Component.Identifier.Key.DELETE;
+ case VK_LWIN:
+ return Component.Identifier.Key.LWIN;
+ case VK_RWIN:
+ return Component.Identifier.Key.RWIN;
+ case VK_APPS:
+ return Component.Identifier.Key.APPS;
+ case VK_SLEEP:
+ return Component.Identifier.Key.SLEEP;
+ default:
+ return Component.Identifier.Key.UNKNOWN;
+ }
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/RawInputEnvironmentPlugin.java b/src/plugins/windows/net/java/games/input/RawInputEnvironmentPlugin.java
new file mode 100644
index 0000000..9d409aa
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/RawInputEnvironmentPlugin.java
@@ -0,0 +1,205 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.List;
+import java.util.ArrayList;
+import java.io.File;
+import java.io.IOException;
+
+import net.java.games.util.plugins.Plugin;
+
+/** DirectInput implementation of controller environment
+ * @author martak
+ * @author elias
+ * @version 1.0
+ */
+public final class RawInputEnvironmentPlugin extends ControllerEnvironment implements Plugin {
+
+ private static boolean supported = false;
+
+ /**
+ * Static utility method for loading native libraries.
+ * It will try to load from either the path given by
+ * the net.java.games.input.librarypath property
+ * or through System.loadLibrary().
+ *
+ */
+ static void loadLibrary(final String lib_name) {
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ try {
+ String lib_path = System.getProperty("net.java.games.input.librarypath");
+ if (lib_path != null)
+ System.load(lib_path + File.separator + System.mapLibraryName(lib_name));
+ else
+ System.loadLibrary(lib_name);
+ } catch (UnsatisfiedLinkError e) {
+ e.printStackTrace();
+ supported = false;
+ }
+ return null;
+ });
+ }
+
+ static String getPrivilegedProperty(final String property) {
+ return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property));
+ }
+
+
+ static String getPrivilegedProperty(final String property, final String default_value) {
+ return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property, default_value));
+ }
+
+ static {
+ String osName = getPrivilegedProperty("os.name", "").trim();
+ if(osName.startsWith("Windows")) {
+ supported = true;
+ if("x86".equals(getPrivilegedProperty("os.arch"))) {
+ loadLibrary("jinput-raw");
+ } else {
+ loadLibrary("jinput-raw_64");
+ }
+ }
+ }
+
+ private final Controller[] controllers;
+
+ /** Creates new DirectInputEnvironment */
+ public RawInputEnvironmentPlugin() {
+ RawInputEventQueue queue;
+ Controller[] controllers = new Controller[]{};
+ if(isSupported()) {
+ try {
+ queue = new RawInputEventQueue();
+ controllers = enumControllers(queue);
+ } catch (IOException e) {
+ log("Failed to enumerate devices: " + e.getMessage());
+ }
+ }
+ this.controllers = controllers;
+ }
+
+ public final Controller[] getControllers() {
+ return controllers;
+ }
+
+ private final static SetupAPIDevice lookupSetupAPIDevice(String device_name, List setupapi_devices) {
+ /* First, replace # with / in the device name, since that
+ * seems to be the format in raw input device name
+ */
+ device_name = device_name.replaceAll("#", "\\\\").toUpperCase();
+ for (int i = 0; i < setupapi_devices.size(); i++) {
+ SetupAPIDevice device = setupapi_devices.get(i);
+ if (device_name.contains(device.getInstanceId().toUpperCase()))
+ return device;
+ }
+ return null;
+ }
+
+ private final static void createControllersFromDevices(RawInputEventQueue queue, List controllers, List devices, List setupapi_devices) throws IOException {
+ List active_devices = new ArrayList<>();
+ for (int i = 0; i < devices.size(); i++) {
+ RawDevice device = devices.get(i);
+ SetupAPIDevice setupapi_device = lookupSetupAPIDevice(device.getName(), setupapi_devices);
+ if (setupapi_device == null) {
+ /* Either the device is an RDP or we failed to locate the
+ * SetupAPI device that matches
+ */
+ continue;
+ }
+ RawDeviceInfo info = device.getInfo();
+ Controller controller = info.createControllerFromDevice(device, setupapi_device);
+ if (controller != null) {
+ controllers.add(controller);
+ active_devices.add(device);
+ }
+ }
+ queue.start(active_devices);
+ }
+
+ private final static native void enumerateDevices(RawInputEventQueue queue, List devices) throws IOException;
+
+ private final Controller[] enumControllers(RawInputEventQueue queue) throws IOException {
+ List controllers = new ArrayList<>();
+ List devices = new ArrayList<>();
+ enumerateDevices(queue, devices);
+ List setupapi_devices = enumSetupAPIDevices();
+ createControllersFromDevices(queue, controllers, devices, setupapi_devices);
+ Controller[] controllers_array = new Controller[controllers.size()];
+ controllers.toArray(controllers_array);
+ return controllers_array;
+ }
+
+ public boolean isSupported() {
+ return supported;
+ }
+
+ /*
+ * The raw input API, while being able to access
+ * multiple mice and keyboards, is a bit raw (hah)
+ * since it lacks some important features:
+ *
+ * 1. The list of keyboards and the list of mice
+ * both include useless Terminal Server
+ * devices (RDP_MOU and RDP_KEY) that we'd
+ * like to skip.
+ * 2. The device names returned by GetRawInputDeviceInfo()
+ * are not for display, but instead synthesized
+ * from a combination of a device instance id
+ * and a GUID.
+ *
+ * A solution to both problems is the SetupAPI that allows
+ * us to enumerate all keyboard and mouse devices and fetch their
+ * descriptive names and at the same time filter out the unwanted
+ * RDP devices.
+ */
+ private final static List enumSetupAPIDevices() throws IOException {
+ List devices = new ArrayList<>();
+ nEnumSetupAPIDevices(getKeyboardClassGUID(), devices);
+ nEnumSetupAPIDevices(getMouseClassGUID(), devices);
+ return devices;
+ }
+ private final static native void nEnumSetupAPIDevices(byte[] guid, List devices) throws IOException;
+
+ private final static native byte[] getKeyboardClassGUID();
+ private final static native byte[] getMouseClassGUID();
+
+} // class DirectInputEnvironment
diff --git a/src/plugins/windows/net/java/games/input/RawInputEventQueue.java b/src/plugins/windows/net/java/games/input/RawInputEventQueue.java
new file mode 100644
index 0000000..823f5f5
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/RawInputEventQueue.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ */
+package net.java.games.input;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
+
+/** Java wrapper of RAWDEVICELIST
+ * @author elias
+ * @version 1.0
+ */
+final class RawInputEventQueue {
+ private final Object monitor = new Object();
+
+ private List devices;
+
+ public final void start(List devices) throws IOException {
+ this.devices = devices;
+ QueueThread queue = new QueueThread();
+ synchronized (monitor) {
+ queue.start();
+ // wait for initialization
+ while (!queue.isInitialized()) {
+ try {
+ monitor.wait();
+ } catch (InterruptedException e) {}
+ }
+ }
+ if (queue.getException() != null)
+ throw queue.getException();
+ }
+
+ private final RawDevice lookupDevice(long handle) {
+ for (int i = 0; i < devices.size(); i++) {
+ RawDevice device = devices.get(i);
+ if (device.getHandle() == handle)
+ return device;
+ }
+ return null;
+ }
+
+ /* Event methods called back from native code in nPoll() */
+ private final void addMouseEvent(long handle, long millis, int flags, int button_flags, int button_data, long raw_buttons, long last_x, long last_y, long extra_information) {
+ RawDevice device = lookupDevice(handle);
+ if (device == null)
+ return;
+ device.addMouseEvent(millis, flags, button_flags, button_data, raw_buttons, last_x, last_y, extra_information);
+ }
+
+ private final void addKeyboardEvent(long handle, long millis, int make_code, int flags, int vkey, int message, long extra_information) {
+ RawDevice device = lookupDevice(handle);
+ if (device == null)
+ return;
+ device.addKeyboardEvent(millis, make_code, flags, vkey, message, extra_information);
+ }
+
+ private final void poll(DummyWindow window) throws IOException {
+ nPoll(window.getHwnd());
+ }
+ private final native void nPoll(long hwnd_handle) throws IOException;
+
+ private final static void registerDevices(DummyWindow window, RawDeviceInfo[] devices) throws IOException {
+ nRegisterDevices(0, window.getHwnd(), devices);
+ }
+ private final static native void nRegisterDevices(int flags, long hwnd_addr, RawDeviceInfo[] devices) throws IOException;
+
+ private final class QueueThread extends Thread {
+ private boolean initialized;
+ private DummyWindow window;
+ private IOException exception;
+
+ public QueueThread() {
+ setDaemon(true);
+ }
+
+ public final boolean isInitialized() {
+ return initialized;
+ }
+
+ public final IOException getException() {
+ return exception;
+ }
+
+ public final void run() {
+ // We have to create the window in the (private) queue thread
+ try {
+ window = new DummyWindow();
+ } catch (IOException e) {
+ exception = e;
+ }
+ initialized = true;
+ synchronized (monitor) {
+ monitor.notify();
+ }
+ if (exception != null)
+ return;
+ Set active_infos = new HashSet<>();
+ try {
+ for (int i = 0; i < devices.size(); i++) {
+ RawDevice device = devices.get(i);
+ active_infos.add(device.getInfo());
+ }
+ RawDeviceInfo[] active_infos_array = new RawDeviceInfo[active_infos.size()];
+ active_infos.toArray(active_infos_array);
+ try {
+ registerDevices(window, active_infos_array);
+ while (!isInterrupted()) {
+ poll(window);
+ }
+ } finally {
+ window.destroy();
+ }
+ } catch (IOException e) {
+ exception = e;
+ }
+ }
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/RawKeyboard.java b/src/plugins/windows/net/java/games/input/RawKeyboard.java
new file mode 100644
index 0000000..61a05ed
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/RawKeyboard.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ */
+package net.java.games.input;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+/**
+* @author elias
+* @version 1.0
+*/
+final class RawKeyboard extends Keyboard {
+ private final RawKeyboardEvent raw_event = new RawKeyboardEvent();
+ private final RawDevice device;
+
+ protected RawKeyboard(String name, RawDevice device, Controller[] children, Rumbler[] rumblers) throws IOException {
+ super(name, createKeyboardComponents(device), children, rumblers);
+ this.device = device;
+ }
+
+ private final static Component[] createKeyboardComponents(RawDevice device) {
+ List components = new ArrayList<>();
+ Field[] vkey_fields = RawIdentifierMap.class.getFields();
+ for (int i = 0; i < vkey_fields.length; i++) {
+ Field vkey_field = vkey_fields[i];
+ try {
+ if (Modifier.isStatic(vkey_field.getModifiers()) && vkey_field.getType() == int.class) {
+ int vkey_code = vkey_field.getInt(null);
+ Component.Identifier.Key key_id = RawIdentifierMap.mapVKey(vkey_code);
+ if (key_id != Component.Identifier.Key.UNKNOWN)
+ components.add(new Key(device, vkey_code, key_id));
+ }
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return components.toArray(new Component[]{});
+ }
+
+ protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException {
+ while (true) {
+ if (!device.getNextKeyboardEvent(raw_event))
+ return false;
+ int vkey = raw_event.getVKey();
+ Component.Identifier.Key key_id = RawIdentifierMap.mapVKey(vkey);
+ Component key = getComponent(key_id);
+ if (key == null)
+ continue;
+ int message = raw_event.getMessage();
+ if (message == RawDevice.WM_KEYDOWN || message == RawDevice.WM_SYSKEYDOWN) {
+ event.set(key, 1, raw_event.getNanos());
+ return true;
+ } else if (message == RawDevice.WM_KEYUP || message == RawDevice.WM_SYSKEYUP) {
+ event.set(key, 0, raw_event.getNanos());
+ return true;
+ }
+ }
+ }
+
+ public final void pollDevice() throws IOException {
+ device.pollKeyboard();
+ }
+
+ protected final void setDeviceEventQueueSize(int size) throws IOException {
+ device.setBufferSize(size);
+ }
+
+ final static class Key extends AbstractComponent {
+ private final RawDevice device;
+ private final int vkey_code;
+
+ public Key(RawDevice device, int vkey_code, Component.Identifier.Key key_id) {
+ super(key_id.getName(), key_id);
+ this.device = device;
+ this.vkey_code = vkey_code;
+ }
+
+ protected final float poll() throws IOException {
+ return device.isKeyDown(vkey_code) ? 1f : 0f;
+ }
+
+ public final boolean isAnalog() {
+ return false;
+ }
+
+ public final boolean isRelative() {
+ return false;
+ }
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/RawKeyboardEvent.java b/src/plugins/windows/net/java/games/input/RawKeyboardEvent.java
new file mode 100644
index 0000000..753baa9
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/RawKeyboardEvent.java
@@ -0,0 +1,79 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Java wrapper of RAWKEYBOARD
+ * @author elias
+ * @version 1.0
+ */
+final class RawKeyboardEvent {
+ private long millis;
+ private int make_code;
+ private int flags;
+ private int vkey;
+ private int message;
+ private long extra_information;
+
+ public final void set(long millis, int make_code, int flags, int vkey, int message, long extra_information) {
+ this.millis = millis;
+ this.make_code = make_code;
+ this.flags = flags;
+ this.vkey = vkey;
+ this.message = message;
+ this.extra_information = extra_information;
+ }
+
+ public final void set(RawKeyboardEvent event) {
+ set(event.millis, event.make_code, event.flags, event.vkey, event.message, event.extra_information);
+ }
+
+ public final int getVKey() {
+ return vkey;
+ }
+
+ public final int getMessage() {
+ return message;
+ }
+
+ public final long getNanos() {
+ return millis*1000000L;
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/RawKeyboardInfo.java b/src/plugins/windows/net/java/games/input/RawKeyboardInfo.java
new file mode 100644
index 0000000..3b4add3
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/RawKeyboardInfo.java
@@ -0,0 +1,81 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Java wrapper of RID_DEVICE_INFO_KEYBOARD
+ * @author elias
+ * @version 1.0
+ */
+class RawKeyboardInfo extends RawDeviceInfo {
+ private final RawDevice device;
+ private final int type;
+ private final int sub_type;
+ private final int keyboard_mode;
+ private final int num_function_keys;
+ private final int num_indicators;
+ private final int num_keys_total;
+
+ public RawKeyboardInfo(RawDevice device, int type, int sub_type, int keyboard_mode, int num_function_keys, int num_indicators, int num_keys_total) {
+ this.device = device;
+ this.type = type;
+ this.sub_type = sub_type;
+ this.keyboard_mode = keyboard_mode;
+ this.num_function_keys = num_function_keys;
+ this.num_indicators = num_indicators;
+ this.num_keys_total = num_keys_total;
+ }
+
+ public final int getUsage() {
+ return 6;
+ }
+
+ public final int getUsagePage() {
+ return 1;
+ }
+
+ public final long getHandle() {
+ return device.getHandle();
+ }
+
+ public final Controller createControllerFromDevice(RawDevice device, SetupAPIDevice setupapi_device) throws IOException {
+ return new RawKeyboard(setupapi_device.getName(), device, new Controller[]{}, new Rumbler[]{});
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/RawMouse.java b/src/plugins/windows/net/java/games/input/RawMouse.java
new file mode 100644
index 0000000..57b6cc0
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/RawMouse.java
@@ -0,0 +1,214 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistribution of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistribution in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materails provided with the distribution.
+*
+* Neither the name Sun Microsystems, Inc. or the names of the contributors
+* may be used to endorse or promote products derived from this software
+* without specific prior written permission.
+*
+* This software is provided "AS IS," without a warranty of any kind.
+* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+*
+* You acknowledge that this software is not designed or intended for us in
+* the design, construction, operation or maintenance of any nuclear facility
+*
+*****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/**
+* @author elias
+* @version 1.0
+*/
+final class RawMouse extends Mouse {
+ /* Because one raw event can contain multiple
+ * changes, we'll make a simple state machine
+ * to keep track of which change to report next
+ */
+
+ // Another event should be read
+ private final static int EVENT_DONE = 1;
+ // The X axis should be reported next
+ private final static int EVENT_X = 2;
+ // The Y axis should be reported next
+ private final static int EVENT_Y = 3;
+ // The Z axis should be reported next
+ private final static int EVENT_Z = 4;
+ // Button 0 should be reported next
+ private final static int EVENT_BUTTON_0 = 5;
+ // Button 1 should be reported next
+ private final static int EVENT_BUTTON_1 = 6;
+ // Button 2 should be reported next
+ private final static int EVENT_BUTTON_2 = 7;
+ // Button 3 should be reported next
+ private final static int EVENT_BUTTON_3 = 8;
+ // Button 4 should be reported next
+ private final static int EVENT_BUTTON_4 = 9;
+
+ private final RawDevice device;
+
+ private final RawMouseEvent current_event = new RawMouseEvent();
+ private int event_state = EVENT_DONE;
+
+ protected RawMouse(String name, RawDevice device, Component[] components, Controller[] children, Rumbler[] rumblers) throws IOException {
+ super(name, components, children, rumblers);
+ this.device = device;
+ }
+
+ public final void pollDevice() throws IOException {
+ device.pollMouse();
+ }
+
+ private final static boolean makeButtonEvent(RawMouseEvent mouse_event, Event event, Component button_component, int down_flag, int up_flag) {
+ if ((mouse_event.getButtonFlags() & down_flag) != 0) {
+ event.set(button_component, 1, mouse_event.getNanos());
+ return true;
+ } else if ((mouse_event.getButtonFlags() & up_flag) != 0) {
+ event.set(button_component, 0, mouse_event.getNanos());
+ return true;
+ } else
+ return false;
+ }
+
+ protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException {
+ while (true) {
+ switch (event_state) {
+ case EVENT_DONE:
+ if (!device.getNextMouseEvent(current_event))
+ return false;
+ event_state = EVENT_X;
+ break;
+ case EVENT_X:
+ int rel_x = device.getEventRelativeX();
+ event_state = EVENT_Y;
+ if (rel_x != 0) {
+ event.set(getX(), rel_x, current_event.getNanos());
+ return true;
+ }
+ break;
+ case EVENT_Y:
+ int rel_y = device.getEventRelativeY();
+ event_state = EVENT_Z;
+ if (rel_y != 0) {
+ event.set(getY(), rel_y, current_event.getNanos());
+ return true;
+ }
+ break;
+ case EVENT_Z:
+ int wheel = current_event.getWheelDelta();
+ event_state = EVENT_BUTTON_0;
+ if (wheel != 0) {
+ event.set(getWheel(), wheel, current_event.getNanos());
+ return true;
+ }
+ break;
+ case EVENT_BUTTON_0:
+ event_state = EVENT_BUTTON_1;
+ if (makeButtonEvent(current_event, event, getPrimaryButton(), RawDevice.RI_MOUSE_BUTTON_1_DOWN, RawDevice.RI_MOUSE_BUTTON_1_UP))
+ return true;
+ break;
+ case EVENT_BUTTON_1:
+ event_state = EVENT_BUTTON_2;
+ if (makeButtonEvent(current_event, event, getSecondaryButton(), RawDevice.RI_MOUSE_BUTTON_2_DOWN, RawDevice.RI_MOUSE_BUTTON_2_UP))
+ return true;
+ break;
+ case EVENT_BUTTON_2:
+ event_state = EVENT_BUTTON_3;
+ if (makeButtonEvent(current_event, event, getTertiaryButton(), RawDevice.RI_MOUSE_BUTTON_3_DOWN, RawDevice.RI_MOUSE_BUTTON_3_UP))
+ return true;
+ break;
+ case EVENT_BUTTON_3:
+ event_state = EVENT_BUTTON_4;
+ if (makeButtonEvent(current_event, event, getButton3(), RawDevice.RI_MOUSE_BUTTON_4_DOWN, RawDevice.RI_MOUSE_BUTTON_4_UP))
+ return true;
+ break;
+ case EVENT_BUTTON_4:
+ event_state = EVENT_DONE;
+ if (makeButtonEvent(current_event, event, getButton4(), RawDevice.RI_MOUSE_BUTTON_5_DOWN, RawDevice.RI_MOUSE_BUTTON_5_UP))
+ return true;
+ break;
+ default:
+ throw new RuntimeException("Unknown event state: " + event_state);
+ }
+ }
+ }
+
+ protected final void setDeviceEventQueueSize(int size) throws IOException {
+ device.setBufferSize(size);
+ }
+
+ final static class Axis extends AbstractComponent {
+ private final RawDevice device;
+
+ public Axis(RawDevice device, Component.Identifier.Axis axis) {
+ super(axis.getName(), axis);
+ this.device = device;
+ }
+
+ public final boolean isRelative() {
+ return true;
+ }
+
+ public final boolean isAnalog() {
+ return true;
+ }
+
+ protected final float poll() throws IOException {
+ if (getIdentifier() == Component.Identifier.Axis.X) {
+ return device.getRelativeX();
+ } else if (getIdentifier() == Component.Identifier.Axis.Y) {
+ return device.getRelativeY();
+ } else if (getIdentifier() == Component.Identifier.Axis.Z) {
+ return device.getWheel();
+ } else
+ throw new RuntimeException("Unknown raw axis: " + getIdentifier());
+ }
+ }
+
+ final static class Button extends AbstractComponent {
+ private final RawDevice device;
+ private final int button_id;
+
+ public Button(RawDevice device, Component.Identifier.Button id, int button_id) {
+ super(id.getName(), id);
+ this.device = device;
+ this.button_id = button_id;
+ }
+
+ protected final float poll() throws IOException {
+ return device.getButtonState(button_id) ? 1 : 0;
+ }
+
+ public final boolean isAnalog() {
+ return false;
+ }
+
+ public final boolean isRelative() {
+ return false;
+ }
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/RawMouseEvent.java b/src/plugins/windows/net/java/games/input/RawMouseEvent.java
new file mode 100644
index 0000000..1cc8fce
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/RawMouseEvent.java
@@ -0,0 +1,108 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Java wrapper of RAWMOUSE
+ * @author elias
+ * @version 1.0
+ */
+final class RawMouseEvent {
+ /* It seems that raw input scales wheel
+ * the same way as direcinput
+ */
+ private final static int WHEEL_SCALE = 120;
+
+ private long millis;
+ private int flags;
+ private int button_flags;
+ private int button_data;
+ private long raw_buttons;
+ private long last_x;
+ private long last_y;
+ private long extra_information;
+
+ public final void set(long millis, int flags, int button_flags, int button_data, long raw_buttons, long last_x, long last_y, long extra_information) {
+ this.millis = millis;
+ this.flags = flags;
+ this.button_flags = button_flags;
+ this.button_data = button_data;
+ this.raw_buttons = raw_buttons;
+ this.last_x = last_x;
+ this.last_y = last_y;
+ this.extra_information = extra_information;
+ }
+
+ public final void set(RawMouseEvent event) {
+ set(event.millis, event.flags, event.button_flags, event.button_data, event.raw_buttons, event.last_x, event.last_y, event.extra_information);
+ }
+
+ public final int getWheelDelta() {
+ return button_data/WHEEL_SCALE;
+ }
+
+ private final int getButtonData() {
+ return button_data;
+ }
+
+ public final int getFlags() {
+ return flags;
+ }
+
+ public final int getButtonFlags() {
+ return button_flags;
+ }
+
+ public final int getLastX() {
+ return (int)last_x;
+ }
+
+ public final int getLastY() {
+ return (int)last_y;
+ }
+
+ public final long getRawButtons() {
+ return raw_buttons;
+ }
+
+ public final long getNanos() {
+ return millis*1000000L;
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/RawMouseInfo.java b/src/plugins/windows/net/java/games/input/RawMouseInfo.java
new file mode 100644
index 0000000..aa89e94
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/RawMouseInfo.java
@@ -0,0 +1,88 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Java wrapper of RID_DEVICE_INFO_MOUSE
+ * @author elias
+ * @version 1.0
+ */
+class RawMouseInfo extends RawDeviceInfo {
+ private final RawDevice device;
+ private final int id;
+ private final int num_buttons;
+ private final int sample_rate;
+
+ public RawMouseInfo(RawDevice device, int id, int num_buttons, int sample_rate) {
+ this.device = device;
+ this.id = id;
+ this.num_buttons = num_buttons;
+ this.sample_rate = sample_rate;
+ }
+
+ public final int getUsage() {
+ return 2;
+ }
+
+ public final int getUsagePage() {
+ return 1;
+ }
+
+ public final long getHandle() {
+ return device.getHandle();
+ }
+
+ public final Controller createControllerFromDevice(RawDevice device, SetupAPIDevice setupapi_device) throws IOException {
+ if (num_buttons == 0)
+ return null;
+ // A raw mouse contains the x and y and z axis and the buttons
+ Component[] components = new Component[3 + num_buttons];
+ int index = 0;
+ components[index++] = new RawMouse.Axis(device, Component.Identifier.Axis.X);
+ components[index++] = new RawMouse.Axis(device, Component.Identifier.Axis.Y);
+ components[index++] = new RawMouse.Axis(device, Component.Identifier.Axis.Z);
+ for (int i = 0; i < num_buttons; i++) {
+ Component.Identifier.Button id = DIIdentifierMap.mapMouseButtonIdentifier(DIIdentifierMap.getButtonIdentifier(i));
+ components[index++] = new RawMouse.Button(device, id, i);
+ }
+ Controller mouse = new RawMouse(setupapi_device.getName(), device, components, new Controller[]{}, new Rumbler[]{});
+ return mouse;
+ }
+}
diff --git a/src/plugins/windows/net/java/games/input/SetupAPIDevice.java b/src/plugins/windows/net/java/games/input/SetupAPIDevice.java
new file mode 100644
index 0000000..1c84545
--- /dev/null
+++ b/src/plugins/windows/net/java/games/input/SetupAPIDevice.java
@@ -0,0 +1,63 @@
+/*
+ * %W% %E%
+ *
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+/*****************************************************************************
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistribution of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materails provided with the distribution.
+ *
+ * Neither the name Sun Microsystems, Inc. or the names of the contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
+ * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
+ * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
+ * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
+ * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for us in
+ * the design, construction, operation or maintenance of any nuclear facility
+ *
+ *****************************************************************************/
+package net.java.games.input;
+
+import java.io.IOException;
+
+/** Java wrapper of a SetupAPI device
+ * @author elias
+ * @version 1.0
+ */
+final class SetupAPIDevice {
+ private final String device_instance_id;
+ private final String device_name;
+
+ public SetupAPIDevice(String device_instance_id, String device_name) {
+ this.device_instance_id = device_instance_id;
+ this.device_name = device_name;
+ }
+
+ public final String getName() {
+ return device_name;
+ }
+
+ public final String getInstanceId() {
+ return device_instance_id;
+ }
+}
diff --git a/src/plugins/wintab/net/java/games/input/WinTabButtonComponent.java b/src/plugins/wintab/net/java/games/input/WinTabButtonComponent.java
new file mode 100644
index 0000000..2d74a2d
--- /dev/null
+++ b/src/plugins/wintab/net/java/games/input/WinTabButtonComponent.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2006 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+public class WinTabButtonComponent extends WinTabComponent {
+
+ private int index;
+
+ protected WinTabButtonComponent(WinTabContext context, int parentDevice, String name, Identifier id, int index) {
+ super(context, parentDevice, name, id);
+ this.index = index;
+ }
+
+ public Event processPacket(WinTabPacket packet) {
+ Event newEvent = null;
+
+ float newValue = ((packet.PK_BUTTONS & (int)Math.pow(2, index))>0) ? 1.0f : 0.0f;
+ if(newValue!=getPollData()) {
+ lastKnownValue = newValue;
+
+ //Generate an event
+ newEvent = new Event();
+ newEvent.set(this, newValue, packet.PK_TIME*1000);
+ return newEvent;
+ }
+
+ return newEvent;
+ }
+}
diff --git a/src/plugins/wintab/net/java/games/input/WinTabComponent.java b/src/plugins/wintab/net/java/games/input/WinTabComponent.java
new file mode 100644
index 0000000..a4c2ad9
--- /dev/null
+++ b/src/plugins/wintab/net/java/games/input/WinTabComponent.java
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) 2006 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class WinTabComponent extends AbstractComponent {
+
+ private int min;
+ private int max;
+ protected float lastKnownValue;
+ private boolean analog;
+
+ protected WinTabComponent(WinTabContext context, int parentDevice, String name, Identifier id, int min, int max) {
+ super(name, id);
+ this.min = min;
+ this.max = max;
+ analog = true;
+ }
+
+ protected WinTabComponent(WinTabContext context, int parentDevice, String name, Identifier id) {
+ super(name, id);
+ this.min = 0;
+ this.max = 1;
+ analog = false;
+ }
+
+ protected float poll() throws IOException {
+ return lastKnownValue;
+ }
+
+ public boolean isAnalog() {
+ return analog;
+ }
+
+ public boolean isRelative() {
+ // All axis are absolute
+ return false;
+ }
+
+ public static List createComponents(WinTabContext context, int parentDevice, int axisId, int[] axisRanges) {
+ List components = new ArrayList<>();
+ Identifier id;
+ switch(axisId) {
+ case WinTabDevice.XAxis:
+ id = Identifier.Axis.X;
+ components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[0], axisRanges[1]));
+ break;
+ case WinTabDevice.YAxis:
+ id = Identifier.Axis.Y;
+ components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[0], axisRanges[1]));
+ break;
+ case WinTabDevice.ZAxis:
+ id = Identifier.Axis.Z;
+ components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[0], axisRanges[1]));
+ break;
+ case WinTabDevice.NPressureAxis:
+ id = Identifier.Axis.X_FORCE;
+ components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[0], axisRanges[1]));
+ break;
+ case WinTabDevice.TPressureAxis:
+ id = Identifier.Axis.Y_FORCE;
+ components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[0], axisRanges[1]));
+ break;
+ case WinTabDevice.OrientationAxis:
+ id = Identifier.Axis.RX;
+ components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[0], axisRanges[1]));
+ id = Identifier.Axis.RY;
+ components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[2], axisRanges[3]));
+ id = Identifier.Axis.RZ;
+ components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[4], axisRanges[5]));
+ break;
+ case WinTabDevice.RotationAxis:
+ id = Identifier.Axis.RX;
+ components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[0], axisRanges[1]));
+ id = Identifier.Axis.RY;
+ components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[2], axisRanges[3]));
+ id = Identifier.Axis.RZ;
+ components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[4], axisRanges[5]));
+ break;
+ }
+
+ return components;
+ }
+
+ public static Collection createButtons(WinTabContext context, int deviceIndex, int numberOfButtons) {
+ List buttons = new ArrayList<>();
+ Identifier id;
+
+ for(int i=0;i buttonIdClass = Identifier.Button.class;
+ Field idField = buttonIdClass.getField("_" + i);
+ id = (Identifier)idField.get(null);
+ buttons.add(new WinTabButtonComponent(context, deviceIndex, id.getName(), id, i));
+ } catch (SecurityException|NoSuchFieldException|IllegalArgumentException|IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ return buttons;
+ }
+
+ public Event processPacket(WinTabPacket packet) {
+ // Set this to be the old value incase we don't change it
+ float newValue=lastKnownValue;
+
+ if(getIdentifier()==Identifier.Axis.X) {
+ newValue = normalise(packet.PK_X);
+ }
+ if(getIdentifier()==Identifier.Axis.Y) {
+ newValue = normalise(packet.PK_Y);
+ }
+ if(getIdentifier()==Identifier.Axis.Z) {
+ newValue = normalise(packet.PK_Z);
+ }
+ if(getIdentifier()==Identifier.Axis.X_FORCE) {
+ newValue = normalise(packet.PK_NORMAL_PRESSURE);
+ }
+ if(getIdentifier()==Identifier.Axis.Y_FORCE) {
+ newValue = normalise(packet.PK_TANGENT_PRESSURE);
+ }
+ if(getIdentifier()==Identifier.Axis.RX) {
+ newValue = normalise(packet.PK_ORIENTATION_ALT);
+ }
+ if(getIdentifier()==Identifier.Axis.RY) {
+ newValue = normalise(packet.PK_ORIENTATION_AZ);
+ }
+ if(getIdentifier()==Identifier.Axis.RZ) {
+ newValue = normalise(packet.PK_ORIENTATION_TWIST);
+ }
+ if(newValue!=getPollData()) {
+ lastKnownValue = newValue;
+
+ //Generate an event
+ Event newEvent = new Event();
+ newEvent.set(this, newValue, packet.PK_TIME*1000);
+ return newEvent;
+ }
+
+ return null;
+ }
+
+ private float normalise(float value) {
+ if(max == min) return value;
+ float bottom = max - min;
+ return (value - min)/bottom;
+ }
+
+ public static Collection createCursors(WinTabContext context, int deviceIndex, String[] cursorNames) {
+ Identifier id;
+ List cursors = new ArrayList<>();
+
+ for(int i=0;i devices = new ArrayList<>();
+
+ int numSupportedDevices = nGetNumberOfSupportedDevices();
+ for(int i=0;i eventList = new ArrayList<>();
+
+ private WinTabDevice(WinTabContext context, int index, String name, Component[] components) {
+ super(name, components, new Controller[0], new Rumbler[0]);
+ this.context = context;
+ }
+
+ protected boolean getNextDeviceEvent(Event event) throws IOException {
+ if(eventList.size()>0) {
+ Event ourEvent = eventList.remove(0);
+ event.set(ourEvent);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ protected void pollDevice() throws IOException {
+ // Get the data off the native queue.
+ context.processEvents();
+
+ super.pollDevice();
+ }
+
+ public Type getType() {
+ return Type.TRACKPAD;
+ }
+
+ public void processPacket(WinTabPacket packet) {
+ Component[] components = getComponents();
+ for(int i=0;i componentsList = new ArrayList<>();
+
+ int[] axisDetails = nGetAxisDetails(deviceIndex, XAxis);
+ if(axisDetails.length==0) {
+ WinTabEnvironmentPlugin.log("ZAxis not supported");
+ } else {
+ WinTabEnvironmentPlugin.log("Xmin: " + axisDetails[0] + ", Xmax: " + axisDetails[1]);
+ componentsList.addAll(WinTabComponent.createComponents(context, deviceIndex, XAxis, axisDetails));
+ }
+
+ axisDetails = nGetAxisDetails(deviceIndex, YAxis);
+ if(axisDetails.length==0) {
+ WinTabEnvironmentPlugin.log("YAxis not supported");
+ } else {
+ WinTabEnvironmentPlugin.log("Ymin: " + axisDetails[0] + ", Ymax: " + axisDetails[1]);
+ componentsList.addAll(WinTabComponent.createComponents(context, deviceIndex, YAxis, axisDetails));
+ }
+
+ axisDetails = nGetAxisDetails(deviceIndex, ZAxis);
+ if(axisDetails.length==0) {
+ WinTabEnvironmentPlugin.log("ZAxis not supported");
+ } else {
+ WinTabEnvironmentPlugin.log("Zmin: " + axisDetails[0] + ", Zmax: " + axisDetails[1]);
+ componentsList.addAll(WinTabComponent.createComponents(context, deviceIndex, ZAxis, axisDetails));
+ }
+
+ axisDetails = nGetAxisDetails(deviceIndex, NPressureAxis);
+ if(axisDetails.length==0) {
+ WinTabEnvironmentPlugin.log("NPressureAxis not supported");
+ } else {
+ WinTabEnvironmentPlugin.log("NPressMin: " + axisDetails[0] + ", NPressMax: " + axisDetails[1]);
+ componentsList.addAll(WinTabComponent.createComponents(context, deviceIndex, NPressureAxis, axisDetails));
+ }
+
+ axisDetails = nGetAxisDetails(deviceIndex, TPressureAxis);
+ if(axisDetails.length==0) {
+ WinTabEnvironmentPlugin.log("TPressureAxis not supported");
+ } else {
+ WinTabEnvironmentPlugin.log("TPressureAxismin: " + axisDetails[0] + ", TPressureAxismax: " + axisDetails[1]);
+ componentsList.addAll(WinTabComponent.createComponents(context, deviceIndex, TPressureAxis, axisDetails));
+ }
+
+ axisDetails = nGetAxisDetails(deviceIndex, OrientationAxis);
+ if(axisDetails.length==0) {
+ WinTabEnvironmentPlugin.log("OrientationAxis not supported");
+ } else {
+ WinTabEnvironmentPlugin.log("OrientationAxis mins/maxs: " + axisDetails[0] + "," + axisDetails[1] + ", " + axisDetails[2] + "," + axisDetails[3] + ", " + axisDetails[4] + "," + axisDetails[5]);
+ componentsList.addAll(WinTabComponent.createComponents(context, deviceIndex, OrientationAxis, axisDetails));
+ }
+
+ axisDetails = nGetAxisDetails(deviceIndex, RotationAxis);
+ if(axisDetails.length==0) {
+ WinTabEnvironmentPlugin.log("RotationAxis not supported");
+ } else {
+ WinTabEnvironmentPlugin.log("RotationAxis is supported (by the device, not by this plugin)");
+ componentsList.addAll(WinTabComponent.createComponents(context, deviceIndex, RotationAxis, axisDetails));
+ }
+
+ String[] cursorNames = nGetCursorNames(deviceIndex);
+ componentsList.addAll(WinTabComponent.createCursors(context, deviceIndex, cursorNames));
+ for(int i=0;i) () -> {
+ try {
+ String lib_path = System.getProperty("net.java.games.input.librarypath");
+ if (lib_path != null)
+ System.load(lib_path + File.separator + System.mapLibraryName(lib_name));
+ else
+ System.loadLibrary(lib_name);
+ } catch (UnsatisfiedLinkError e) {
+ e.printStackTrace();
+ supported = false;
+ }
+ return null;
+ });
+ }
+
+ static String getPrivilegedProperty(final String property) {
+ return AccessController.doPrivileged((PrivilegedAction)() -> System.getProperty(property));
+ }
+
+
+ static String getPrivilegedProperty(final String property, final String default_value) {
+ return AccessController.doPrivileged((PrivilegedAction)() -> System.getProperty(property, default_value));
+ }
+
+ static {
+ String osName = getPrivilegedProperty("os.name", "").trim();
+ if(osName.startsWith("Windows")) {
+ supported = true;
+ loadLibrary("jinput-wintab");
+ }
+ }
+
+ private final Controller[] controllers;
+ private final List active_devices = new ArrayList<>();
+ private final WinTabContext winTabContext;
+
+ /** Creates new DirectInputEnvironment */
+ public WinTabEnvironmentPlugin() {
+ if(isSupported()) {
+ DummyWindow window;
+ WinTabContext winTabContext = null;
+ Controller[] controllers = new Controller[]{};
+ try {
+ window = new DummyWindow();
+ winTabContext = new WinTabContext(window);
+ try {
+ winTabContext.open();
+ controllers = winTabContext.getControllers();
+ } catch (Exception e) {
+ window.destroy();
+ throw e;
+ }
+ } catch (Exception e) {
+ log("Failed to enumerate devices: " + e.getMessage());
+ e.printStackTrace();
+ }
+ this.controllers = controllers;
+ this.winTabContext = winTabContext;
+ AccessController.doPrivileged((PrivilegedAction)() -> {
+ Runtime.getRuntime().addShutdownHook(new ShutdownHook());
+ return null;
+ });
+ } else {
+ winTabContext = null;
+ controllers = new Controller[]{};
+ }
+ }
+
+ public boolean isSupported() {
+ return supported;
+ }
+
+ public Controller[] getControllers() {
+ return controllers;
+ }
+
+ private final class ShutdownHook extends Thread {
+ public final void run() {
+ /* Release the devices to kill off active force feedback effects */
+ for (int i = 0; i < active_devices.size(); i++) {
+ // TODO free the devices
+ }
+ //Close the context
+ winTabContext.close();
+ /* We won't release the window since it is
+ * owned by the thread that created the environment.
+ */
+ }
+ }
+}
diff --git a/src/plugins/wintab/net/java/games/input/WinTabPacket.java b/src/plugins/wintab/net/java/games/input/WinTabPacket.java
new file mode 100644
index 0000000..ae6018d
--- /dev/null
+++ b/src/plugins/wintab/net/java/games/input/WinTabPacket.java
@@ -0,0 +1,36 @@
+/**
+ * Copyright (C) 2006 Jeremy Booth (jeremy@newdawnsoftware.com)
+ *
+ * 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.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
+
+public class WinTabPacket {
+ long PK_TIME;
+ int PK_X, PK_Y, PK_Z, PK_BUTTONS, PK_NORMAL_PRESSURE, PK_TANGENT_PRESSURE, PK_CURSOR;
+ int PK_ORIENTATION_ALT, PK_ORIENTATION_AZ, PK_ORIENTATION_TWIST;
+
+ public WinTabPacket() {
+
+ }
+}
diff --git a/src/samples/samples/net/java/games/TestSample.java b/src/samples/samples/net/java/games/TestSample.java
new file mode 100644
index 0000000..4401c23
--- /dev/null
+++ b/src/samples/samples/net/java/games/TestSample.java
@@ -0,0 +1,58 @@
+/*
+Copyright (C) 2021 Herve Girod
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+2. 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.
+
+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.
+
+The views and conclusions contained in the software and documentation are those
+of the authors and should not be interpreted as representing official policies,
+either expressed or implied, of the FreeBSD Project.
+
+Alternatively if you have any questions about this project, you can visit
+the project website at the project page on https://github.com/hervegirod/jinput2
+ */
+package samples.net.java.games;
+
+import net.java.games.input.Component;
+import net.java.games.input.Controller;
+import net.java.games.input.ControllerEnvironment;
+
+/**
+ *
+ * @since 2.10
+ */
+public class TestSample {
+ public static void main(String[] args) {
+ Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
+ for (int i = 0; i < controllers.length; i++) {
+ Controller controller = controllers[i];
+ System.out.println("********************");
+ System.out.println("Name: " + controller.getName());
+ System.out.println("Type: " + controller.getType().toString());
+ Component[] components = controller.getComponents();
+ for (int j = 0; j < components.length; j++) {
+ Component comp = components[j];
+ Component.Identifier ident = comp.getIdentifier();
+ System.out.println("Component: " + ident.getName() + " analog: " + comp.isAnalog());
+ System.out.println("Component Data: " + comp.getPollData());
+ }
+ }
+ }
+}
diff --git a/test/net/java/games/input/DefaultControllerEnvironmentTest.java b/test/net/java/games/input/DefaultControllerEnvironmentTest.java
new file mode 100644
index 0000000..2fed767
--- /dev/null
+++ b/test/net/java/games/input/DefaultControllerEnvironmentTest.java
@@ -0,0 +1,72 @@
+/*
+Copyright (C) 2021 Herve Girod
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+2. 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.
+
+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.
+
+The views and conclusions contained in the software and documentation are those
+of the authors and should not be interpreted as representing official policies,
+either expressed or implied, of the FreeBSD Project.
+
+Alternatively if you have any questions about this project, you can visit
+the project website at the project page on https://github.com/hervegirod/jinput2
+ */
+package net.java.games.input;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ * @author Herve
+ */
+public class DefaultControllerEnvironmentTest {
+
+ public DefaultControllerEnvironmentTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+ /**
+ * Test of getDefaultEnvironment method, of class ControllerEnvironment.
+ */
+ @Test
+ public void testGetDefaultEnvironment() {
+ System.out.println("testgetDefaultEnvironment");
+ Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
+ }
+
+}
diff --git a/test/net/java/games/input/VersionTest.java b/test/net/java/games/input/VersionTest.java
new file mode 100644
index 0000000..363ff6a
--- /dev/null
+++ b/test/net/java/games/input/VersionTest.java
@@ -0,0 +1,82 @@
+/*
+Copyright (C) 2021 Herve Girod
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+2. 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.
+
+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.
+
+The views and conclusions contained in the software and documentation are those
+of the authors and should not be interpreted as representing official policies,
+either expressed or implied, of the FreeBSD Project.
+
+Alternatively if you have any questions about this project, you can visit
+the project website at the project page on https://github.com/hervegirod/jinput2
+ */
+package net.java.games.input;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @since 2.10
+ */
+public class VersionTest {
+
+ public VersionTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+ /**
+ * Test of main method, of class Version.
+ */
+ @Test
+ public void testMain() {
+ String[] args = new String[1];
+ Version.main(args);
+ }
+ /**
+ * Test of getVersion method, of class Version.
+ */
+ @Test
+ public void testGetVersion() {
+ System.out.println("VersionTest : testGetVersion");
+ String result = Version.getVersion();
+ assertEquals("2.10", result);
+ }
+
+}