diff options
author | Pierre Ossman <ossman@cendio.se> | 2018-03-26 14:17:04 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2018-03-26 14:17:04 +0200 |
commit | be6909b3c03f61dab35c491b2a9dea0ffd2e5658 (patch) | |
tree | d2f543638f541a94bd253698fa6f330b0419a6eb /vncviewer/Viewport.cxx | |
parent | 9a74732b5cbb1a11b950cd09ff5e764ddffc3897 (diff) | |
download | tigervnc-be6909b3c03f61dab35c491b2a9dea0ffd2e5658.tar.gz tigervnc-be6909b3c03f61dab35c491b2a9dea0ffd2e5658.zip |
Avoid clipboard updates when not focused
We don't want to surprise the user with unexpected clipboard changes
when vncviewer is in the background, and it is both wasteful and
possibly insecure to inform the server of every clipboard update
when the user isn't interacting with it.
Diffstat (limited to 'vncviewer/Viewport.cxx')
-rw-r--r-- | vncviewer/Viewport.cxx | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx index 3b56fce5..6c10f357 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -118,6 +118,7 @@ Viewport::Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_) #ifdef WIN32 altGrArmed(false), #endif + pendingServerCutText(NULL), pendingClientCutText(NULL), menuCtrlKey(false), menuAltKey(false), cursor(NULL) { #if !defined(WIN32) && !defined(__APPLE__) @@ -206,6 +207,8 @@ Viewport::~Viewport() delete cursor; } + clearPendingClipboard(); + // FLTK automatically deletes all child widgets, so we shouldn't touch // them ourselves here } @@ -233,6 +236,8 @@ void Viewport::serverCutText(const char* str, rdr::U32 len) char *buffer; int size, ret; + clearPendingClipboard(); + if (!acceptClipboard) return; @@ -249,6 +254,11 @@ void Viewport::serverCutText(const char* str, rdr::U32 len) vlog.debug("Got clipboard data (%d bytes)", (int)strlen(buffer)); + if (!hasFocus()) { + pendingServerCutText = buffer; + return; + } + // RFB doesn't have separate selection and clipboard concepts, so we // dump the data into both variants. if (setPrimary) @@ -534,11 +544,18 @@ int Viewport::handle(int event) case FL_PASTE: buffer = new char[Fl::event_length() + 1]; + clearPendingClipboard(); + // This is documented as to ASCII, but actually does to 8859-1 ret = fl_utf8toa(Fl::event_text(), Fl::event_length(), buffer, Fl::event_length() + 1); assert(ret < (Fl::event_length() + 1)); + if (!hasFocus()) { + pendingClientCutText = buffer; + return 1; + } + vlog.debug("Sending clipboard data (%d bytes)", (int)strlen(buffer)); try { @@ -598,6 +615,8 @@ int Viewport::handle(int event) Fl::disable_im(); try { + flushPendingClipboard(); + // We may have gotten our lock keys out of sync with the server // whilst we didn't have focus. Try to sort this out. pushLEDState(); @@ -704,6 +723,33 @@ void Viewport::handleClipboardChange(int source, void *data) } +void Viewport::clearPendingClipboard() +{ + delete [] pendingServerCutText; + pendingServerCutText = NULL; + delete [] pendingClientCutText; + pendingClientCutText = NULL; +} + + +void Viewport::flushPendingClipboard() +{ + if (pendingServerCutText) { + size_t len = strlen(pendingServerCutText); + if (setPrimary) + Fl::copy(pendingServerCutText, len, 0); + Fl::copy(pendingServerCutText, len, 1); + } + if (pendingClientCutText) { + size_t len = strlen(pendingClientCutText); + vlog.debug("Sending pending clipboard data (%d bytes)", (int)len); + cc->writer()->clientCutText(pendingClientCutText, len); + } + + clearPendingClipboard(); +} + + void Viewport::handlePointerEvent(const rfb::Point& pos, int buttonMask) { if (!viewOnly) { |