Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait SET_CLIPBOARD ack before Ctrl+v via HID #2814

Merged
merged 9 commits into from
Nov 24, 2021
Prev Previous commit
Next Next commit
Do not inject Ctrl+v if clipboard sync failed
This prevents to paste the current Android clipboard, which would be
unexpected.

PR #2814 <#2814>
  • Loading branch information
rom1v committed Nov 23, 2021
commit 854de9659a503291fc310ed6702bd4278bf2a725
15 changes: 11 additions & 4 deletions app/src/input_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,19 @@ collapse_panels(struct controller *controller) {
}
}

static void
static bool
set_device_clipboard(struct controller *controller, bool paste) {
char *text = SDL_GetClipboardText();
if (!text) {
LOGW("Could not get clipboard text: %s", SDL_GetError());
return;
return false;
}

char *text_dup = strdup(text);
SDL_free(text);
if (!text_dup) {
LOGW("Could not strdup input text");
return;
return false;
}

struct control_msg msg;
Expand All @@ -231,7 +231,10 @@ set_device_clipboard(struct controller *controller, bool paste) {
if (!controller_push_msg(controller, &msg)) {
free(text_dup);
LOGW("Could not request 'set device clipboard'");
return false;
}

return true;
}

static void
Expand Down Expand Up @@ -515,7 +518,11 @@ input_manager_process_key(struct input_manager *im,
}
// Synchronize the computer clipboard to the device clipboard before
// 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);
Expand Down