aboutsummaryrefslogtreecommitdiff
path: root/libdbusmenu-gtk/menuitem.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-06-14 14:50:16 -0500
committerTed Gould <ted@gould.cx>2010-06-14 14:50:16 -0500
commit16b5a01c2cb8c4d8ce6216f984c4a06f6aa14c3a (patch)
tree0c1554cd342e915802533d8ac00315a0f277c34b /libdbusmenu-gtk/menuitem.c
parent4ead60b99de627e29d0aae213c622ba10ef72069 (diff)
downloadlibdbusmenu-16b5a01c2cb8c4d8ce6216f984c4a06f6aa14c3a.tar.gz
libdbusmenu-16b5a01c2cb8c4d8ce6216f984c4a06f6aa14c3a.tar.bz2
libdbusmenu-16b5a01c2cb8c4d8ce6216f984c4a06f6aa14c3a.zip
Fleshing out getting the shortcut
Diffstat (limited to 'libdbusmenu-gtk/menuitem.c')
-rw-r--r--libdbusmenu-gtk/menuitem.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c
index a4818ca..f56e9e5 100644
--- a/libdbusmenu-gtk/menuitem.c
+++ b/libdbusmenu-gtk/menuitem.c
@@ -268,7 +268,58 @@ dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, c
void
dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * key, GdkModifierType * modifier)
{
+ *key = 0;
+ *modifier = 0;
+
g_return_if_fail(DBUSMENU_IS_MENUITEM(menuitem));
+ const GValue * wrapper = dbusmenu_menuitem_property_get_value(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT);
+ if (wrapper == NULL) {
+ return;
+ }
+
+ g_return_if_fail(G_VALUE_HOLDS_BOXED(wrapper));
+
+ GPtrArray * wrapperarray = (GPtrArray *)g_value_get_boxed(wrapper);
+ if (wrapperarray->len == 0) {
+ return;
+ }
+
+ if (wrapperarray->len != 1) {
+ g_warning("Shortcut is more than one entry. Which we don't currently support. Taking the first.");
+ }
+
+ GPtrArray * entryarray = g_ptr_array_index(wrapperarray, 0);
+ if (entryarray->len == 0) {
+ /* Seems a little odd, but really, we're saying that it isn't a
+ shortcut, so I'm comfortable with exiting silently. */
+ return;
+ }
+
+ /* Parse through modifiers */
+ int i;
+ for (i = 0; i < entryarray->len - 1; i++) {
+ if (g_strcmp0(g_ptr_array_index(entryarray, i), DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) {
+ *modifier |= GDK_CONTROL_MASK;
+ continue;
+ }
+ if (g_strcmp0(g_ptr_array_index(entryarray, i), DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) {
+ *modifier |= GDK_MOD1_MASK;
+ continue;
+ }
+ if (g_strcmp0(g_ptr_array_index(entryarray, i), DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) {
+ *modifier |= GDK_SHIFT_MASK;
+ continue;
+ }
+ if (g_strcmp0(g_ptr_array_index(entryarray, i), DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) {
+ *modifier |= GDK_SUPER_MASK;
+ continue;
+ }
+ }
+
+ GdkModifierType tempmod;
+
+ gtk_accelerator_parse(g_ptr_array_index(entryarray, entryarray->len - 1), key, &tempmod);
+
return;
}