[gnome-terminal/wip/rishi/keypad-accels: 1/2] accels: Support using the '0', '+' and '-' keys from the numeric keypad




commit 811c6d19ed32413d4c6ea9595f81d65ffc6bac4a
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Nov 19 19:25:05 2020 +0100

    accels: Support using the '0', '+' and '-' keys from the numeric keypad
    
    Currently, the default accelerators for zooming (ie., Ctrl+0, Ctrl++
    and Ctrl+-) only work with the alphanumeric keys, not the numeric
    keypad, which can confuse users. From now on, any accelerator that has
    the '0', '+' or '-' key will work with both sets of keys.
    
    https://gitlab.gnome.org/GNOME/gnome-terminal/-/issues/313

 src/terminal-accels.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 2 deletions(-)
---
diff --git a/src/terminal-accels.c b/src/terminal-accels.c
index 333c6d17..d2cd49b4 100644
--- a/src/terminal-accels.c
+++ b/src/terminal-accels.c
@@ -22,6 +22,7 @@
 
 #include <glib.h>
 #include <glib/gi18n.h>
+#include <gdk/gdk.h>
 #include <gtk/gtk.h>
 
 #include "terminal-accels.h"
@@ -258,13 +259,45 @@ binding_name (guint            keyval,
   return g_strdup ("disabled");
 }
 
+static guint
+get_alternate_accel_key (guint key)
+{
+  guint retval = 0;
+
+  switch (key) {
+    case GDK_KEY_0:
+      retval = GDK_KEY_KP_0;
+      break;
+    case GDK_KEY_minus:
+      retval = GDK_KEY_KP_Subtract;
+      break;
+    case GDK_KEY_plus:
+      retval = GDK_KEY_KP_Add;
+      break;
+    case GDK_KEY_KP_0:
+      retval = GDK_KEY_0;
+      break;
+    case GDK_KEY_KP_Add:
+      retval = GDK_KEY_plus;
+      break;
+    case GDK_KEY_KP_Subtract:
+      retval = GDK_KEY_minus;
+      break;
+    default:
+      break;
+  }
+
+  return retval;
+}
+
 static void
 key_changed_cb (GSettings *settings,
                 const char *settings_key,
                 gpointer user_data)
 {
   GtkApplication *application = user_data;
-  const gchar *accels[2] = { NULL, NULL };
+  const gchar *accels[3] = { NULL, NULL, NULL };
+  gsize accels_offset = 0;
 
   _terminal_debug_print (TERMINAL_DEBUG_ACCELS,
                          "key %s changed\n",
@@ -280,6 +313,7 @@ key_changed_cb (GSettings *settings,
     }
 
   gs_free char *value = g_settings_get_string (settings, settings_key);
+  gs_free char *alternate_value = NULL;
 
   gs_free char *detailed = g_action_print_detailed_name (key_entry->action_name,
                                                          key_entry->parameter);
@@ -299,7 +333,20 @@ key_changed_cb (GSettings *settings,
   if (g_str_equal (value, "disabled")) {
     accels[0] = NULL;
   } else {
-    accels[0] = value;
+    accels[accels_offset] = value;
+    accels_offset++;
+
+    GdkModifierType mods;
+    guint key;
+    gtk_accelerator_parse (value, &key, &mods);
+
+    guint alternate_key = get_alternate_accel_key (key);
+
+    if (alternate_key != 0) {
+      alternate_value = gtk_accelerator_name (alternate_key, mods);
+      accels[accels_offset] = alternate_value;
+      accels_offset++;
+    }
   }
 
   gtk_application_set_accels_for_action (application,


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