Compare commits

..

1 commit

Author SHA1 Message Date
no author b1864b2f51 This commit was manufactured by cvs2svn to create tag 'post-issue-36'. 2007-08-12 21:59:26 +00:00
174 changed files with 2275 additions and 3949 deletions

13
.gitignore vendored
View file

@ -1,13 +0,0 @@
.classpath
.project
.settings/
build/
target/
apidocs/
bin/
classes/
dist/
eclipse_bin/
*.iml
.idea/
dependency-reduced-pom.xml

144
Jenkinsfile vendored
View file

@ -1,144 +0,0 @@
pipeline {
agent none
triggers { pollSCM('H/15 * * * *') }
tools {
maven 'Maven 3.5.3'
jdk 'OpenJDK 9'
}
options { buildDiscarder(logRotator(numToKeepStr: '5')) }
parameters {
booleanParam(defaultValue: false, description: 'Perform Release', name: 'release')
}
stages {
stage('Build core') {
agent {
label "osx"
}
steps {
sh 'mvn -B -Dmaven.antrun.skip -Dmaven.source.skip -Dmaven.test.skip -DskipTests -DskipITs -pl coreAPI/ package'
}
post {
success {
archiveArtifacts artifacts: 'coreAPI/target/apidocs/**/*', fingerprint: true
}
}
}
stage('Build natives') {
parallel {
stage('Build Windows natives') {
agent {
label "windows"
}
steps {
bat 'mvn -B -am -pl plugins/windows/,plugins/wintab/ clean compile'
}
post {
success {
stash includes: 'plugins/**/target/natives/*.dll', name: 'windows-natives'
}
}
}
stage('Build Linux natives') {
agent {
label "linux"
}
steps {
sh 'mvn -B -am -pl plugins/linux/ clean compile'
}
post {
success {
stash includes: 'plugins/**/target/natives/*.so*', name: 'linux-natives'
}
}
}
stage('Build OSX natives') {
agent {
label "osx"
}
steps {
sh 'mvn -B -am -pl plugins/OSX/ clean compile'
}
post {
success {
stash includes: '**/target/natives/*.jnilib', name: 'osx-natives'
}
}
}
}
}
stage('Build') {
agent {
label "linux"
}
steps {
unstash 'windows-natives'
unstash 'osx-natives'
unstash 'linux-natives'
sh 'mvn -B -P windows,linux,osx,wintab -Dmaven.antrun.skip -Dmaven.javadoc.skip -Dmaven.source.skip -Dmaven.test.skip -DskipTests -DskipITs package'
}
post {
success {
stash includes: '**/target/*.jar', name: 'all-java-jars'
archiveArtifacts artifacts: '**/target/*.jar*', fingerprint: true
}
}
}
stage('Deploy') {
agent {
label "linux"
}
when { branch 'master' }
steps {
milestone(1)
unstash 'windows-natives'
unstash 'osx-natives'
unstash 'linux-natives'
sh 'echo $GPG_SECRET_KEYS | base64 --decode | gpg --batch --import'
sh 'echo $GPG_OWNERTRUST | base64 --decode | gpg --import-ownertrust'
withMaven(
maven: 'Maven 3.5.3',
jdk: 'OpenJDK 9',
globalMavenSettingsConfig: 'global-maven-settings-ossrh',
mavenOpts: '-Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts' //Work around for JDK9 missing cacerts
) {
sh "mvn -P windows,linux,osx,wintab -Dmaven.antrun.skip -Dmaven.test.skip -DskipTests -DskipITs deploy"
}
}
}
stage('Release') {
agent {
label "linux"
}
when {
expression {
return params.release
}
}
steps {
milestone(3)
unstash 'windows-natives'
unstash 'osx-natives'
unstash 'linux-natives'
sh 'echo $GPG_SECRET_KEYS | base64 --decode | gpg --batch --import'
sh 'echo $GPG_OWNERTRUST | base64 --decode | gpg --import-ownertrust'
withMaven(
maven: 'Maven 3.5.3',
jdk: 'OpenJDK 9',
globalMavenSettingsConfig: 'global-maven-settings-ossrh',
mavenOpts: '-Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts' //Work around for JDK9 missing cacerts
) {
sh "mvn -P windows,linux,osx,wintab versions:set -DremoveSnapshot"
script {
VERSION_TAG = sh(script: "mvn -Dexpression=project.version help:evaluate | grep -e '^[[:digit:]]'", returnStdout: true).trim()
}
sh "git tag -a ${VERSION_TAG} -m 'Release tag ${VERSION_TAG}'"
sh "mvn -P windows,linux,osx,wintab,release -Dmaven.antrun.skip -Dmaven.test.skip -DskipTests -DskipITs deploy"
sh "mvn -P windows,linux,osx,wintab versions:revert"
sh "mvn -P windows,linux,osx,wintab versions:set -DnextSnapshot"
sh "git commit -m 'Next development release' ."
sh "git push origin HEAD:master --follow-tags"
}
}
}
}
}

View file

@ -1,9 +0,0 @@
# JInput
[![Maven Central](https://img.shields.io/maven-central/v/net.java.jinput/coreapi.svg)](https://maven-badges.herokuapp.com/maven-central/net.java.jinput/coreapi)
[![Javadocs](http://www.javadoc.io/badge/net.java.jinput/coreapi.svg)](http://www.javadoc.io/doc/net.java.jinput/coreapi)
Library for access to input devices.
## License
Licensed under [BSD License](https://opensource.org/licenses/BSD-3-Clause), copyright is attributed in each source file committed.

View file

@ -1,18 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="content-language" content="en">
<title>JInput Applet Test</title>
<script src="http://java.com/js/deployJava.js"></script>
</head>
<body>
<script>
deployJava.setInstallerType('kernel');
// include any required packages as shown below
deployJava.setAdditionalPackages('javax.swing, javax.xml');
deployJava.runApplet({codebase:".",
archive:"jinput.jar,jinput-test.jar,jinput-applet-test.jar", code:"net.java.games.input.applet.test.ControllerEventTestApplet",
width:"320", Height:"400"}, null, "1.4.2");
</script>
</body>
</html>

View file

@ -1,18 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="content-language" content="en">
<title>JInput Applet Test</title>
<script src="http://java.com/js/deployJava.js"></script>
</head>
<body>
<script>
deployJava.setInstallerType('kernel');
// include any required packages as shown below
deployJava.setAdditionalPackages('javax.swing, javax.xml');
deployJava.runApplet({codebase:".",
archive:"jinput.jar,jinput-test.jar,jinput-applet-test.jar", code:"net.java.games.input.applet.test.ControllerReadTestApplet",
width:"320", Height:"400"}, null, "1.4.2");
</script>
</body>
</html>

View file

@ -1,27 +0,0 @@
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<artifactId>applet</artifactId>
<packaging>jar</packaging>
<name>JInput - applet</name>
<parent>
<groupId>net.java.jinput</groupId>
<artifactId>jinput-parent</artifactId>
<version>2.0.10-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View file

@ -1,213 +0,0 @@
/**
* 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.applet;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
public class JInputAppletResourceLoader {
private static final Logger diagnosticLog = Logger.getLogger(JInputAppletResourceLoader.class.getName());
private int percentageDone = 0;
private String getPrivilegedProperty(final String property) {
return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property));
}
private String setPrivilegedProperty(final String property, final String value) {
return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.setProperty(property, value));
}
public void loadResources(URL codeBase) throws IOException {
downloadNativesJar(codeBase);
extractNativesJar(codeBase);
setJInputClasspath(codeBase);
}
public int getPercentageDone() {
return percentageDone;
}
private void setJInputClasspath(URL codeBase) {
setPrivilegedProperty("net.java.games.input.librarypath", getTempDir(codeBase) + File.separator + "natives" + File.separator);
}
private void extractNativesJar(URL codeBase) throws IOException {
File tempDir = new File(getTempDir(codeBase));
String osName = getPrivilegedProperty("os.name");
String nativeJar = null;
if (osName.startsWith("Win")) {
nativeJar = "jinput-windows-native.jar";
} else if (osName.startsWith("Linux") || osName.startsWith("FreeBSD")) {
nativeJar = "jinput-linux-native.jar";
} else if (osName.startsWith("Mac")) {
nativeJar = "jinput-osx-native.jar";
} else {
}
JarFile localJarFile = new JarFile(new File(tempDir, nativeJar), true);
Enumeration<JarEntry> jarEntries = localJarFile.entries();
int totalUncompressedBytes = 0;
int totalUncompressedBytesWritten = 0;
List<JarEntry> entriesToUse = new ArrayList<>();
while(jarEntries.hasMoreElements()) {
JarEntry jarEntry = jarEntries.nextElement();
String entryName = jarEntry.getName();
if(!entryName.startsWith("META-INF")) {
totalUncompressedBytes+=jarEntry.getSize();
entriesToUse.add(jarEntry);
diagnosticLog.log(Level.INFO, "Got entry " + entryName + " " + jarEntry.getSize() + " big, total of " + totalUncompressedBytes);
}
}
File tempNativesDir = new File(tempDir, "natives");
if(!tempNativesDir.exists()) {
tempNativesDir.mkdirs();
tempNativesDir.deleteOnExit();
}
for(int i=0;i<entriesToUse.size();i++) {
JarEntry jarEntry = entriesToUse.get(i);
InputStream inStream = localJarFile.getInputStream(localJarFile.getEntry(jarEntry.getName()));
File nativeFile = new File(tempNativesDir, jarEntry.getName());
FileOutputStream fos = new FileOutputStream(nativeFile);
byte[] dataBuffer = new byte[65535];
int bytesRead = 0;
// Read the first block
bytesRead = inStream.read(dataBuffer, 0, dataBuffer.length);
while(bytesRead!=-1) {
fos.write(dataBuffer, 0, bytesRead);
totalUncompressedBytesWritten+=bytesRead;
int unpackingPercentageDone = (int)((((float)totalUncompressedBytesWritten)/totalUncompressedBytes)*100);
percentageDone = 50 + (unpackingPercentageDone/2); //Reading the file is only 1/2 the job
diagnosticLog.log(Level.INFO, "Written " + totalUncompressedBytesWritten + " out of " + totalUncompressedBytes + " " + unpackingPercentageDone + "%, (" + percentageDone + "% total)");
// Read the next block
bytesRead = inStream.read(dataBuffer, 0, dataBuffer.length);
}
long entryModifiedTime = jarEntry.getTime();
nativeFile.setLastModified(entryModifiedTime);
diagnosticLog.log(Level.INFO, "Setting native modified time to " + new Date(entryModifiedTime));
fos.close();
inStream.close();
}
}
private void downloadNativesJar(URL codeBase) throws IOException {
diagnosticLog.log(Level.INFO, "codebase: " + codeBase);
File tempDir = new File(getTempDir(codeBase));
if(!tempDir.exists()) {
tempDir.mkdirs();
tempDir.deleteOnExit();
}
String osName = getPrivilegedProperty("os.name");
String nativeJar = null;
if (osName.startsWith("Win")) {
nativeJar = "jinput-windows-native.jar";
} else if (osName.startsWith("Linux") || osName.startsWith("FreeBSD")) {
nativeJar = "jinput-linux-native.jar";
} else if (osName.startsWith("Mac")) {
nativeJar = "jinput-osx-native.jar";
} else {
}
File localJarFile = new File(tempDir, nativeJar);
localJarFile.deleteOnExit();
diagnosticLog.log(Level.INFO, "Using local file " + localJarFile.getCanonicalPath());
OutputStream outStream = new FileOutputStream(localJarFile);
outStream = new BufferedOutputStream(outStream);
URL remoteJarURL = new URL(codeBase, nativeJar);
diagnosticLog.log(Level.INFO, "Using remote file " + remoteJarURL);
URLConnection connection = remoteJarURL.openConnection();
connection.setUseCaches(false);
connection.setConnectTimeout(2000);
int contentLength = connection.getContentLength();
diagnosticLog.log(Level.INFO, "remote jar is " + contentLength + " bytes");
InputStream inStream = connection.getInputStream();
byte[] dataBuffer = new byte[65535];
int bytesRead = 0;
int totalRead = 0;
int totalWritten = 0;
// Read the first block
bytesRead = inStream.read(dataBuffer, 0, dataBuffer.length);
while(bytesRead!=-1) {
//Update total read
totalRead+=bytesRead;
outStream.write(dataBuffer, 0, bytesRead);
totalWritten+=bytesRead;
int thisFilePercent = (int)((((float)totalRead)/contentLength)*100);
percentageDone = thisFilePercent/2; //Reading the file is only 1/2 the job
diagnosticLog.log(Level.INFO, "Written " + totalRead + " out of " + contentLength + " " + thisFilePercent + "%, (" + percentageDone + "% total)");
// Read the next block
bytesRead = inStream.read(dataBuffer, 0, dataBuffer.length);
}
inStream.close();
outStream.close();
}
private String getTempDir(URL codeBase) {
return getPrivilegedProperty("java.io.tmpdir") + File.separator + codeBase.getHost() + File.separator + "jinput";
}
}

54
coreAPI/README.txt Normal file
View file

@ -0,0 +1,54 @@
This file modified last on 06/06/2003 by Jeff Kesselman
This is the source tree for the core input API.
Directory Organization:
The root contains a master ANT build.xml.
After a successful build of the project you will have the following sub directories:
-- apidocs Where the javadocs get built to
-- lib Where dependant libraries are kept.
-- bin Where the actual API is built to
-- src The source files.
-- src/test Execution directories and data for tests.
Build instructions:
To clean: ant clean
To build: ant all (or just ant)
To build docs: ant javadoc
To test:
Textest: A simple discovery test that dumps
the data about the discovered controllers to stdout
To run: ant textest
Readtest: A test that creates a window for each discovered
controller (or sub-controller) which displays the
current state of all the controller's axiis.
(Note: The windows currrently all open at the same
place on the screen so yo uwill have to move them to
see them all.)
To run: ant readtest
Release Info:
Initial Release: This release contains an implementation of the input
API designed by Mike Martak of Sun and Thomas (?) of Sony CEA for
the WIn32 platform. All the code in src/input is cross platform. The
Win32 code is segregated to the DirectX plugin (src/DXplugin) which
depends on DirectInput from DX7 (or later).
05/09/2003: A number of bugs and problems with the DXPlugin are fixed in this
release. This release also brings the code up to date using the DI8
interface. This thus is the first release that requries Peter Puck's
DX8 bindings to compile with MinGW.
05/09/2003 (second update):
This version adds a new standard value type to the API.
Axis.POV holds standard definitions for values for POV (hat) switches
-- Axis.POV.CENTER and Axis.POV.OFF are synonmous and are
the center position.
-- Axis.POV.UP, Axis.POV.DOWN, Axis.POV.LEFT and Axis.POV.RIGHT
should be self explainatory.
Any hat that claims to be "normalized" will return these values. (It is
recommended that all hats be normalized by the systemn specific plugins.)

53
coreAPI/build.xml Normal file
View file

@ -0,0 +1,53 @@
<?xml version="1.0"?>
<project name="Game Input API" basedir="." default="all">
<target name="init">
<property name="utils" location="../lib/jutils.jar"/>
<mkdir dir="apidocs"/>
<mkdir dir="classes"/>
<mkdir dir="bin"/>
</target>
<target name="compile" depends="init">
<javac srcdir="src/java" destdir="classes" debug="true" deprecation="true" source="1.4" target="1.4">
<include name="net/**"/>
<!-- To add something to the classpath: -->
<classpath>
<pathelement location="${utils}"/>
</classpath>
</javac>
</target>
<target name="jar" depends="init,compile">
<jar jarfile="bin/jinput-core.jar" compress="true" basedir="classes">
<include name="net/java/games/input/*class"/>
</jar>
<jar jarfile="bin/jinput-test.jar" compress="true" basedir="classes">
<include name="net/java/games/input/test/*class"/>
</jar>
</target>
<target name="javadoc" depends="init" description="Javadoc for my API.">
<javadoc packagenames="net.java.games.input.*"
destdir="apidocs"
additionalparam="-source 1.4"
excludepackagenames="net.java.games.input.example.*,net.java.games.input.test.*">
<sourcepath>
<pathelement location="src/java"/>
</sourcepath>
<classpath>
<pathelement location="${utils}"/>
</classpath>
</javadoc>
</target>
<target name="clean" depends="init" description="Clean all build products.">
<delete dir="classes"/>
<delete dir="bin"/>
<delete dir="apidocs"/>
</target>
<target name="all" depends="init,jar" description="Build everything.">
<echo message="JInput has been built and jinput.jar is located in the bin directory."/>
</target>
</project>

View file

@ -1,31 +0,0 @@
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<artifactId>coreapi</artifactId>
<packaging>jar</packaging>
<name>JInput - core API</name>
<parent>
<groupId>net.java.jinput</groupId>
<artifactId>jinput-parent</artifactId>
<version>2.0.10-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>net.java.jutils</groupId>
<artifactId>jutils</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<!-- <plugin> -->
<!-- <artifactId>maven-javadoc-plugin</artifactId> -->
<!-- </plugin> -->
</plugins>
</build>
</project>

View file

@ -94,9 +94,9 @@ public abstract class AbstractComponent implements Component {
/**
* 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 normalised, the value returned will be between -1.0f and
* If this axis is normalized, the value returned will be between -1.0f and
* 1.0f.
* @return The data from the last time the control has been polled.
* @return 0.0f by default, can be overridden
*/
public final float getPollData() {
if (!has_polled && !isRelative()) {

View file

@ -1,4 +1,10 @@
/*
* %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:
@ -29,11 +35,13 @@
* 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.util.Map;
import java.util.List;
import java.util.HashMap;
import java.util.ArrayList;
import java.io.IOException;
@ -69,7 +77,7 @@ public abstract class AbstractController implements Controller {
/**
* Map from Component.Identifiers to Components
*/
private final Map<Component.Identifier, Component> id_to_components = new HashMap<>();
private final Map id_to_components = new HashMap();
private EventQueue event_queue = new EventQueue(EVENT_QUEUE_DEPTH);
@ -120,7 +128,7 @@ public abstract class AbstractController implements Controller {
* if no component with the specified type could be found.
*/
public final Component getComponent(Component.Identifier id) {
return id_to_components.get(id);
return (Component)id_to_components.get(id);
}
/**
@ -175,7 +183,7 @@ public abstract class AbstractController implements Controller {
setDeviceEventQueueSize(size);
event_queue = new EventQueue(size);
} catch (IOException e) {
ControllerEnvironment.log("Failed to create new event queue of size " + size + ": " + e);
ControllerEnvironment.logln("Failed to create new event queue of size " + size + ": " + e);
}
}
@ -225,7 +233,7 @@ public abstract class AbstractController implements Controller {
}
return true;
} catch (IOException e) {
ControllerEnvironment.log("Failed to poll device: " + e.getMessage());
ControllerEnvironment.logln("Failed to poll device: " + e.getMessage());
return false;
}
}

View file

@ -444,11 +444,7 @@ public interface Component {
/** '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");
@ -544,50 +540,6 @@ public interface Component {
* 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");
}
/**

View file

@ -39,11 +39,10 @@
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
@ -70,9 +69,12 @@ import java.util.logging.Logger;
*
*/
public abstract class ControllerEnvironment {
static void logln(String msg) {
log(msg + "\n");
}
static void log(String msg) {
Logger.getLogger(ControllerEnvironment.class.getName()).info(msg);
System.out.print(msg);
}
/**
@ -84,17 +86,12 @@ public abstract class ControllerEnvironment {
/**
* List of controller listeners
*/
protected final ArrayList<ControllerListener> controllerListeners = new ArrayList<>();
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);
}
}
/**
@ -132,9 +129,9 @@ public abstract class ControllerEnvironment {
*/
protected void fireControllerAdded(Controller c) {
ControllerEvent ev = new ControllerEvent(c);
Iterator<ControllerListener> it = controllerListeners.iterator();
Iterator it = controllerListeners.iterator();
while (it.hasNext()) {
it.next().controllerAdded(ev);
((ControllerListener)it.next()).controllerAdded(ev);
}
}
@ -144,9 +141,9 @@ public abstract class ControllerEnvironment {
*/
protected void fireControllerRemoved(Controller c) {
ControllerEvent ev = new ControllerEvent(c);
Iterator<ControllerListener> it = controllerListeners.iterator();
Iterator it = controllerListeners.iterator();
while (it.hasNext()) {
it.next().controllerRemoved(ev);
((ControllerListener)it.next()).controllerRemoved(ev);
}
}
@ -157,4 +154,4 @@ public abstract class ControllerEnvironment {
public static ControllerEnvironment getDefaultEnvironment() {
return defaultEnvironment;
}
}
} // ControllerEnvironment

View file

@ -1,4 +1,10 @@
/*
* %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:
@ -29,19 +35,21 @@
* 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.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import net.java.games.util.plugins.*;
/**
* The default controller environment.
@ -52,8 +60,6 @@ import java.util.logging.Logger;
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
@ -62,31 +68,42 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
*
*/
static void loadLibrary(final String lib_name) {
AccessController.doPrivileged((PrivilegedAction<String>) () -> {
AccessController.doPrivileged(
new PrivilegedAction() {
public final Object run() {
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<String>) () -> System.getProperty(property));
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property);
}
});
}
static String getPrivilegedProperty(final String property, final String default_value) {
return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property, default_value));
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property, default_value);
}
});
}
/**
* List of all controllers in this environment
*/
private ArrayList<Controller> controllers;
private ArrayList controllers;
private Collection<String> loadedPluginNames = new ArrayList<>();
private Collection loadedPlugins = new ArrayList();
/**
* Public no-arg constructor.
@ -101,8 +118,13 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
public Controller[] getControllers() {
if (controllers == null) {
// Controller list has not been scanned.
controllers = new ArrayList<>();
AccessController.doPrivileged((PrivilegedAction<Void>) () -> scanControllers());
controllers = new ArrayList();
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
scanControllers();
return null;
}
});
//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")) {
@ -111,16 +133,17 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
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")) {
} else if(osName.equals("Windows XP")) {
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";
System.out.println("WARNING: Found unknown Windows version: " + osName);
System.out.println("Attempting to use default windows plug-in.");
System.out.flush();
pluginClasses = pluginClasses + " net.java.games.input.DirectInputEnvironmentPlugin";
} else {
log.warning("Trying to use default plugin, OS name " + osName +" not recognised");
System.out.println("Trying to use default plugin, OS name " + osName +" not recognised");
}
}
@ -128,15 +151,15 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
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(!loadedPlugins.contains(className)) {
System.out.println("Loading: " + className);
Class ceClass = Class.forName(className);
ControllerEnvironment ce = (ControllerEnvironment) ceClass.newInstance();
if(ce.isSupported()) {
addControllers(ce.getControllers());
loadedPluginNames.add(ce.getClass().getName());
loadedPlugins.add(ce.getClass().getName());
} else {
log(ceClass.getName() + " is not supported");
logln(ceClass.getName() + " is not supported");
}
}
} catch (Throwable e) {
@ -145,17 +168,17 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
}
}
Controller[] ret = new Controller[controllers.size()];
Iterator<Controller> it = controllers.iterator();
Iterator it = controllers.iterator();
int i = 0;
while (it.hasNext()) {
ret[i] = it.next();
ret[i] = (Controller)it.next();
i++;
}
return ret;
}
/* This is jeff's new plugin code using Jeff's Plugin manager */
private Void scanControllers() {
private void scanControllers() {
String pluginPathName = getPrivilegedProperty("jinput.controllerPluginPath");
if(pluginPathName == null) {
pluginPathName = "controller";
@ -165,8 +188,6 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
File.separator + "lib"+File.separator + pluginPathName);
scanControllersAt(getPrivilegedProperty("user.dir")+
File.separator + pluginPathName);
return null;
}
private void scanControllersAt(String path) {
@ -176,19 +197,19 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
}
try {
Plugins plugins = new Plugins(file);
@SuppressWarnings("unchecked")
Class<ControllerEnvironment>[] envClasses = plugins.getExtends(ControllerEnvironment.class);
Class[] envClasses = plugins.getExtends(ControllerEnvironment.class);
for(int i=0;i<envClasses.length;i++){
try {
ControllerEnvironment.log("ControllerEnvironment "+
ControllerEnvironment.logln("ControllerEnvironment "+
envClasses[i].getName()
+" loaded by "+envClasses[i].getClassLoader());
ControllerEnvironment ce = envClasses[i].getDeclaredConstructor().newInstance();
ControllerEnvironment ce = (ControllerEnvironment)
envClasses[i].newInstance();
if(ce.isSupported()) {
addControllers(ce.getControllers());
loadedPluginNames.add(ce.getClass().getName());
loadedPlugins.add(ce.getClass().getName());
} else {
log(envClasses[i].getName() + " is not supported");
logln(envClasses[i].getName() + " is not supported");
}
} catch (Throwable e) {
e.printStackTrace();

View file

@ -38,53 +38,31 @@
*****************************************************************************/
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;

View file

@ -1,4 +1,10 @@
/*
* %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:
@ -29,7 +35,7 @@
* 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;
@ -71,7 +77,7 @@ class PluginClassLoader extends ClassLoader {
* 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)
protected Class findClass(String name)
throws ClassNotFoundException {
// Try loading the class from the file system.
byte[] b = loadClassData(name);
@ -117,14 +123,13 @@ class PluginClassLoader extends ClassLoader {
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;
}
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;
}
/**
@ -142,15 +147,14 @@ class PluginClassLoader extends ClassLoader {
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;
}
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);

View file

@ -33,14 +33,9 @@
package net.java.games.input;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* The version and build number of this implementation.
* Version numbers for a release are of the form: w.x.y, where:
* Version numbers for a release are of the form: w.x.y[-a]-z, where:
* <ul>
* <li>
* w - the major version number of the release. This number should
@ -58,13 +53,27 @@ import java.util.Properties;
* bump in the minor-minor version number signifies that new bug
* fixes have been added to the build.
* </li>
* <li>
* a - an optional build designator followed by a digit. Valid build
* designators are:
* <ul>
* <li>alpha</li>
* <li>beta</li>
* </ul>
* </li>
* <li>
* 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.
* </li>
* </ul>
*
* For example, the following are all valid version strings:
* <ul>
* <li>1.1.2</li>
* <li>1.3.5-SNAPSHOT</li>
* <li>4.7.1-M2</li>
* <li>1.1.2-b02</li>
* <li>1.3.5-alpha1-b19</li>
* <li>4.7.1-beta3-b20</li>
* </ul>
*
*/
@ -77,26 +86,19 @@ public final class Version {
private Version() {
}
/**
* Version string of this build.
*/
private static final String version = "2.0.0-b01";
/**
* Returns the verison string and build number of
* this implementation. See the class descritpion
* for the version string format.
* for the version string format.
*
* @return The version string of this implementation.
*/
public static String getVersion() {
String version = "Unversioned";
try {
Properties p = new Properties();
InputStream is = Version.class.getResourceAsStream("/META-INF/maven/net.java.jinput/coreapi/pom.properties");
if(is != null) {
p.load(is);
version = p.getProperty("version", "");
}
} catch(IOException e) {
// ignore
}
return version;
return version;
}
}

View file

@ -39,7 +39,7 @@ public class ReadAllEvents {
while (queue.getNextEvent(event)) {
/*
* Create a string buffer and put in it, the controller name,
* Create a strug buffer and put in it, the controller name,
* the time stamp of the event, the name of the component
* that changed and the new value.
*

View file

@ -3,6 +3,7 @@ package net.java.games.input.example;
import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
import net.java.games.input.test.ControllerTextTest;
/**
* This class shows how to read the values in a polling loop for the first mouse

View file

@ -9,6 +9,5 @@ Top level package for JInput.
Use -Djinput.useDefaultPlugin=false (or net.java.games.input.useDefaultPlugin=false) to disable automatic loading of the default plugin for the platform.<BR/>
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)<BR/>
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.
</body>
</html>

View file

@ -30,7 +30,7 @@
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
package net.java.games.input.test;
import java.awt.BorderLayout;
import java.awt.Color;
@ -46,20 +46,15 @@ import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
import net.java.games.input.EventQueue;
import net.java.games.input.Event;
import net.java.games.input.Version;
public class ControllerEventTest extends JFrame{
private static final long serialVersionUID = -8266185848160199092L;
private static abstract class AxisPanel extends JPanel{
private static final long serialVersionUID = -6200599064870672000L;
Component axis;
float data;
@ -83,7 +78,6 @@ public class ControllerEventTest extends JFrame{
}
private static class DigitalAxisPanel extends AxisPanel {
private static final long serialVersionUID = -4729666037860134626L;
JLabel digitalState = new JLabel("<unread>");
public DigitalAxisPanel(Component ax) {
@ -107,7 +101,6 @@ public class ControllerEventTest extends JFrame{
}
private static class DigitalHatPanel extends AxisPanel {
private static final long serialVersionUID = -6582605379682496832L;
JLabel digitalState = new JLabel("<unread>");
public DigitalHatPanel(Component ax) {
@ -151,7 +144,6 @@ public class ControllerEventTest extends JFrame{
}
}
private static class AnalogAxisPanel extends AxisPanel {
private static final long serialVersionUID = 7536173405896285590L;
JLabel analogState = new JLabel("<unread>");
public AnalogAxisPanel(Component ax) {
@ -171,9 +163,8 @@ public class ControllerEventTest extends JFrame{
private static class ControllerWindow extends JFrame {
private static final long serialVersionUID = 8623977198558568961L;
Controller ca;
Map<Component, AxisPanel> axes_to_panels = new HashMap<>();
Map axes_to_panels = new HashMap();
boolean disabled = false;
public ControllerWindow(JFrame frame,Controller ca){
@ -215,7 +206,7 @@ public class ControllerEventTest extends JFrame{
}
private void addAxis(JPanel p, Component ax){
AxisPanel p2;
JPanel p2;
if (ax.isAnalog()) {
p2 = new AnalogAxisPanel(ax);
} else {
@ -242,29 +233,31 @@ public class ControllerEventTest extends JFrame{
EventQueue event_queue = ca.getEventQueue();
Event event = new Event();
while (event_queue.getNextEvent(event)) {
AxisPanel panel = axes_to_panels.get(event.getComponent());
AxisPanel panel = (AxisPanel)axes_to_panels.get(event.getComponent());
panel.setPollData(event.getValue());
}
}
}
static final long HEARTBEATMS =100; // 10th of a second
List<ControllerWindow> controllers = new ArrayList<>();
List controllers = new ArrayList();
public ControllerEventTest() {
super("Controller Event Test. Version: " + Version.getVersion());
super("Controller Event Test");
ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
Controller[] ca = ce.getControllers();
for(int i =0;i<ca.length;i++){
makeController(ca[i]);
}
new Thread(() -> {
new Thread(new Runnable() {
public void run(){
try {
while(true){
for(Iterator<ControllerWindow> i=controllers.iterator();i.hasNext();){
for(Iterator i=controllers.iterator();i.hasNext();){
try {
i.next().poll();
ControllerWindow cw = (ControllerWindow)i.next();
cw.poll();
} catch (Exception e) {
e.printStackTrace();
}
@ -274,10 +267,11 @@ public class ControllerEventTest extends JFrame{
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
pack();
setSize(400,400);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}

View file

@ -35,7 +35,7 @@
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
package net.java.games.input.test;
import java.awt.BorderLayout;
import java.awt.Color;
@ -49,17 +49,13 @@ import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
public class ControllerReadTest extends JFrame{
private static final long serialVersionUID = -7129976919159465311L;
private abstract static class AxisPanel extends JPanel{
private static final long serialVersionUID = -2117191506803328790L;
Component axis;
float data;
@ -83,7 +79,6 @@ public class ControllerReadTest extends JFrame{
}
private static class DigitalAxisPanel extends AxisPanel {
private static final long serialVersionUID = -4006900519933869168L;
JLabel digitalState = new JLabel("<unread>");
public DigitalAxisPanel(Component ax) {
@ -107,7 +102,6 @@ public class ControllerReadTest extends JFrame{
}
private static class DigitalHatPanel extends AxisPanel {
private static final long serialVersionUID = -3293100130201231029L;
JLabel digitalState = new JLabel("<unread>");
public DigitalHatPanel(Component ax) {
@ -151,7 +145,6 @@ public class ControllerReadTest extends JFrame{
}
}
private static class AnalogAxisPanel extends AxisPanel {
private static final long serialVersionUID = -3220244985697453835L;
JLabel analogState = new JLabel("<unread>");
public AnalogAxisPanel(Component ax) {
@ -171,9 +164,8 @@ public class ControllerReadTest extends JFrame{
private static class ControllerWindow extends JFrame {
private static final long serialVersionUID = 5812903945250431578L;
Controller ca;
List<AxisPanel> axisList = new ArrayList<>();
List axisList = new ArrayList();
boolean disabled = false;
public ControllerWindow(JFrame frame,Controller ca){
@ -215,7 +207,7 @@ public class ControllerReadTest extends JFrame{
}
private void addAxis(JPanel p, Component ax){
AxisPanel p2;
JPanel p2;
if (ax.isAnalog()) {
p2 = new AnalogAxisPanel(ax);
} else {
@ -241,9 +233,9 @@ public class ControllerReadTest extends JFrame{
setDisabled(false);
}
//System.out.println("Polled "+ca.getName());
for(Iterator<AxisPanel> i =axisList.iterator();i.hasNext();){
for(Iterator i =axisList.iterator();i.hasNext();){
try {
i.next().poll();
((AxisPanel)i.next()).poll();
}catch (Exception e) {
e.printStackTrace();
}
@ -252,22 +244,23 @@ public class ControllerReadTest extends JFrame{
}
static final long HEARTBEATMS =100; // 10th of a second
List<ControllerWindow> controllers = new ArrayList<>();
List controllers = new ArrayList();
public ControllerReadTest() {
super("Controller Read Test. Version: " + Version.getVersion());
super("Controller Read Test");
ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
Controller[] ca = ce.getControllers();
for(int i =0;i<ca.length;i++){
makeController(ca[i]);
}
new Thread(() ->{
new Thread(new Runnable() {
public void run(){
try {
while(true){
for(Iterator<ControllerWindow> i=controllers.iterator();i.hasNext();){
for(Iterator i=controllers.iterator();i.hasNext();){
try {
ControllerWindow cw = i.next();
ControllerWindow cw = (ControllerWindow)i.next();
cw.poll();
} catch (Exception e) {
e.printStackTrace();
@ -278,10 +271,11 @@ public class ControllerReadTest extends JFrame{
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
pack();
setSize(400,400);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}

View file

@ -35,14 +35,19 @@
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
package net.java.games.input.test;
/**
*
* @author administrator
*/
import net.java.games.input.*;
public class ControllerTextTest {
ControllerEnvironment ce;
/** Creates a new instance of ControllerScanner */
public ControllerTextTest() {
ce = ControllerEnvironment.getDefaultEnvironment();
System.out.println("JInput version: " + Version.getVersion());
System.out.println("Controller Env = "+ce.toString());

View file

@ -1,36 +1,23 @@
/*
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
* RumbleTest.java
*
* 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
* Created on 01 December 2003, 23:02
*/
package net.java.games.input;
package net.java.games.input.test;
import net.java.games.input.ControllerEnvironment;
import net.java.games.input.Controller;
import net.java.games.input.Rumbler;
/**
*
* @author Jeremy
*/
public class RumbleTest {
/** Creates a new instance of RumbleTest */
public RumbleTest() {
ControllerEnvironment ca = ControllerEnvironment.getDefaultEnvironment();
System.out.println("JInput version: " + Version.getVersion());
Controller[] controllers = ca.getControllers();
for(int i=0;i<controllers.length;i++) {
System.out.println("Scanning " + controllers[i].getName());
@ -72,7 +59,6 @@ public class RumbleTest {
}
}
}
System.exit(0);
}
/**

View file

@ -1,6 +0,0 @@
title: JInput
description: Java library for access to input devices.
show_downloads: true
google_analytics:
theme: jekyll-theme-architect
jinput_version: 2.0.9

View file

@ -1,93 +0,0 @@
---
layout: default
---
[![Maven Central](https://img.shields.io/maven-central/v/net.java.jinput/coreapi.svg)](https://maven-badges.herokuapp.com/maven-central/net.java.jinput/coreapi)
[![Javadocs](http://www.javadoc.io/badge/net.java.jinput/coreapi.svg)](http://www.javadoc.io/doc/net.java.jinput/coreapi)
# Welcome to the Java Input API Project!
<p>The JInput Project hosts an implementation of an API for game controller
discovery and polled input. It is part of a suite of open-source technologies
initiated by the Game Technology Group at Sun Microsystems with intention of
making the development of high performance games in Java a reality.</p>
<p>The API itself is pure Java and presents a platform-neutral
completely portable model of controller discovery and polling.
It can handle arbitrary controllers and returns both human and
machine understandable descriptions of the inputs available.</p>
<p>The implementation hosted here also includes plug-ins to allow
the API to adapt to various specific platforms. These plug-ins
often contain a native code portion to interface to the host system.
</p>
## Getting Started
### Maven
Include the dependency in your project:
```xml
<dependency>
<groupId>net.java.jinput</groupId>
<artifactId>jinput</artifactId>
<version>{{site.jinput_version}}</version>
</dependency>
<dependency>
<groupId>net.java.jinput</groupId>
<artifactId>jinput</artifactId>
<version>{{site.jinput_version}}</version>
<classifier>natives-all</classifier>
</dependency>
```
You'll also need to add the build plugin in your `build/plugins` section of your pom
```xml
<plugin>
<groupId>com.googlecode.mavennatives</groupId>
<artifactId>maven-nativedependencies-plugin</artifactId>
</plugin>
```
A full pom might look like [this one](https://github.com/jinput/jinput/blob/master/examples/example.pom.xml)
### Without maven
The jar file with the java code in should be in maven central, you'll need the [jinput.jar](http://repo1.maven.org/maven2/net/java/jinput/jinput/{{site.jinput_version}}/jinput-{{site.jinput_version}}.jar) and [jinput-natives-all.jar](http://repo1.maven.org/maven2/net/java/jinput/jinput/{{site.jinput_version}}/jinput-{{site.jinput_version}}-natives-all.jar) that contains the native binaries.
## Running
Add the jinput jar to your classpath, if you are using maven and have the native dependencies plugin working, it will have unpacked the native binaries to `target/natives`, you must specify the `java.library.path` property to point to this directy.
Example
```
java -cp ~/.m2/repository/net/java/jinput/jinput/{{site.jinput_version}}/jinput-{{site.jinput_version}}.jar:target/examples-pom-{{site.jinput_version}}.jar -Djava.library.path=target/natives net.java.games.input.example.ReadFirstMouse
```
More generally
```
java -cp <path to jinput.jar>:<your own jars> -Djava.library.path=<path to natives> <main class>
```
## Usage
```java
/* Create an event object for the underlying plugin to populate */
Event event = new Event();
/* Get the available controllers */
Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
for (int i = 0; i < controllers.length; i++) {
/* Remember to poll each one */
controllers[i].poll();
/* Get the controllers event queue */
EventQueue queue = controllers[i].getEventQueue();
/* For each object in the queue */
while (queue.getNextEvent(event)) {
/* Get event component */
Component comp = event.getComponent();
/* Process event (your awesome code) */
...
}
}
```
[More examples here](https://github.com/jinput/jinput/tree/master/examples/src/main/java/net/java/games/input/example).

View file

@ -1,77 +0,0 @@
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>net.java.jinput</groupId>
<artifactId>examples-pom</artifactId>
<packaging>jar</packaging>
<name>JInput - example pom</name>
<version>2.0.9</version>
<repositories>
<repository>
<id>central-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>net.java.jinput</groupId>
<artifactId>jinput</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.java.jinput</groupId>
<artifactId>jinput</artifactId>
<version>${project.version}</version>
<classifier>natives-all</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.googlecode.mavennatives</groupId>
<artifactId>maven-nativedependencies-plugin</artifactId>
<version>0.0.7</version>
<executions>
<execution>
<id>unpacknatives</id>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>-Djava.library.path=${project.build.directory}/natives</argument>
<argument>-Djinput.loglevel=OFF</argument>
<argument>net.java.games.input.example.ReadAllEvents</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -1,78 +0,0 @@
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<artifactId>examples</artifactId>
<packaging>jar</packaging>
<name>JInput - examples</name>
<parent>
<groupId>net.java.jinput</groupId>
<artifactId>jinput-parent</artifactId>
<version>2.0.10-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<repositories>
<repository>
<id>central-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jinput</artifactId>
<version>${project.version}</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.googlecode.mavennatives</groupId>
<artifactId>maven-nativedependencies-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>ReadAllEvents</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>-Djava.library.path=${project.build.directory}/natives</argument>
<argument>-Djinput.loglevel=OFF</argument>
<argument>net.java.games.input.example.ReadAllEvents</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View file

@ -1,52 +1,80 @@
<?xml version="1.0" ?>
<project name="OS X Plugin, Native code" basedir="." default="compileNativeJinputLib">
<description>OSX JInput Native Plugin</description>
<project basedir="." default="all" name="OSX Plugin">
<description>OSX JInput Plugin</description>
<property name="src" location="src" />
<property name="build" location="classes"/>
<property name="bin" location="bin" />
<property name="plugins" location="plugins" />
<target name="init">
<mkdir dir="${build}"/>
<mkdir dir="${bin}"/>
<condition property="macosx">
<and>
<os family="mac" />
<os family="unix" />
</and>
</condition>
</target>
<target name="init">
<mkdir dir="target/natives/arm64"/>
</target>
<target depends="init" name="compile">
<javac debug="true" deprecation="true" destdir="${build}" source="1.4" srcdir="src/java">
<classpath>
<pathelement location="../../coreAPI/bin/jinput-core.jar"/>
<pathelement location="../../lib/jutils.jar"/>
</classpath>
</javac>
</target>
<target depends="init,compile" name="jar">
<jar jarfile="${bin}/HIDWrapper.jar" compress="true" basedir="${build}">
<include name="**/*.class"/>
</jar>
</target>
<target depends="compileNativeJinputLib,jar" description="Build everything." name="all">
</target>
<target name="javadoc" depends="init" description="Javadoc for OS X plugin for JInput.">
<mkdir dir="apidocs"/>
<javadoc packagenames="net.java.games.input.*"
destdir="apidocs"
additionalparam="-source 1.4"
link="../../../coreAPI/apidocs">
<sourcepath>
<pathelement location="src/java"/>
</sourcepath>
<classpath>
<pathelement location="../../coreAPI/bin/jinput-core.jar"/>
<pathelement location="../../lib/jutils.jar"/>
</classpath>
</javadoc>
</target>
<target description="Clean all build products." name="clean">
<delete dir="classes" failonerror="no"/>
<delete dir="bin" failonerror="no"/>
<delete dir="apidocs" failonerror="no"/>
<ant inheritAll="false" antfile="src/native/build.xml" target="clean"/>
</target>
<target depends="init,compile" name="createJNIHeaders">
<javah destdir="src/native">
<classpath>
<pathelement path="${build}"/>
<pathelement location="../../coreAPI/classes"/>
</classpath>
<class name="net.java.games.input.OSXHIDDeviceIterator"/>
<class name="net.java.games.input.OSXHIDDevice"/>
<class name="net.java.games.input.OSXHIDQueue"/>
</javah>
</target>
<target name="compile">
<apply dir="${dstdir}" executable="${compiler}" os="Mac OS X" skipemptyfilesets="true" failonerror="true" dest="${dstdir}">
<arg line="${cflags} -O2 -Wall -c -fPIC -I${sdkroot}/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers -I../../../../common/src/native -I../../generated-sources/natives/"/>
<mapper type="glob" from="*.c" to="*.o"/>
<fileset dir="src/main/native" includes="*.c"/>
<fileset dir="../common/src/native" includes="*.c"/>
</apply>
</target>
<target name="link">
<apply dir="${objdir}" parallel="true" executable="${linker}" os="Mac OS X" failonerror="true" skipemptyfilesets="true">
<arg line="${linkerflags} -dynamiclib -o ${libname} -framework CoreFoundation -framework IOKit -framework CoreServices -L/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/lib"/>
<fileset dir="${objdir}" includes="*.o"/>
</apply>
<apply dir="${objdir}" executable="strip" os="Mac OS X" failonerror="true">
<arg line="-S -X"/>
<fileset dir="." includes="${libname}"/>
</apply>
</target>
<target name="compileNativeJinputLib" depends="init">
<property name="arm64_sdkroot" location="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"/>
<property name="arm64_flags" value="-isysroot ${arm64_sdkroot} -arch arm64 -mmacosx-version-min=10.5 -I/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/include/ -I/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/include/darwin/"/>
<antcall target="compile">
<param name="dstdir" location="target/natives/arm64"/>
<param name="compiler" value="gcc"/>
<param name="sdkroot" location="${arm64_sdkroot}"/>
<param name="cflags" value="${arm64_flags}"/>
</antcall>
<antcall target="link">
<param name="objdir" location="target/natives/arm64"/>
<param name="libname" value="libjinput-osx-arm64.jnilib"/>
<param name="linker" value="gcc"/>
<param name="linkerflags" value="${arm64_flags}"/>
</antcall>
<apply dir="target/natives" parallel="true" executable="lipo" os="Mac OS X" failonerror="true" skipemptyfilesets="true" >
<arg value="-create"/>
<srcfile/>
<arg value="-output"/>
<arg path="target/natives/libjinput-osx.jnilib"/>
<fileset file="target/natives/arm64/libjinput-osx-arm64.jnilib"/>
</apply>
</target>
<target name="compileNativeJinputLib" depends="init,createJNIHeaders" if="macosx">
<ant dir="src/native" target="compileNativeJinputLib"/>
<copy todir="${bin}">
<fileset dir="src/native" includes="*.jnilib"/>
</copy>
</target>
</project>

View file

@ -1,69 +0,0 @@
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<artifactId>osx-plugin</artifactId>
<packaging>jar</packaging>
<name>JInput - OSX Plugin</name>
<parent>
<groupId>net.java.jinput</groupId>
<artifactId>plugins</artifactId>
<version>2.0.10-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>net.java.jinput</groupId>
<artifactId>coreapi</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<!-- <plugin> -->
<!-- <artifactId>maven-javadoc-plugin</artifactId> -->
<!-- </plugin> -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>
<ant dir="." target="compileNativeJinputLib"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.directory}/natives</classesDirectory>
<classifier>natives-osx</classifier>
<includes>
<include>*.jnilib</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View file

@ -1,35 +1,41 @@
/*
* 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
* %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.util.Map;
@ -40,13 +46,13 @@ import java.util.HashMap;
* @version 1.0
*/
final class ButtonUsage implements Usage {
private final static Map<Integer, ButtonUsage> map = new HashMap<>();
private final static Map 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);
Integer button_id_obj = new Integer(button_id);
ButtonUsage existing = (ButtonUsage)map.get(button_id_obj);
if (existing != null)
return existing;
ButtonUsage new_button = new ButtonUsage(button_id);

View file

@ -1,35 +1,41 @@
/*
* 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
* %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;
/** Generic Desktop Usages

View file

@ -1,37 +1,46 @@
/*
* 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
* %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.util.Map;
import java.util.HashMap;
/** Mapping from Keyboard HID usages to Component.Identifier.Key
* @author elias
* @version 1.0

View file

@ -1,35 +1,41 @@
/*
* 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
* %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;
@ -61,28 +67,34 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
*
*/
static void loadLibrary(final String lib_name) {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
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;
}
AccessController.doPrivileged(
new PrivilegedAction() {
public final Object run() {
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<String>)() -> System.getProperty(property));
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property);
}
});
}
static String getPrivilegedProperty(final String property, final String default_value) {
return AccessController.doPrivileged((PrivilegedAction<String>)() -> System.getProperty(property, default_value));
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property, default_value);
}
});
}
static {
@ -105,7 +117,7 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
major = Integer.parseInt(major_str);
minor = Integer.parseInt(minor_str);
} catch (Exception e) {
log("Exception occurred while trying to determine OS version: " + e);
logln("Exception occurred while trying to determine OS version: " + e);
// Best guess, no
return false;
}
@ -130,10 +142,10 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
return supported;
}
private final static void addElements(OSXHIDQueue queue, List<OSXHIDElement> elements, List<OSXComponent> components, boolean map_mouse_buttons) throws IOException {
Iterator<OSXHIDElement> it = elements.iterator();
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();
OSXHIDElement element = (OSXHIDElement)it.next();
Component.Identifier id = element.getIdentifier();
if (id == null)
continue;
@ -152,8 +164,8 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
}
}
private final static Keyboard createKeyboardFromDevice(OSXHIDDevice device, List<OSXHIDElement> elements) throws IOException {
List<OSXComponent> components = new ArrayList<>();
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);
@ -163,11 +175,12 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
}
Component[] components_array = new Component[components.size()];
components.toArray(components_array);
return new OSXKeyboard(device, queue, components_array, new Controller[]{}, new Rumbler[]{});
Keyboard keyboard = new OSXKeyboard(device, queue, components_array, new Controller[]{}, new Rumbler[]{});
return keyboard;
}
private final static Mouse createMouseFromDevice(OSXHIDDevice device, List<OSXHIDElement> elements) throws IOException {
List<OSXComponent> components = new ArrayList<>();
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);
@ -186,8 +199,8 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
}
}
private final static AbstractController createControllerFromDevice(OSXHIDDevice device, List<OSXHIDElement> elements, Controller.Type type) throws IOException {
List<OSXComponent> components = new ArrayList<>();
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);
@ -197,14 +210,15 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
}
Component[] components_array = new Component[components.size()];
components.toArray(components_array);
return new OSXAbstractController(device, queue, components_array, new Controller[]{}, new Rumbler[]{}, type);
AbstractController controller = new OSXAbstractController(device, queue, components_array, new Controller[]{}, new Rumbler[]{}, type);
return controller;
}
private final static void createControllersFromDevice(OSXHIDDevice device, List<Controller> controllers) throws IOException {
private final static void createControllersFromDevice(OSXHIDDevice device, List controllers) throws IOException {
UsagePair usage_pair = device.getUsagePair();
if (usage_pair == null)
return;
List<OSXHIDElement> elements = device.getElements();
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);
@ -212,18 +226,22 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
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));
Controller keyboard = createKeyboardFromDevice(device, elements);
if (keyboard != null)
controllers.add(keyboard);
} 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));
Controller joystick = createControllerFromDevice(device, elements, Controller.Type.STICK);
if (joystick != null)
controllers.add(joystick);
} else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.GAME_PAD) {
controllers.add(createControllerFromDevice(device, elements, Controller.Type.GAMEPAD));
Controller game_pad = createControllerFromDevice(device, elements, Controller.Type.GAMEPAD);
if (game_pad != null)
controllers.add(game_pad);
}
}
private final static Controller[] enumerateControllers() {
List<Controller> controllers = new ArrayList<>();
List controllers = new ArrayList();
try {
OSXHIDDeviceIterator it = new OSXHIDDeviceIterator();
try {
@ -239,12 +257,12 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
createControllersFromDevice(device, controllers);
device_used = old_size != controllers.size();
} catch (IOException e) {
log("Failed to create controllers from device: " + device.getProductName());
logln("Failed to create controllers from device: " + device.getProductName());
}
if (!device_used)
device.release();
} catch (IOException e) {
log("Failed to enumerate device: " + e.getMessage());
logln("Failed to enumerate device: " + e.getMessage());
}
}
} finally {

View file

@ -1,35 +1,41 @@
/*
* 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
* %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;
@ -37,7 +43,6 @@ 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
@ -45,7 +50,6 @@ import java.util.logging.Logger;
* @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;
@ -98,7 +102,7 @@ final class OSXHIDDevice {
private final long device_address;
private final long device_interface_address;
private final Map<String,?> properties;
private final Map properties;
private boolean released;
@ -124,7 +128,7 @@ final class OSXHIDDevice {
return (String)properties.get(kIOHIDProductKey);
}
private final OSXHIDElement createElementFromElementProperties(Map<String,?> element_properties) {
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)
@ -148,20 +152,19 @@ final class OSXHIDDevice {
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);
//System.out.println("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<OSXHIDElement> elements, Map<String,?> properties) {
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<String,?> element_properties = (Map<String,?>)elements_properties[i];
Map element_properties = (Map)elements_properties[i];
OSXHIDElement element = createElementFromElementProperties(element_properties);
if (element != null) {
elements.add(element);
@ -170,28 +173,28 @@ final class OSXHIDDevice {
}
}
public final List<OSXHIDElement> getElements() {
List<OSXHIDElement> elements = new ArrayList<>();
public final List getElements() {
List elements = new ArrayList();
addElements(elements, properties);
return elements;
}
private final static long getLongFromProperties(Map<String,?> properties, String key, long default_value) {
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<String,?> properties, String key, boolean default_value) {
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<String,?> properties, String key) {
private final static int getIntFromProperties(Map properties, String key) {
return (int)getLongFromProperties(properties, key);
}
private final static long getLongFromProperties(Map<String,?> properties, String key) {
private final static long getLongFromProperties(Map properties, String key) {
Long long_obj = (Long)properties.get(key);
return long_obj.longValue();
}
@ -212,22 +215,44 @@ final class OSXHIDDevice {
return createUsagePair(usage_page_id, usage_id);
}
/*
public final List getUsagePairs() {
List usage_pairs_list = new ArrayList();
Object[] usage_pairs = (Object[])properties.get(kIOHIDDeviceUsagePairsKey);
if (usage_pairs == null) {
int usage_page_id = getIntFromProperties(properties, kIOHIDPrimaryUsagePageKey);
int usage_id = getIntFromProperties(properties, kIOHIDPrimaryUsageKey);
UsagePair pair = createUsagePair(usage_page_id, usage_id);
if (pair != null)
usage_pairs_list.add(pair);
}
for (int i = 0; i < usage_pairs.length; i++) {
Map usage_pair = (Map)usage_pairs[i];
int usage_page_id = getIntFromProperties(usage_pair, kIOHIDDeviceUsagePageKey);
int usage_id = getIntFromProperties(usage_pair, kIOHIDDeviceUsageKey);
UsagePair pair = createUsagePair(usage_page_id, usage_id);
if (pair != null)
usage_pairs_list.add(pair);
}
return usage_pairs_list;
}
*/
private final void dumpProperties() {
log.info(toString());
System.out.println(toString());
dumpMap("", properties);
}
private final static void dumpArray(String prefix, Object[] array) {
log.info(prefix + "{");
System.out.println(prefix + "{");
for (int i = 0; i < array.length; i++) {
dumpObject(prefix + "\t", array[i]);
log.info(prefix + ",");
System.out.println(prefix + ",");
}
log.info(prefix + "}");
System.out.println(prefix + "}");
}
private final static void dumpMap(String prefix, Map<String,?> map) {
Iterator<String> keys = map.keySet().iterator();
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);
@ -235,24 +260,23 @@ final class OSXHIDDevice {
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()));
System.out.println(prefix + "0x" + Long.toHexString(l.longValue()));
} else if (obj instanceof Map)
dumpMap(prefix, (Map<String,?>)obj);
dumpMap(prefix, (Map)obj);
else if (obj.getClass().isArray())
dumpArray(prefix, (Object[])obj);
else
log.info(prefix + obj);
System.out.println(prefix + obj);
}
private final Map<String,?> getDeviceProperties() throws IOException {
private final Map getDeviceProperties() throws IOException {
return nGetDeviceProperties(device_address);
}
private final static native Map<String,?> nGetDeviceProperties(long device_address) throws IOException;
private final static native Map nGetDeviceProperties(long device_address) throws IOException;
public final synchronized void release() throws IOException {
try {

View file

@ -1,35 +1,41 @@
/*
* 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
* %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;
@ -41,7 +47,7 @@ import java.util.HashMap;
* @version 1.0
*/
final class OSXHIDQueue {
private final Map<Long,OSXComponent> map = new HashMap<>();
private final Map map = new HashMap();
private final long queue_address;
private boolean released;
@ -74,7 +80,7 @@ final class OSXHIDQueue {
}
public final OSXComponent mapEvent(OSXEvent event) {
return map.get(event.getCookie());
return (OSXComponent)map.get(new Long(event.getCookie()));
}
private final void open(int queue_depth) throws IOException {
@ -112,13 +118,13 @@ final class OSXHIDQueue {
public final void addElement(OSXHIDElement element, OSXComponent component) throws IOException {
nAddElement(queue_address, element.getCookie());
map.put(element.getCookie(), component);
map.put(new Long(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());
map.remove(new Long(element.getCookie()));
}
private final static native void nRemoveElement(long queue_address, long cookie) throws IOException;

View file

@ -0,0 +1,46 @@
/*
* %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;
/** Generic Desktop Usages
* @author elias
* @version 1.0
*/
public interface Usage {
}

View file

@ -1,35 +1,41 @@
/*
* 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
* %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;
@ -71,7 +77,7 @@ final class UsagePage {
/* 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 Class usage_class;
private final int usage_page_id;
public final static UsagePage map(int page_id) {
@ -80,7 +86,7 @@ final class UsagePage {
return map[page_id];
}
private UsagePage(int page_id, Class<? extends Usage> usage_class) {
private UsagePage(int page_id, Class usage_class) {
map[page_id] = this;
this.usage_class = usage_class;
this.usage_page_id = page_id;
@ -98,8 +104,8 @@ final class UsagePage {
if (usage_class == null)
return null;
try {
Method map_method = usage_class.getMethod("map", int.class);
Object result = map_method.invoke(null, usage_id);
Method map_method = usage_class.getMethod("map", new Class[]{int.class});
Object result = map_method.invoke(null, new Object[]{new Integer(usage_id)});
return (Usage)result;
} catch (Exception e) {
throw new Error(e);

View file

@ -1,40 +0,0 @@
/*
* 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 {
}

View file

@ -0,0 +1,75 @@
<?xml version="1.0" ?>
<project name="OS X Plugin, Native code" basedir="." default="compileNativeJinputLib">
<description>OSX JInput Native Plugin</description>
<target name="init">
<mkdir dir="ppc"/>
<mkdir dir="intel"/>
</target>
<target name="clean">
<delete failonerror="false">
<fileset dir="intel"/>
<fileset dir="ppc"/>
<fileset file="libjinput-osx.jnilib"/>
</delete>
</target>
<target name="compile">
<apply dir="${dstdir}" executable="${compiler}" os="Mac OS X" skipemptyfilesets="true" failonerror="true" dest="${dstdir}">
<arg line="${cflags} -O2 -Wall -c -fPIC -I${sdkroot}/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers -I../../../../common/src/native -I.."/>
<mapper type="glob" from="*.c" to="*.o"/>
<fileset dir="." includes="*.c"/>
<fileset dir="../../../common/src/native" includes="*.c"/>
</apply>
</target>
<target name="link">
<apply dir="${objdir}" parallel="true" executable="${linker}" os="Mac OS X" failonerror="true" skipemptyfilesets="true">
<arg line="${linkerflags} -dynamiclib -o ${libname} -framework JavaVM -framework CoreFoundation -framework IOKit -framework CoreServices"/>
<fileset dir="${objdir}" includes="*.o"/>
</apply>
<apply dir="${objdir}" executable="strip" os="Mac OS X" failonerror="true">
<arg line="-S -X"/>
<fileset dir="." includes="${libname}"/>
</apply>
</target>
<target name="compileNativeJinputLib" depends="init">
<property name="universal_sdkroot" location="/Developer/SDKs/MacOSX10.4u.sdk"/>
<property name="legacy_sdkroot" location="/Developer/SDKs/MacOSX10.3.9.sdk"/>
<property name="universal_flags" value="-isysroot ${universal_sdkroot} -arch i386"/>
<antcall target="compile">
<param name="dstdir" location="intel"/>
<param name="compiler" value="gcc-4.0"/>
<param name="sdkroot" location="${universal_sdkroot}"/>
<param name="cflags" value="${universal_flags}"/>
</antcall>
<antcall target="link">
<param name="objdir" location="intel"/>
<param name="libname" value="libjinput-osx-intel.jnilib"/>
<param name="linker" value="gcc-4.0"/>
<param name="linkerflags" value="${universal_flags}"/>
</antcall>
<antcall target="compile">
<param name="dstdir" location="ppc"/>
<param name="compiler" value="gcc-3.3"/>
<param name="sdkroot" location="${legacy_sdkroot}"/>
<param name="cflags" value=""/>
</antcall>
<antcall target="link">
<param name="objdir" location="ppc"/>
<param name="libname" value="libjinput-osx-ppc.jnilib"/>
<param name="linker" value="gcc-3.3"/>
<param name="linkerflags" value=""/>
</antcall>
<apply dir="." parallel="true" executable="lipo" os="Mac OS X" failonerror="true" skipemptyfilesets="true" >
<arg value="-create"/>
<srcfile/>
<arg value="-output"/>
<arg path="libjinput-osx.jnilib"/>
<fileset file="ppc/libjinput-osx-ppc.jnilib"/>
<fileset file="intel/libjinput-osx-intel.jnilib"/>
</apply>
</target>
</project>

View file

@ -1,32 +0,0 @@
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<artifactId>awt-plugin</artifactId>
<packaging>jar</packaging>
<name>JInput - AWT Plugin</name>
<parent>
<groupId>net.java.jinput</groupId>
<artifactId>plugins</artifactId>
<version>2.0.10-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>net.java.jinput</groupId>
<artifactId>coreapi</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<!-- <plugin> -->
<!-- <artifactId>maven-javadoc-plugin</artifactId> -->
<!-- </plugin> -->
</plugins>
</build>
</project>

View file

@ -1,4 +1,4 @@
/*
/**
* Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -43,7 +43,7 @@ import java.lang.reflect.Modifier;
* @author elias
*/
final class AWTKeyboard extends Keyboard implements AWTEventListener {
private final List<KeyEvent> awt_events = new ArrayList<>();
private final List awt_events = new ArrayList();
private Event[] processed_events;
private int processed_events_index;
@ -54,7 +54,7 @@ final class AWTKeyboard extends Keyboard implements AWTEventListener {
}
private final static Component[] createComponents() {
List<Component> components = new ArrayList<>();
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];
@ -80,7 +80,7 @@ final class AWTKeyboard extends Keyboard implements AWTEventListener {
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[]{});
return (Component[])components.toArray(new Component[]{});
}
private final void resizeEventQueue(int size) {
@ -96,12 +96,13 @@ final class AWTKeyboard extends Keyboard implements AWTEventListener {
public final synchronized void eventDispatched(AWTEvent event) {
if (event instanceof KeyEvent)
awt_events.add((KeyEvent)event);
awt_events.add(event);
}
public final synchronized void pollDevice() throws IOException {
for (int i = 0; i < awt_events.size(); i++) {
processEvent(awt_events.get(i));
KeyEvent event = (KeyEvent)awt_events.get(i);
processEvent(event);
}
awt_events.clear();
}

View file

@ -1,4 +1,4 @@
/*
/**
* Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -27,6 +27,7 @@
package net.java.games.input;
import java.awt.AWTEvent;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.MouseEvent;
@ -46,8 +47,8 @@ final class AWTMouse extends Mouse implements AWTEventListener {
private final static int EVENT_Y = 2;
private final static int EVENT_BUTTON = 4;
private final List<AWTEvent> awt_events = new ArrayList<>();
private final List<AWTEvent> processed_awt_events = new ArrayList<>();
private final List awt_events = new ArrayList();
private final List processed_awt_events = new ArrayList();
private int event_state = EVENT_X;
@ -114,7 +115,7 @@ final class AWTMouse extends Mouse implements AWTEventListener {
Axis wheel = (Axis)getWheel();
wheel.setValue(0);
for (int i = 0; i < awt_events.size(); i++) {
AWTEvent event = awt_events.get(i);
AWTEvent event = (AWTEvent)awt_events.get(i);
processEvent(event);
processed_awt_events.add(event);
}
@ -125,7 +126,7 @@ final class AWTMouse extends Mouse implements AWTEventListener {
while (true) {
if (processed_awt_events.isEmpty())
return false;
AWTEvent awt_event = processed_awt_events.get(0);
AWTEvent awt_event = (AWTEvent)processed_awt_events.get(0);
if (awt_event instanceof MouseWheelEvent) {
MouseWheelEvent awt_wheel_event = (MouseWheelEvent)awt_event;
long nanos = awt_wheel_event.getWhen()*1000000L;

View file

@ -1,45 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="compileNativeJinputLib" name="Linux Plugin">
<property name="libname64" value="libjinput-linux64.so"/>
<property name="libname32" value="libjinput-linux.so"/>
<project basedir="." default="all" name="Linux Plugin">
<target name="init">
<mkdir dir="target/natives"/>
</target>
<target name="createNativeDefinitions.java">
<exec dir="src/main/native" executable="gawk" os="Linux" output="../java/net/java/games/input/NativeDefinitions.java">
<arg line="-f"/>
<arg line="getDefinitions"/>
<arg line="/usr/include/linux/input.h"/>
</exec>
</target>
<target depends="init" name="compileNativeJinputLib">
<exec executable="uname" outputproperty="hwplatform">
<arg value="-m"/>
</exec>
<condition property="libname" value="${libname64}" else="${libname32}">
<equals arg1="${hwplatform}" arg2="x86_64"/>
<mkdir dir="classes"/>
<mkdir dir="bin"/>
<condition property="linux" >
<!--<os family="unix" />-->
<os name="Linux" />
</condition>
<apply dir="target/natives" executable="cc" os="Linux" dest="target/natives" skipemptyfilesets="true" failonerror="true">
<arg line="-O2 -Wall -c -fPIC"/>
<arg value="-I${java.home}/include"/>
<arg value="-I${java.home}/include/linux"/>
<arg value="-I${java.home}/../include"/>
<arg value="-I${java.home}/../include/linux"/>
<arg value="-I../../../common/src/native"/>
<arg value="-I../generated-sources/natives"/>
<mapper type="glob" from="*.c" to="*.o"/>
<fileset dir="src/main/native" includes="*.c"/>
<fileset dir="../common/src/native" includes="*.c"/>
</apply>
<apply dir="target/natives" parallel="true" executable="cc" os="Linux" failonerror="true">
<arg line="-shared -O2 -Wall -o ${libname}"/>
<fileset dir="target/natives" includes="*.o"/>
</apply>
<apply dir="target/natives" parallel="true" executable="strip" os="Linux" failonerror="true">
<fileset file="target/natives/${libname}"/>
</apply>
</target>
<target depends="init" name="compile">
<!-- <ant dir="src/native" target="createNativeDefinitions.java"/>-->
<javac debug="true" deprecation="true" destdir="classes" source="1.4" target="1.4" srcdir="src/java">
<classpath>
<pathelement location="../../coreAPI/bin/jinput-core.jar"/>
<pathelement location="../../lib/jutils.jar"/>
</classpath>
</javac>
</target>
<target depends="init,compile" name="jar">
<jar jarfile="bin/linux.jar" compress="true" basedir="classes">
<include name="**/*.class"/>
</jar>
</target>
<target depends="jar,compileNativeJinputLib" description="Build everything." name="all">
</target>
<target name="javadoc" depends="init" description="Javadoc for Linux plugin for JInput.">
<mkdir dir="apidocs"/>
<javadoc packagenames="net.java.games.input.*"
destdir="apidocs"
additionalparam="-source 1.4"
link="../../../coreAPI/apidocs">
<sourcepath>
<pathelement location="src/java"/>
</sourcepath>
<classpath>
<pathelement location="../../coreAPI/bin/jinput-core.jar"/>
<pathelement location="../../coreAPI/lib/jutils.jar"/>
</classpath>
</javadoc>
</target>
<target description="Clean all build products." name="clean">
<delete dir="classes" failonerror="no"/>
<delete dir="bin" failonerror="no"/>
<delete dir="apidocs" failonerror="no"/>
<ant inheritAll="false" antfile="src/native/build.xml" target="clean"/>
</target>
<target depends="init,compile" name="createJNIHeaders">
<javah destdir="src/native">
<classpath>
<pathelement location="classes"/>
</classpath>
<class name="net.java.games.input.LinuxEventDevice"/>
<class name="net.java.games.input.LinuxJoystickDevice"/>
</javah>
</target>
<target depends="init,createJNIHeaders" name="compileNativeJinputLib" if="linux">
<ant dir="src/native" target="compileNativeJinputLib"/>
<copy todir="bin">
<fileset dir="src/native" includes="libjinput-linux*.so"/>
</copy>
</target>
</project>

View file

@ -1,69 +0,0 @@
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<artifactId>linux-plugin</artifactId>
<packaging>jar</packaging>
<name>JInput - Linux Plugin</name>
<parent>
<groupId>net.java.jinput</groupId>
<artifactId>plugins</artifactId>
<version>2.0.10-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>net.java.jinput</groupId>
<artifactId>coreapi</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>
<ant dir="." target="compileNativeJinputLib"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.directory}/natives</classesDirectory>
<classifier>natives-linux</classifier>
<includes>
<include>*.so</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View file

@ -40,7 +40,7 @@ import java.util.ArrayList;
* is run on a single thread.
*/
final class LinuxDeviceThread extends Thread {
private final List<LinuxDeviceTask> tasks = new ArrayList<>();
private final List tasks = new ArrayList();
public LinuxDeviceThread() {
setDaemon(true);
@ -50,7 +50,7 @@ final class LinuxDeviceThread extends Thread {
public synchronized final void run() {
while (true) {
if (!tasks.isEmpty()) {
LinuxDeviceTask task = tasks.remove(0);
LinuxDeviceTask task = (LinuxDeviceTask)tasks.remove(0);
task.doExecute();
synchronized (task) {
task.notify();

View file

@ -0,0 +1,489 @@
/**
* 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.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(
new PrivilegedAction() {
public final Object run() {
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 (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property);
}
});
}
static String getPrivilegedProperty(final String property, final String default_value) {
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property, default_value);
}
});
}
static {
String osName = getPrivilegedProperty("os.name", "").trim();
if(osName.equals("Linux")) {
supported = true;
try {
loadLibrary(LIBNAME);
} catch (UnsatisfiedLinkError e) {
try {
loadLibrary(LIBNAME + POSTFIX64BIT);
} catch (UnsatisfiedLinkError e2) {
logln("Failed to load 64 bit library: " + e2.getMessage());
// throw original error
throw e;
}
}
}
}
public final static Object execute(LinuxDeviceTask task) throws IOException {
return device_thread.execute(task);
}
public LinuxEnvironmentPlugin() {
if(isSupported()) {
this.controllers = enumerateControllers();
logln("Linux plugin claims to have found " + controllers.length + " controllers");
AccessController.doPrivileged(
new PrivilegedAction() {
public final Object run() {
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 = (LinuxEventComponent)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:
logln("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 = (Controller) eventControllers.get(i);
Controller jsController = (Controller) 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--;
}
}
}
}
}
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 = (Component.Identifier)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, (Component[])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) {
logln("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 (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return file.getAbsolutePath();
}
});
}
private static File[] listFilesPrivileged(final File dir, final FilenameFilter filter) {
return (File[])AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return dir.listFiles(filter);
}
});
}
private final void enumerateEventControllers(List controllers) {
final File dev = new File("/dev/input");
File[] event_device_files = listFilesPrivileged(dev, new FilenameFilter() {
public final boolean accept(File dir, String name) {
return 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) {
logln("Failed to create Controller: " + e.getMessage());
device.close();
}
} catch (IOException e) {
logln("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 = (LinuxDevice)devices.get(i);
device.close();
} catch (IOException e) {
logln("Failed to close device: " + e.getMessage());
}
}
}
}
public boolean isSupported() {
return supported;
}
}

View file

@ -1,4 +1,4 @@
/*
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -35,12 +35,12 @@ import java.util.ArrayList;
* @author elias
*/
final class LinuxEventDevice implements LinuxDevice {
private final Map<LinuxAxisDescriptor, LinuxComponent> component_map = new HashMap<>();
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<LinuxEventComponent> components;
private final List components;
private final Controller.Type type;
/* Closed state variable that protects the validity of the file descriptor.
@ -83,10 +83,10 @@ final class LinuxEventDevice implements LinuxDevice {
return type;
}
private final static int countComponents(List<LinuxEventComponent> components, Class<?> id_type, boolean relative) {
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);
LinuxEventComponent component = (LinuxEventComponent)components.get(i);
if (id_type.isInstance(component.getIdentifier()) && relative == component.isRelative())
count++;
}
@ -94,7 +94,29 @@ final class LinuxEventDevice implements LinuxDevice {
}
private final Controller.Type guessType() throws IOException {
List<LinuxEventComponent> components = getComponents();
Controller.Type type_from_usages = guessTypeFromUsages();
if (type_from_usages == Controller.Type.UNKNOWN)
return guessTypeFromComponents();
else
return type_from_usages;
}
private final Controller.Type guessTypeFromUsages() throws IOException {
byte[] usage_bits = getDeviceUsageBits();
if (isBitSet(usage_bits, NativeDefinitions.USAGE_MOUSE))
return Controller.Type.MOUSE;
else if (isBitSet(usage_bits, NativeDefinitions.USAGE_KEYBOARD))
return Controller.Type.KEYBOARD;
else if (isBitSet(usage_bits, NativeDefinitions.USAGE_GAMEPAD))
return Controller.Type.GAMEPAD;
else if (isBitSet(usage_bits, NativeDefinitions.USAGE_JOYSTICK))
return Controller.Type.STICK;
else
return Controller.Type.UNKNOWN;
}
private final Controller.Type guessTypeFromComponents() throws IOException {
List components = getComponents();
if (components.size() == 0)
return Controller.Type.UNKNOWN;
int num_rel_axes = countComponents(components, Component.Identifier.Axis.class, true);
@ -118,7 +140,7 @@ final class LinuxEventDevice implements LinuxDevice {
int num_gamepad_button_traits = 0;
// count button traits
for (int i = 0; i < components.size(); i++) {
LinuxEventComponent component = components.get(i);
LinuxEventComponent component = (LinuxEventComponent)components.get(i);
if (component.getButtonTrait() == Controller.Type.MOUSE)
num_mouse_button_traits++;
else if (component.getButtonTrait() == Controller.Type.KEYBOARD)
@ -158,19 +180,19 @@ final class LinuxEventDevice implements LinuxDevice {
}
private final Rumbler[] enumerateRumblers() {
List<Rumbler> rumblers = new ArrayList<>();
List rumblers = new ArrayList();
try {
int num_effects = getNumEffects();
if (num_effects <= 0)
return rumblers.toArray(new Rumbler[]{});
return (Rumbler[])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());
LinuxEnvironmentPlugin.logln("Failed to enumerate rumblers: " + e.getMessage());
}
return rumblers.toArray(new Rumbler[]{});
return (Rumbler[])rumblers.toArray(new Rumbler[]{});
}
public final Rumbler[] getRumblers() {
@ -205,7 +227,7 @@ final class LinuxEventDevice implements LinuxDevice {
}
public final LinuxComponent mapDescriptor(LinuxAxisDescriptor desc) {
return component_map.get(desc);
return (LinuxComponent)component_map.get(desc);
}
public final Controller.PortType getPortType() throws IOException {
@ -243,7 +265,7 @@ final class LinuxEventDevice implements LinuxDevice {
}
private final static native void nGetAbsInfo(long fd, int abs_axis, LinuxAbsInfo abs_info) throws IOException;
private final void addKeys(List<LinuxEventComponent> components) 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)) {
@ -253,7 +275,7 @@ final class LinuxEventDevice implements LinuxDevice {
}
}
private final void addAbsoluteAxes(List<LinuxEventComponent> components) throws IOException {
private final void addAbsoluteAxes(List components) throws IOException {
byte[] bits = getAbsoluteAxesBits();
for (int i = 0; i < bits.length*8; i++) {
if (isBitSet(bits, i)) {
@ -263,7 +285,7 @@ final class LinuxEventDevice implements LinuxDevice {
}
}
private final void addRelativeAxes(List<LinuxEventComponent> components) throws IOException {
private final void addRelativeAxes(List components) throws IOException {
byte[] bits = getRelativeAxesBits();
for (int i = 0; i < bits.length*8; i++) {
if (isBitSet(bits, i)) {
@ -273,12 +295,12 @@ final class LinuxEventDevice implements LinuxDevice {
}
}
public final List<LinuxEventComponent> getComponents() {
public final List getComponents() {
return components;
}
private final List<LinuxEventComponent> getDeviceComponents() throws IOException {
List<LinuxEventComponent> components = new ArrayList<>();
private final List getDeviceComponents() throws IOException {
List components = new ArrayList();
byte[] evtype_bits = getEventTypeBits();
if (isBitSet(evtype_bits, NativeDefinitions.EV_KEY))
addKeys(components);
@ -320,6 +342,15 @@ final class LinuxEventDevice implements LinuxDevice {
}
private final static native void nGetBits(long fd, int ev_type, byte[] evtype_bits) throws IOException;
private final byte[] getDeviceUsageBits() throws IOException {
byte[] bits = new byte[NativeDefinitions.USAGE_MAX/8 + 1];
if (getVersion() >= 0x010001) {
nGetDeviceUsageBits(fd, bits);
}
return bits;
}
private final static native void nGetDeviceUsageBits(long fd, byte[] type_bits) throws IOException;
public final synchronized void pollKeyStates() throws IOException {
nGetKeyStates(fd, key_states);
}
@ -360,7 +391,6 @@ final class LinuxEventDevice implements LinuxDevice {
throw new IOException("Device is closed");
}
@SuppressWarnings("deprecation")
protected void finalize() throws IOException {
close();
}

View file

@ -56,7 +56,7 @@ abstract class LinuxForceFeedbackEffect implements Rumbler {
write_task.write(0);
}
} catch (IOException e) {
LinuxEnvironmentPlugin.log("Failed to rumble: " + e);
LinuxEnvironmentPlugin.logln("Failed to rumble: " + e);
}
}

View file

@ -61,7 +61,7 @@ final class LinuxJoystickAbstractController extends AbstractController {
}
protected final boolean getNextDeviceEvent(Event event) throws IOException {
return device.getNextEvent(event);
return false;
}
public Type getType() {

View file

@ -1,4 +1,4 @@
/*
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -28,6 +28,8 @@ 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
@ -46,8 +48,8 @@ final class LinuxJoystickDevice implements LinuxDevice {
private final Event event = new Event();
private final LinuxJoystickButton[] buttons;
private final LinuxJoystickAxis[] axes;
private final Map<Integer, LinuxJoystickPOV> povXs = new HashMap<>();
private final Map<Integer, LinuxJoystickPOV> povYs = new HashMap<>();
private final Map povXs = new HashMap();
private final Map povYs = new HashMap();
private final byte[] axisMap;
private final char[] buttonMap;
@ -100,12 +102,12 @@ final class LinuxJoystickDevice implements LinuxDevice {
if (axis != null) {
float value = (float)joystick_event.getValue()/AXIS_MAX_VALUE;
axis.setValue(value);
if(povXs.containsKey(index)) {
LinuxJoystickPOV pov = povXs.get(index);
if(povXs.containsKey(new Integer(index))) {
LinuxJoystickPOV pov = (LinuxJoystickPOV)(povXs.get(new Integer(index)));
pov.updateValue();
event.set(pov, pov.getPollData(), joystick_event.getNanos());
} else if(povYs.containsKey(index)) {
LinuxJoystickPOV pov = povYs.get(index);
} else if(povYs.containsKey(new Integer(index))) {
LinuxJoystickPOV pov = (LinuxJoystickPOV)(povYs.get(new Integer(index)));
pov.updateValue();
event.set(pov, pov.getPollData(), joystick_event.getNanos());
} else {
@ -148,8 +150,8 @@ final class LinuxJoystickDevice implements LinuxDevice {
break;
}
}
povXs.put(xIndex,pov);
povYs.put(yIndex,pov);
povXs.put(new Integer(xIndex),pov);
povYs.put(new Integer(yIndex),pov);
}
public final synchronized boolean getNextEvent(Event event) throws IOException {
@ -231,7 +233,6 @@ final class LinuxJoystickDevice implements LinuxDevice {
throw new IOException("Device is closed");
}
@SuppressWarnings("deprecation")
protected void finalize() throws IOException {
close();
}

View file

@ -47,7 +47,7 @@ public class LinuxJoystickPOV extends LinuxJoystickAxis {
else if (last_x == 1 && last_y == 1)
setValue(Component.POV.DOWN_RIGHT);
else {
LinuxEnvironmentPlugin.log("Unknown values x = " + last_x + " | y = " + last_y);
LinuxEnvironmentPlugin.logln("Unknown values x = " + last_x + " | y = " + last_y);
setValue(Component.POV.OFF);
}
}

View file

@ -25,8 +25,6 @@
*/
package net.java.games.input;
import java.util.logging.Logger;
/**
* Mapping utility class between native type ints and string names or
* Key.Identifiers
@ -34,7 +32,6 @@ import java.util.logging.Logger;
*/
class LinuxNativeTypesMap {
private static LinuxNativeTypesMap INSTANCE = new LinuxNativeTypesMap();
private static Logger log = Logger.getLogger(LinuxNativeTypesMap.class.getName());
private final Component.Identifier relAxesIDs[];
private final Component.Identifier absAxesIDs[];
@ -308,52 +305,10 @@ class LinuxNativeTypesMap {
buttonIDs[NativeDefinitions.BTN_TL2] = Component.Identifier.Button.LEFT_THUMB2;
buttonIDs[NativeDefinitions.BTN_TR2] = Component.Identifier.Button.RIGHT_THUMB2;
buttonIDs[NativeDefinitions.BTN_SELECT] = Component.Identifier.Button.SELECT;
buttonIDs[NativeDefinitions.BTN_START] = Component.Identifier.Button.START;
buttonIDs[NativeDefinitions.BTN_MODE] = Component.Identifier.Button.MODE;
buttonIDs[NativeDefinitions.BTN_THUMBL] = Component.Identifier.Button.LEFT_THUMB3;
buttonIDs[NativeDefinitions.BTN_THUMBR] = Component.Identifier.Button.RIGHT_THUMB3;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY1] = Component.Identifier.Button.EXTRA_1;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY2] = Component.Identifier.Button.EXTRA_2;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY3] = Component.Identifier.Button.EXTRA_3;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY4] = Component.Identifier.Button.EXTRA_4;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY5] = Component.Identifier.Button.EXTRA_5;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY6] = Component.Identifier.Button.EXTRA_6;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY7] = Component.Identifier.Button.EXTRA_7;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY8] = Component.Identifier.Button.EXTRA_8;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY9] = Component.Identifier.Button.EXTRA_9;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY10] = Component.Identifier.Button.EXTRA_10;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY11] = Component.Identifier.Button.EXTRA_11;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY12] = Component.Identifier.Button.EXTRA_12;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY13] = Component.Identifier.Button.EXTRA_13;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY14] = Component.Identifier.Button.EXTRA_14;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY15] = Component.Identifier.Button.EXTRA_15;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY16] = Component.Identifier.Button.EXTRA_16;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY17] = Component.Identifier.Button.EXTRA_17;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY18] = Component.Identifier.Button.EXTRA_18;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY19] = Component.Identifier.Button.EXTRA_19;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY20] = Component.Identifier.Button.EXTRA_20;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY21] = Component.Identifier.Button.EXTRA_21;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY22] = Component.Identifier.Button.EXTRA_22;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY23] = Component.Identifier.Button.EXTRA_23;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY24] = Component.Identifier.Button.EXTRA_24;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY25] = Component.Identifier.Button.EXTRA_25;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY26] = Component.Identifier.Button.EXTRA_26;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY27] = Component.Identifier.Button.EXTRA_27;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY28] = Component.Identifier.Button.EXTRA_28;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY29] = Component.Identifier.Button.EXTRA_29;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY30] = Component.Identifier.Button.EXTRA_30;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY31] = Component.Identifier.Button.EXTRA_31;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY32] = Component.Identifier.Button.EXTRA_32;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY33] = Component.Identifier.Button.EXTRA_33;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY34] = Component.Identifier.Button.EXTRA_34;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY35] = Component.Identifier.Button.EXTRA_35;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY36] = Component.Identifier.Button.EXTRA_36;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY37] = Component.Identifier.Button.EXTRA_37;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY38] = Component.Identifier.Button.EXTRA_38;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY39] = Component.Identifier.Button.EXTRA_39;
buttonIDs[NativeDefinitions.BTN_TRIGGER_HAPPY40] = Component.Identifier.Button.EXTRA_40;
// Digitiser
buttonIDs[NativeDefinitions.BTN_TOOL_PEN] = Component.Identifier.Button.TOOL_PEN;
buttonIDs[NativeDefinitions.BTN_TOOL_RUBBER] = Component.Identifier.Button.TOOL_RUBBER;
@ -430,9 +385,8 @@ class LinuxNativeTypesMap {
case NativeDefinitions.BTN_TR :
case NativeDefinitions.BTN_TL2 :
case NativeDefinitions.BTN_TR2 :
case NativeDefinitions.BTN_SELECT :
case NativeDefinitions.BTN_START :
case NativeDefinitions.BTN_MODE :
case NativeDefinitions.BTN_SELECT :
case NativeDefinitions.BTN_MODE :
case NativeDefinitions.BTN_THUMBL :
case NativeDefinitions.BTN_THUMBR :
return Controller.Type.GAMEPAD;
@ -801,7 +755,7 @@ class LinuxNativeTypesMap {
try {
retval = INSTANCE.relAxesIDs[nativeID];
} catch (ArrayIndexOutOfBoundsException e) {
log.warning("INSTANCE.relAxesIDis only " + INSTANCE.relAxesIDs.length + " long, so " + nativeID + " not contained");
System.out.println("INSTANCE.relAxesIDis only " + INSTANCE.relAxesIDs.length + " long, so " + nativeID + " not contained");
//ignore, pretend it was null
}
if(retval == null) {
@ -819,7 +773,7 @@ class LinuxNativeTypesMap {
try {
retval = INSTANCE.absAxesIDs[nativeID];
} catch (ArrayIndexOutOfBoundsException e) {
log.warning("INSTANCE.absAxesIDs is only " + INSTANCE.absAxesIDs.length + " long, so " + nativeID + " not contained");
System.out.println("INSTANCE.absAxesIDs is only " + INSTANCE.absAxesIDs.length + " long, so " + nativeID + " not contained");
//ignore, pretend it was null
}
if(retval == null) {
@ -837,11 +791,11 @@ class LinuxNativeTypesMap {
try {
retval = INSTANCE.buttonIDs[nativeID];
} catch (ArrayIndexOutOfBoundsException e) {
log.warning("INSTANCE.buttonIDs is only " + INSTANCE.buttonIDs.length + " long, so " + nativeID + " not contained");
System.out.println("INSTANCE.buttonIDs is only " + INSTANCE.buttonIDs.length + " long, so " + nativeID + " not contained");
//ignore, pretend it was null
}
if(retval == null) {
retval = Component.Identifier.Button.UNKNOWN;
retval = Component.Identifier.Key.UNKNOWN;
}
return retval;
}

View file

@ -88,7 +88,7 @@ final class LinuxPOV extends LinuxComponent {
else if (last_x == 1 && last_y == 1)
return Component.POV.DOWN_RIGHT;
else {
LinuxEnvironmentPlugin.log("Unknown values x = " + last_x + " | y = " + last_y);
LinuxEnvironmentPlugin.logln("Unknown values x = " + last_x + " | y = " + last_y);
return Component.POV.OFF;
}
}

View file

@ -1,4 +1,4 @@
/*
/**
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -43,9 +43,9 @@ final class LinuxRumbleFF extends LinuxForceFeedbackEffect {
weak_magnitude = (int)(0xc000*intensity);
} else if (intensity > 0.3333333f) {
strong_magnitude = (int)(0x8000*intensity);
weak_magnitude = 0;
weak_magnitude = (int)(0xc000*0);
} else {
strong_magnitude = 0;
strong_magnitude = (int)(0x8000*0);
weak_magnitude = (int)(0xc000*intensity);
}

View file

@ -2,7 +2,7 @@ package net.java.games.input;
/**
* This file is generated from /usr/src/linux-headers-3.2.0-38-generic/include/linux/input.h please do not edit
* This file is generated from /usr/include/linux/input.h please do not edit
*/
class NativeDefinitions {
public static final int EV_VERSION = 0x010001;
@ -11,7 +11,6 @@ class NativeDefinitions {
public static final int EV_REL = 0x02;
public static final int EV_ABS = 0x03;
public static final int EV_MSC = 0x04;
public static final int EV_SW = 0x05;
public static final int EV_LED = 0x11;
public static final int EV_SND = 0x12;
public static final int EV_REP = 0x14;
@ -19,7 +18,6 @@ class NativeDefinitions {
public static final int EV_PWR = 0x16;
public static final int EV_FF_STATUS = 0x17;
public static final int EV_MAX = 0x1f;
public static final int EV_CNT = (EV_MAX+1);
public static final int KEY_RESERVED = 0;
public static final int KEY_ESC = 1;
public static final int KEY_1 = 2;
@ -139,10 +137,8 @@ class NativeDefinitions {
public static final int KEY_KPEQUAL = 117;
public static final int KEY_KPPLUSMINUS = 118;
public static final int KEY_PAUSE = 119;
public static final int KEY_SCALE = 120;
public static final int KEY_KPCOMMA = 121;
public static final int KEY_HANGEUL = 122;
public static final int KEY_HANGUEL = KEY_HANGEUL;
public static final int KEY_HANGUEL = 122;
public static final int KEY_HANJA = 123;
public static final int KEY_YEN = 124;
public static final int KEY_LEFTMETA = 125;
@ -173,7 +169,6 @@ class NativeDefinitions {
public static final int KEY_WWW = 150;
public static final int KEY_MSDOS = 151;
public static final int KEY_COFFEE = 152;
public static final int KEY_SCREENLOCK = KEY_COFFEE;
public static final int KEY_DIRECTION = 153;
public static final int KEY_CYCLEWINDOWS = 154;
public static final int KEY_MAIL = 155;
@ -202,8 +197,6 @@ class NativeDefinitions {
public static final int KEY_SCROLLDOWN = 178;
public static final int KEY_KPLEFTPAREN = 179;
public static final int KEY_KPRIGHTPAREN = 180;
public static final int KEY_NEW = 181;
public static final int KEY_REDO = 182;
public static final int KEY_F13 = 183;
public static final int KEY_F14 = 184;
public static final int KEY_F15 = 185;
@ -220,7 +213,6 @@ class NativeDefinitions {
public static final int KEY_PAUSECD = 201;
public static final int KEY_PROG3 = 202;
public static final int KEY_PROG4 = 203;
public static final int KEY_DASHBOARD = 204;
public static final int KEY_SUSPEND = 205;
public static final int KEY_CLOSE = 206;
public static final int KEY_PLAY = 207;
@ -247,24 +239,7 @@ class NativeDefinitions {
public static final int KEY_KBDILLUMTOGGLE = 228;
public static final int KEY_KBDILLUMDOWN = 229;
public static final int KEY_KBDILLUMUP = 230;
public static final int KEY_SEND = 231;
public static final int KEY_REPLY = 232;
public static final int KEY_FORWARDMAIL = 233;
public static final int KEY_SAVE = 234;
public static final int KEY_DOCUMENTS = 235;
public static final int KEY_BATTERY = 236;
public static final int KEY_BLUETOOTH = 237;
public static final int KEY_WLAN = 238;
public static final int KEY_UWB = 239;
public static final int KEY_UNKNOWN = 240;
public static final int KEY_VIDEO_NEXT = 241;
public static final int KEY_VIDEO_PREV = 242;
public static final int KEY_BRIGHTNESS_CYCLE = 243;
public static final int KEY_BRIGHTNESS_ZERO = 244;
public static final int KEY_DISPLAY_OFF = 245;
public static final int KEY_WIMAX = 246;
public static final int KEY_RFKILL = 247;
public static final int KEY_MICMUTE = 248;
public static final int BTN_MISC = 0x100;
public static final int BTN_0 = 0x100;
public static final int BTN_1 = 0x101;
@ -324,13 +299,11 @@ class NativeDefinitions {
public static final int BTN_TOOL_FINGER = 0x145;
public static final int BTN_TOOL_MOUSE = 0x146;
public static final int BTN_TOOL_LENS = 0x147;
public static final int BTN_TOOL_QUINTTAP = 0x148;
public static final int BTN_TOUCH = 0x14a;
public static final int BTN_STYLUS = 0x14b;
public static final int BTN_STYLUS2 = 0x14c;
public static final int BTN_TOOL_DOUBLETAP = 0x14d;
public static final int BTN_TOOL_TRIPLETAP = 0x14e;
public static final int BTN_TOOL_QUADTAP = 0x14f;
public static final int BTN_WHEEL = 0x150;
public static final int BTN_GEAR_DOWN = 0x150;
public static final int BTN_GEAR_UP = 0x151;
@ -398,33 +371,6 @@ class NativeDefinitions {
public static final int KEY_DIGITS = 0x19d;
public static final int KEY_TEEN = 0x19e;
public static final int KEY_TWEN = 0x19f;
public static final int KEY_VIDEOPHONE = 0x1a0;
public static final int KEY_GAMES = 0x1a1;
public static final int KEY_ZOOMIN = 0x1a2;
public static final int KEY_ZOOMOUT = 0x1a3;
public static final int KEY_ZOOMRESET = 0x1a4;
public static final int KEY_WORDPROCESSOR = 0x1a5;
public static final int KEY_EDITOR = 0x1a6;
public static final int KEY_SPREADSHEET = 0x1a7;
public static final int KEY_GRAPHICSEDITOR = 0x1a8;
public static final int KEY_PRESENTATION = 0x1a9;
public static final int KEY_DATABASE = 0x1aa;
public static final int KEY_NEWS = 0x1ab;
public static final int KEY_VOICEMAIL = 0x1ac;
public static final int KEY_ADDRESSBOOK = 0x1ad;
public static final int KEY_MESSENGER = 0x1ae;
public static final int KEY_DISPLAYTOGGLE = 0x1af;
public static final int KEY_SPELLCHECK = 0x1b0;
public static final int KEY_LOGOFF = 0x1b1;
public static final int KEY_DOLLAR = 0x1b2;
public static final int KEY_EURO = 0x1b3;
public static final int KEY_FRAMEBACK = 0x1b4;
public static final int KEY_FRAMEFORWARD = 0x1b5;
public static final int KEY_CONTEXT_MENU = 0x1b6;
public static final int KEY_MEDIA_REPEAT = 0x1b7;
public static final int KEY_10CHANNELSUP = 0x1b8;
public static final int KEY_10CHANNELSDOWN = 0x1b9;
public static final int KEY_IMAGES = 0x1ba;
public static final int KEY_DEL_EOL = 0x1c0;
public static final int KEY_DEL_EOS = 0x1c1;
public static final int KEY_INS_LINE = 0x1c2;
@ -450,83 +396,7 @@ class NativeDefinitions {
public static final int KEY_FN_F = 0x1e2;
public static final int KEY_FN_S = 0x1e3;
public static final int KEY_FN_B = 0x1e4;
public static final int KEY_BRL_DOT1 = 0x1f1;
public static final int KEY_BRL_DOT2 = 0x1f2;
public static final int KEY_BRL_DOT3 = 0x1f3;
public static final int KEY_BRL_DOT4 = 0x1f4;
public static final int KEY_BRL_DOT5 = 0x1f5;
public static final int KEY_BRL_DOT6 = 0x1f6;
public static final int KEY_BRL_DOT7 = 0x1f7;
public static final int KEY_BRL_DOT8 = 0x1f8;
public static final int KEY_BRL_DOT9 = 0x1f9;
public static final int KEY_BRL_DOT10 = 0x1fa;
public static final int KEY_NUMERIC_0 = 0x200;
public static final int KEY_NUMERIC_1 = 0x201;
public static final int KEY_NUMERIC_2 = 0x202;
public static final int KEY_NUMERIC_3 = 0x203;
public static final int KEY_NUMERIC_4 = 0x204;
public static final int KEY_NUMERIC_5 = 0x205;
public static final int KEY_NUMERIC_6 = 0x206;
public static final int KEY_NUMERIC_7 = 0x207;
public static final int KEY_NUMERIC_8 = 0x208;
public static final int KEY_NUMERIC_9 = 0x209;
public static final int KEY_NUMERIC_STAR = 0x20a;
public static final int KEY_NUMERIC_POUND = 0x20b;
public static final int KEY_CAMERA_FOCUS = 0x210;
public static final int KEY_WPS_BUTTON = 0x211;
public static final int KEY_TOUCHPAD_TOGGLE = 0x212;
public static final int KEY_TOUCHPAD_ON = 0x213;
public static final int KEY_TOUCHPAD_OFF = 0x214;
public static final int KEY_CAMERA_ZOOMIN = 0x215;
public static final int KEY_CAMERA_ZOOMOUT = 0x216;
public static final int KEY_CAMERA_UP = 0x217;
public static final int KEY_CAMERA_DOWN = 0x218;
public static final int KEY_CAMERA_LEFT = 0x219;
public static final int KEY_CAMERA_RIGHT = 0x21a;
public static final int BTN_TRIGGER_HAPPY = 0x2c0;
public static final int BTN_TRIGGER_HAPPY1 = 0x2c0;
public static final int BTN_TRIGGER_HAPPY2 = 0x2c1;
public static final int BTN_TRIGGER_HAPPY3 = 0x2c2;
public static final int BTN_TRIGGER_HAPPY4 = 0x2c3;
public static final int BTN_TRIGGER_HAPPY5 = 0x2c4;
public static final int BTN_TRIGGER_HAPPY6 = 0x2c5;
public static final int BTN_TRIGGER_HAPPY7 = 0x2c6;
public static final int BTN_TRIGGER_HAPPY8 = 0x2c7;
public static final int BTN_TRIGGER_HAPPY9 = 0x2c8;
public static final int BTN_TRIGGER_HAPPY10 = 0x2c9;
public static final int BTN_TRIGGER_HAPPY11 = 0x2ca;
public static final int BTN_TRIGGER_HAPPY12 = 0x2cb;
public static final int BTN_TRIGGER_HAPPY13 = 0x2cc;
public static final int BTN_TRIGGER_HAPPY14 = 0x2cd;
public static final int BTN_TRIGGER_HAPPY15 = 0x2ce;
public static final int BTN_TRIGGER_HAPPY16 = 0x2cf;
public static final int BTN_TRIGGER_HAPPY17 = 0x2d0;
public static final int BTN_TRIGGER_HAPPY18 = 0x2d1;
public static final int BTN_TRIGGER_HAPPY19 = 0x2d2;
public static final int BTN_TRIGGER_HAPPY20 = 0x2d3;
public static final int BTN_TRIGGER_HAPPY21 = 0x2d4;
public static final int BTN_TRIGGER_HAPPY22 = 0x2d5;
public static final int BTN_TRIGGER_HAPPY23 = 0x2d6;
public static final int BTN_TRIGGER_HAPPY24 = 0x2d7;
public static final int BTN_TRIGGER_HAPPY25 = 0x2d8;
public static final int BTN_TRIGGER_HAPPY26 = 0x2d9;
public static final int BTN_TRIGGER_HAPPY27 = 0x2da;
public static final int BTN_TRIGGER_HAPPY28 = 0x2db;
public static final int BTN_TRIGGER_HAPPY29 = 0x2dc;
public static final int BTN_TRIGGER_HAPPY30 = 0x2dd;
public static final int BTN_TRIGGER_HAPPY31 = 0x2de;
public static final int BTN_TRIGGER_HAPPY32 = 0x2df;
public static final int BTN_TRIGGER_HAPPY33 = 0x2e0;
public static final int BTN_TRIGGER_HAPPY34 = 0x2e1;
public static final int BTN_TRIGGER_HAPPY35 = 0x2e2;
public static final int BTN_TRIGGER_HAPPY36 = 0x2e3;
public static final int BTN_TRIGGER_HAPPY37 = 0x2e4;
public static final int BTN_TRIGGER_HAPPY38 = 0x2e5;
public static final int BTN_TRIGGER_HAPPY39 = 0x2e6;
public static final int BTN_TRIGGER_HAPPY40 = 0x2e7;
public static final int KEY_MIN_INTERESTING = KEY_MUTE;
public static final int KEY_MAX = 0x2ff;
public static final int KEY_CNT = (KEY_MAX+1);
public static final int KEY_MAX = 0x1ff;
public static final int REL_X = 0x00;
public static final int REL_Y = 0x01;
public static final int REL_Z = 0x02;
@ -538,7 +408,6 @@ class NativeDefinitions {
public static final int REL_WHEEL = 0x08;
public static final int REL_MISC = 0x09;
public static final int REL_MAX = 0x0f;
public static final int REL_CNT = (REL_MAX+1);
public static final int ABS_X = 0x00;
public static final int ABS_Y = 0x01;
public static final int ABS_Z = 0x02;
@ -565,29 +434,17 @@ class NativeDefinitions {
public static final int ABS_TOOL_WIDTH = 0x1c;
public static final int ABS_VOLUME = 0x20;
public static final int ABS_MISC = 0x28;
public static final int ABS_MT_SLOT = 0x2f;
public static final int ABS_MT_TOUCH_MAJOR = 0x30;
public static final int ABS_MT_TOUCH_MINOR = 0x31;
public static final int ABS_MT_WIDTH_MAJOR = 0x32;
public static final int ABS_MT_WIDTH_MINOR = 0x33;
public static final int ABS_MT_ORIENTATION = 0x34;
public static final int ABS_MT_POSITION_X = 0x35;
public static final int ABS_MT_POSITION_Y = 0x36;
public static final int ABS_MT_TOOL_TYPE = 0x37;
public static final int ABS_MT_BLOB_ID = 0x38;
public static final int ABS_MT_TRACKING_ID = 0x39;
public static final int ABS_MT_PRESSURE = 0x3a;
public static final int ABS_MT_DISTANCE = 0x3b;
public static final int ABS_MT_FIRST = ABS_MT_TOUCH_MAJOR;
public static final int ABS_MT_LAST = ABS_MT_DISTANCE;
public static final int ABS_MAX = 0x3f;
public static final int ABS_CNT = (ABS_MAX+1);
public static final int USAGE_MOUSE = 0x00;
public static final int USAGE_JOYSTICK = 0x01;
public static final int USAGE_GAMEPAD = 0x02;
public static final int USAGE_KEYBOARD = 0x03;
public static final int USAGE_MAX = 0x0f;
public static final int BUS_PCI = 0x01;
public static final int BUS_ISAPNP = 0x02;
public static final int BUS_USB = 0x03;
public static final int BUS_HIL = 0x04;
public static final int BUS_BLUETOOTH = 0x05;
public static final int BUS_VIRTUAL = 0x06;
public static final int BUS_ISA = 0x10;
public static final int BUS_I8042 = 0x11;
public static final int BUS_XTKBD = 0x12;
@ -598,9 +455,6 @@ class NativeDefinitions {
public static final int BUS_ADB = 0x17;
public static final int BUS_I2C = 0x18;
public static final int BUS_HOST = 0x19;
public static final int BUS_GSC = 0x1A;
public static final int BUS_ATARI = 0x1B;
public static final int BUS_SPI = 0x1C;
public static final int FF_STATUS_STOPPED = 0x00;
public static final int FF_STATUS_PLAYING = 0x01;
public static final int FF_STATUS_MAX = 0x01;
@ -612,23 +466,13 @@ class NativeDefinitions {
public static final int FF_DAMPER = 0x55;
public static final int FF_INERTIA = 0x56;
public static final int FF_RAMP = 0x57;
public static final int FF_EFFECT_MIN = FF_RUMBLE;
public static final int FF_EFFECT_MAX = FF_RAMP;
public static final int FF_SQUARE = 0x58;
public static final int FF_TRIANGLE = 0x59;
public static final int FF_SINE = 0x5a;
public static final int FF_SAW_UP = 0x5b;
public static final int FF_SAW_DOWN = 0x5c;
public static final int FF_CUSTOM = 0x5d;
public static final int FF_WAVEFORM_MIN = FF_SQUARE;
public static final int FF_WAVEFORM_MAX = FF_CUSTOM;
public static final int FF_GAIN = 0x60;
public static final int FF_AUTOCENTER = 0x61;
public static final int FF_MAX = 0x7f;
public static final int FF_CNT = (FF_MAX+1);
public static final int USAGE_MOUSE = 0x00;
public static final int USAGE_JOYSTICK = 0x01;
public static final int USAGE_GAMEPAD = 0x02;
public static final int USAGE_KEYBOARD = 0x03;
public static final int USAGE_MAX = 0x0f;
}

View file

@ -1,477 +0,0 @@
/*
* 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<LinuxDevice> devices = new ArrayList<LinuxDevice>();
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<Void>) () -> {
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<String>)() -> System.getProperty(property));
}
static String getPrivilegedProperty(final String property, final String default_value) {
return AccessController.doPrivileged((PrivilegedAction<String>)() -> 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<Void>)() -> {
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<LinuxEventComponent> event_components, LinuxEventDevice device) {
LinuxEventComponent[][] povs = new LinuxEventComponent[4][2];
List<LinuxComponent> 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<LinuxEventComponent> 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<Controller> controllers = new ArrayList<>();
List<Controller> eventControllers = new ArrayList<>();
List<Controller> 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<AbstractComponent> 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<Controller> 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<String>) () -> file.getAbsolutePath());
}
private static File[] listFilesPrivileged(final File dir, final FilenameFilter filter) {
return AccessController.doPrivileged((PrivilegedAction<File[]>) () -> {
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<Controller> 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;
}
}

View file

@ -0,0 +1,54 @@
<?xml version="1.0"?>
<!-- Written to assume that classpath is rooted in the current directory. -->
<!-- So this should be OK if you make this script in the root of a filesystem. -->
<!-- If not, you may prefer to adjust the basedir, or move some directories around. -->
<!-- The idea is that both Ant and NetBeans have to know what the package root is -->
<!-- for the classes in your application. -->
<project name="JInput Linux port, Native code" basedir="." default="compileNativeJinputLib">
<property name="libname64" value="libjinput-linux64.so"/>
<property name="libname32" value="libjinput-linux.so"/>
<target name="createNativeDefinitions.java">
<exec dir="." executable="gawk" os="Linux" output="../java/net/java/games/input/NativeDefinitions.java">
<arg line="-f"/>
<arg line="getDefinitions"/>
<arg line="/usr/include/linux/input.h"/>
</exec>
</target>
<target name="clean">
<delete>
<fileset dir="." includes="*.o"/>
<fileset dir="." includes="*.so"/>
</delete>
</target>
<target name="compileNativeJinputLib">
<exec executable="uname" outputproperty="hwplatform">
<arg value="-m"/>
</exec>
<condition property="libname" value="${libname64}" else="${libname32}">
<equals arg1="${hwplatform}" arg2="x86_64"/>
</condition>
<apply dir="." executable="cc" os="Linux" dest="." skipemptyfilesets="true" failonerror="true">
<arg line="-O2 -Wall -c -fPIC"/>
<arg value="-I${java.home}/include"/>
<arg value="-I${java.home}/include/linux"/>
<arg value="-I${java.home}/../include"/>
<arg value="-I${java.home}/../include/linux"/>
<arg value="-I../../../common/src/native"/>
<mapper type="glob" from="*.c" to="*.o"/>
<fileset dir="." includes="*.c"/>
<fileset dir="../../../common/src/native" includes="*.c"/>
</apply>
<apply dir="." parallel="true" executable="cc" os="Linux" failonerror="true">
<arg line="-shared -O2 -Wall -o ${libname}"/>
<fileset dir="." includes="*.o"/>
</apply>
<apply dir="." parallel="true" executable="strip" os="Linux" failonerror="true">
<fileset file="${libname}"/>
</apply>
</target>
</project>

Some files were not shown because too many files have changed in this diff Show more