mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-02-16 10:30:47 +00:00
-new controller listener to be a singleton thread that listens for controller input even when not streaming, then sends input when streaming.\ -main frame will stop controller listener when closing -gamepads should now use the gamepad config settings (WIP)
65 lines
1.3 KiB
Java
65 lines
1.3 KiB
Java
package com.limelight.input;
|
|
|
|
|
|
import java.util.Collections;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
import com.limelight.nvstream.NvConnection;
|
|
|
|
import net.java.games.input.Controller;
|
|
|
|
public class GamepadHandler {
|
|
private static LinkedList<Gamepad> gamepads = new LinkedList<Gamepad>();
|
|
private static NvConnection conn;
|
|
private static Thread handler;
|
|
|
|
public static void addGamepads(List<Controller> pads) {
|
|
|
|
gamepads.clear();
|
|
|
|
for (Controller pad : pads) {
|
|
|
|
gamepads.add(new Gamepad(pad, null)); //TODO: need to create/get the settings for this controller
|
|
}
|
|
}
|
|
|
|
public static void setConnection(NvConnection connection) {
|
|
conn = connection;
|
|
}
|
|
|
|
public static List<Gamepad> getGamepads() {
|
|
return Collections.unmodifiableList(gamepads);
|
|
}
|
|
|
|
public static void startUp() {
|
|
if (handler == null || !handler.isAlive()) {
|
|
handler = new Thread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
while (true) {
|
|
for (Gamepad gamepad : gamepads) {
|
|
if (!gamepad.poll()) {
|
|
break;
|
|
}
|
|
gamepad.handleEvents(conn);
|
|
}
|
|
try {
|
|
Thread.sleep(20);
|
|
} catch (InterruptedException e) {}
|
|
}
|
|
}
|
|
});
|
|
handler.start();
|
|
}
|
|
}
|
|
|
|
public static void stopHandler() {
|
|
if (handler != null && handler.isAlive()) {
|
|
handler.interrupt();
|
|
conn = null;
|
|
}
|
|
}
|
|
|
|
}
|