[virt-tools-list] [PATCH virt-viewer] Grab the focus when showing the display

Marc-André Lureau marcandre.lureau at gmail.com
Fri Feb 3 15:22:00 UTC 2012


Override the grab_focus() method in the display class. Since both VNC
and Spice displays are the direct child, let's just grab the child.
It can be that this behaviour need to be overriden if Spice or VNC
display become more complex (using sub-childs or different objects)
---
 src/virt-viewer-display.c  |   11 +++++++++++
 src/virt-viewer-notebook.c |    1 +
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/src/virt-viewer-display.c b/src/virt-viewer-display.c
index aa91151..665c4f7 100644
--- a/src/virt-viewer-display.c
+++ b/src/virt-viewer-display.c
@@ -63,6 +63,7 @@ static void virt_viewer_display_get_property(GObject *object,
 					     guint prop_id,
 					     GValue *value,
 					     GParamSpec *pspec);
+static void virt_viewer_display_grab_focus(GtkWidget *widget);
 static void set_zoom_level(VirtViewerDisplay *display, guint zoom);
 
 G_DEFINE_ABSTRACT_TYPE(VirtViewerDisplay, virt_viewer_display, GTK_TYPE_BIN)
@@ -94,6 +95,7 @@ virt_viewer_display_class_init(VirtViewerDisplayClass *class)
 	widget_class->size_request = virt_viewer_display_size_request;
 #endif
 	widget_class->size_allocate = virt_viewer_display_size_allocate;
+        widget_class->grab_focus = virt_viewer_display_grab_focus;
 
 	class->set_zoom_level = set_zoom_level;
 
@@ -307,6 +309,15 @@ virt_viewer_display_get_property(GObject *object,
 }
 
 
+static void
+virt_viewer_display_grab_focus(GtkWidget *widget)
+{
+	GtkBin *bin = GTK_BIN(widget);
+
+	gtk_widget_grab_focus(gtk_bin_get_child(bin));
+}
+
+
 static gboolean
 virt_viewer_display_idle(gpointer opaque)
 {
diff --git a/src/virt-viewer-notebook.c b/src/virt-viewer-notebook.c
index fa28593..b4e09ec 100644
--- a/src/virt-viewer-notebook.c
+++ b/src/virt-viewer-notebook.c
@@ -127,6 +127,7 @@ virt_viewer_notebook_show_display(VirtViewerNotebook *self)
 
 	display = gtk_notebook_get_nth_page(GTK_NOTEBOOK(self), 1);
 	g_warn_if_fail(display != NULL);
+	gtk_widget_grab_focus(display);
 
 	gtk_notebook_set_current_page(GTK_NOTEBOOK(self), 1);
 	gtk_widget_show_all(GTK_WIDGET(self));
-- 
1.7.7.6




More information about the virt-tools-list mailing list