Do not inject Ctrl+v if clipboard sync failed
This prevents to paste the current Android clipboard, which would be unexpected. PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
This commit is contained in:
parent
ea8028332c
commit
854de9659a
1 changed files with 11 additions and 4 deletions
|
@ -208,19 +208,19 @@ collapse_panels(struct controller *controller) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static bool
|
||||||
set_device_clipboard(struct controller *controller, bool paste) {
|
set_device_clipboard(struct controller *controller, bool paste) {
|
||||||
char *text = SDL_GetClipboardText();
|
char *text = SDL_GetClipboardText();
|
||||||
if (!text) {
|
if (!text) {
|
||||||
LOGW("Could not get clipboard text: %s", SDL_GetError());
|
LOGW("Could not get clipboard text: %s", SDL_GetError());
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *text_dup = strdup(text);
|
char *text_dup = strdup(text);
|
||||||
SDL_free(text);
|
SDL_free(text);
|
||||||
if (!text_dup) {
|
if (!text_dup) {
|
||||||
LOGW("Could not strdup input text");
|
LOGW("Could not strdup input text");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct control_msg msg;
|
struct control_msg msg;
|
||||||
|
@ -231,7 +231,10 @@ set_device_clipboard(struct controller *controller, bool paste) {
|
||||||
if (!controller_push_msg(controller, &msg)) {
|
if (!controller_push_msg(controller, &msg)) {
|
||||||
free(text_dup);
|
free(text_dup);
|
||||||
LOGW("Could not request 'set device clipboard'");
|
LOGW("Could not request 'set device clipboard'");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -515,7 +518,11 @@ input_manager_process_key(struct input_manager *im,
|
||||||
}
|
}
|
||||||
// Synchronize the computer clipboard to the device clipboard before
|
// Synchronize the computer clipboard to the device clipboard before
|
||||||
// sending Ctrl+v, to allow seamless copy-paste.
|
// sending Ctrl+v, to allow seamless copy-paste.
|
||||||
set_device_clipboard(controller, false);
|
bool ok = set_device_clipboard(controller, false);
|
||||||
|
if (!ok) {
|
||||||
|
LOGW("Clipboard could not be synchronized, Ctrl+v not injected");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
im->kp->ops->process_key(im->kp, event);
|
im->kp->ops->process_key(im->kp, event);
|
||||||
|
|
Loading…
Reference in a new issue