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 <https://github.com/Genymobile/scrcpy/issues/1580>
@@ -25,12 +25,21 @@ receiver_destroy(struct receiver *receiver) {
static void
process_msg(struct device_msg *msg) {
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");
SDL_SetClipboardText(msg->clipboard.text);
break;
}
}
+}
static ssize_t
process_msgs(const unsigned char *buf, size_t len) {
