libkeybinder/bind.c
static gboolean
grab_ungrab (GdkWindow *rootwin,
             guint      keyval,
             guint      modifiers,
             gboolean   grab)
{
	int k;
	GdkKeymap *map;
	GdkKeymapKey *keys;
	gint n_keys;
	GdkModifierType add_modifiers = 0;
	XkbDescPtr xmap = NULL;
	gboolean success = FALSE;

	if (!keybinder_supported()) {
		return FALSE;
	}

	if (use_xkb_extension) {
		xmap = XkbGetMap(GDK_WINDOW_XDISPLAY(rootwin),
		                 XkbAllClientInfoMask,
		                 XkbUseCoreKbd);
	}

	map = gdk_keymap_get_default();
	gdk_keymap_get_entries_for_keyval(map, keyval, &keys, &n_keys);

	if (n_keys == 0)
		return FALSE;

	for (k = 0; k < n_keys; k++) {
		/* NOTE: We only bind for the first group,
		 * so regardless of current keyboard layout, it will
		 * grab the key from the default Layout.
		 */
		if (keys[k].group != WE_ONLY_USE_ONE_GROUP) {
			continue;
		}


		TRACE (g_print("grab/ungrab keycode: %d, lev: %d, grp: %d, ",
			keys[k].keycode, keys[k].level, keys[k].group));
		if (use_xkb_extension) {
			add_modifiers = FinallyGetModifiersForKeycode(xmap,
		                                              keys[k].keycode,
		                                              keys[k].group,
		                                              keys[k].level);
		} else if (keys[k].level > 0) {
			/* skip shifted/modified keys in non-xkb mode
			 * this might mean the key can't be bound at all
			 */
			continue;
		}

		if (add_modifiers == MODIFIERS_ERROR) {
			continue;
		}
		TRACE (g_print("modifiers: 0x%x (consumed: 0x%x)\n",
		               add_modifiers | modifiers, add_modifiers));
		if (grab_ungrab_with_ignorable_modifiers(rootwin,
		                                         keys[k].keycode,
		                                         add_modifiers | modifiers,
		                                         grab)) {

			success = TRUE;
		} else {
			/* When grabbing, break on error */
			if (grab && !success) {
				break;
			}
		}

	}
	g_free(keys);
	if (xmap) {
		XkbFreeKeyboard(xmap, 0, TRUE);
	}

	return success;
}
/* Grab or ungrab then keyval and modifiers combination, grabbing all key
 * combinations yielding the same key values.
 * Includes ignorable modifiers using grab_ungrab_with_ignorable_modifiers.
 */
Grab or ungrab then keyval and modifiers combination, grabbing all key
combinations yielding the same key values.
Includes ignorable modifiers using grab_ungrab_with_ignorable_modifiers.
Grab or ungrab then keyval and modifiers combination grabbing all key combinations yielding the same key values . Includes ignorable modifiers using grab_ungrab_with_ignorable_modifiers .
static gboolean
grab_ungrab (GdkWindow *rootwin,
             guint      keyval,
             guint      modifiers,
             gboolean   grab)
{
	int k;
	GdkKeymap *map;
	GdkKeymapKey *keys;
	gint n_keys;
	GdkModifierType add_modifiers = 0;
	XkbDescPtr xmap = NULL;
	gboolean success = FALSE;
	if (!keybinder_supported()) {
		return FALSE;
	}
	if (use_xkb_extension) {
		xmap = XkbGetMap(GDK_WINDOW_XDISPLAY(rootwin),
		                 XkbAllClientInfoMask,
		                 XkbUseCoreKbd);
	}
	map = gdk_keymap_get_default();
	gdk_keymap_get_entries_for_keyval(map, keyval, &keys, &n_keys);
	if (n_keys == 0)
		return FALSE;
	for (k = 0; k < n_keys; k++) {
		if (keys[k].group != WE_ONLY_USE_ONE_GROUP) {
			continue;
		}
		TRACE (g_print("grab/ungrab keycode: %d, lev: %d, grp: %d, ",
			keys[k].keycode, keys[k].level, keys[k].group));
		if (use_xkb_extension) {
			add_modifiers = FinallyGetModifiersForKeycode(xmap,
		                                              keys[k].keycode,
		                                              keys[k].group,
		                                              keys[k].level);
		} else if (keys[k].level > 0) {
			continue;
		}
		if (add_modifiers == MODIFIERS_ERROR) {
			continue;
		}
		TRACE (g_print("modifiers: 0x%x (consumed: 0x%x)\n",
		               add_modifiers | modifiers, add_modifiers));
		if (grab_ungrab_with_ignorable_modifiers(rootwin,
		                                         keys[k].keycode,
		                                         add_modifiers | modifiers,
		                                         grab)) {
			success = TRUE;
		} else {
			if (grab && !success) {
				break;
			}
		}
	}
	g_free(keys);
	if (xmap) {
		XkbFreeKeyboard(xmap, 0, TRUE);
	}
	return success;
}
static gboolean grab_ungrab ( GdkWindow * rootwin , guint keyval , guint modifiers , gboolean grab ) { int k ; GdkKeymap * map ; GdkKeymapKey * keys ; gint n_keys ; GdkModifierType add_modifiers = 0 ; XkbDescPtr xmap = NULL ; gboolean success = FALSE ; if ( ! keybinder_supported ( ) ) { return FALSE ; } if ( use_xkb_extension ) { xmap = XkbGetMap ( GDK_WINDOW_XDISPLAY ( rootwin ) , XkbAllClientInfoMask , XkbUseCoreKbd ) ; } map = gdk_keymap_get_default ( ) ; gdk_keymap_get_entries_for_keyval ( map , keyval , & keys , & n_keys ) ; if ( n_keys == 0 ) return FALSE ; for ( k = 0 ; k < n_keys ; k ++ ) { if ( keys [ k ] . group != WE_ONLY_USE_ONE_GROUP ) { continue ; } TRACE ( g_print ( " " , keys [ k ] . keycode , keys [ k ] . level , keys [ k ] . group ) ) ; if ( use_xkb_extension ) { add_modifiers = FinallyGetModifiersForKeycode ( xmap , keys [ k ] . keycode , keys [ k ] . group , keys [ k ] . level ) ; } else if ( keys [ k ] . level > 0 ) { continue ; } if ( add_modifiers == MODIFIERS_ERROR ) { continue ; } TRACE ( g_print ( " \n " , add_modifiers | modifiers , add_modifiers ) ) ; if ( grab_ungrab_with_ignorable_modifiers ( rootwin , keys [ k ] . keycode , add_modifiers | modifiers , grab ) ) { success = TRUE ; } else { if ( grab && ! success ) { break ; } } } g_free ( keys ) ; if ( xmap ) { XkbFreeKeyboard ( xmap , 0 , TRUE ) ; } return success ; }
Grab or ungrab then keyval and modifiers combination, grabbing all key
 combinations yielding the same key values.
Grab or ungrab then keyval and modifiers combination grabbing all key combinations yielding the same key values .
/* NOTE: We only bind for the first group,
		 * so regardless of current keyboard layout, it will
		 * grab the key from the default Layout.
		 */ /* skip shifted/modified keys in non-xkb mode
			 * this might mean the key can't be bound at all
			 */ /* When grabbing, break on error */