diff options
author | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2016-07-22 16:06:18 -0300 |
---|---|---|
committer | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2016-07-26 13:03:32 -0300 |
commit | ad818e62875e8773aee77dcba0fdd3cc1cf99bbe (patch) | |
tree | 2c766bcd68a2a22965c047c08dae2d2c563a7c5c | |
parent | a372fba04fb1d374f3ff989db62023f49d7691fc (diff) | |
download | gnome-control-center-ad818e62875e8773aee77dcba0fdd3cc1cf99bbe.tar.gz |
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
-rw-r--r-- | panels/keyboard/keyboard-shortcuts.c | 29 | ||||
-rw-r--r-- | panels/keyboard/keyboard-shortcuts.h | 4 |
2 files changed, 33 insertions, 0 deletions
diff --git a/panels/keyboard/keyboard-shortcuts.c b/panels/keyboard/keyboard-shortcuts.c index 5b59eba90..46e156937 100644 --- a/panels/keyboard/keyboard-shortcuts.c +++ b/panels/keyboard/keyboard-shortcuts.c @@ -397,3 +397,32 @@ parse_keylist_from_file (const gchar *path) return keylist; } + +/* + * 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 4631b3499..ddf864021 100644 --- a/panels/keyboard/keyboard-shortcuts.h +++ b/panels/keyboard/keyboard-shortcuts.h @@ -90,3 +90,7 @@ gboolean is_valid_binding (guint keyval, guint keycode); KeyList* parse_keylist_from_file (const gchar *path); + +gchar* convert_keysym_state_to_string (guint keysym, + GdkModifierType mask, + guint keycode); |