Press COPY on "get clipboard" request if possible
If the device runs at least Android 7, just press COPY on the device (the clipboard content will be sent via the clipboard listener). <https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_COPY>
This commit is contained in:
@@ -245,7 +245,8 @@ scrcpy_print_usage(const char *arg0) {
|
||||
" Collapse notification panel\n"
|
||||
"\n"
|
||||
" " MOD "+c\n"
|
||||
" Copy device clipboard to computer\n"
|
||||
" Press COPY (Android >= 7), then copy device clipboard to\n"
|
||||
" computer\n"
|
||||
"\n"
|
||||
" " MOD "+v\n"
|
||||
" Paste computer clipboard to device\n"
|
||||
|
||||
@@ -66,6 +66,9 @@ control_msg_serialize(const struct control_msg *msg, unsigned char *buf) {
|
||||
buffer_write32be(&buf[17],
|
||||
(uint32_t) msg->inject_scroll_event.vscroll);
|
||||
return 21;
|
||||
case CONTROL_MSG_TYPE_GET_CLIPBOARD:
|
||||
buf[1] = msg->get_clipboard.copy;
|
||||
return 2;
|
||||
case CONTROL_MSG_TYPE_SET_CLIPBOARD: {
|
||||
buf[1] = !!msg->set_clipboard.paste;
|
||||
size_t len = write_string(msg->set_clipboard.text,
|
||||
@@ -79,7 +82,6 @@ control_msg_serialize(const struct control_msg *msg, unsigned char *buf) {
|
||||
case CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON:
|
||||
case CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||
case CONTROL_MSG_TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
||||
case CONTROL_MSG_TYPE_GET_CLIPBOARD:
|
||||
case CONTROL_MSG_TYPE_ROTATE_DEVICE:
|
||||
// no additional data
|
||||
return 1;
|
||||
|
||||
@@ -60,6 +60,9 @@ struct control_msg {
|
||||
int32_t hscroll;
|
||||
int32_t vscroll;
|
||||
} inject_scroll_event;
|
||||
struct {
|
||||
bool copy;
|
||||
} get_clipboard;
|
||||
struct {
|
||||
char *text; // owned, to be freed by SDL_free()
|
||||
bool paste;
|
||||
|
||||
@@ -102,9 +102,10 @@ collapse_notification_panel(struct controller *controller) {
|
||||
}
|
||||
|
||||
static void
|
||||
request_device_clipboard(struct controller *controller) {
|
||||
request_device_clipboard(struct controller *controller, bool copy) {
|
||||
struct control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_GET_CLIPBOARD;
|
||||
msg.get_clipboard.copy = copy;
|
||||
|
||||
if (!controller_push_msg(controller, &msg)) {
|
||||
LOGW("Could not request device clipboard");
|
||||
@@ -341,7 +342,8 @@ input_manager_process_key(struct input_manager *im,
|
||||
return;
|
||||
case SDLK_c:
|
||||
if (control && !shift && !repeat && down) {
|
||||
request_device_clipboard(controller);
|
||||
// Press COPY, then get the clipboard content
|
||||
request_device_clipboard(controller, true);
|
||||
}
|
||||
return;
|
||||
case SDLK_v:
|
||||
|
||||
Reference in New Issue
Block a user