mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-06-17 06:11:36 +00:00
Optimize Evdev input by sending axis and controller events only after EV_SYN comes in. Implement support for vertical mouse scrolling.
This commit is contained in:
@@ -137,6 +137,7 @@ public class EvdevConstants {
|
|||||||
/* Mouse constants */
|
/* Mouse constants */
|
||||||
public static final short REL_X = 0x00;
|
public static final short REL_X = 0x00;
|
||||||
public static final short REL_Y = 0x01;
|
public static final short REL_Y = 0x01;
|
||||||
|
public static final short REL_WHEEL = 0x08;
|
||||||
|
|
||||||
public static final short BTN_LEFT = 0x110;
|
public static final short BTN_LEFT = 0x110;
|
||||||
public static final short BTN_RIGHT = 0x111;
|
public static final short BTN_RIGHT = 0x111;
|
||||||
@@ -174,6 +175,7 @@ public class EvdevConstants {
|
|||||||
public static final short BTN_DPAD_RIGHT = 0x223;
|
public static final short BTN_DPAD_RIGHT = 0x223;
|
||||||
|
|
||||||
/* Event types */
|
/* Event types */
|
||||||
|
public static final short EV_SYN = 0x00;
|
||||||
public static final short EV_KEY = 0x01;
|
public static final short EV_KEY = 0x01;
|
||||||
public static final short EV_REL = 0x02;
|
public static final short EV_REL = 0x02;
|
||||||
public static final short EV_ABS = 0x03;
|
public static final short EV_ABS = 0x03;
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ public class EvdevHandler extends EvdevReader {
|
|||||||
private short buttonFlags;
|
private short buttonFlags;
|
||||||
private byte leftTrigger, rightTrigger;
|
private byte leftTrigger, rightTrigger;
|
||||||
private short leftStickX, leftStickY, rightStickX, rightStickY;
|
private short leftStickX, leftStickY, rightStickX, rightStickY;
|
||||||
|
private boolean gamepadModified = false;
|
||||||
|
|
||||||
|
private short mouseDeltaX, mouseDeltaY;
|
||||||
|
private byte mouseScroll;
|
||||||
|
|
||||||
private EvdevAbsolute absLX, absLY, absRX, absRY, absLT, absRT, absDX, absDY;
|
private EvdevAbsolute absLX, absLY, absRX, absRY, absLT, absRT, absDX, absDY;
|
||||||
|
|
||||||
@@ -58,9 +62,22 @@ public class EvdevHandler extends EvdevReader {
|
|||||||
short type = buffer.getShort();
|
short type = buffer.getShort();
|
||||||
short code = buffer.getShort();
|
short code = buffer.getShort();
|
||||||
int value = buffer.getInt();
|
int value = buffer.getInt();
|
||||||
boolean mapped = true;
|
|
||||||
|
|
||||||
if (type==EvdevConstants.EV_KEY) {
|
if (type==EvdevConstants.EV_SYN) {
|
||||||
|
if (gamepadModified) {
|
||||||
|
conn.sendControllerInput(buttonFlags, leftTrigger, rightTrigger, leftStickX, leftStickY, rightStickX, rightStickY);
|
||||||
|
gamepadModified = false;
|
||||||
|
}
|
||||||
|
if (mouseDeltaX != 0 || mouseDeltaY != 0) {
|
||||||
|
conn.sendMouseMove(mouseDeltaX, mouseDeltaY);
|
||||||
|
mouseDeltaX = mouseDeltaY = 0;
|
||||||
|
}
|
||||||
|
if (mouseScroll != 0) {
|
||||||
|
conn.sendMouseScroll(mouseScroll);
|
||||||
|
mouseScroll = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type==EvdevConstants.EV_KEY) {
|
||||||
if (code<EvdevConstants.KEY_CODES.length) {
|
if (code<EvdevConstants.KEY_CODES.length) {
|
||||||
short gfCode = translator.translate(EvdevConstants.KEY_CODES[code]);
|
short gfCode = translator.translate(EvdevConstants.KEY_CODES[code]);
|
||||||
|
|
||||||
@@ -68,8 +85,6 @@ public class EvdevHandler extends EvdevReader {
|
|||||||
conn.sendKeyboardInput(gfCode, KeyboardPacket.KEY_DOWN, (byte) 0);
|
conn.sendKeyboardInput(gfCode, KeyboardPacket.KEY_DOWN, (byte) 0);
|
||||||
else if (value==EvdevConstants.KEY_RELEASED)
|
else if (value==EvdevConstants.KEY_RELEASED)
|
||||||
conn.sendKeyboardInput(gfCode, KeyboardPacket.KEY_UP, (byte) 0);
|
conn.sendKeyboardInput(gfCode, KeyboardPacket.KEY_UP, (byte) 0);
|
||||||
|
|
||||||
mapped = false;
|
|
||||||
} else {
|
} else {
|
||||||
byte mouseButton = 0;
|
byte mouseButton = 0;
|
||||||
short gamepadButton = 0;
|
short gamepadButton = 0;
|
||||||
@@ -115,8 +130,10 @@ public class EvdevHandler extends EvdevReader {
|
|||||||
if (value==EvdevConstants.KEY_PRESSED)
|
if (value==EvdevConstants.KEY_PRESSED)
|
||||||
conn.sendMouseButtonDown(mouseButton);
|
conn.sendMouseButtonDown(mouseButton);
|
||||||
else if (value==EvdevConstants.KEY_RELEASED)
|
else if (value==EvdevConstants.KEY_RELEASED)
|
||||||
conn.sendMouseButtonUp(mouseButton);
|
conn.sendMouseButtonUp(mouseButton);
|
||||||
} else {
|
} else {
|
||||||
|
gamepadModified = true;
|
||||||
|
|
||||||
if (gamepadButton != 0) {
|
if (gamepadButton != 0) {
|
||||||
if (value==EvdevConstants.KEY_PRESSED) {
|
if (value==EvdevConstants.KEY_PRESSED) {
|
||||||
buttonFlags |= gamepadButton;
|
buttonFlags |= gamepadButton;
|
||||||
@@ -128,17 +145,20 @@ public class EvdevHandler extends EvdevReader {
|
|||||||
} else if (code==mapping.btn_tr2) {
|
} else if (code==mapping.btn_tr2) {
|
||||||
rightTrigger = (byte) (value==EvdevConstants.KEY_PRESSED ? -1 : 0);
|
rightTrigger = (byte) (value==EvdevConstants.KEY_PRESSED ? -1 : 0);
|
||||||
} else
|
} else
|
||||||
mapped = false;
|
gamepadModified = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (type==EvdevConstants.EV_REL) {
|
} else if (type==EvdevConstants.EV_REL) {
|
||||||
if (code==EvdevConstants.REL_X)
|
if (code==EvdevConstants.REL_X)
|
||||||
conn.sendMouseMove((short) value, (short) 0);
|
mouseDeltaX = (short) value;
|
||||||
else if (code==EvdevConstants.REL_Y)
|
else if (code==EvdevConstants.REL_Y)
|
||||||
conn.sendMouseMove((short) 0, (short) value);
|
mouseDeltaY = (short) value;
|
||||||
|
else if (code==EvdevConstants.REL_WHEEL) {
|
||||||
mapped = false;
|
mouseScroll = (byte) value;
|
||||||
|
}
|
||||||
} else if (type==EvdevConstants.EV_ABS) {
|
} else if (type==EvdevConstants.EV_ABS) {
|
||||||
|
gamepadModified = true;
|
||||||
|
|
||||||
if (code==mapping.abs_x)
|
if (code==mapping.abs_x)
|
||||||
leftStickX = accountForDeadzone(absLX.getShort(value));
|
leftStickX = accountForDeadzone(absLX.getShort(value));
|
||||||
else if (code==mapping.abs_y)
|
else if (code==mapping.abs_y)
|
||||||
@@ -176,12 +196,8 @@ public class EvdevHandler extends EvdevReader {
|
|||||||
buttonFlags &= ~ControllerPacket.UP_FLAG;
|
buttonFlags &= ~ControllerPacket.UP_FLAG;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
mapped = false;
|
gamepadModified = false;
|
||||||
} else
|
}
|
||||||
mapped = false;
|
|
||||||
|
|
||||||
if (mapped)
|
|
||||||
conn.sendControllerInput(buttonFlags, leftTrigger, rightTrigger, leftStickX, leftStickY, rightStickX, rightStickY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private short accountForDeadzone(short value) {
|
private short accountForDeadzone(short value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user