Set computer clipboard only if necessary

Do not explicitly set the clipboard text if it already contains the
expected content.

Even if copy-paste loops are avoided by the previous commit, this avoids
to trigger a clipboard change on the computer-side.

Refs #1580 <https://github.com/Genymobile/scrcpy/issues/1580>
This commit is contained in:
Romain Vimont 2020-07-17 00:00:42 +02:00
parent 1223a72eb8
commit 20d3925099

View File

@ -25,11 +25,20 @@ receiver_destroy(struct receiver *receiver) {
static void static void
process_msg(struct device_msg *msg) { process_msg(struct device_msg *msg) {
switch (msg->type) { switch (msg->type) {
case DEVICE_MSG_TYPE_CLIPBOARD: case DEVICE_MSG_TYPE_CLIPBOARD: {
char *current = SDL_GetClipboardText();
bool same = current && !strcmp(current, msg->clipboard.text);
SDL_free(current);
if (same) {
LOGD("Computer clipboard unchanged");
return;
}
LOGI("Device clipboard copied"); LOGI("Device clipboard copied");
SDL_SetClipboardText(msg->clipboard.text); SDL_SetClipboardText(msg->clipboard.text);
break; break;
} }
}
} }
static ssize_t static ssize_t