mirror of
https://github.com/shadowfacts/jinput-arm64.git
synced 2025-12-06 08:01:59 +01:00
Fixed compile warnings
This commit is contained in:
parent
db8c6804b4
commit
0cfd2ae7cd
|
|
@ -47,7 +47,7 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
|
||||||
private static boolean supported = false;
|
private static boolean supported = false;
|
||||||
|
|
||||||
private final Controller[] controllers;
|
private final Controller[] controllers;
|
||||||
private final List devices = new ArrayList();
|
private final List<LinuxDevice> devices = new ArrayList<LinuxDevice>();
|
||||||
private final static LinuxDeviceThread device_thread = new LinuxDeviceThread();
|
private final static LinuxDeviceThread device_thread = new LinuxDeviceThread();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -58,9 +58,7 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static void loadLibrary(final String lib_name) {
|
static void loadLibrary(final String lib_name) {
|
||||||
AccessController.doPrivileged(
|
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
|
||||||
new PrivilegedAction() {
|
|
||||||
public final Object run() {
|
|
||||||
String lib_path = System.getProperty("net.java.games.input.librarypath");
|
String lib_path = System.getProperty("net.java.games.input.librarypath");
|
||||||
try {
|
try {
|
||||||
if(lib_path != null)
|
if(lib_path != null)
|
||||||
|
|
@ -73,25 +71,16 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
|
||||||
supported = false;
|
supported = false;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getPrivilegedProperty(final String property) {
|
static String getPrivilegedProperty(final String property) {
|
||||||
return (String) AccessController.doPrivileged(new PrivilegedAction() {
|
return AccessController.doPrivileged((PrivilegedAction<String>)() -> System.getProperty(property));
|
||||||
public Object run() {
|
|
||||||
return System.getProperty(property);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static String getPrivilegedProperty(final String property, final String default_value) {
|
static String getPrivilegedProperty(final String property, final String default_value) {
|
||||||
return (String) AccessController.doPrivileged(new PrivilegedAction() {
|
return AccessController.doPrivileged((PrivilegedAction<String>)() -> System.getProperty(property, default_value));
|
||||||
public Object run() {
|
|
||||||
return System.getProperty(property, default_value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
@ -114,12 +103,9 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
|
||||||
if(isSupported()) {
|
if(isSupported()) {
|
||||||
this.controllers = enumerateControllers();
|
this.controllers = enumerateControllers();
|
||||||
log("Linux plugin claims to have found " + controllers.length + " controllers");
|
log("Linux plugin claims to have found " + controllers.length + " controllers");
|
||||||
AccessController.doPrivileged(
|
AccessController.doPrivileged((PrivilegedAction<Void>)() -> {
|
||||||
new PrivilegedAction() {
|
|
||||||
public final Object run() {
|
|
||||||
Runtime.getRuntime().addShutdownHook(new ShutdownHook());
|
Runtime.getRuntime().addShutdownHook(new ShutdownHook());
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
controllers = new Controller[0];
|
controllers = new Controller[0];
|
||||||
|
|
@ -135,11 +121,11 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Component[] createComponents(List event_components, LinuxEventDevice device) {
|
private final static Component[] createComponents(List<LinuxEventComponent> event_components, LinuxEventDevice device) {
|
||||||
LinuxEventComponent[][] povs = new LinuxEventComponent[4][2];
|
LinuxEventComponent[][] povs = new LinuxEventComponent[4][2];
|
||||||
List components = new ArrayList();
|
List<LinuxComponent> components = new ArrayList<>();
|
||||||
for(int i = 0; i < event_components.size(); i++) {
|
for(int i = 0; i < event_components.size(); i++) {
|
||||||
LinuxEventComponent event_component = (LinuxEventComponent) event_components.get(i);
|
LinuxEventComponent event_component = event_components.get(i);
|
||||||
Component.Identifier identifier = event_component.getIdentifier();
|
Component.Identifier identifier = event_component.getIdentifier();
|
||||||
|
|
||||||
if(identifier == Component.Identifier.Axis.POV) {
|
if(identifier == Component.Identifier.Axis.POV) {
|
||||||
|
|
@ -213,7 +199,7 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Controller createControllerFromDevice(LinuxEventDevice device) throws IOException {
|
private final static Controller createControllerFromDevice(LinuxEventDevice device) throws IOException {
|
||||||
List event_components = device.getComponents();
|
List<LinuxEventComponent> event_components = device.getComponents();
|
||||||
Component[] components = createComponents(event_components, device);
|
Component[] components = createComponents(event_components, device);
|
||||||
Controller.Type type = device.getType();
|
Controller.Type type = device.getType();
|
||||||
|
|
||||||
|
|
@ -228,16 +214,16 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Controller[] enumerateControllers() {
|
private final Controller[] enumerateControllers() {
|
||||||
List controllers = new ArrayList();
|
List<Controller> controllers = new ArrayList<>();
|
||||||
List eventControllers = new ArrayList();
|
List<Controller> eventControllers = new ArrayList<>();
|
||||||
List jsControllers = new ArrayList();
|
List<Controller> jsControllers = new ArrayList<>();
|
||||||
enumerateEventControllers(eventControllers);
|
enumerateEventControllers(eventControllers);
|
||||||
enumerateJoystickControllers(jsControllers);
|
enumerateJoystickControllers(jsControllers);
|
||||||
|
|
||||||
for(int i = 0; i < eventControllers.size(); i++) {
|
for(int i = 0; i < eventControllers.size(); i++) {
|
||||||
for(int j = 0; j < jsControllers.size(); j++) {
|
for(int j = 0; j < jsControllers.size(); j++) {
|
||||||
Controller evController = (Controller) eventControllers.get(i);
|
Controller evController = eventControllers.get(i);
|
||||||
Controller jsController = (Controller) jsControllers.get(j);
|
Controller jsController = jsControllers.get(j);
|
||||||
|
|
||||||
// compare
|
// compare
|
||||||
// Check if the nodes have the same name
|
// Check if the nodes have the same name
|
||||||
|
|
@ -345,13 +331,13 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Controller createJoystickFromJoystickDevice(LinuxJoystickDevice device) {
|
private final static Controller createJoystickFromJoystickDevice(LinuxJoystickDevice device) {
|
||||||
List components = new ArrayList();
|
List<AbstractComponent> components = new ArrayList<>();
|
||||||
byte[] axisMap = device.getAxisMap();
|
byte[] axisMap = device.getAxisMap();
|
||||||
char[] buttonMap = device.getButtonMap();
|
char[] buttonMap = device.getButtonMap();
|
||||||
LinuxJoystickAxis[] hatBits = new LinuxJoystickAxis[6];
|
LinuxJoystickAxis[] hatBits = new LinuxJoystickAxis[6];
|
||||||
|
|
||||||
for(int i = 0; i < device.getNumButtons(); i++) {
|
for(int i = 0; i < device.getNumButtons(); i++) {
|
||||||
Component.Identifier button_id = (Component.Identifier) LinuxNativeTypesMap.getButtonID(buttonMap[i]);
|
Component.Identifier button_id = LinuxNativeTypesMap.getButtonID(buttonMap[i]);
|
||||||
if(button_id != null) {
|
if(button_id != null) {
|
||||||
LinuxJoystickButton button = new LinuxJoystickButton(button_id);
|
LinuxJoystickButton button = new LinuxJoystickButton(button_id);
|
||||||
device.registerButton(i, button);
|
device.registerButton(i, button);
|
||||||
|
|
@ -391,10 +377,10 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new LinuxJoystickAbstractController(device, (Component[]) components.toArray(new Component[]{}), new Controller[]{}, new Rumbler[]{});
|
return new LinuxJoystickAbstractController(device, components.toArray(new Component[]{}), new Controller[]{}, new Rumbler[]{});
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void enumerateJoystickControllers(List controllers) {
|
private final void enumerateJoystickControllers(List<Controller> controllers) {
|
||||||
File[] joystick_device_files = enumerateJoystickDeviceFiles("/dev/input");
|
File[] joystick_device_files = enumerateJoystickDeviceFiles("/dev/input");
|
||||||
if(joystick_device_files == null || joystick_device_files.length == 0) {
|
if(joystick_device_files == null || joystick_device_files.length == 0) {
|
||||||
joystick_device_files = enumerateJoystickDeviceFiles("/dev");
|
joystick_device_files = enumerateJoystickDeviceFiles("/dev");
|
||||||
|
|
@ -428,39 +414,26 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getAbsolutePathPrivileged(final File file) {
|
private static String getAbsolutePathPrivileged(final File file) {
|
||||||
return (String) AccessController.doPrivileged(new PrivilegedAction() {
|
return AccessController.doPrivileged((PrivilegedAction<String>) () -> file.getAbsolutePath());
|
||||||
public Object run() {
|
|
||||||
return file.getAbsolutePath();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File[] listFilesPrivileged(final File dir, final FilenameFilter filter) {
|
private static File[] listFilesPrivileged(final File dir, final FilenameFilter filter) {
|
||||||
return (File[]) AccessController.doPrivileged(new PrivilegedAction() {
|
return AccessController.doPrivileged((PrivilegedAction<File[]>) () -> {
|
||||||
public Object run() {
|
|
||||||
File[] files = dir.listFiles(filter);
|
File[] files = dir.listFiles(filter);
|
||||||
if(files == null) {
|
if(files == null) {
|
||||||
log("dir " + dir.getName() + " exists: " + dir.exists() + ", is writable: " + dir.isDirectory());
|
log("dir " + dir.getName() + " exists: " + dir.exists() + ", is writable: " + dir.isDirectory());
|
||||||
files = new File[]{};
|
files = new File[]{};
|
||||||
} else {
|
} else {
|
||||||
Arrays.sort(files, new Comparator() {
|
Arrays.sort(files, Comparator.comparing(File::getName));
|
||||||
public int compare(Object f1, Object f2) {
|
|
||||||
return ((File) f1).getName().compareTo(((File) f2).getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return files;
|
return files;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void enumerateEventControllers(List controllers) {
|
private final void enumerateEventControllers(List<Controller> controllers) {
|
||||||
final File dev = new File("/dev/input");
|
final File dev = new File("/dev/input");
|
||||||
File[] event_device_files = listFilesPrivileged(dev, new FilenameFilter() {
|
File[] event_device_files = listFilesPrivileged(dev, (File dir, String name) -> name.startsWith("event"));
|
||||||
public final boolean accept(File dir, String name) {
|
|
||||||
return name.startsWith("event");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if(event_device_files == null)
|
if(event_device_files == null)
|
||||||
return;
|
return;
|
||||||
for(int i = 0; i < event_device_files.length; i++) {
|
for(int i = 0; i < event_device_files.length; i++) {
|
||||||
|
|
@ -489,7 +462,7 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
|
||||||
public final void run() {
|
public final void run() {
|
||||||
for(int i = 0; i < devices.size(); i++) {
|
for(int i = 0; i < devices.size(); i++) {
|
||||||
try {
|
try {
|
||||||
LinuxDevice device = (LinuxDevice) devices.get(i);
|
LinuxDevice device = devices.get(i);
|
||||||
device.close();
|
device.close();
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
log("Failed to close device: " + e.getMessage());
|
log("Failed to close device: " + e.getMessage());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue