Add UHID_DESTROY control message

This message will be sent on gamepad disconnection.

Contrary to keyboard and mouse devices, which are registered once and
unregistered when scrcpy exists, each physical gamepad is mapped with
its own HID id, and they can be plugged and unplugged dynamically.

PR #5270 <https://github.com/Genymobile/scrcpy/pull/5270>
This commit is contained in:
Romain Vimont
2024-09-06 23:08:08 +02:00
parent 5fe884276b
commit 64a25f6e9d
6 changed files with 69 additions and 3 deletions

View File

@@ -21,7 +21,8 @@ public final class ControlMessage {
public static final int TYPE_ROTATE_DEVICE = 11;
public static final int TYPE_UHID_CREATE = 12;
public static final int TYPE_UHID_INPUT = 13;
public static final int TYPE_OPEN_HARD_KEYBOARD_SETTINGS = 14;
public static final int TYPE_UHID_DESTROY = 14;
public static final int TYPE_OPEN_HARD_KEYBOARD_SETTINGS = 15;
public static final long SEQUENCE_INVALID = 0;
@@ -146,6 +147,13 @@ public final class ControlMessage {
return msg;
}
public static ControlMessage createUhidDestroy(int id) {
ControlMessage msg = new ControlMessage();
msg.type = TYPE_UHID_DESTROY;
msg.id = id;
return msg;
}
public int getType() {
return type;
}

View File

@@ -51,6 +51,8 @@ public class ControlMessageReader {
return parseUhidCreate();
case ControlMessage.TYPE_UHID_INPUT:
return parseUhidInput();
case ControlMessage.TYPE_UHID_DESTROY:
return parseUhidDestroy();
default:
throw new ControlProtocolException("Unknown event type: " + type);
}
@@ -142,6 +144,11 @@ public class ControlMessageReader {
return ControlMessage.createUhidInput(id, data);
}
private ControlMessage parseUhidDestroy() throws IOException {
int id = dis.readUnsignedShort();
return ControlMessage.createUhidDestroy(id);
}
private Position parsePosition() throws IOException {
int x = dis.readInt();
int y = dis.readInt();