Implement computer-to-device clipboard copy

It was already possible to _paste_ (with Ctrl+v) the content of the
computer clipboard on the device. Technically, it injects a sequence of
events to generate the text.

Add a new feature (Ctrl+Shift+v) to copy to the device clipboard
instead, without injecting the content. Contrary to events injection,
this preserves the UTF-8 content exactly, so the text is not broken by
special characters.

<https://github.com/Genymobile/scrcpy/issues/413>
This commit is contained in:
Romain Vimont
2019-05-30 20:25:23 +02:00
parent 2322069656
commit c13a24389c
12 changed files with 138 additions and 6 deletions

View File

@@ -193,6 +193,26 @@ static void test_serialize_get_clipboard_event(void) {
assert(!memcmp(buf, expected, sizeof(expected)));
}
static void test_serialize_set_clipboard_event(void) {
struct control_event event = {
.type = CONTROL_EVENT_TYPE_SET_CLIPBOARD,
.text_event = {
.text = "hello, world!",
},
};
unsigned char buf[CONTROL_EVENT_SERIALIZED_MAX_SIZE];
int size = control_event_serialize(&event, buf);
assert(size == 16);
const unsigned char expected[] = {
0x08, // CONTROL_EVENT_TYPE_SET_CLIPBOARD
0x00, 0x0d, // text length
'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', // text
};
assert(!memcmp(buf, expected, sizeof(expected)));
}
int main(void) {
test_serialize_keycode_event();
test_serialize_text_event();
@@ -203,5 +223,6 @@ int main(void) {
test_serialize_expand_notification_panel_event();
test_serialize_collapse_notification_panel_event();
test_serialize_get_clipboard_event();
test_serialize_set_clipboard_event();
return 0;
}