[sugar] [PATCH 1/2] Add is_modifier and is_special_modifier functions to SugarKeyGrabber.

Benjamin Berg benjamin
Thu Jun 19 15:06:44 EDT 2008


---

 src/sugar/_sugarext.defs      |   19 +++++++++++++
 src/sugar/sugar-key-grabber.c |   59 +++++++++++++++++++++++++++++++++++++++++
 src/sugar/sugar-key-grabber.h |    6 ++++
 3 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/src/sugar/_sugarext.defs b/src/sugar/_sugarext.defs
index 02b673c..6bc068f 100644
--- a/src/sugar/_sugarext.defs
+++ b/src/sugar/_sugarext.defs
@@ -121,6 +121,25 @@
   )
 )
 
+(define-method is_modifier
+  (of-object "SugarKeyGrabber")
+  (c-name "sugar_key_grabber_is_modifier")
+  (return-type "gboolean")
+  (parameters
+    '("guint" "keycode")
+  )
+)
+
+(define-method is_specific_modifier
+  (of-object "SugarKeyGrabber")
+  (c-name "sugar_key_grabber_is_specific_modifier")
+  (return-type "gboolean")
+  (parameters
+    '("guint" "keycode")
+    '("guint" "mask")
+  )
+)
+
 ;; From sexy-icon-entry.h
 
 (define-function sexy_icon_entry_get_type
diff --git a/src/sugar/sugar-key-grabber.c b/src/sugar/sugar-key-grabber.c
index baddab5..ed0cf9f 100644
--- a/src/sugar/sugar-key-grabber.c
+++ b/src/sugar/sugar-key-grabber.c
@@ -217,3 +217,62 @@ sugar_key_grabber_grab(SugarKeyGrabber *grabber, const char *key)
 
 	grabber->keys = g_list_append(grabber->keys, keyinfo);	
 }
+
+gboolean
+sugar_key_grabber_is_modifier(SugarKeyGrabber *grabber, guint keycode)
+{
+	Display *xdisplay;
+	XModifierKeymap *modmap;
+	gint size, i;
+	gboolean is_modifier = FALSE;
+
+	xdisplay = gdk_x11_drawable_get_xdisplay(GDK_DRAWABLE (grabber->root));
+
+	modmap = XGetModifierMapping (xdisplay);
+	
+	size = 8 * modmap->max_keypermod;
+	for (i = 0; i < size; i++) {
+		if (keycode == modmap->modifiermap[i]) {
+			is_modifier = TRUE;
+			break;
+		}
+	}
+	
+	XFreeModifiermap (modmap);
+	
+	return is_modifier;
+}
+
+
+gboolean
+sugar_key_grabber_is_specific_modifier(SugarKeyGrabber *grabber, guint keycode, guint mask)
+{
+	Display *xdisplay;
+	XModifierKeymap *modmap;
+	gint start, end, i, mod_index;
+	gboolean is_modifier = FALSE;
+
+	xdisplay = gdk_x11_drawable_get_xdisplay(GDK_DRAWABLE (grabber->root));
+
+	modmap = XGetModifierMapping (xdisplay);
+	
+	mod_index = 0;
+	mask = mask >> 1;
+	while (mask != 0) {
+		mask = mask >> 1;
+		mod_index += 1;
+	}
+	
+	start = mod_index * modmap->max_keypermod;
+	end = (mod_index + 1) * modmap->max_keypermod;
+	for (i = start; i < end; i++) {
+		if (keycode == modmap->modifiermap[i]) {
+			is_modifier = TRUE;
+			break;
+		}
+	}
+	
+	XFreeModifiermap (modmap);
+	
+	return is_modifier;
+}
diff --git a/src/sugar/sugar-key-grabber.h b/src/sugar/sugar-key-grabber.h
index 5b734e7..cf6efe2 100644
--- a/src/sugar/sugar-key-grabber.h
+++ b/src/sugar/sugar-key-grabber.h
@@ -60,6 +60,12 @@ void     sugar_key_grabber_grab		(SugarKeyGrabber *grabber,
 char    *sugar_key_grabber_get_key  (SugarKeyGrabber *grabber,
 									 guint            keycode,
 									 guint            state);
+gboolean sugar_key_grabber_is_modifier          (SugarKeyGrabber *grabber,
+                                                 guint            keycode);
+gboolean sugar_key_grabber_is_specific_modifier (SugarKeyGrabber *grabber,
+                                                 guint            keycode,
+                                                 guint            mask);
+
 
 G_END_DECLS
 




More information about the Sugar-devel mailing list