diff options
author | Brian P. Hinz <bphinz@users.sf.net> | 2021-03-11 19:31:11 -0500 |
---|---|---|
committer | Brian P. Hinz <bphinz@users.sf.net> | 2021-03-11 19:31:57 -0500 |
commit | 91fccb66b9558d94aa1799e62bf37af02f74d3c0 (patch) | |
tree | 8dd403d135554ba05e53055a3c8cd1d64704a5f8 | |
parent | 2be74db342d432a6110770979cd778fbb34b93f7 (diff) | |
download | tigervnc-91fccb66b9558d94aa1799e62bf37af02f74d3c0.tar.gz tigervnc-91fccb66b9558d94aa1799e62bf37af02f74d3c0.zip |
Fix for issue 1215
-rw-r--r-- | java/com/tigervnc/vncviewer/ClipboardDialog.java | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/java/com/tigervnc/vncviewer/ClipboardDialog.java b/java/com/tigervnc/vncviewer/ClipboardDialog.java index 4a5d9f27..23923895 100644 --- a/java/com/tigervnc/vncviewer/ClipboardDialog.java +++ b/java/com/tigervnc/vncviewer/ClipboardDialog.java @@ -41,22 +41,24 @@ class ClipboardDialog extends Dialog { // Custom TransferHandler designed to limit the size of outbound // clipboard transfers to VncViewer.maxCutText.getValue() bytes. private LogWriter vlog = new LogWriter("VncTransferHandler"); + private long start; - public void exportToClipboard(JComponent c, Clipboard clip, int a) + public void exportToClipboard(JComponent comp, Clipboard clip, int action) throws IllegalStateException { - if (!(c instanceof JTextComponent)) return; - String text = ((JTextComponent)c).getText(); + if (action != TransferHandler.COPY) return; + if (start == 0) + start = System.currentTimeMillis(); + StringSelection selection = new StringSelection(((JTextArea)comp).getText()); try { - if (text.equals((String)clip.getData(DataFlavor.stringFlavor))) return; - } catch (IOException e) { - // worst case we set the clipboard contents unnecessarily - vlog.info(e.toString()); - } catch (UnsupportedFlavorException e) { - // worst case we set the clipboard contents unnecessarily - vlog.info(e.toString()); + clip.setContents(selection, selection); + } catch(IllegalStateException e) { + // something else has the clipboard, keep trying for at most 50ms + if ((System.currentTimeMillis() - start) < 50) + exportToClipboard(comp, clip, action); + else + vlog.info("Couldn't access system clipboard for > 50ms"); } - StringSelection selection = new StringSelection(text); - clip.setContents(selection, null); + start = 0; } public boolean importData(JComponent c, Transferable t) { @@ -217,6 +219,5 @@ class ClipboardDialog extends Dialog { private static boolean listen = true; static ClipboardDialog dialog; static MyJTextArea textArea = new MyJTextArea(); - static Toolkit tk = Toolkit.getDefaultToolkit(); static LogWriter vlog = new LogWriter("ClipboardDialog"); } |