gnome-settings-daemon r239 - in trunk: . plugins/keybindings
- From: jensg svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-settings-daemon r239 - in trunk: . plugins/keybindings
- Date: Sat, 29 Mar 2008 12:00:13 +0000 (GMT)
Author: jensg
Date: Sat Mar 29 12:00:13 2008
New Revision: 239
URL: http://svn.gnome.org/viewvc/gnome-settings-daemon?rev=239&view=rev
Log:
2008-03-29 Jens Granseuer <jensgr gmx net>
* plugins/keybindings/eggaccelerators.c:
(egg_accelerator_parse_virtual), (egg_virtual_accelerator_name),
(egg_virtual_accelerator_label),
(egg_keymap_resolve_virtual_modifiers),
(egg_keymap_virtualize_modifiers), (reload_modmap),
(egg_keymap_get_modmap):
* plugins/keybindings/eggaccelerators.h: fix mismatched modifier
mapping between egg and GTK (so that e.g. <Super> works) and replace
some custom functionality with stock GTK
Modified:
trunk/ChangeLog
trunk/plugins/keybindings/eggaccelerators.c
trunk/plugins/keybindings/eggaccelerators.h
Modified: trunk/plugins/keybindings/eggaccelerators.c
==============================================================================
--- trunk/plugins/keybindings/eggaccelerators.c (original)
+++ trunk/plugins/keybindings/eggaccelerators.c Sat Mar 29 12:00:13 2008
@@ -24,6 +24,7 @@
#include <string.h>
#include <gdk/gdkx.h>
#include <gdk/gdkkeysyms.h>
+#include <gtk/gtkaccelgroup.h>
enum
{
@@ -205,7 +206,7 @@
* can represent various keyboard keys (numlock, meta, hyper, etc.),
* the virtual modifier represents the keyboard key, the concrete
* modifier the actual Mod2-Mod5 bits in the key press event.
- *
+ *
* Returns: %TRUE on success.
*/
gboolean
@@ -218,7 +219,7 @@
GdkModifierType mods;
gint len;
gboolean bad_keyval;
-
+
if (accelerator_key)
*accelerator_key = 0;
if (accelerator_mods)
@@ -229,7 +230,7 @@
g_return_val_if_fail (accelerator != NULL, FALSE);
bad_keyval = FALSE;
-
+
keyval = 0;
mods = 0;
len = strlen (accelerator);
@@ -312,7 +313,7 @@
else
{
gchar last_ch;
-
+
last_ch = *accelerator;
while (last_ch && last_ch != '>')
{
@@ -328,7 +329,7 @@
if (keyval == 0)
{
- /* If keyval is 0, than maybe it's a keycode. Check for 0x## */
+ /* If keyval is 0, then maybe it's a keycode. Check for 0x## */
if (len >= 4 && is_keycode (accelerator))
{
char keystring[5];
@@ -344,7 +345,7 @@
{
bad_keyval = TRUE;
}
- else if (keycode != NULL)
+ else
{
*keycode = tmp_keycode;
/* 0x00 is an invalid keycode too. */
@@ -352,17 +353,13 @@
bad_keyval = TRUE;
}
}
- } else if (keycode != NULL) {
- *keycode = XKeysymToKeycode (GDK_DISPLAY(), keyval);
- if (*keycode == 0)
- bad_keyval = TRUE;
}
accelerator += len;
len -= len;
}
}
-
+
if (accelerator_key)
*accelerator_key = gdk_keyval_to_lower (keyval);
if (accelerator_mods)
@@ -371,13 +368,12 @@
return !bad_keyval;
}
-
/**
* egg_virtual_accelerator_name:
* @accelerator_key: accelerator keyval
* @accelerator_mods: accelerator modifier mask
* @returns: a newly-allocated accelerator name
- *
+ *
* Converts an accelerator keyval and modifier mask
* into a string parseable by egg_accelerator_parse_virtual().
* For example, if you pass in #GDK_q and #EGG_VIRTUAL_CONTROL_MASK,
@@ -390,122 +386,57 @@
guint keycode,
EggVirtualModifierType accelerator_mods)
{
- static const gchar text_release[] = "<Release>";
- static const gchar text_shift[] = "<Shift>";
- static const gchar text_control[] = "<Control>";
- static const gchar text_mod1[] = "<Alt>";
- static const gchar text_mod2[] = "<Mod2>";
- static const gchar text_mod3[] = "<Mod3>";
- static const gchar text_mod4[] = "<Mod4>";
- static const gchar text_mod5[] = "<Mod5>";
- static const gchar text_meta[] = "<Meta>";
- static const gchar text_super[] = "<Super>";
- static const gchar text_hyper[] = "<Hyper>";
- guint l;
- gchar *keyval_name;
- gchar *accelerator;
+ gchar *gtk_name;
+ GdkModifierType gdkmods = 0;
- accelerator_mods &= EGG_VIRTUAL_MODIFIER_MASK;
+ egg_keymap_resolve_virtual_modifiers (NULL, accelerator_mods, &gdkmods);
+ gtk_name = gtk_accelerator_name (accelerator_key, gdkmods);
if (!accelerator_key)
{
- keyval_name = g_strdup_printf ("0x%02x", keycode);
- }
- else
- {
- keyval_name = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
- if (!keyval_name)
- keyval_name = "";
+ gchar *name;
+ name = g_strdup_printf ("%s0x%02x", gtk_name, keycode);
+ g_free (gtk_name);
+ return name;
}
- l = 0;
- if (accelerator_mods & EGG_VIRTUAL_RELEASE_MASK)
- l += sizeof (text_release) - 1;
- if (accelerator_mods & EGG_VIRTUAL_SHIFT_MASK)
- l += sizeof (text_shift) - 1;
- if (accelerator_mods & EGG_VIRTUAL_CONTROL_MASK)
- l += sizeof (text_control) - 1;
- if (accelerator_mods & EGG_VIRTUAL_ALT_MASK)
- l += sizeof (text_mod1) - 1;
- if (accelerator_mods & EGG_VIRTUAL_MOD2_MASK)
- l += sizeof (text_mod2) - 1;
- if (accelerator_mods & EGG_VIRTUAL_MOD3_MASK)
- l += sizeof (text_mod3) - 1;
- if (accelerator_mods & EGG_VIRTUAL_MOD4_MASK)
- l += sizeof (text_mod4) - 1;
- if (accelerator_mods & EGG_VIRTUAL_MOD5_MASK)
- l += sizeof (text_mod5) - 1;
- if (accelerator_mods & EGG_VIRTUAL_META_MASK)
- l += sizeof (text_meta) - 1;
- if (accelerator_mods & EGG_VIRTUAL_HYPER_MASK)
- l += sizeof (text_hyper) - 1;
- if (accelerator_mods & EGG_VIRTUAL_SUPER_MASK)
- l += sizeof (text_super) - 1;
- l += strlen (keyval_name);
-
- accelerator = g_new (gchar, l + 1);
-
- l = 0;
- accelerator[l] = 0;
- if (accelerator_mods & EGG_VIRTUAL_RELEASE_MASK)
- {
- strcpy (accelerator + l, text_release);
- l += sizeof (text_release) - 1;
- }
- if (accelerator_mods & EGG_VIRTUAL_SHIFT_MASK)
- {
- strcpy (accelerator + l, text_shift);
- l += sizeof (text_shift) - 1;
- }
- if (accelerator_mods & EGG_VIRTUAL_CONTROL_MASK)
- {
- strcpy (accelerator + l, text_control);
- l += sizeof (text_control) - 1;
- }
- if (accelerator_mods & EGG_VIRTUAL_ALT_MASK)
- {
- strcpy (accelerator + l, text_mod1);
- l += sizeof (text_mod1) - 1;
- }
- if (accelerator_mods & EGG_VIRTUAL_MOD2_MASK)
- {
- strcpy (accelerator + l, text_mod2);
- l += sizeof (text_mod2) - 1;
- }
- if (accelerator_mods & EGG_VIRTUAL_MOD3_MASK)
- {
- strcpy (accelerator + l, text_mod3);
- l += sizeof (text_mod3) - 1;
- }
- if (accelerator_mods & EGG_VIRTUAL_MOD4_MASK)
- {
- strcpy (accelerator + l, text_mod4);
- l += sizeof (text_mod4) - 1;
- }
- if (accelerator_mods & EGG_VIRTUAL_MOD5_MASK)
- {
- strcpy (accelerator + l, text_mod5);
- l += sizeof (text_mod5) - 1;
- }
- if (accelerator_mods & EGG_VIRTUAL_META_MASK)
- {
- strcpy (accelerator + l, text_meta);
- l += sizeof (text_meta) - 1;
- }
- if (accelerator_mods & EGG_VIRTUAL_HYPER_MASK)
- {
- strcpy (accelerator + l, text_hyper);
- l += sizeof (text_hyper) - 1;
- }
- if (accelerator_mods & EGG_VIRTUAL_SUPER_MASK)
+ return gtk_name;
+}
+
+/**
+ * egg_virtual_accelerator_label:
+ * @accelerator_key: accelerator keyval
+ * @accelerator_mods: accelerator modifier mask
+ * @returns: a newly-allocated accelerator label
+ *
+ * Converts an accelerator keyval and modifier mask
+ * into a (possibly translated) string that can be displayed to
+ * a user.
+ * For example, if you pass in #GDK_q and #EGG_VIRTUAL_CONTROL_MASK,
+ * and you use a German locale, this function returns "Strg+Q".
+ *
+ * The caller of this function must free the returned string.
+ */
+gchar*
+egg_virtual_accelerator_label (guint accelerator_key,
+ guint keycode,
+ EggVirtualModifierType accelerator_mods)
+{
+ gchar *gtk_label;
+ GdkModifierType gdkmods = 0;
+
+ egg_keymap_resolve_virtual_modifiers (NULL, accelerator_mods, &gdkmods);
+ gtk_label = gtk_accelerator_get_label (accelerator_key, gdkmods);
+
+ if (!accelerator_key)
{
- strcpy (accelerator + l, text_super);
- l += sizeof (text_super) - 1;
+ gchar *label;
+ label = g_strdup_printf ("%s0x%02x", gtk_label, keycode);
+ g_free (gtk_label);
+ return label;
}
-
- strcpy (accelerator + l, keyval_name);
- return accelerator;
+ return gtk_label;
}
void
@@ -517,21 +448,18 @@
int i;
const EggModmap *modmap;
- g_return_if_fail (GDK_IS_KEYMAP (keymap));
g_return_if_fail (concrete_mods != NULL);
-
+ g_return_if_fail (keymap == NULL || GDK_IS_KEYMAP (keymap));
+
modmap = egg_keymap_get_modmap (keymap);
-
+
/* Not so sure about this algorithm. */
-
+
concrete = 0;
- i = 0;
- while (i < EGG_MODMAP_ENTRY_LAST)
+ for (i = 0; i < EGG_MODMAP_ENTRY_LAST; ++i)
{
if (modmap->mapping[i] & virtual_mods)
- concrete |= (1 << i);
-
- ++i;
+ concrete |= MODMAP_ENTRY_TO_MODIFIER (i);
}
*concrete_mods = concrete;
@@ -545,27 +473,26 @@
GdkModifierType virtual;
int i;
const EggModmap *modmap;
-
- g_return_if_fail (GDK_IS_KEYMAP (keymap));
+
g_return_if_fail (virtual_mods != NULL);
+ g_return_if_fail (keymap == NULL || GDK_IS_KEYMAP (keymap));
modmap = egg_keymap_get_modmap (keymap);
-
+
/* Not so sure about this algorithm. */
-
+
virtual = 0;
- i = 0;
- while (i < EGG_MODMAP_ENTRY_LAST)
+ for (i = 0; i < EGG_MODMAP_ENTRY_LAST; ++i)
{
- if ((1 << i) & concrete_mods)
+ if (MODMAP_ENTRY_TO_MODIFIER (i) & concrete_mods)
{
EggVirtualModifierType cleaned;
-
+
cleaned = modmap->mapping[i] & ~(EGG_VIRTUAL_MOD2_MASK |
EGG_VIRTUAL_MOD3_MASK |
EGG_VIRTUAL_MOD4_MASK |
EGG_VIRTUAL_MOD5_MASK);
-
+
if (cleaned != 0)
{
virtual |= cleaned;
@@ -578,10 +505,8 @@
virtual |= modmap->mapping[i];
}
}
-
- ++i;
}
-
+
*virtual_mods = virtual;
}
@@ -597,13 +522,12 @@
xmodmap = XGetModifierMapping (gdk_x11_get_default_xdisplay ());
memset (modmap->mapping, 0, sizeof (modmap->mapping));
-
- /* there are 8 modifiers, and the first 3 are shift, shift lock,
- * and control
+
+ /* there are 8 modifiers in the order shift, shift lock,
+ * control, mod1-5 with up to max_keypermod bindings each
*/
map_size = 8 * xmodmap->max_keypermod;
- i = 3 * xmodmap->max_keypermod;
- while (i < map_size)
+ for (i = 3 * xmodmap->max_keypermod; i < map_size; ++i)
{
/* get the key code at this point in the map,
* see if its keysym is one we're interested in
@@ -614,7 +538,7 @@
int n_entries;
int j;
EggVirtualModifierType mask;
-
+
keys = NULL;
keyvals = NULL;
n_entries = 0;
@@ -622,11 +546,10 @@
gdk_keymap_get_entries_for_keycode (keymap,
keycode,
&keys, &keyvals, &n_entries);
-
+
mask = 0;
- j = 0;
- while (j < n_entries)
- {
+ for (j = 0; j < n_entries; ++j)
+ {
if (keyvals[j] == GDK_Num_Lock)
mask |= EGG_VIRTUAL_NUM_LOCK_MASK;
else if (keyvals[j] == GDK_Scroll_Lock)
@@ -642,20 +565,16 @@
mask |= EGG_VIRTUAL_SUPER_MASK;
else if (keyvals[j] == GDK_Mode_switch)
mask |= EGG_VIRTUAL_MODE_SWITCH_MASK;
-
- ++j;
}
/* Mod1Mask is 1 << 3 for example, i.e. the
* fourth modifier, i / keyspermod is the modifier
* index
- */
+ */
modmap->mapping[i/xmodmap->max_keypermod] |= mask;
-
+
g_free (keyvals);
- g_free (keys);
-
- ++i;
+ g_free (keys);
}
/* Add in the not-really-virtual fixed entries */
@@ -667,7 +586,7 @@
modmap->mapping[EGG_MODMAP_ENTRY_MOD3] |= EGG_VIRTUAL_MOD3_MASK;
modmap->mapping[EGG_MODMAP_ENTRY_MOD4] |= EGG_VIRTUAL_MOD4_MASK;
modmap->mapping[EGG_MODMAP_ENTRY_MOD5] |= EGG_VIRTUAL_MOD5_MASK;
-
+
XFreeModifiermap (xmodmap);
}
@@ -676,12 +595,14 @@
{
EggModmap *modmap;
+ if (keymap == NULL)
+ keymap = gdk_keymap_get_default ();
+
/* This is all a hack, much simpler when we can just
* modify GDK directly.
*/
-
- modmap = g_object_get_data (G_OBJECT (keymap),
- "egg-modmap");
+
+ modmap = g_object_get_data (G_OBJECT (keymap), "egg-modmap");
if (modmap == NULL)
{
@@ -690,9 +611,9 @@
/* FIXME modify keymap change events with an event filter
* and force a reload if we get one
*/
-
+
reload_modmap (keymap, modmap);
-
+
g_object_set_data_full (G_OBJECT (keymap),
"egg-modmap",
modmap,
@@ -700,6 +621,6 @@
}
g_assert (modmap != NULL);
-
+
return modmap;
}
Modified: trunk/plugins/keybindings/eggaccelerators.h
==============================================================================
--- trunk/plugins/keybindings/eggaccelerators.h (original)
+++ trunk/plugins/keybindings/eggaccelerators.h Sat Mar 29 12:00:13 2008
@@ -36,7 +36,7 @@
EGG_VIRTUAL_CONTROL_MASK = 1 << 2,
EGG_VIRTUAL_ALT_MASK = 1 << 3, /* fixed as Mod1 */
-
+
EGG_VIRTUAL_MOD2_MASK = 1 << 4,
EGG_VIRTUAL_MOD3_MASK = 1 << 5,
EGG_VIRTUAL_MOD4_MASK = 1 << 6,
@@ -50,21 +50,23 @@
GDK_BUTTON5_MASK = 1 << 12,
/* 13, 14 are used by Xkb for the keyboard group */
#endif
-
- EGG_VIRTUAL_META_MASK = 1 << 24,
- EGG_VIRTUAL_SUPER_MASK = 1 << 25,
- EGG_VIRTUAL_HYPER_MASK = 1 << 26,
- EGG_VIRTUAL_MODE_SWITCH_MASK = 1 << 27,
- EGG_VIRTUAL_NUM_LOCK_MASK = 1 << 28,
- EGG_VIRTUAL_SCROLL_LOCK_MASK = 1 << 29,
+
+ EGG_VIRTUAL_MODE_SWITCH_MASK = 1 << 23,
+ EGG_VIRTUAL_NUM_LOCK_MASK = 1 << 24,
+ EGG_VIRTUAL_SCROLL_LOCK_MASK = 1 << 25,
+
+ /* Also in GdkModifierType */
+ EGG_VIRTUAL_SUPER_MASK = 1 << 26,
+ EGG_VIRTUAL_HYPER_MASK = 1 << 27,
+ EGG_VIRTUAL_META_MASK = 1 << 28,
/* Also in GdkModifierType */
EGG_VIRTUAL_RELEASE_MASK = 1 << 30,
/* 28-31 24-27 20-23 16-19 12-15 8-11 4-7 0-3
- * 7 f 0 0 0 0 f f
- */
- EGG_VIRTUAL_MODIFIER_MASK = 0x7f0000ff
+ * 5 f 8 0 0 0 f f
+ */
+ EGG_VIRTUAL_MODIFIER_MASK = 0x5f8000ff
} EggVirtualModifierType;
@@ -83,6 +85,10 @@
guint keycode,
EggVirtualModifierType accelerator_mods);
+gchar* egg_virtual_accelerator_label (guint accelerator_key,
+ guint keycode,
+ EggVirtualModifierType accelerator_mods);
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]