[gnome-remote-desktop] session-vnc: Add clipboard support



commit cbded0eec9b1e869f868eb2966b8ae787e73d440
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Wed Aug 12 02:36:05 2020 +0200

    session-vnc: Add clipboard support
    
    Add clipboard support to the VNC backend using the previously
    implemented VNC clipboard.

 src/grd-session-vnc.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
---
diff --git a/src/grd-session-vnc.c b/src/grd-session-vnc.c
index e208bbd..0e520dc 100644
--- a/src/grd-session-vnc.c
+++ b/src/grd-session-vnc.c
@@ -28,6 +28,7 @@
 #include <linux/input.h>
 #include <rfb/rfb.h>
 
+#include "grd-clipboard-vnc.h"
 #include "grd-context.h"
 #include "grd-prompt.h"
 #include "grd-settings.h"
@@ -66,6 +67,8 @@ struct _GrdSessionVnc
   int prev_y;
   int prev_button_mask;
   GHashTable *pressed_keys;
+
+  GrdClipboardVnc *clipboard_vnc;
 };
 
 G_DEFINE_TYPE (GrdSessionVnc, grd_session_vnc, GRD_TYPE_SESSION);
@@ -379,6 +382,17 @@ handle_release_all_keys (rfbClientPtr rfb_client)
                                session_vnc);
 }
 
+static void
+handle_set_clipboard_text (char         *text,
+                           int           text_length,
+                           rfbClientPtr  rfb_client)
+{
+  GrdSessionVnc *session_vnc = rfb_client->screen->screenData;
+  GrdClipboardVnc *clipboard_vnc = session_vnc->clipboard_vnc;
+
+  grd_clipboard_vnc_set_clipboard_text (clipboard_vnc, text, text_length);
+}
+
 static void
 grd_session_vnc_notify_axis (GrdSessionVnc *session_vnc,
                              int            button_mask_bit_index)
@@ -551,6 +565,8 @@ init_vnc_session (GrdSessionVnc *session_vnc)
 
   update_server_format (session_vnc);
 
+  session_vnc->clipboard_vnc = grd_clipboard_vnc_new (session_vnc);
+
   socket = g_socket_connection_get_socket (session_vnc->connection);
   rfb_screen->inetdSock = g_socket_get_fd (socket);
   rfb_screen->desktopName = "GNOME";
@@ -564,6 +580,7 @@ init_vnc_session (GrdSessionVnc *session_vnc)
 
   rfb_screen->kbdAddEvent = handle_key_event;
   rfb_screen->kbdReleaseAllKeys = handle_release_all_keys;
+  rfb_screen->setXCutText = handle_set_clipboard_text;
   rfb_screen->ptrAddEvent = handle_pointer_event;
 
   rfb_screen->frameBuffer = g_malloc0 (screen_width * screen_height * 4);
@@ -593,6 +610,17 @@ handle_socket_data (GSocket *socket,
                                       session_vnc->pending_framebuffer_width,
                                       session_vnc->pending_framebuffer_height);
               session_vnc->pending_framebuffer_resize = FALSE;
+
+              /**
+               * This is a workaround. libvncserver is unable to handle clipboard
+               * changes early and either disconnects the client or crashes g-r-d
+               * if it receives rfbSendServerCutText too early altough the
+               * authentification process is already done.
+               * Doing this after resizing the framebuffer, seems to work fine,
+               * so enable the clipboard here and not when the remote desktop
+               * session proxy is acquired.
+               */
+              grd_clipboard_vnc_maybe_enable_clipboard (session_vnc->clipboard_vnc);
             }
         }
     }
@@ -671,6 +699,7 @@ grd_session_vnc_stop (GrdSession *session)
   grd_session_vnc_detach_source (session_vnc);
 
   g_clear_object (&session_vnc->connection);
+  g_clear_object (&session_vnc->clipboard_vnc);
   g_clear_pointer (&session_vnc->rfb_screen->frameBuffer, g_free);
   g_clear_pointer (&session_vnc->rfb_screen, rfbScreenCleanup);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]