Make the device acknowledge device clipboard
If the client provided a sequence number on SET_CLIPBOARD request, make the device send back an acknowledgement once the clipboard is set. PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
This commit is contained in:
parent
2a0730ee9b
commit
41abe021e2
4 changed files with 30 additions and 3 deletions
|
@ -18,6 +18,8 @@ public final class ControlMessage {
|
||||||
public static final int TYPE_SET_SCREEN_POWER_MODE = 10;
|
public static final int TYPE_SET_SCREEN_POWER_MODE = 10;
|
||||||
public static final int TYPE_ROTATE_DEVICE = 11;
|
public static final int TYPE_ROTATE_DEVICE = 11;
|
||||||
|
|
||||||
|
public static final long SEQUENCE_INVALID = 0;
|
||||||
|
|
||||||
private int type;
|
private int type;
|
||||||
private String text;
|
private String text;
|
||||||
private int metaState; // KeyEvent.META_*
|
private int metaState; // KeyEvent.META_*
|
||||||
|
|
|
@ -120,7 +120,12 @@ public class Controller {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ControlMessage.TYPE_SET_CLIPBOARD:
|
case ControlMessage.TYPE_SET_CLIPBOARD:
|
||||||
|
long sequence = msg.getSequence();
|
||||||
setClipboard(msg.getText(), msg.getPaste());
|
setClipboard(msg.getText(), msg.getPaste());
|
||||||
|
if (sequence != ControlMessage.SEQUENCE_INVALID) {
|
||||||
|
// Acknowledgement requested
|
||||||
|
sender.pushAckClipboard(sequence);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ControlMessage.TYPE_SET_SCREEN_POWER_MODE:
|
case ControlMessage.TYPE_SET_SCREEN_POWER_MODE:
|
||||||
if (device.supportsInputEvents()) {
|
if (device.supportsInputEvents()) {
|
||||||
|
|
|
@ -5,6 +5,8 @@ public final class DeviceMessage {
|
||||||
public static final int TYPE_CLIPBOARD = 0;
|
public static final int TYPE_CLIPBOARD = 0;
|
||||||
public static final int TYPE_ACK_CLIPBOARD = 1;
|
public static final int TYPE_ACK_CLIPBOARD = 1;
|
||||||
|
|
||||||
|
public static final long SEQUENCE_INVALID = ControlMessage.SEQUENCE_INVALID;
|
||||||
|
|
||||||
private int type;
|
private int type;
|
||||||
private String text;
|
private String text;
|
||||||
private long sequence;
|
private long sequence;
|
||||||
|
|
|
@ -8,6 +8,8 @@ public final class DeviceMessageSender {
|
||||||
|
|
||||||
private String clipboardText;
|
private String clipboardText;
|
||||||
|
|
||||||
|
private long ack;
|
||||||
|
|
||||||
public DeviceMessageSender(DesktopConnection connection) {
|
public DeviceMessageSender(DesktopConnection connection) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
@ -17,18 +19,34 @@ public final class DeviceMessageSender {
|
||||||
notify();
|
notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void pushAckClipboard(long sequence) {
|
||||||
|
ack = sequence;
|
||||||
|
notify();
|
||||||
|
}
|
||||||
|
|
||||||
public void loop() throws IOException, InterruptedException {
|
public void loop() throws IOException, InterruptedException {
|
||||||
while (true) {
|
while (true) {
|
||||||
String text;
|
String text;
|
||||||
|
long sequence;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
while (clipboardText == null) {
|
while (ack == DeviceMessage.SEQUENCE_INVALID && clipboardText == null) {
|
||||||
wait();
|
wait();
|
||||||
}
|
}
|
||||||
text = clipboardText;
|
text = clipboardText;
|
||||||
clipboardText = null;
|
clipboardText = null;
|
||||||
|
|
||||||
|
sequence = ack;
|
||||||
|
ack = DeviceMessage.SEQUENCE_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sequence != DeviceMessage.SEQUENCE_INVALID) {
|
||||||
|
DeviceMessage event = DeviceMessage.createAckClipboard(sequence);
|
||||||
|
connection.sendDeviceMessage(event);
|
||||||
|
}
|
||||||
|
if (text != null) {
|
||||||
DeviceMessage event = DeviceMessage.createClipboard(text);
|
DeviceMessage event = DeviceMessage.createClipboard(text);
|
||||||
connection.sendDeviceMessage(event);
|
connection.sendDeviceMessage(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue