Skip to content

Commit

Permalink
Set device clipboard only if necessary
Browse files Browse the repository at this point in the history
Do not explicitly set the clipboard text if it already contains the
expected content. This avoids possible copy-paste loops between the
computer and the device.
  • Loading branch information
rom1v committed Aug 1, 2020
1 parent 7683be8 commit 1223a72
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/src/main/java/com/genymobile/scrcpy/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ public boolean setClipboardText(String text) {
if (clipboardManager == null) {
return false;
}

String currentClipboard = getClipboardText();
if (currentClipboard == null || currentClipboard.equals(text)) {
// The clipboard already contains the requested text.
// Since pasting text from the computer involves setting the device clipboard, it could be set twice on a copy-paste. This would cause
// the clipboard listeners to be notified twice, and that would flood the Android keyboard clipboard history. To workaround this
// problem, do not explicitly set the clipboard text if it already contains the expected content.
return false;
}

isSettingClipboard.set(true);
boolean ok = clipboardManager.setText(text);
isSettingClipboard.set(false);
Expand Down

0 comments on commit 1223a72

Please sign in to comment.