diff --git a/build/built-jar.properties b/build/built-jar.properties index 7e13819..a2afdd5 100644 --- a/build/built-jar.properties +++ b/build/built-jar.properties @@ -1,4 +1,4 @@ -#Wed, 08 Jun 2022 20:04:54 +0000 +#Wed, 08 Jun 2022 21:14:18 -0500 -/workspace/jinput2.10= +/home/niconiconii/Documents/jinput2.10= diff --git a/build/classes/net/java/games/input/LinuxEnvironmentPlugin$1.class b/build/classes/net/java/games/input/LinuxEnvironmentPlugin$1.class index 1f5cb1b..ba1cd00 100644 Binary files a/build/classes/net/java/games/input/LinuxEnvironmentPlugin$1.class and b/build/classes/net/java/games/input/LinuxEnvironmentPlugin$1.class differ diff --git a/build/classes/net/java/games/input/LinuxEnvironmentPlugin$ShutdownHook.class b/build/classes/net/java/games/input/LinuxEnvironmentPlugin$ShutdownHook.class index f2fba2a..2766221 100644 Binary files a/build/classes/net/java/games/input/LinuxEnvironmentPlugin$ShutdownHook.class and b/build/classes/net/java/games/input/LinuxEnvironmentPlugin$ShutdownHook.class differ diff --git a/build/classes/net/java/games/input/LinuxEnvironmentPlugin.class b/build/classes/net/java/games/input/LinuxEnvironmentPlugin.class index 851dffe..1c3eb18 100644 Binary files a/build/classes/net/java/games/input/LinuxEnvironmentPlugin.class and b/build/classes/net/java/games/input/LinuxEnvironmentPlugin.class differ diff --git a/build/classes/net/java/games/input/LinuxEventDevice.class b/build/classes/net/java/games/input/LinuxEventDevice.class index 2071e51..bc2f777 100644 Binary files a/build/classes/net/java/games/input/LinuxEventDevice.class and b/build/classes/net/java/games/input/LinuxEventDevice.class differ diff --git a/build/classes/net/java/games/input/LinuxJoystickDevice.class b/build/classes/net/java/games/input/LinuxJoystickDevice.class index 436f8c6..df7b1d8 100644 Binary files a/build/classes/net/java/games/input/LinuxJoystickDevice.class and b/build/classes/net/java/games/input/LinuxJoystickDevice.class differ diff --git a/dist/jinput-with-sources.jar b/dist/jinput-with-sources.jar index df3efa1..2fa2a4e 100644 Binary files a/dist/jinput-with-sources.jar and b/dist/jinput-with-sources.jar differ diff --git a/dist/jinput.jar b/dist/jinput.jar index b45e1cd..686a891 100644 Binary files a/dist/jinput.jar and b/dist/jinput.jar differ diff --git a/src/plugins/linux/net/java/games/input/LinuxEnvironmentPlugin.java b/src/plugins/linux/net/java/games/input/LinuxEnvironmentPlugin.java index d015663..c6e7ffe 100644 --- a/src/plugins/linux/net/java/games/input/LinuxEnvironmentPlugin.java +++ b/src/plugins/linux/net/java/games/input/LinuxEnvironmentPlugin.java @@ -47,7 +47,8 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen private static boolean supported = false; private final Controller[] controllers; - private final List devices = new ArrayList(); + private final List joystickDevices = new ArrayList<>(); + private final List eventDevices = new ArrayList<>(); private final static LinuxDeviceThread device_thread = new LinuxDeviceThread(); /** @@ -122,7 +123,9 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen } public final Controller[] rescanControllers() { - return enumerateControllers(); + Controller[] newControllers = enumerateControllers(); + log("Linux plugin claims to have found " + newControllers.length + " controllers"); + return newControllers; } private final static Component[] createComponents(List event_components, LinuxEventDevice device) { @@ -232,15 +235,19 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen // compare // Check if the nodes have the same name if(evController.getName().equals(jsController.getName())) { + System.out.println("Same names. "+jsController.getName()); // Check they have the same component count Component[] evComponents = evController.getComponents(); Component[] jsComponents = jsController.getComponents(); if(evComponents.length == jsComponents.length) { + System.out.println("Same component count."+evComponents.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())) { + + System.out.println("Differing components: "+evComponents[k].getIdentifier()+"//"+jsComponents[k].getIdentifier()); foundADifference = true; } } @@ -395,13 +402,24 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen File event_file = joystick_device_files[i]; try { String path = getAbsolutePathPrivileged(event_file); - LinuxJoystickDevice device = new LinuxJoystickDevice(path); + LinuxJoystickDevice device; + if (joystickDevices.size()>i) { + device=joystickDevices.get(i); + if (device==null) { + device = new LinuxJoystickDevice(path); + joystickDevices.set(i,device); + } + } else { + device = new LinuxJoystickDevice(path); + joystickDevices.add(device); + } Controller controller = createJoystickFromJoystickDevice(device); if(controller != null) { controllers.add(controller); - devices.add(device); - } else + } else { device.close(); + joystickDevices.set(i,null); + } } catch(IOException e) { log("Failed to open device (" + event_file + "): " + e.getMessage()); } @@ -444,14 +462,26 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen File event_file = event_device_files[i]; try { String path = getAbsolutePathPrivileged(event_file); - LinuxEventDevice device = new LinuxEventDevice(path); + LinuxEventDevice device; + //System.out.println(event_file+":"+i); + if (eventDevices.size()>i) { + device=eventDevices.get(i); + if (device==null) { + device = new LinuxEventDevice(path); + eventDevices.set(i,device); + } + } else { + device = new LinuxEventDevice(path); + eventDevices.add(device); + } try { Controller controller = createControllerFromDevice(device); if(controller != null) { controllers.add(controller); - devices.add(device); - } else + } else { device.close(); + eventDevices.set(i,null); + } } catch(IOException e) { log("Failed to create Controller: " + e.getMessage()); device.close(); @@ -464,9 +494,17 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen private final class ShutdownHook extends Thread { public final void run() { - for(int i = 0; i < devices.size(); i++) { + for(int i = 0; i < eventDevices.size(); i++) { + try { + LinuxEventDevice device = eventDevices.get(i); + device.close(); + } catch(IOException e) { + log("Failed to close device: " + e.getMessage()); + } + } + for(int i = 0; i < joystickDevices.size(); i++) { try { - LinuxDevice device = devices.get(i); + LinuxJoystickDevice device = joystickDevices.get(i); device.close(); } catch(IOException e) { log("Failed to close device: " + e.getMessage()); diff --git a/src/plugins/linux/net/java/games/input/LinuxEventDevice.java b/src/plugins/linux/net/java/games/input/LinuxEventDevice.java index a69f9e8..bd09ffc 100644 --- a/src/plugins/linux/net/java/games/input/LinuxEventDevice.java +++ b/src/plugins/linux/net/java/games/input/LinuxEventDevice.java @@ -364,4 +364,8 @@ final class LinuxEventDevice implements LinuxDevice { protected void finalize() throws IOException { close(); } + @Override + public boolean equals(Object obj) { + return obj instanceof LinuxEventDevice&&((LinuxEventDevice)obj).getName().equals(getName()); + } } diff --git a/src/plugins/linux/net/java/games/input/LinuxJoystickDevice.java b/src/plugins/linux/net/java/games/input/LinuxJoystickDevice.java index c749684..1525706 100644 --- a/src/plugins/linux/net/java/games/input/LinuxJoystickDevice.java +++ b/src/plugins/linux/net/java/games/input/LinuxJoystickDevice.java @@ -235,4 +235,13 @@ final class LinuxJoystickDevice implements LinuxDevice { protected void finalize() throws IOException { close(); } + @Override + public boolean equals(Object obj) { + try { + return obj instanceof LinuxJoystickDevice&&((LinuxJoystickDevice)obj).getDeviceName().equals(getDeviceName()); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } }