[gnome-flashback] common: add two getter functions to GfKeybindings
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] common: add two getter functions to GfKeybindings
- Date: Thu, 24 Sep 2015 20:08:48 +0000 (UTC)
commit 308e24aafdf9d701c0f1079dfb2a997e1b4e76ca
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Thu Sep 24 21:46:19 2015 +0300
common: add two getter functions to GfKeybindings
gnome-flashback/libcommon/gf-keybindings.c | 108 ++++++++++++++++++++++++----
gnome-flashback/libcommon/gf-keybindings.h | 16 +++--
2 files changed, 104 insertions(+), 20 deletions(-)
---
diff --git a/gnome-flashback/libcommon/gf-keybindings.c b/gnome-flashback/libcommon/gf-keybindings.c
index b759672..484359e 100644
--- a/gnome-flashback/libcommon/gf-keybindings.c
+++ b/gnome-flashback/libcommon/gf-keybindings.c
@@ -41,11 +41,14 @@ struct _GfKeybindings
typedef struct
{
- const gchar *name;
- guint action;
- guint keyval;
- guint keycode;
- guint modifiers;
+ gchar *name;
+
+ guint action;
+ guint keyval;
+ guint keycode;
+
+ GdkModifierType modifiers;
+ guint real_modifiers;
} Keybinding;
enum
@@ -59,6 +62,57 @@ static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (GfKeybindings, gf_keybindings, G_TYPE_OBJECT)
+static Keybinding *
+keybinding_new (const gchar *name,
+ guint action,
+ guint keyval,
+ guint keycode,
+ GdkModifierType modifiers,
+ guint real_modifiers)
+{
+ Keybinding *keybinding;
+
+ keybinding = g_new0 (Keybinding, 1);
+
+ keybinding->name = g_strdup (name);
+
+ keybinding->action = action;
+ keybinding->keyval = keyval;
+ keybinding->keycode = keycode;
+
+ keybinding->modifiers = modifiers;
+ keybinding->real_modifiers = real_modifiers;
+
+ return keybinding;
+}
+
+static void
+keybinding_free (gpointer data)
+{
+ Keybinding *keybinding;
+
+ keybinding = (Keybinding *) data;
+
+ g_free (keybinding->name);
+
+ g_free (keybinding);
+}
+
+static Keybinding *
+get_keybinding (GfKeybindings *keybindings,
+ guint action)
+{
+ gpointer paction;
+ gpointer pkeybinding;
+ Keybinding *keybinding;
+
+ paction = GUINT_TO_POINTER (action);
+ pkeybinding = g_hash_table_lookup (keybindings->table, paction);
+ keybinding = (Keybinding *) pkeybinding;
+
+ return keybinding;
+}
+
static GVariant *
build_parameters (guint device_id,
guint timestamp,
@@ -111,7 +165,7 @@ filter_func (GdkXEvent *xevent,
state = ev->xkey.state & 0xff & ~(keybindings->ignore_mask);
if (keybinding->keycode == ev->xkey.keycode &&
- keybinding->modifiers == state)
+ keybinding->real_modifiers == state)
{
GVariant *parameters;
@@ -305,7 +359,8 @@ gf_keybindings_init (GfKeybindings *keybindings)
guint num_lock_mask;
guint scroll_lock_mask;
- keybindings->table = g_hash_table_new_full (NULL, NULL, NULL, g_free);
+ keybindings->table = g_hash_table_new_full (NULL, NULL, NULL,
+ keybinding_free);
display = gdk_display_get_default ();
keybindings->xdisplay = gdk_x11_display_get_xdisplay (display);
@@ -388,13 +443,8 @@ gf_keybindings_grab (GfKeybindings *keybindings,
action = get_next_action();
paction = GUINT_TO_POINTER (action);
- keybinding = g_new0 (Keybinding, 1);
-
- keybinding->name = accelerator;
- keybinding->action = action;
- keybinding->keyval = keyval;
- keybinding->keycode = keycode;
- keybinding->modifiers = real_modifiers;
+ keybinding = keybinding_new (accelerator, action, keyval, keycode,
+ modifiers, real_modifiers);
change_keygrab (keybindings, TRUE, keyval, keycode, real_modifiers);
@@ -428,9 +478,37 @@ gf_keybindings_ungrab (GfKeybindings *keybindings,
return FALSE;
change_keygrab (keybindings, FALSE, keybinding->keyval,
- keybinding->keycode, keybinding->modifiers);
+ keybinding->keycode, keybinding->real_modifiers);
g_hash_table_remove (keybindings->table, paction);
return TRUE;
}
+
+guint
+gf_keybindings_get_keyval (GfKeybindings *keybindings,
+ guint action)
+{
+ Keybinding *keybinding;
+
+ keybinding = get_keybinding (keybindings, action);
+
+ if (keybinding == NULL)
+ return 0;
+
+ return keybinding->keyval;
+}
+
+GdkModifierType
+gf_keybindings_get_modifiers (GfKeybindings *keybindings,
+ guint action)
+{
+ Keybinding *keybinding;
+
+ keybinding = get_keybinding (keybindings, action);
+
+ if (keybinding == NULL)
+ return 0;
+
+ return keybinding->modifiers;
+}
diff --git a/gnome-flashback/libcommon/gf-keybindings.h b/gnome-flashback/libcommon/gf-keybindings.h
index 23ce7be..571b89e 100644
--- a/gnome-flashback/libcommon/gf-keybindings.h
+++ b/gnome-flashback/libcommon/gf-keybindings.h
@@ -25,13 +25,19 @@ G_BEGIN_DECLS
#define GF_TYPE_KEYBINDINGS gf_keybindings_get_type ()
G_DECLARE_FINAL_TYPE (GfKeybindings, gf_keybindings, GF, KEYBINDINGS, GObject)
-GfKeybindings *gf_keybindings_new (void);
+GfKeybindings *gf_keybindings_new (void);
-guint gf_keybindings_grab (GfKeybindings *keybindings,
- const gchar *accelerator);
+guint gf_keybindings_grab (GfKeybindings *keybindings,
+ const gchar *accelerator);
-gboolean gf_keybindings_ungrab (GfKeybindings *keybindings,
- guint action);
+gboolean gf_keybindings_ungrab (GfKeybindings *keybindings,
+ guint action);
+
+guint gf_keybindings_get_keyval (GfKeybindings *keybindings,
+ guint action);
+
+GdkModifierType gf_keybindings_get_modifiers (GfKeybindings *keybindings,
+ guint action);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]