[gnome-settings-daemon] common: Add helper to parse key strings



commit e3b832d3f34753c7a8c642962fe5948d79cbbbc2
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Nov 1 15:00:16 2011 +0000

    common: Add helper to parse key strings

 plugins/common/gsd-keygrab.c |   28 ++++++++++++++++++++++++++++
 plugins/common/gsd-keygrab.h |    4 ++++
 2 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/plugins/common/gsd-keygrab.c b/plugins/common/gsd-keygrab.c
index 26abe9d..ac37997 100644
--- a/plugins/common/gsd-keygrab.c
+++ b/plugins/common/gsd-keygrab.c
@@ -384,3 +384,31 @@ match_key (Key *key, XEvent *event)
                 && key->state == (event->xkey.state & gsd_used_mods)
                 && key_uses_keycode (key, event->xkey.keycode));
 }
+
+Key *
+parse_key (const char    *str,
+	   EggParseError *error)
+{
+	Key *key;
+	EggParseError ret;
+
+	if (str == NULL ||
+	    *str == '\0' ||
+	    g_str_equal (str, "disabled")) {
+		if (error)
+			*error = EGG_PARSE_ERROR_NONE;
+		return NULL;
+	}
+
+	key = g_new0 (Key, 1);
+	ret = egg_accelerator_parse_virtual (str, &key->keysym, &key->keycodes, &key->state);
+	if (error != NULL)
+		*error = ret;
+
+	if (ret != EGG_PARSE_ERROR_NONE) {
+		g_free (key);
+                return NULL;
+	}
+
+	return key;
+}
diff --git a/plugins/common/gsd-keygrab.h b/plugins/common/gsd-keygrab.h
index 90957b3..8b36576 100644
--- a/plugins/common/gsd-keygrab.h
+++ b/plugins/common/gsd-keygrab.h
@@ -25,6 +25,7 @@ G_BEGIN_DECLS
 #include <glib.h>
 #include <X11/keysym.h>
 #include <X11/extensions/XInput2.h>
+#include <eggaccelerators.h>
 
 typedef struct {
         guint keysym;
@@ -45,6 +46,9 @@ gboolean        match_key       (Key           *key,
 gboolean        key_uses_keycode (const Key *key,
                                   guint keycode);
 
+Key *           parse_key        (const char    *str,
+				  EggParseError *error);
+
 G_END_DECLS
 
 #endif /* __GSD_COMMON_KEYGRAB_H */



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