[virt-tools-list] [PATCH virt-viewer 21/25] Add VirtViewerSession::session-display-updated

Marc-André Lureau marcandre.lureau at gmail.com
Tue Jul 17 19:25:03 UTC 2012


Rebuild menu when agent is connected. Only when the agent is running
may a display be enabled/disabled.
---
 src/virt-viewer-app.c           |    9 +++++++++
 src/virt-viewer-session-spice.c |   18 ++++++++++++++----
 src/virt-viewer-session.c       |   10 ++++++++++
 src/virt-viewer-session.h       |    1 +
 4 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index a88264b..def52c5 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -685,6 +685,13 @@ virt_viewer_app_display_removed(VirtViewerSession *session G_GNUC_UNUSED,
         virt_viewer_app_remove_nth_window(self, nth);
 }
 
+static void
+virt_viewer_app_display_updated(VirtViewerSession *session G_GNUC_UNUSED,
+                                VirtViewerApp *self)
+{
+    virt_viewer_app_update_menu_displays(self);
+}
+
 int
 virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type)
 {
@@ -735,6 +742,8 @@ virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type)
                      G_CALLBACK(virt_viewer_app_display_added), self);
     g_signal_connect(priv->session, "session-display-removed",
                      G_CALLBACK(virt_viewer_app_display_removed), self);
+    g_signal_connect(priv->session, "session-display-updated",
+                     G_CALLBACK(virt_viewer_app_display_updated), self);
 
     g_signal_connect(priv->session, "session-cut-text",
                      G_CALLBACK(virt_viewer_app_server_cut_text), self);
diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-session-spice.c
index a728cb1..5fcd7fb 100644
--- a/src/virt-viewer-session-spice.c
+++ b/src/virt-viewer-session-spice.c
@@ -406,12 +406,21 @@ virt_viewer_session_spice_usb_device_selection(VirtViewerSession *session,
 }
 
 static void
-agent_connected_changed(SpiceChannel *cmain,
+agent_connected_changed(SpiceChannel *cmain G_GNUC_UNUSED,
                         GParamSpec *pspec G_GNUC_UNUSED,
                         VirtViewerSessionSpice *self)
 {
+    // this will force refresh of application menu
+    g_signal_emit_by_name(self, "session-display-updated");
+}
+
+static void
+agent_connected_fullscreen_auto_conf(SpiceChannel *cmain,
+                                     GParamSpec *pspec G_GNUC_UNUSED,
+                                     VirtViewerSessionSpice *self)
+{
     if (virt_viewer_session_spice_fullscreen_auto_conf(self))
-        g_signal_handlers_disconnect_by_func(cmain, agent_connected_changed, self);
+        g_signal_handlers_disconnect_by_func(cmain, agent_connected_fullscreen_auto_conf, self);
 }
 
 static void
@@ -512,8 +521,9 @@ virt_viewer_session_spice_channel_new(SpiceSession *s,
                          G_CALLBACK(virt_viewer_session_spice_main_channel_event), self);
         self->priv->main_channel = SPICE_MAIN_CHANNEL(channel);
 
-        g_signal_connect(channel, "notify::agent-connected", G_CALLBACK(agent_connected_changed),  self);
-        agent_connected_changed(channel, NULL, self);
+        g_signal_connect(channel, "notify::agent-connected", G_CALLBACK(agent_connected_changed), self);
+        g_signal_connect(channel, "notify::agent-connected", G_CALLBACK(agent_connected_fullscreen_auto_conf), self);
+        agent_connected_fullscreen_auto_conf(channel, NULL, self);
 
         g_signal_emit_by_name(session, "session-connected");
     }
diff --git a/src/virt-viewer-session.c b/src/virt-viewer-session.c
index 9249a1f..a1d96c2 100644
--- a/src/virt-viewer-session.c
+++ b/src/virt-viewer-session.c
@@ -233,6 +233,16 @@ virt_viewer_session_class_init(VirtViewerSessionClass *class)
                  1,
                  VIRT_VIEWER_TYPE_DISPLAY);
 
+    g_signal_new("session-display-updated",
+                 G_OBJECT_CLASS_TYPE(object_class),
+                 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS,
+                 G_STRUCT_OFFSET(VirtViewerSessionClass, session_display_updated),
+                 NULL,
+                 NULL,
+                 g_cclosure_marshal_VOID__VOID,
+                 G_TYPE_NONE,
+                 0);
+
     g_signal_new("session-cut-text",
                  G_OBJECT_CLASS_TYPE(object_class),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS,
diff --git a/src/virt-viewer-session.h b/src/virt-viewer-session.h
index 44e4674..38ed988 100644
--- a/src/virt-viewer-session.h
+++ b/src/virt-viewer-session.h
@@ -88,6 +88,7 @@ struct _VirtViewerSessionClass {
                                   VirtViewerDisplay *display);
     void (*session_display_removed)(VirtViewerSession *session,
                                     VirtViewerDisplay *display);
+    void (*session_display_updated)(VirtViewerSession *session);
 
     void (*session_cut_text)(VirtViewerSession *session, const gchar *str);
     void (*session_bell)(VirtViewerSession *session);
-- 
1.7.10.4




More information about the virt-tools-list mailing list