Add is_modifier and is_special_modifier functions to SugarKeyGrabber.

This commit is contained in:
Benjamin Berg 2008-06-20 14:46:09 +02:00
parent 3e86ce8b89
commit b781b70107
3 changed files with 52 additions and 0 deletions

View File

@ -121,6 +121,16 @@
)
)
(define-method is_modifier
(of-object "SugarKeyGrabber")
(c-name "sugar_key_grabber_is_modifier")
(return-type "gboolean")
(parameters
'("guint" "keycode")
'("guint" "mask" (default "-1"))
)
)
;; From sexy-icon-entry.h
(define-function sexy_icon_entry_get_type

View File

@ -217,3 +217,42 @@ 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, 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);
if (mask != -1) {
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;
} else {
start = 0;
end = 8 * modmap->max_keypermod;
}
for (i = start; i < end; i++) {
if (keycode == modmap->modifiermap[i]) {
is_modifier = TRUE;
break;
}
}
XFreeModifiermap (modmap);
return is_modifier;
}

View File

@ -60,6 +60,9 @@ 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,
guint mask);
G_END_DECLS