[virt-tools-list] [PATCH virt-viewer 7/9] Use the accelgroup to define key bindings

Marc-André Lureau marcandre.lureau at gmail.com
Wed Feb 15 00:29:58 UTC 2012


With accelgroups, we can redefine the keybindings
---
 src/virt-viewer-app.c    |    5 +++++
 src/virt-viewer-window.c |   22 ++++++++++++++++++++++
 src/virt-viewer.xml      |    1 -
 3 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 540675e..630394c 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -1261,6 +1261,11 @@ virt_viewer_app_constructor (GType gtype,
     priv->main_window = virt_viewer_app_window_new(self, priv->container, 0);
     priv->main_notebook = GTK_WIDGET(virt_viewer_window_get_notebook(priv->main_window));
 
+    gtk_accel_map_add_entry("<virt-viewer>/file/smartcard-insert", GDK_KEY_F8, GDK_SHIFT_MASK);
+    gtk_accel_map_add_entry("<virt-viewer>/file/smartcard-remove", GDK_KEY_F9, GDK_SHIFT_MASK);
+    gtk_accel_map_add_entry("<virt-viewer>/view/fullscreen", GDK_KEY_F11, 0);
+    gtk_accel_map_add_entry("<virt-viewer>/view/release-cursor", GDK_KEY_F12, GDK_SHIFT_MASK);
+
     return obj;
 }
 
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index 7f50e90..5318bff 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -93,6 +93,7 @@ struct _VirtViewerWindowPrivate {
     GtkWidget *window;
     GtkWidget *layout;
     GtkWidget *toolbar;
+    GtkAccelGroup *accel_group;
     VirtViewerNotebook *notebook;
     VirtViewerDisplay *display;
 
@@ -272,6 +273,14 @@ virt_viewer_window_class_init (VirtViewerWindowClass *klass)
                                                         G_PARAM_STATIC_STRINGS));
 }
 
+static gboolean
+can_activate_cb (GtkWidget *widget G_GNUC_UNUSED,
+                 guint signal_id G_GNUC_UNUSED,
+                 VirtViewerWindow *self G_GNUC_UNUSED)
+{
+    return TRUE;
+}
+
 static void
 virt_viewer_window_init (VirtViewerWindow *self)
 {
@@ -295,6 +304,18 @@ virt_viewer_window_init (VirtViewerWindow *self)
 
     gtk_builder_connect_signals(priv->builder, self);
 
+    priv->accel_group = GTK_ACCEL_GROUP(gtk_builder_get_object(priv->builder, "accelgroup"));
+
+    /* make sure they can be activated even if the menu item is not visible */
+    g_signal_connect(gtk_builder_get_object(priv->builder, "menu-view-fullscreen"),
+                     "can-activate-accel", G_CALLBACK(can_activate_cb), self);
+    g_signal_connect(gtk_builder_get_object(priv->builder, "menu-file-smartcard-insert"),
+                     "can-activate-accel", G_CALLBACK(can_activate_cb), self);
+    g_signal_connect(gtk_builder_get_object(priv->builder, "menu-file-smartcard-remove"),
+                     "can-activate-accel", G_CALLBACK(can_activate_cb), self);
+    g_signal_connect(gtk_builder_get_object(priv->builder, "menu-view-release-cursor"),
+                     "can-activate-accel", G_CALLBACK(can_activate_cb), self);
+
     vbox = GTK_WIDGET(gtk_builder_get_object(priv->builder, "viewer-box"));
     virt_viewer_window_toolbar_setup(self);
 
@@ -303,6 +324,7 @@ virt_viewer_window_init (VirtViewerWindow *self)
     gtk_widget_modify_bg(priv->layout, GTK_STATE_NORMAL, &color);
 
     priv->window = GTK_WIDGET(gtk_builder_get_object(priv->builder, "viewer"));
+    gtk_window_add_accel_group(GTK_WINDOW(priv->window), priv->accel_group);
 
     virt_viewer_window_update_title(self);
     gtk_window_set_resizable(GTK_WINDOW(priv->window), TRUE);
diff --git a/src/virt-viewer.xml b/src/virt-viewer.xml
index bef89ac..cce1f0d 100644
--- a/src/virt-viewer.xml
+++ b/src/virt-viewer.xml
@@ -110,7 +110,6 @@
                         <property name="accel_path"><virt-viewer>/view/fullscreen</property>
                         <property name="label" translatable="yes">Full screen</property>
                         <property name="use_underline">True</property>
-                        <accelerator key="F11" signal="activate"/>
                         <signal name="toggled" handler="virt_viewer_window_menu_view_fullscreen" swapped="no"/>
                       </object>
                     </child>
-- 
1.7.7.6




More information about the virt-tools-list mailing list