[connections/fix-simultaneous-displays-2: 6/6] display-view, vnc: Make sure Vnc.Display always has a window




commit 18c3f71b9b51664cca39ddd6e79f9a02dfbcf931
Author: Felipe Borges <felipeborges gnome org>
Date:   Wed Jul 28 11:59:59 2021 +0200

    display-view, vnc: Make sure Vnc.Display always has a window
    
    This introduces a dispose_display() method for Connection objects
    to have a way to run protocol-specific instructions when a connection
    is supposed to persist but hide its display.
    
    This is useful in particular for Vnc.Display, which always requires
    a Gtk.Window mapped to it.
    
    This fixes the issue preventing multiple VNC connections to work
    in parallel.

 src/connection.vala     |  2 ++
 src/display-view.vala   |  4 ++++
 src/rdp-connection.vala |  3 +++
 src/vnc-connection.vala | 21 +++++++++++++++------
 4 files changed, 24 insertions(+), 6 deletions(-)
---
diff --git a/src/connection.vala b/src/connection.vala
index 33c16f7..113e67b 100644
--- a/src/connection.vala
+++ b/src/connection.vala
@@ -166,5 +166,7 @@ namespace Connections {
 
         public abstract void connect_it ();
         public abstract void disconnect_it ();
+
+        public abstract void dispose_display ();
     }
 }
diff --git a/src/display-view.vala b/src/display-view.vala
index ea014a4..c731038 100644
--- a/src/display-view.vala
+++ b/src/display-view.vala
@@ -49,6 +49,10 @@ namespace Connections {
             if (widget != null)
                 event_box.remove (widget);
 
+            if (connection == null)
+                return;
+
+            connection.dispose_display ();
             connection = null;
         }
 
diff --git a/src/rdp-connection.vala b/src/rdp-connection.vala
index 4806f4c..64995f0 100644
--- a/src/rdp-connection.vala
+++ b/src/rdp-connection.vala
@@ -92,6 +92,9 @@ namespace Connections {
             connected = false;
         }
 
+        public override void dispose_display () {
+        }
+
         public override void send_keys (uint[] keyvals) {
         }
 
diff --git a/src/vnc-connection.vala b/src/vnc-connection.vala
index 0548244..bce8975 100644
--- a/src/vnc-connection.vala
+++ b/src/vnc-connection.vala
@@ -23,7 +23,7 @@ using Vnc;
 
 namespace Connections {
     private class VncConnection : Connection {
-        private Gtk.Window window;
+        private Gtk.Window sidecar_vnc_window;
         private Gtk.Clipboard clipboard;
 
         private Vnc.Display display;
@@ -33,8 +33,8 @@ namespace Connections {
             }
 
             get {
-                if (window.get_child () != null)
-                    window.remove (display);
+                if (sidecar_vnc_window.get_child () != null)
+                    sidecar_vnc_window.remove (display);
 
                 return display as Gtk.Widget;
             }
@@ -90,9 +90,7 @@ namespace Connections {
             display.set_pointer_grab (true);
             display.set_force_size (false);
 
-            window = new Gtk.Window ();
-            window.add (display);
-            display.realize ();
+            dispose_display ();
 
             clipboard = Gtk.Clipboard.get_default (Application.application.main_window.get_display ());
 
@@ -177,6 +175,17 @@ namespace Connections {
             connected = false;
         }
 
+        public override void dispose_display () {
+            /* The Vnc.Display widget doesn't like not having a realized window.
+             * so we pack it on a temporary window for initialization and for
+             * when the connection persists but the display is not being presented. */
+            if (sidecar_vnc_window == null)
+                sidecar_vnc_window = new Gtk.Window ();
+
+            sidecar_vnc_window.add (display);
+            display.realize ();
+        }
+
         public override void send_keys (uint[] keyvals) {
             display.send_keys (keyvals);
         }


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