[virt-tools-list] [PATCH 07/22] window: set sensitivity based on display capability

marcandre.lureau at redhat.com marcandre.lureau at redhat.com
Tue Jul 31 13:41:10 UTC 2018


From: Marc-André Lureau <marcandre.lureau at redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
---
 src/virt-viewer-display.h |  6 ++++++
 src/virt-viewer-window.c  | 14 ++++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/virt-viewer-display.h b/src/virt-viewer-display.h
index 7016a85..eadc333 100644
--- a/src/virt-viewer-display.h
+++ b/src/virt-viewer-display.h
@@ -86,6 +86,12 @@ struct _VirtViewerDisplayClass {
     void (*disable)(VirtViewerDisplay *display);
 };
 
+#define VIRT_VIEWER_DISPLAY_CAN_SCREENSHOT(display) \
+    (VIRT_VIEWER_DISPLAY_GET_CLASS(display)->get_pixbuf != NULL)
+
+#define VIRT_VIEWER_DISPLAY_CAN_SEND_KEYS(display) \
+    (VIRT_VIEWER_DISPLAY_GET_CLASS(display)->send_keys != NULL)
+
 GType virt_viewer_display_get_type(void);
 
 GtkWidget *virt_viewer_display_new(void);
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index b9b8ce9..ec9bae6 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -1339,15 +1339,21 @@ virt_viewer_window_set_menus_sensitive(VirtViewerWindow *self, gboolean sensitiv
     gtk_widget_set_sensitive(menu, sensitive);
 
     menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, "menu-file-screenshot"));
-    gtk_widget_set_sensitive(menu, sensitive);
+    gtk_widget_set_sensitive(menu, sensitive && self->priv->display != NULL &&
+                             VIRT_VIEWER_DISPLAY_CAN_SCREENSHOT(self->priv->display));
 
     menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, "menu-view-zoom"));
     gtk_widget_set_sensitive(menu, sensitive);
 
-    menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, "menu-send"));
-    gtk_widget_set_sensitive(menu, sensitive);
+    {
+        gboolean can_send = sensitive && self->priv->display != NULL &&
+            VIRT_VIEWER_DISPLAY_CAN_SEND_KEYS(self->priv->display);
 
-    gtk_widget_set_sensitive(self->priv->toolbar_send_key, sensitive);
+        menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, "menu-send"));
+        gtk_widget_set_sensitive(menu, can_send);
+
+        gtk_widget_set_sensitive(self->priv->toolbar_send_key, can_send);
+    }
 }
 
 static void
-- 
2.18.0.321.gffc6fa0e39




More information about the virt-tools-list mailing list