[virt-tools-list] [PATCH virt-viewer] Forward directly key events to display

Marc-André Lureau marcandre.lureau at gmail.com
Thu Mar 21 20:41:29 UTC 2013


Even if the display is disabled, we should keep sending key events to
guest. It can wake up from sleep for instance.

There is a single widget per window, so we can directly send key
events there. If the menu is active, it has the grab, so the window
doesn't receive those key events.

https://bugzilla.redhat.com/show_bug.cgi?id=870710
---
 src/virt-viewer-window.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index f8958a1..ea8c699 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -1097,6 +1097,14 @@ display_show_hint(VirtViewerDisplay *display,
     gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object(self->priv->builder, "menu-file-screenshot")), hint);
     gtk_widget_set_sensitive(self->priv->toolbar_send_key, hint);
 }
+static gboolean
+window_key_pressed (GtkWidget *widget G_GNUC_UNUSED,
+                    GdkEvent  *event,
+                    GtkWidget *display)
+{
+    gtk_widget_grab_focus(display);
+    return gtk_widget_event(display, event);
+}
 
 void
 virt_viewer_window_set_display(VirtViewerWindow *self, VirtViewerDisplay *display)
@@ -1121,6 +1129,10 @@ virt_viewer_window_set_display(VirtViewerWindow *self, VirtViewerDisplay *displa
 
         gtk_widget_show_all(GTK_WIDGET(display));
         gtk_notebook_append_page(GTK_NOTEBOOK(priv->notebook), GTK_WIDGET(display), NULL);
+
+        virt_viewer_signal_connect_object(priv->window, "key-press-event",
+                                          G_CALLBACK(window_key_pressed), display, 0);
+
         /* switch back to non-display if not ready */
         if (!(virt_viewer_display_get_show_hint(display) &
               VIRT_VIEWER_DISPLAY_SHOW_HINT_READY))
-- 
1.8.1.1.439.g50a6b54




More information about the virt-tools-list mailing list