[gnome-control-center/wip/gbsneto/new-keyboard-panel: 15/26] keyboard: add helper method for user-friendly accelerators



commit 51691c7c016db9fdbf9d718e7523fca0f1252620
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Jul 22 16:06:18 2016 -0300

    keyboard: add helper method for user-friendly accelerators
    
    The accelerator formatting method itself is copied from
    GtkCellRendererAccel, and will be used throughout the code
    to format the accelerators just like they used to be before
    moving to the listbox.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=769063

 panels/keyboard/keyboard-shortcuts.c |   28 ++++++++++++++++++++++++++++
 panels/keyboard/keyboard-shortcuts.h |    4 ++++
 2 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/panels/keyboard/keyboard-shortcuts.c b/panels/keyboard/keyboard-shortcuts.c
index de09087..0de41f0 100644
--- a/panels/keyboard/keyboard-shortcuts.c
+++ b/panels/keyboard/keyboard-shortcuts.c
@@ -357,3 +357,31 @@ setup_keyboard_options (GtkListStore *store)
                       G_CALLBACK (xkb_option_changed), store);
 }
 
+/*
+ * Stolen from GtkCellRendererAccel:
+ * https://git.gnome.org/browse/gtk+/tree/gtk/gtkcellrendereraccel.c#n261
+ */
+gchar*
+convert_keysym_state_to_string (guint           keysym,
+                                GdkModifierType mask,
+                                guint           keycode)
+{
+  gchar *name;
+
+  if (keysym == 0 && keycode == 0)
+    {
+      /* This label is displayed in a treeview cell displaying
+       * a disabled accelerator key combination.
+       */
+      name = g_strdup (_("Disabled"));
+    }
+  else
+    {
+      name = gtk_accelerator_get_label_with_keycode (NULL, keysym, keycode, mask);
+
+      if (name == NULL)
+        name = gtk_accelerator_name_with_keycode (NULL, keysym, keycode, mask);
+    }
+
+  return name;
+}
diff --git a/panels/keyboard/keyboard-shortcuts.h b/panels/keyboard/keyboard-shortcuts.h
index 6e53d62..0f4c890 100644
--- a/panels/keyboard/keyboard-shortcuts.h
+++ b/panels/keyboard/keyboard-shortcuts.h
@@ -95,3 +95,7 @@ void     parse_start_tag                (GMarkupParseContext  *ctx,
                                          const gchar         **attr_values,
                                          gpointer              user_data,
                                          GError              **error);
+
+gchar*   convert_keysym_state_to_string (guint           keysym,
+                                         GdkModifierType mask,
+                                         guint           keycode);


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