Blame SOURCES/0030-window-Allow-to-control-zoom-using-keypad.patch

1efd99
From 400c937247380756ab6fa56593edc07dc5c092fc Mon Sep 17 00:00:00 2001
1efd99
From: Pavel Grunt <pgrunt@redhat.com>
1efd99
Date: Tue, 9 May 2017 13:53:13 +0200
1efd99
Subject: [PATCH virt-viewer 30/32] window: Allow to control zoom using keypad
1efd99
To: virt-tools-list@redhat.com
1efd99
1efd99
Support for more than one key combo for accelerator is available
1efd99
since GTK 3.12 through GAction. It is currently not possible to
1efd99
use mnemonics also for numpad keys, for more info see:
1efd99
 https://bugzilla.gnome.org/show_bug.cgi?id=699823
1efd99
1efd99
Resolves: rhbz#1337575
1efd99
1efd99
Reviewed-by: Victor Toso <victortoso@redhat.com>
1efd99
(cherry picked from commit 701d57742fad8edf40ae53bfcd41f81235fc5d90)
1efd99
---
1efd99
 configure.ac             |  4 ++--
1efd99
 src/virt-viewer-window.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
1efd99
 2 files changed, 58 insertions(+), 2 deletions(-)
1efd99
1efd99
diff --git a/configure.ac b/configure.ac
1efd99
index 3d03687..395659b 100644
1efd99
--- a/configure.ac
1efd99
+++ b/configure.ac
1efd99
@@ -17,8 +17,8 @@ GLIB2_REQUIRED="2.38"
1efd99
 GLIB2_ENCODED_VERSION="GLIB_VERSION_2_38"
1efd99
 
1efd99
 # Keep these two definitions in agreement.
1efd99
-GTK_REQUIRED="3.10"
1efd99
-GTK_ENCODED_VERSION="GDK_VERSION_3_10"
1efd99
+GTK_REQUIRED="3.12"
1efd99
+GTK_ENCODED_VERSION="GDK_VERSION_3_12"
1efd99
 
1efd99
 LIBXML2_REQUIRED="2.6.0"
1efd99
 LIBVIRT_REQUIRED="0.10.0"
1efd99
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
1efd99
index 867a7b0..f5448c6 100644
1efd99
--- a/src/virt-viewer-window.c
1efd99
+++ b/src/virt-viewer-window.c
1efd99
@@ -693,6 +693,45 @@ virt_viewer_window_get_keycombo_menu(VirtViewerWindow *self)
1efd99
     return menu;
1efd99
 }
1efd99
 
1efd99
+static void
1efd99
+action_zoom_in(G_GNUC_UNUSED GSimpleAction *action,
1efd99
+               G_GNUC_UNUSED GVariant *state,
1efd99
+               gpointer user_data)
1efd99
+{
1efd99
+    virt_viewer_window_menu_view_zoom_in(NULL, VIRT_VIEWER_WINDOW(user_data));
1efd99
+}
1efd99
+
1efd99
+static void
1efd99
+action_zoom_out(G_GNUC_UNUSED GSimpleAction *action,
1efd99
+                G_GNUC_UNUSED GVariant *state,
1efd99
+                gpointer user_data)
1efd99
+{
1efd99
+    virt_viewer_window_menu_view_zoom_out(NULL, VIRT_VIEWER_WINDOW(user_data));
1efd99
+}
1efd99
+
1efd99
+static void
1efd99
+action_zoom_reset(G_GNUC_UNUSED GSimpleAction *action,
1efd99
+                  G_GNUC_UNUSED GVariant *state,
1efd99
+                  gpointer user_data)
1efd99
+{
1efd99
+    virt_viewer_window_menu_view_zoom_reset(NULL, VIRT_VIEWER_WINDOW(user_data));
1efd99
+}
1efd99
+
1efd99
+/* Keep keypad_action_entries and keypad_action_accels in sync */
1efd99
+static const GActionEntry keypad_action_entries[] = {
1efd99
+    { .name = "zoom-in", .activate = action_zoom_in },
1efd99
+    { .name = "zoom-out", .activate = action_zoom_out },
1efd99
+    { .name = "zoom-reset", .activate = action_zoom_reset },
1efd99
+};
1efd99
+
1efd99
+static const gchar *const keypad_action_accels[][2] = {
1efd99
+    /* numpad keys are not handled automatically by gtk, see bgo#699823 */
1efd99
+    {"<control>KP_Add", NULL},
1efd99
+    {"<control>KP_Subtract", NULL},
1efd99
+    {"<control>KP_0", NULL},
1efd99
+};
1efd99
+G_STATIC_ASSERT(G_N_ELEMENTS(keypad_action_entries) == G_N_ELEMENTS(keypad_action_accels));
1efd99
+
1efd99
 void
1efd99
 virt_viewer_window_disable_modifiers(VirtViewerWindow *self)
1efd99
 {
1efd99
@@ -700,6 +739,7 @@ virt_viewer_window_disable_modifiers(VirtViewerWindow *self)
1efd99
     VirtViewerWindowPrivate *priv = self->priv;
1efd99
     GValue empty;
1efd99
     GSList *accels;
1efd99
+    guint i;
1efd99
 
1efd99
     if (!priv->accel_enabled)
1efd99
         return;
1efd99
@@ -726,6 +766,10 @@ virt_viewer_window_disable_modifiers(VirtViewerWindow *self)
1efd99
                  "gtk-enable-mnemonics", FALSE,
1efd99
                  NULL);
1efd99
 
1efd99
+    for (i = 0; i < G_N_ELEMENTS(keypad_action_entries); i++) {
1efd99
+        g_action_map_remove_action(G_ACTION_MAP(priv->window), keypad_action_entries[i].name);
1efd99
+    }
1efd99
+
1efd99
     priv->accel_enabled = FALSE;
1efd99
 }
1efd99
 
1efd99
@@ -735,6 +779,7 @@ virt_viewer_window_enable_modifiers(VirtViewerWindow *self)
1efd99
     GtkSettings *settings = gtk_settings_get_default();
1efd99
     VirtViewerWindowPrivate *priv = self->priv;
1efd99
     GSList *accels;
1efd99
+    guint i;
1efd99
 
1efd99
     if (priv->accel_enabled)
1efd99
         return;
1efd99
@@ -755,6 +800,17 @@ virt_viewer_window_enable_modifiers(VirtViewerWindow *self)
1efd99
                  "gtk-enable-mnemonics", priv->enable_mnemonics_save,
1efd99
                  NULL);
1efd99
 
1efd99
+    g_action_map_add_action_entries(G_ACTION_MAP(priv->window),
1efd99
+                                    keypad_action_entries, G_N_ELEMENTS(keypad_action_entries),
1efd99
+                                    self);
1efd99
+    for (i = 0; i < G_N_ELEMENTS(keypad_action_entries); i++) {
1efd99
+        gchar *detailed_name = g_strdup_printf("win.%s", keypad_action_entries[i].name);
1efd99
+        gtk_application_set_accels_for_action(GTK_APPLICATION(priv->app),
1efd99
+                                              detailed_name,
1efd99
+                                              keypad_action_accels[i]);
1efd99
+        g_free(detailed_name);
1efd99
+    }
1efd99
+
1efd99
     priv->accel_enabled = TRUE;
1efd99
 }
1efd99
 
1efd99
-- 
1efd99
2.12.2
1efd99