mirror of
https://github.com/shadowfacts/jinput-arm64.git
synced 2026-04-05 06:25:47 +00:00
Implement the isSupported method and make plugins work again. There was an issue where accessing the static methods in DefaultControllerEnvironment and ControllerEnvironment would cause ploblems when the plugins were loaded using the PluginLoader class loader.
This commit is contained in:
parent
d6368e8dc5
commit
083eee58ee
18 changed files with 455 additions and 154 deletions
|
|
@ -21,12 +21,10 @@ public class WinTabContext {
|
|||
}
|
||||
|
||||
public synchronized void open() {
|
||||
ControllerEnvironment.logln("Opening context");
|
||||
this.hCTX = nOpen(window.getHwnd());
|
||||
List devices = new ArrayList();
|
||||
|
||||
int numSupportedDevices = nGetNumberOfSupportedDevices();
|
||||
ControllerEnvironment.logln(numSupportedDevices + " devices maximum supported");
|
||||
for(int i=0;i<numSupportedDevices;i++) {
|
||||
WinTabDevice newDevice = WinTabDevice.createDevice(this,i);
|
||||
if(newDevice!=null) {
|
||||
|
|
@ -38,26 +36,12 @@ public class WinTabContext {
|
|||
}
|
||||
|
||||
public synchronized void close() {
|
||||
ControllerEnvironment.logln("Closing context");
|
||||
nClose(hCTX);
|
||||
}
|
||||
|
||||
public synchronized void processEvents() {
|
||||
WinTabPacket[] packets = nGetPackets(hCTX);
|
||||
//ControllerEnvironment.logln("Packets read: " + packets.length);
|
||||
for(int i=0;i<packets.length;i++) {
|
||||
//ControllerEnvironment.logln("Packet time: " + packets[i].PK_TIME);
|
||||
//ControllerEnvironment.logln("Packet x: " + packets[i].PK_X);
|
||||
//ControllerEnvironment.logln("Packet y: " + packets[i].PK_Y);
|
||||
//ControllerEnvironment.logln("Packet z: " + packets[i].PK_Z);
|
||||
//ControllerEnvironment.logln("Packet buttons: " + packets[i].PK_BUTTONS);
|
||||
//ControllerEnvironment.logln("Packet cursor: " + packets[i].PK_CURSOR);
|
||||
//ControllerEnvironment.logln("Packet Normal Pressure: " + packets[i].PK_NORMAL_PRESSURE);
|
||||
//ControllerEnvironment.logln("Packet Tangent Pressure: " + packets[i].PK_TANGENT_PRESSURE);
|
||||
//ControllerEnvironment.logln("Packet Alt: " + packets[i].PK_ORIENTATION_ALT);
|
||||
//ControllerEnvironment.logln("Packet Az: " + packets[i].PK_ORIENTATION_AZ);
|
||||
//ControllerEnvironment.logln("Packet Twist: " + packets[i].PK_ORIENTATION_TWIST);
|
||||
|
||||
// TODO I can't seem to find a way to identify which device the packet is for
|
||||
// This is not good.
|
||||
// NASTY HACK based of assumptions that might very well be wrong
|
||||
|
|
|
|||
|
|
@ -50,73 +50,73 @@ public class WinTabDevice extends AbstractController {
|
|||
|
||||
public static WinTabDevice createDevice(WinTabContext context, int deviceIndex) {
|
||||
String name = nGetName(deviceIndex);
|
||||
ControllerEnvironment.logln("Device " + deviceIndex + ", name: " + name);
|
||||
WinTabEnvironmentPlugin.logln("Device " + deviceIndex + ", name: " + name);
|
||||
List componentsList = new ArrayList();
|
||||
|
||||
int[] axisDetails = nGetAxisDetails(deviceIndex, WinTabComponent.XAxis);
|
||||
if(axisDetails.length==0) {
|
||||
ControllerEnvironment.logln("ZAxis not supported");
|
||||
WinTabEnvironmentPlugin.logln("ZAxis not supported");
|
||||
} else {
|
||||
ControllerEnvironment.logln("Xmin: " + axisDetails[0] + ", Xmax: " + axisDetails[1]);
|
||||
WinTabEnvironmentPlugin.logln("Xmin: " + axisDetails[0] + ", Xmax: " + axisDetails[1]);
|
||||
componentsList.addAll(WinTabComponent.createComponents(context, deviceIndex, WinTabComponent.XAxis, axisDetails));
|
||||
}
|
||||
|
||||
axisDetails = nGetAxisDetails(deviceIndex, WinTabComponent.YAxis);
|
||||
if(axisDetails.length==0) {
|
||||
ControllerEnvironment.logln("YAxis not supported");
|
||||
WinTabEnvironmentPlugin.logln("YAxis not supported");
|
||||
} else {
|
||||
ControllerEnvironment.logln("Ymin: " + axisDetails[0] + ", Ymax: " + axisDetails[1]);
|
||||
WinTabEnvironmentPlugin.logln("Ymin: " + axisDetails[0] + ", Ymax: " + axisDetails[1]);
|
||||
componentsList.addAll(WinTabComponent.createComponents(context, deviceIndex, WinTabComponent.YAxis, axisDetails));
|
||||
}
|
||||
|
||||
axisDetails = nGetAxisDetails(deviceIndex, WinTabComponent.ZAxis);
|
||||
if(axisDetails.length==0) {
|
||||
ControllerEnvironment.logln("ZAxis not supported");
|
||||
WinTabEnvironmentPlugin.logln("ZAxis not supported");
|
||||
} else {
|
||||
ControllerEnvironment.logln("Zmin: " + axisDetails[0] + ", Zmax: " + axisDetails[1]);
|
||||
WinTabEnvironmentPlugin.logln("Zmin: " + axisDetails[0] + ", Zmax: " + axisDetails[1]);
|
||||
componentsList.addAll(WinTabComponent.createComponents(context, deviceIndex, WinTabComponent.ZAxis, axisDetails));
|
||||
}
|
||||
|
||||
axisDetails = nGetAxisDetails(deviceIndex, WinTabComponent.NPressureAxis);
|
||||
if(axisDetails.length==0) {
|
||||
ControllerEnvironment.logln("NPressureAxis not supported");
|
||||
WinTabEnvironmentPlugin.logln("NPressureAxis not supported");
|
||||
} else {
|
||||
ControllerEnvironment.logln("NPressMin: " + axisDetails[0] + ", NPressMax: " + axisDetails[1]);
|
||||
WinTabEnvironmentPlugin.logln("NPressMin: " + axisDetails[0] + ", NPressMax: " + axisDetails[1]);
|
||||
componentsList.addAll(WinTabComponent.createComponents(context, deviceIndex, WinTabComponent.NPressureAxis, axisDetails));
|
||||
}
|
||||
|
||||
axisDetails = nGetAxisDetails(deviceIndex, WinTabComponent.TPressureAxis);
|
||||
if(axisDetails.length==0) {
|
||||
ControllerEnvironment.logln("TPressureAxis not supported");
|
||||
WinTabEnvironmentPlugin.logln("TPressureAxis not supported");
|
||||
} else {
|
||||
ControllerEnvironment.logln("TPressureAxismin: " + axisDetails[0] + ", TPressureAxismax: " + axisDetails[1]);
|
||||
WinTabEnvironmentPlugin.logln("TPressureAxismin: " + axisDetails[0] + ", TPressureAxismax: " + axisDetails[1]);
|
||||
componentsList.addAll(WinTabComponent.createComponents(context, deviceIndex, WinTabComponent.TPressureAxis, axisDetails));
|
||||
}
|
||||
|
||||
axisDetails = nGetAxisDetails(deviceIndex, WinTabComponent.OrientationAxis);
|
||||
if(axisDetails.length==0) {
|
||||
ControllerEnvironment.logln("OrientationAxis not supported");
|
||||
WinTabEnvironmentPlugin.logln("OrientationAxis not supported");
|
||||
} else {
|
||||
ControllerEnvironment.logln("OrientationAxis mins/maxs: " + axisDetails[0] + "," + axisDetails[1] + ", " + axisDetails[2] + "," + axisDetails[3] + ", " + axisDetails[4] + "," + axisDetails[5]);
|
||||
WinTabEnvironmentPlugin.logln("OrientationAxis mins/maxs: " + axisDetails[0] + "," + axisDetails[1] + ", " + axisDetails[2] + "," + axisDetails[3] + ", " + axisDetails[4] + "," + axisDetails[5]);
|
||||
componentsList.addAll(WinTabComponent.createComponents(context, deviceIndex, WinTabComponent.OrientationAxis, axisDetails));
|
||||
}
|
||||
|
||||
axisDetails = nGetAxisDetails(deviceIndex, WinTabComponent.RotationAxis);
|
||||
if(axisDetails.length==0) {
|
||||
ControllerEnvironment.logln("RotationAxis not supported");
|
||||
WinTabEnvironmentPlugin.logln("RotationAxis not supported");
|
||||
} else {
|
||||
ControllerEnvironment.logln("RotationAxis is supported (by the device, not by this plugin)");
|
||||
WinTabEnvironmentPlugin.logln("RotationAxis is supported (by the device, not by this plugin)");
|
||||
componentsList.addAll(WinTabComponent.createComponents(context, deviceIndex, WinTabComponent.RotationAxis, axisDetails));
|
||||
}
|
||||
|
||||
String[] cursorNames = nGetCursorNames(deviceIndex);
|
||||
componentsList.addAll(WinTabComponent.createCursors(context, deviceIndex, cursorNames));
|
||||
for(int i=0;i<cursorNames.length;i++) {
|
||||
ControllerEnvironment.logln("Cursor " + i + "'s name: " + cursorNames[i]);
|
||||
WinTabEnvironmentPlugin.logln("Cursor " + i + "'s name: " + cursorNames[i]);
|
||||
}
|
||||
|
||||
int numberOfButtons = nGetMaxButtonCount(deviceIndex);
|
||||
ControllerEnvironment.logln("Device has " + numberOfButtons + " buttons");
|
||||
WinTabEnvironmentPlugin.logln("Device has " + numberOfButtons + " buttons");
|
||||
componentsList.addAll(WinTabComponent.createButtons(context, deviceIndex, numberOfButtons));
|
||||
|
||||
Component[] components = (Component[])componentsList.toArray(new Component[0]);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package net.java.games.input;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
|
@ -9,8 +10,52 @@ import java.util.List;
|
|||
import net.java.games.util.plugins.Plugin;
|
||||
|
||||
public class WinTabEnvironmentPlugin extends ControllerEnvironment implements Plugin {
|
||||
static {
|
||||
DefaultControllerEnvironment.loadLibrary("jinput-wintab");
|
||||
private static boolean supported = false;
|
||||
|
||||
/**
|
||||
* Static utility method for loading native libraries.
|
||||
* It will try to load from either the path given by
|
||||
* the net.java.games.input.librarypath property
|
||||
* or through System.loadLibrary().
|
||||
*
|
||||
*/
|
||||
static void loadLibrary(final String lib_name) {
|
||||
AccessController.doPrivileged(
|
||||
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.startsWith("Windows")) {
|
||||
supported = true;
|
||||
loadLibrary("jinput-wintab");
|
||||
}
|
||||
}
|
||||
|
||||
private final Controller[] controllers;
|
||||
|
|
@ -20,35 +65,45 @@ public class WinTabEnvironmentPlugin extends ControllerEnvironment implements Pl
|
|||
|
||||
/** Creates new DirectInputEnvironment */
|
||||
public WinTabEnvironmentPlugin() {
|
||||
DummyWindow window = null;
|
||||
WinTabContext winTabContext = null;
|
||||
Controller[] controllers = new Controller[]{};
|
||||
try {
|
||||
window = new DummyWindow();
|
||||
winTabContext = new WinTabContext(window);
|
||||
if(isSupported()) {
|
||||
DummyWindow window = null;
|
||||
WinTabContext winTabContext = null;
|
||||
Controller[] controllers = new Controller[]{};
|
||||
try {
|
||||
winTabContext.open();
|
||||
controllers = winTabContext.getControllers();
|
||||
window = new DummyWindow();
|
||||
winTabContext = new WinTabContext(window);
|
||||
try {
|
||||
winTabContext.open();
|
||||
controllers = winTabContext.getControllers();
|
||||
} catch (Exception e) {
|
||||
window.destroy();
|
||||
throw e;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
window.destroy();
|
||||
throw e;
|
||||
logln("Failed to enumerate devices: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ControllerEnvironment.logln("Failed to enumerate devices: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
this.window = window;
|
||||
this.controllers = controllers;
|
||||
this.winTabContext = winTabContext;
|
||||
AccessController.doPrivileged(
|
||||
new PrivilegedAction() {
|
||||
public final Object run() {
|
||||
Runtime.getRuntime().addShutdownHook(new ShutdownHook());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
winTabContext = null;
|
||||
controllers = new Controller[]{};
|
||||
window = null;
|
||||
}
|
||||
this.window = window;
|
||||
this.controllers = controllers;
|
||||
this.winTabContext = winTabContext;
|
||||
AccessController.doPrivileged(
|
||||
new PrivilegedAction() {
|
||||
public final Object run() {
|
||||
Runtime.getRuntime().addShutdownHook(new ShutdownHook());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isSupported() {
|
||||
return supported;
|
||||
}
|
||||
|
||||
public Controller[] getControllers() {
|
||||
return controllers;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue