[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] [PATCH virt-viewer 5/5] Unify configured hotkey behaviour



Whether the hotkeys are set through command line, controller or file, we
should get the same keybinding result (clear unspecified, and enable
global bindings)

However, when started from command line arguments, without --hotkey
argument, it will have basic non-global default bindings.

https://bugzilla.redhat.com/show_bug.cgi?id=1023447
---
 src/virt-viewer-app.c  | 20 +++++++++++++-------
 src/virt-viewer-app.h  |  1 +
 src/virt-viewer-file.c | 10 ++++++----
 3 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 53149e6..cdf6104 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -1764,6 +1764,17 @@ virt_viewer_app_set_direct(VirtViewerApp *self, gboolean direct)
 }
 
 void
+virt_viewer_app_clear_hotkeys(VirtViewerApp *self)
+{
+    /* Disable default bindings and replace them with our own */
+    gtk_accel_map_change_entry("<virt-viewer>/view/toggle-fullscreen", 0, 0, TRUE);
+    gtk_accel_map_change_entry("<virt-viewer>/view/release-cursor", 0, 0, TRUE);
+    gtk_accel_map_change_entry("<virt-viewer>/send/secure-attention", 0, 0, TRUE);
+    virt_viewer_set_insert_smartcard_accel(self, 0, 0);
+    virt_viewer_set_remove_smartcard_accel(self, 0, 0);
+}
+
+void
 virt_viewer_app_set_hotkeys(VirtViewerApp *self, const gchar *hotkeys_str)
 {
     gchar **hotkey, **hotkeys = NULL;
@@ -1779,12 +1790,8 @@ virt_viewer_app_set_hotkeys(VirtViewerApp *self, const gchar *hotkeys_str)
         return;
     }
 
-    /* Disable default bindings and replace them with our own */
-    gtk_accel_map_change_entry("<virt-viewer>/view/toggle-fullscreen", 0, 0, TRUE);
-    gtk_accel_map_change_entry("<virt-viewer>/view/release-cursor", 0, 0, TRUE);
-    gtk_accel_map_change_entry("<virt-viewer>/send/secure-attention", 0, 0, TRUE);
-    virt_viewer_set_insert_smartcard_accel(self, 0, 0);
-    virt_viewer_set_remove_smartcard_accel(self, 0, 0);
+    virt_viewer_app_clear_hotkeys(self);
+    g_object_set(self, "enable-accel", TRUE, NULL);
 
     for (hotkey = hotkeys; *hotkey != NULL; hotkey++) {
         gchar *key = strstr(*hotkey, "=");
@@ -1816,7 +1823,6 @@ virt_viewer_app_set_hotkeys(VirtViewerApp *self, const gchar *hotkeys_str)
     }
     g_strfreev(hotkeys);
 
-    g_object_set(self, "enable-accel", TRUE, NULL);
     virt_viewer_update_smartcard_accels(self);
 }
 
diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
index 4721fe3..f72f5b3 100644
--- a/src/virt-viewer-app.h
+++ b/src/virt-viewer-app.h
@@ -99,6 +99,7 @@ VirtViewerSession* virt_viewer_app_get_session(VirtViewerApp *self);
 gboolean virt_viewer_app_get_fullscreen(VirtViewerApp *app);
 gboolean virt_viewer_app_get_fullscreen_auto_conf(VirtViewerApp *app);
 const GOptionEntry* virt_viewer_app_get_options(void);
+void virt_viewer_app_clear_hotkeys(VirtViewerApp *app);
 
 G_END_DECLS
 
diff --git a/src/virt-viewer-file.c b/src/virt-viewer-file.c
index 3ff8b35..238ffea 100644
--- a/src/virt-viewer-file.c
+++ b/src/virt-viewer-file.c
@@ -595,7 +595,7 @@ virt_viewer_file_set_secure_channels(VirtViewerFile* self, const gchar* const* v
 }
 
 static void
-spice_hotkey_set_accel(VirtViewerApp *app, const gchar *accel_path, const gchar *key)
+spice_hotkey_set_accel(const gchar *accel_path, const gchar *key)
 {
     gchar *accel;
     guint accel_key;
@@ -606,8 +606,6 @@ spice_hotkey_set_accel(VirtViewerApp *app, const gchar *accel_path, const gchar
     g_free(accel);
 
     gtk_accel_map_change_entry(accel_path, accel_key, accel_mods, TRUE);
-
-    g_object_set(G_OBJECT(app), "enable-accel", TRUE, NULL);
 }
 
 gboolean
@@ -636,6 +634,10 @@ virt_viewer_file_fill_app(VirtViewerFile* self, VirtViewerApp *app, GError **err
     if (virt_viewer_file_is_set(self, "title"))
         virt_viewer_app_set_title(app, virt_viewer_file_get_title(self));
 
+
+    virt_viewer_app_clear_hotkeys(app);
+    g_object_set(G_OBJECT(app), "enable-accel", TRUE, NULL);
+
     {
         gchar *val;
         static const struct {
@@ -654,7 +656,7 @@ virt_viewer_file_fill_app(VirtViewerFile* self, VirtViewerApp *app, GError **err
             if (!virt_viewer_file_is_set(self, accels[i].prop))
                 continue;
             g_object_get(self, accels[i].prop, &val, NULL);
-            spice_hotkey_set_accel(app, accels[i].accel, val);
+            spice_hotkey_set_accel(accels[i].accel, val);
             g_free(val);
         }
     }
-- 
1.8.3.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]