Implement device-to-computer clipboard copy

On Ctrl+C:
 - the client sends a GET_CLIPBOARD command to the device;
 - the device retrieve its current clipboard text and sends it in a
   GET_CLIPBOARD device event;
 - the client sets this text as the system clipboard text, so that it
   can be pasted in another application.

Fixes <https://github.com/Genymobile/scrcpy/issues/145>
This commit is contained in:
Romain Vimont
2019-05-30 15:23:01 +02:00
parent 3149e2cf4a
commit 63c078ee6c
13 changed files with 109 additions and 0 deletions

View File

@@ -178,6 +178,21 @@ static void test_serialize_collapse_notification_panel_event(void) {
assert(!memcmp(buf, expected, sizeof(expected)));
}
static void test_serialize_get_clipboard_event(void) {
struct control_event event = {
.type = CONTROL_EVENT_TYPE_GET_CLIPBOARD,
};
unsigned char buf[CONTROL_EVENT_SERIALIZED_MAX_SIZE];
int size = control_event_serialize(&event, buf);
assert(size == 1);
const unsigned char expected[] = {
0x07, // CONTROL_EVENT_TYPE_GET_CLIPBOARD
};
assert(!memcmp(buf, expected, sizeof(expected)));
}
int main(void) {
test_serialize_keycode_event();
test_serialize_text_event();
@@ -187,5 +202,6 @@ int main(void) {
test_serialize_back_or_screen_on_event();
test_serialize_expand_notification_panel_event();
test_serialize_collapse_notification_panel_event();
test_serialize_get_clipboard_event();
return 0;
}