mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-04-22 08:20:12 +00:00
Use the device vibrator for devices with built-in gamepads
This commit is contained in:
@@ -111,6 +111,7 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
|||||||
private final InputDeviceContext defaultContext = new InputDeviceContext();
|
private final InputDeviceContext defaultContext = new InputDeviceContext();
|
||||||
private final GameGestures gestures;
|
private final GameGestures gestures;
|
||||||
private final Vibrator deviceVibrator;
|
private final Vibrator deviceVibrator;
|
||||||
|
private final VibratorManager deviceVibratorManager;
|
||||||
private final SceManager sceManager;
|
private final SceManager sceManager;
|
||||||
private final Handler handler;
|
private final Handler handler;
|
||||||
private boolean hasGameController;
|
private boolean hasGameController;
|
||||||
@@ -126,6 +127,13 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
|||||||
this.deviceVibrator = (Vibrator) activityContext.getSystemService(Context.VIBRATOR_SERVICE);
|
this.deviceVibrator = (Vibrator) activityContext.getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
this.handler = new Handler(Looper.getMainLooper());
|
this.handler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
this.deviceVibratorManager = (VibratorManager) activityContext.getSystemService(Context.VIBRATOR_MANAGER_SERVICE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.deviceVibratorManager = null;
|
||||||
|
}
|
||||||
|
|
||||||
this.sceManager = new SceManager(activityContext);
|
this.sceManager = new SceManager(activityContext);
|
||||||
this.sceManager.start();
|
this.sceManager.start();
|
||||||
|
|
||||||
@@ -613,6 +621,7 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
|||||||
context.hasShare = MoonBridge.guessControllerHasShareButton(context.vendorId, context.productId);
|
context.hasShare = MoonBridge.guessControllerHasShareButton(context.vendorId, context.productId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to use the InputDevice's associated vibrators first
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && hasQuadAmplitudeControlledRumbleVibrators(dev.getVibratorManager())) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && hasQuadAmplitudeControlledRumbleVibrators(dev.getVibratorManager())) {
|
||||||
context.vibratorManager = dev.getVibratorManager();
|
context.vibratorManager = dev.getVibratorManager();
|
||||||
context.quadVibrators = true;
|
context.quadVibrators = true;
|
||||||
@@ -624,6 +633,20 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
|||||||
else if (dev.getVibrator().hasVibrator()) {
|
else if (dev.getVibrator().hasVibrator()) {
|
||||||
context.vibrator = dev.getVibrator();
|
context.vibrator = dev.getVibrator();
|
||||||
}
|
}
|
||||||
|
else if (!context.external) {
|
||||||
|
// If this is an internal controller, try to use the device's vibrator
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && hasQuadAmplitudeControlledRumbleVibrators(deviceVibratorManager)) {
|
||||||
|
context.vibratorManager = deviceVibratorManager;
|
||||||
|
context.quadVibrators = true;
|
||||||
|
}
|
||||||
|
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && hasDualAmplitudeControlledRumbleVibrators(deviceVibratorManager)) {
|
||||||
|
context.vibratorManager = deviceVibratorManager;
|
||||||
|
context.quadVibrators = false;
|
||||||
|
}
|
||||||
|
else if (deviceVibrator.hasVibrator()) {
|
||||||
|
context.vibrator = deviceVibrator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Detect if the gamepad has Mode and Select buttons according to the Android key layouts.
|
// Detect if the gamepad has Mode and Select buttons according to the Android key layouts.
|
||||||
// We do this first because other codepaths below may override these defaults.
|
// We do this first because other codepaths below may override these defaults.
|
||||||
@@ -2790,10 +2813,10 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
|||||||
|
|
||||||
// Most of the advanced InputDevice capabilities came in Android S
|
// Most of the advanced InputDevice capabilities came in Android S
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
if (hasQuadAmplitudeControlledRumbleVibrators(inputDevice.getVibratorManager())) {
|
if (quadVibrators) {
|
||||||
capabilities |= MoonBridge.LI_CCAP_RUMBLE | MoonBridge.LI_CCAP_TRIGGER_RUMBLE;
|
capabilities |= MoonBridge.LI_CCAP_RUMBLE | MoonBridge.LI_CCAP_TRIGGER_RUMBLE;
|
||||||
}
|
}
|
||||||
else if (hasDualAmplitudeControlledRumbleVibrators(inputDevice.getVibratorManager())) {
|
else if (vibratorManager != null || vibrator != null) {
|
||||||
capabilities |= MoonBridge.LI_CCAP_RUMBLE;
|
capabilities |= MoonBridge.LI_CCAP_RUMBLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user