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:
@@ -50,6 +50,7 @@ control_event_serialize(const struct control_event *event, unsigned char *buf) {
|
||||
case CONTROL_EVENT_TYPE_BACK_OR_SCREEN_ON:
|
||||
case CONTROL_EVENT_TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||
case CONTROL_EVENT_TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
||||
case CONTROL_EVENT_TYPE_GET_CLIPBOARD:
|
||||
// no additional data
|
||||
return 1;
|
||||
default:
|
||||
|
||||
@@ -20,6 +20,7 @@ enum control_event_type {
|
||||
CONTROL_EVENT_TYPE_BACK_OR_SCREEN_ON,
|
||||
CONTROL_EVENT_TYPE_EXPAND_NOTIFICATION_PANEL,
|
||||
CONTROL_EVENT_TYPE_COLLAPSE_NOTIFICATION_PANEL,
|
||||
CONTROL_EVENT_TYPE_GET_CLIPBOARD,
|
||||
};
|
||||
|
||||
struct control_event {
|
||||
|
||||
@@ -126,6 +126,16 @@ collapse_notification_panel(struct controller *controller) {
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
request_device_clipboard(struct controller *controller) {
|
||||
struct control_event control_event;
|
||||
control_event.type = CONTROL_EVENT_TYPE_GET_CLIPBOARD;
|
||||
|
||||
if (!controller_push_event(controller, &control_event)) {
|
||||
LOGW("Cannot get device clipboard");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
switch_fps_counter_state(struct video_buffer *vb) {
|
||||
mutex_lock(vb->mutex);
|
||||
@@ -250,6 +260,12 @@ input_manager_process_key(struct input_manager *input_manager,
|
||||
action_volume_up(input_manager->controller, action);
|
||||
}
|
||||
return;
|
||||
case SDLK_c:
|
||||
if (control && ctrl && !meta && !shift && !repeat
|
||||
&& event->type == SDL_KEYDOWN) {
|
||||
request_device_clipboard(input_manager->controller);
|
||||
}
|
||||
return;
|
||||
case SDLK_v:
|
||||
if (control && ctrl && !meta && !shift && !repeat
|
||||
&& event->type == SDL_KEYDOWN) {
|
||||
|
||||
@@ -137,6 +137,9 @@ static void usage(const char *arg0) {
|
||||
" Ctrl+Shift+n\n"
|
||||
" collapse notification panel\n"
|
||||
"\n"
|
||||
" Ctrl+c\n"
|
||||
" copy device clipboard to computer\n"
|
||||
"\n"
|
||||
" Ctrl+v\n"
|
||||
" paste computer clipboard to device\n"
|
||||
"\n"
|
||||
|
||||
Reference in New Issue
Block a user