diff options
author | Pierre Ossman <ossman@cendio.se> | 2019-07-01 11:37:50 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2019-07-01 11:37:50 +0200 |
commit | 5b8a629661c25f7c11c4b37825b0c80c633c2bf6 (patch) | |
tree | f80a2734a4fc32acb2d5d1cacf33577b3a1fe4c7 /vncviewer | |
parent | 1d696c6bfa2ccfd6a3655602593dd3dff968aebe (diff) | |
parent | 0ff2655456097926a1720545830b1e34f072371f (diff) | |
download | tigervnc-5b8a629661c25f7c11c4b37825b0c80c633c2bf6.tar.gz tigervnc-5b8a629661c25f7c11c4b37825b0c80c633c2bf6.zip |
Merge branch 'exclipboard' of https://github.com/CendioOssman/tigervnc
Diffstat (limited to 'vncviewer')
-rw-r--r-- | vncviewer/CConn.cxx | 20 | ||||
-rw-r--r-- | vncviewer/CConn.h | 6 | ||||
-rw-r--r-- | vncviewer/DesktopWindow.cxx | 22 | ||||
-rw-r--r-- | vncviewer/DesktopWindow.h | 8 | ||||
-rw-r--r-- | vncviewer/Viewport.cxx | 163 | ||||
-rw-r--r-- | vncviewer/Viewport.h | 17 | ||||
-rw-r--r-- | vncviewer/vncviewer.man | 5 |
7 files changed, 137 insertions, 104 deletions
diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx index b4610e6a..6ba3276b 100644 --- a/vncviewer/CConn.cxx +++ b/vncviewer/CConn.cxx @@ -377,11 +377,6 @@ void CConn::bell() fl_beep(); } -void CConn::serverCutText(const char* str, rdr::U32 len) -{ - desktop->serverCutText(str, len); -} - void CConn::dataRect(const Rect& r, int encoding) { sock->inStream().startTiming(); @@ -422,6 +417,21 @@ void CConn::setLEDState(unsigned int state) desktop->setLEDState(state); } +void CConn::handleClipboardRequest() +{ + desktop->handleClipboardRequest(); +} + +void CConn::handleClipboardAnnounce(bool available) +{ + desktop->handleClipboardAnnounce(available); +} + +void CConn::handleClipboardData(const char* data) +{ + desktop->handleClipboardData(data); +} + ////////////////////// Internal methods ////////////////////// diff --git a/vncviewer/CConn.h b/vncviewer/CConn.h index 2e3362ce..4d935c96 100644 --- a/vncviewer/CConn.h +++ b/vncviewer/CConn.h @@ -61,8 +61,6 @@ public: void bell(); - void serverCutText(const char* str, rdr::U32 len); - void framebufferUpdateStart(); void framebufferUpdateEnd(); void dataRect(const rfb::Rect& r, int encoding); @@ -74,6 +72,10 @@ public: void setLEDState(unsigned int state); + virtual void handleClipboardRequest(); + virtual void handleClipboardAnnounce(bool available); + virtual void handleClipboardData(const char* data); + private: void resizeFramebuffer(); diff --git a/vncviewer/DesktopWindow.cxx b/vncviewer/DesktopWindow.cxx index c52a9150..1b666f94 100644 --- a/vncviewer/DesktopWindow.cxx +++ b/vncviewer/DesktopWindow.cxx @@ -276,12 +276,6 @@ void DesktopWindow::resizeFramebuffer(int new_w, int new_h) } -void DesktopWindow::serverCutText(const char* str, rdr::U32 len) -{ - viewport->serverCutText(str, len); -} - - void DesktopWindow::setCursor(int width, int height, const rfb::Point& hotspot, const rdr::U8* data) @@ -442,6 +436,22 @@ void DesktopWindow::setLEDState(unsigned int state) } +void DesktopWindow::handleClipboardRequest() +{ + viewport->handleClipboardRequest(); +} + +void DesktopWindow::handleClipboardAnnounce(bool available) +{ + viewport->handleClipboardAnnounce(available); +} + +void DesktopWindow::handleClipboardData(const char* data) +{ + viewport->handleClipboardData(data); +} + + void DesktopWindow::resize(int x, int y, int w, int h) { bool resizing; diff --git a/vncviewer/DesktopWindow.h b/vncviewer/DesktopWindow.h index 97a8178d..ef3dbb08 100644 --- a/vncviewer/DesktopWindow.h +++ b/vncviewer/DesktopWindow.h @@ -62,9 +62,6 @@ public: // Resize the current framebuffer, but retain the contents void resizeFramebuffer(int new_w, int new_h); - // Incoming clipboard from server - void serverCutText(const char* str, rdr::U32 len); - // New image for the locally rendered cursor void setCursor(int width, int height, const rfb::Point& hotspot, const rdr::U8* data); @@ -72,6 +69,11 @@ public: // Change client LED state void setLEDState(unsigned int state); + // Clipboard events + void handleClipboardRequest(); + void handleClipboardAnnounce(bool available); + void handleClipboardData(const char* data); + // Fl_Window callback methods virtual void show(); virtual void draw(); diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx index 5df5c796..cd613279 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -1,5 +1,5 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. - * Copyright 2011-2014 Pierre Ossman for Cendio AB + * Copyright 2011-2019 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -119,7 +119,7 @@ Viewport::Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_) altGrArmed(false), #endif firstLEDState(true), - pendingServerCutText(NULL), pendingClientCutText(NULL), + pendingServerClipboard(false), pendingClientClipboard(false), menuCtrlKey(false), menuAltKey(false), cursor(NULL) { #if !defined(WIN32) && !defined(__APPLE__) @@ -208,8 +208,6 @@ Viewport::~Viewport() delete cursor; } - clearPendingClipboard(); - // FLTK automatically deletes all child widgets, so we shouldn't touch // them ourselves here } @@ -232,45 +230,6 @@ void Viewport::updateWindow() damage(FL_DAMAGE_USER1, r.tl.x + x(), r.tl.y + y(), r.width(), r.height()); } -void Viewport::serverCutText(const char* str, rdr::U32 len) -{ - char *buffer; - int size, ret; - - clearPendingClipboard(); - - if (!acceptClipboard) - return; - - size = fl_utf8froma(NULL, 0, str, len); - if (size <= 0) - return; - - size++; - - buffer = new char[size]; - - ret = fl_utf8froma(buffer, size, str, len); - assert(ret < size); - - 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 !defined(WIN32) && !defined(__APPLE__) - if (setPrimary) - Fl::copy(buffer, ret, 0); -#endif - Fl::copy(buffer, ret, 1); - - delete [] buffer; -} - static const char * dotcursor_xpm[] = { "5 5 2 1", ". c #000000", @@ -319,6 +278,55 @@ void Viewport::setCursor(int width, int height, const Point& hotspot, window()->cursor(cursor, cursorHotspot.x, cursorHotspot.y); } +void Viewport::handleClipboardRequest() +{ + Fl::paste(*this, clipboardSource); +} + +void Viewport::handleClipboardAnnounce(bool available) +{ + if (!acceptClipboard) + return; + + if (available) + vlog.debug("Got notification of new clipboard on server"); + else + vlog.debug("Clipboard is no longer available on server"); + + if (!available) { + pendingServerClipboard = false; + return; + } + + pendingClientClipboard = false; + + if (!hasFocus()) { + pendingServerClipboard = true; + return; + } + + cc->requestClipboard(); +} + +void Viewport::handleClipboardData(const char* data) +{ + size_t len; + + if (!hasFocus()) + return; + + len = strlen(data); + + vlog.debug("Got clipboard data (%d bytes)", (int)len); + + // RFB doesn't have separate selection and clipboard concepts, so we + // dump the data into both variants. +#if !defined(WIN32) && !defined(__APPLE__) + if (setPrimary) + Fl::copy(data, len, 0); +#endif + Fl::copy(data, len, 1); +} void Viewport::setLEDState(unsigned int state) { @@ -549,37 +557,24 @@ void Viewport::resize(int x, int y, int w, int h) int Viewport::handle(int event) { - char *buffer; - int ret; + char *filtered; int buttonMask, wheelMask; DownMap::const_iterator iter; switch (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)); + filtered = convertLF(Fl::event_text(), Fl::event_length()); - if (!hasFocus()) { - pendingClientCutText = buffer; - return 1; - } - - vlog.debug("Sending clipboard data (%d bytes)", (int)strlen(buffer)); + vlog.debug("Sending clipboard data (%d bytes)", (int)strlen(filtered)); try { - cc->writer()->writeClientCutText(buffer, ret); + cc->sendClipboardData(filtered); } catch (rdr::Exception& e) { vlog.error("%s", e.str()); exit_vncviewer(e.str()); } - delete [] buffer; + strFree(filtered); return 1; @@ -737,41 +732,47 @@ void Viewport::handleClipboardChange(int source, void *data) return; #endif - Fl::paste(*self, source); -} + self->clipboardSource = source; + self->pendingServerClipboard = false; -void Viewport::clearPendingClipboard() -{ - delete [] pendingServerCutText; - pendingServerCutText = NULL; - delete [] pendingClientCutText; - pendingClientCutText = NULL; + if (!self->hasFocus()) { + self->pendingClientClipboard = true; + // Clear any older client clipboard from the server + self->cc->announceClipboard(false); + return; + } + + try { + self->cc->announceClipboard(true); + } catch (rdr::Exception& e) { + vlog.error("%s", e.str()); + exit_vncviewer(e.str()); + } } void Viewport::flushPendingClipboard() { - if (pendingServerCutText) { - size_t len = strlen(pendingServerCutText); -#if !defined(WIN32) && !defined(__APPLE__) - if (setPrimary) - Fl::copy(pendingServerCutText, len, 0); -#endif - Fl::copy(pendingServerCutText, len, 1); + if (pendingServerClipboard) { + try { + cc->requestClipboard(); + } catch (rdr::Exception& e) { + vlog.error("%s", e.str()); + exit_vncviewer(e.str()); + } } - if (pendingClientCutText) { - size_t len = strlen(pendingClientCutText); - vlog.debug("Sending pending clipboard data (%d bytes)", (int)len); + if (pendingClientClipboard) { try { - cc->writer()->writeClientCutText(pendingClientCutText, len); + cc->announceClipboard(true); } catch (rdr::Exception& e) { vlog.error("%s", e.str()); exit_vncviewer(e.str()); } } - clearPendingClipboard(); + pendingServerClipboard = false; + pendingClientClipboard = false; } diff --git a/vncviewer/Viewport.h b/vncviewer/Viewport.h index be2192b8..1fb93c66 100644 --- a/vncviewer/Viewport.h +++ b/vncviewer/Viewport.h @@ -1,5 +1,5 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. - * Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB + * Copyright 2011-2019 Pierre Ossman <ossman@cendio.se> for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,9 +45,6 @@ public: // Flush updates to screen void updateWindow(); - // Incoming clipboard from server - void serverCutText(const char* str, rdr::U32 len); - // New image for the locally rendered cursor void setCursor(int width, int height, const rfb::Point& hotspot, const rdr::U8* data); @@ -57,6 +54,11 @@ public: void draw(Surface* dst); + // Clipboard events + void handleClipboardRequest(); + void handleClipboardAnnounce(bool available); + void handleClipboardData(const char* data); + // Fl_Widget callback methods void draw(); @@ -72,7 +74,6 @@ private: static void handleClipboardChange(int source, void *data); - void clearPendingClipboard(); void flushPendingClipboard(); void handlePointerEvent(const rfb::Point& pos, int buttonMask); @@ -114,8 +115,10 @@ private: bool firstLEDState; - const char* pendingServerCutText; - const char* pendingClientCutText; + bool pendingServerClipboard; + bool pendingClientClipboard; + + int clipboardSource; rdr::U32 menuKeySym; int menuKeyCode, menuKeyFLTK; diff --git a/vncviewer/vncviewer.man b/vncviewer/vncviewer.man index ebfe7725..f93e096a 100644 --- a/vncviewer/vncviewer.man +++ b/vncviewer/vncviewer.man @@ -182,6 +182,11 @@ Set the primary selection as well as the clipboard selection. Default is on. . .TP +.B \-MaxCutText \fIbytes\fP +The maximum size of a clipboard update that will be accepted from a server. +Default is \fB262144\fP. +. +.TP .B \-SendClipboard Send clipboard changes to the server. Default is on. . |