Implement support for sending the local clipboard to the server.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4432 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx
index 3e82990..acbf36c 100644
--- a/vncviewer/Viewport.cxx
+++ b/vncviewer/Viewport.cxx
@@ -66,6 +66,11 @@
set_simple_keyboard();
#endif
+// FLTK STR #2636 gives us the ability to monitor clipboard changes
+#ifdef HAVE_FLTK_CLIPBOARD
+ Fl::add_clipboard_notify(handleClipboardChange, this);
+#endif
+
frameBuffer = new ManagedPixelBuffer(getPreferredPF(), w, h);
assert(frameBuffer);
@@ -84,6 +89,10 @@
Fl::remove_timeout(handleColourMap, this);
Fl::remove_timeout(handlePointerTimeout, this);
+#ifdef HAVE_FLTK_CLIPBOARD
+ Fl::remove_clipboard_notify(handleClipboardChange);
+#endif
+
delete frameBuffer;
if (pixelTrans)
@@ -172,10 +181,22 @@
int Viewport::handle(int event)
{
+ char buffer[1024];
+ int ret;
int buttonMask, wheelMask;
DownMap::const_iterator iter;
switch (event) {
+ case FL_PASTE:
+ // This is documented as to ASCII, but actually does to 8859-1
+ ret = fl_utf8toa(Fl::event_text(), Fl::event_length(), buffer, sizeof(buffer));
+ if (ret >= sizeof(buffer)) {
+ vlog.error(_("Clipboard buffer overflow!"));
+ return 1;
+ }
+ vlog.debug("Sending clipboard data: '%s'", buffer);
+ cc->writer()->clientCutText(buffer, ret);
+ return 1;
case FL_ENTER:
// Yes, we would like some pointer events please!
return 1;
@@ -260,6 +281,19 @@
}
+void Viewport::handleClipboardChange(int source, void *data)
+{
+ Viewport *self = (Viewport *)data;
+
+ assert(self);
+
+ if (!sendPrimary && (source == 0))
+ return;
+
+ Fl::paste(*self, source);
+}
+
+
void Viewport::handlePointerEvent(const rfb::Point& pos, int buttonMask)
{
if (!viewOnly) {
diff --git a/vncviewer/Viewport.h b/vncviewer/Viewport.h
index 58ac30e..87a9cf9 100644
--- a/vncviewer/Viewport.h
+++ b/vncviewer/Viewport.h
@@ -93,6 +93,8 @@
static void handleUpdateTimeout(void *data);
static void handleColourMap(void *data);
+ static void handleClipboardChange(int source, void *data);
+
void handlePointerEvent(const rfb::Point& pos, int buttonMask);
static void handlePointerTimeout(void *data);