]> Pileus Git - ~andy/gtk/commitdiff
Fixes for non XKB operation. (#73103)
authorOwen Taylor <otaylor@redhat.com>
Mon, 4 Mar 2002 20:19:04 +0000 (20:19 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Mon, 4 Mar 2002 20:19:04 +0000 (20:19 +0000)
Mon Mar  4 12:43:48 2002  Owen Taylor  <otaylor@redhat.com>

        Fixes for non XKB operation. (#73103)

        * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
        Fix problem where GDK_Tab was converted to GDK_ISO_Left_Tab
        always, not just if Shift was pressed.

        * gdk/x11/gdkkeys-x11.c gdk/x11/gdkprivate-x11.c
        gdk/x11/gdkevents-x11.c: Move determination of group
        to _gdk_x11_get_group_for_state(), fix to handle non-XKB.

        * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): Only
        add in SHIFT_MASK | LOCK_MASK to consumed_modifiers if the shifted
        and unshifted keysyms are different. Only add in group_switch_mask
        if the group-switched and non-group-switched keysyms are diferent.

        * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
        When calling XKeycodeToKeysym, use group * keysyms_per_keycode / 2
        not group * keysyms_per_keycode. (Tor Lillquist)

        * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
        Remove the hack to fudge the return value for GDK_Tab + Shift
        since that didn't work -- it didn't affect the reverse mapping.
        Instead fudge the non-XKB keymap instead.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gdk/x11/gdkevents-x11.c
gdk/x11/gdkkeys-x11.c
gdk/x11/gdkprivate-x11.h

index 5277172def7f7d61545f100381fcc0c55b2d84be..520c25b4e044c201172ffbe7826b26a67ae5df27 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+Mon Mar  4 12:43:48 2002  Owen Taylor  <otaylor@redhat.com>
+
+        Fixes for non XKB operation. (#73103)
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
+       Fix problem where GDK_Tab was converted to GDK_ISO_Left_Tab
+       always, not just if Shift was pressed.
+       
+       * gdk/x11/gdkkeys-x11.c gdk/x11/gdkprivate-x11.c 
+       gdk/x11/gdkevents-x11.c: Move determination of group
+       to _gdk_x11_get_group_for_state(), fix to handle non-XKB.
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): Only
+       add in SHIFT_MASK | LOCK_MASK to consumed_modifiers if the shifted
+       and unshifted keysyms are different. Only add in group_switch_mask
+       if the group-switched and non-group-switched keysyms are diferent.
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): 
+       When calling XKeycodeToKeysym, use group * keysyms_per_keycode / 2
+       not group * keysyms_per_keycode. (Tor Lillquist)
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
+       Remove the hack to fudge the return value for GDK_Tab + Shift
+       since that didn't work -- it didn't affect the reverse mapping.
+       Instead fudge the non-XKB keymap instead.
+
 Mon Mar  4 11:02:18 2002  Owen Taylor  <otaylor@redhat.com>
 
        * gtk/gtkfilesel.c (gtk_file_selection_get_selections): Fix
index 5277172def7f7d61545f100381fcc0c55b2d84be..520c25b4e044c201172ffbe7826b26a67ae5df27 100644 (file)
@@ -1,3 +1,29 @@
+Mon Mar  4 12:43:48 2002  Owen Taylor  <otaylor@redhat.com>
+
+        Fixes for non XKB operation. (#73103)
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
+       Fix problem where GDK_Tab was converted to GDK_ISO_Left_Tab
+       always, not just if Shift was pressed.
+       
+       * gdk/x11/gdkkeys-x11.c gdk/x11/gdkprivate-x11.c 
+       gdk/x11/gdkevents-x11.c: Move determination of group
+       to _gdk_x11_get_group_for_state(), fix to handle non-XKB.
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): Only
+       add in SHIFT_MASK | LOCK_MASK to consumed_modifiers if the shifted
+       and unshifted keysyms are different. Only add in group_switch_mask
+       if the group-switched and non-group-switched keysyms are diferent.
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): 
+       When calling XKeycodeToKeysym, use group * keysyms_per_keycode / 2
+       not group * keysyms_per_keycode. (Tor Lillquist)
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
+       Remove the hack to fudge the return value for GDK_Tab + Shift
+       since that didn't work -- it didn't affect the reverse mapping.
+       Instead fudge the non-XKB keymap instead.
+
 Mon Mar  4 11:02:18 2002  Owen Taylor  <otaylor@redhat.com>
 
        * gtk/gtkfilesel.c (gtk_file_selection_get_selections): Fix
index 5277172def7f7d61545f100381fcc0c55b2d84be..520c25b4e044c201172ffbe7826b26a67ae5df27 100644 (file)
@@ -1,3 +1,29 @@
+Mon Mar  4 12:43:48 2002  Owen Taylor  <otaylor@redhat.com>
+
+        Fixes for non XKB operation. (#73103)
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
+       Fix problem where GDK_Tab was converted to GDK_ISO_Left_Tab
+       always, not just if Shift was pressed.
+       
+       * gdk/x11/gdkkeys-x11.c gdk/x11/gdkprivate-x11.c 
+       gdk/x11/gdkevents-x11.c: Move determination of group
+       to _gdk_x11_get_group_for_state(), fix to handle non-XKB.
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): Only
+       add in SHIFT_MASK | LOCK_MASK to consumed_modifiers if the shifted
+       and unshifted keysyms are different. Only add in group_switch_mask
+       if the group-switched and non-group-switched keysyms are diferent.
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): 
+       When calling XKeycodeToKeysym, use group * keysyms_per_keycode / 2
+       not group * keysyms_per_keycode. (Tor Lillquist)
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
+       Remove the hack to fudge the return value for GDK_Tab + Shift
+       since that didn't work -- it didn't affect the reverse mapping.
+       Instead fudge the non-XKB keymap instead.
+
 Mon Mar  4 11:02:18 2002  Owen Taylor  <otaylor@redhat.com>
 
        * gtk/gtkfilesel.c (gtk_file_selection_get_selections): Fix
index 5277172def7f7d61545f100381fcc0c55b2d84be..520c25b4e044c201172ffbe7826b26a67ae5df27 100644 (file)
@@ -1,3 +1,29 @@
+Mon Mar  4 12:43:48 2002  Owen Taylor  <otaylor@redhat.com>
+
+        Fixes for non XKB operation. (#73103)
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
+       Fix problem where GDK_Tab was converted to GDK_ISO_Left_Tab
+       always, not just if Shift was pressed.
+       
+       * gdk/x11/gdkkeys-x11.c gdk/x11/gdkprivate-x11.c 
+       gdk/x11/gdkevents-x11.c: Move determination of group
+       to _gdk_x11_get_group_for_state(), fix to handle non-XKB.
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): Only
+       add in SHIFT_MASK | LOCK_MASK to consumed_modifiers if the shifted
+       and unshifted keysyms are different. Only add in group_switch_mask
+       if the group-switched and non-group-switched keysyms are diferent.
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): 
+       When calling XKeycodeToKeysym, use group * keysyms_per_keycode / 2
+       not group * keysyms_per_keycode. (Tor Lillquist)
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
+       Remove the hack to fudge the return value for GDK_Tab + Shift
+       since that didn't work -- it didn't affect the reverse mapping.
+       Instead fudge the non-XKB keymap instead.
+
 Mon Mar  4 11:02:18 2002  Owen Taylor  <otaylor@redhat.com>
 
        * gtk/gtkfilesel.c (gtk_file_selection_get_selections): Fix
index 5277172def7f7d61545f100381fcc0c55b2d84be..520c25b4e044c201172ffbe7826b26a67ae5df27 100644 (file)
@@ -1,3 +1,29 @@
+Mon Mar  4 12:43:48 2002  Owen Taylor  <otaylor@redhat.com>
+
+        Fixes for non XKB operation. (#73103)
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
+       Fix problem where GDK_Tab was converted to GDK_ISO_Left_Tab
+       always, not just if Shift was pressed.
+       
+       * gdk/x11/gdkkeys-x11.c gdk/x11/gdkprivate-x11.c 
+       gdk/x11/gdkevents-x11.c: Move determination of group
+       to _gdk_x11_get_group_for_state(), fix to handle non-XKB.
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): Only
+       add in SHIFT_MASK | LOCK_MASK to consumed_modifiers if the shifted
+       and unshifted keysyms are different. Only add in group_switch_mask
+       if the group-switched and non-group-switched keysyms are diferent.
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): 
+       When calling XKeycodeToKeysym, use group * keysyms_per_keycode / 2
+       not group * keysyms_per_keycode. (Tor Lillquist)
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
+       Remove the hack to fudge the return value for GDK_Tab + Shift
+       since that didn't work -- it didn't affect the reverse mapping.
+       Instead fudge the non-XKB keymap instead.
+
 Mon Mar  4 11:02:18 2002  Owen Taylor  <otaylor@redhat.com>
 
        * gtk/gtkfilesel.c (gtk_file_selection_get_selections): Fix
index 5277172def7f7d61545f100381fcc0c55b2d84be..520c25b4e044c201172ffbe7826b26a67ae5df27 100644 (file)
@@ -1,3 +1,29 @@
+Mon Mar  4 12:43:48 2002  Owen Taylor  <otaylor@redhat.com>
+
+        Fixes for non XKB operation. (#73103)
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
+       Fix problem where GDK_Tab was converted to GDK_ISO_Left_Tab
+       always, not just if Shift was pressed.
+       
+       * gdk/x11/gdkkeys-x11.c gdk/x11/gdkprivate-x11.c 
+       gdk/x11/gdkevents-x11.c: Move determination of group
+       to _gdk_x11_get_group_for_state(), fix to handle non-XKB.
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): Only
+       add in SHIFT_MASK | LOCK_MASK to consumed_modifiers if the shifted
+       and unshifted keysyms are different. Only add in group_switch_mask
+       if the group-switched and non-group-switched keysyms are diferent.
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): 
+       When calling XKeycodeToKeysym, use group * keysyms_per_keycode / 2
+       not group * keysyms_per_keycode. (Tor Lillquist)
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
+       Remove the hack to fudge the return value for GDK_Tab + Shift
+       since that didn't work -- it didn't affect the reverse mapping.
+       Instead fudge the non-XKB keymap instead.
+
 Mon Mar  4 11:02:18 2002  Owen Taylor  <otaylor@redhat.com>
 
        * gtk/gtkfilesel.c (gtk_file_selection_get_selections): Fix
index 5277172def7f7d61545f100381fcc0c55b2d84be..520c25b4e044c201172ffbe7826b26a67ae5df27 100644 (file)
@@ -1,3 +1,29 @@
+Mon Mar  4 12:43:48 2002  Owen Taylor  <otaylor@redhat.com>
+
+        Fixes for non XKB operation. (#73103)
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
+       Fix problem where GDK_Tab was converted to GDK_ISO_Left_Tab
+       always, not just if Shift was pressed.
+       
+       * gdk/x11/gdkkeys-x11.c gdk/x11/gdkprivate-x11.c 
+       gdk/x11/gdkevents-x11.c: Move determination of group
+       to _gdk_x11_get_group_for_state(), fix to handle non-XKB.
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): Only
+       add in SHIFT_MASK | LOCK_MASK to consumed_modifiers if the shifted
+       and unshifted keysyms are different. Only add in group_switch_mask
+       if the group-switched and non-group-switched keysyms are diferent.
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): 
+       When calling XKeycodeToKeysym, use group * keysyms_per_keycode / 2
+       not group * keysyms_per_keycode. (Tor Lillquist)
+
+       * gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
+       Remove the hack to fudge the return value for GDK_Tab + Shift
+       since that didn't work -- it didn't affect the reverse mapping.
+       Instead fudge the non-XKB keymap instead.
+
 Mon Mar  4 11:02:18 2002  Owen Taylor  <otaylor@redhat.com>
 
        * gtk/gtkfilesel.c (gtk_file_selection_get_selections): Fix
index babd7e35c8a30d0bbcfd44286efcb6753ab3a8f9..b903cf7b79704bf88f4ed0b23f5caa0ebe653f82 100644 (file)
@@ -619,10 +619,6 @@ gdk_event_translate (GdkEvent *event,
        }
 #endif /* G_ENABLE_DEBUG */
 
-      /* bits 13 and 14 in the "state" field are the keyboard group */
-#define KEYBOARD_GROUP_SHIFT 13
-#define KEYBOARD_GROUP_MASK ((1 << 13) | (1 << 14))
-      
       event->key.type = GDK_KEY_PRESS;
       event->key.window = window;
       event->key.time = xevent->xkey.time;
@@ -630,7 +626,11 @@ gdk_event_translate (GdkEvent *event,
       event->key.string = g_strdup (buf);
       event->key.length = charcount;
 
-      event->key.group = (xevent->xkey.state & KEYBOARD_GROUP_MASK) >> KEYBOARD_GROUP_SHIFT;
+      /* bits 13 and 14 in the "state" field are the keyboard group */
+#define KEYBOARD_GROUP_SHIFT 13
+#define KEYBOARD_GROUP_MASK ((1 << 13) | (1 << 14))
+      
+      event->key.group = _gdk_x11_get_group_for_state (xevent->xkey.state);
       
       break;
       
index 027090f2da9786682b504ace73ba5906e7325465..f80b742abb59439e4a9d31315c43510f35bfea5e 100644 (file)
@@ -115,6 +115,11 @@ gdk_keymap_get_default (void)
   return default_keymap;
 }
 
+/* Find the index of the group/level pair within the keysyms for a key.
+ */
+#define KEYSYM_INDEX(group, level) \
+  (2 * ((group) % (keysyms_per_keycode / 2)) + (level))
+
 static void
 update_keymaps (void)
 {
@@ -129,7 +134,8 @@ update_keymaps (void)
     {
       gint i;
       gint map_size;
-
+      gint keycode;
+      
       current_serial = _gdk_keymap_serial;
 
       update_keyrange ();
@@ -144,6 +150,26 @@ update_keymaps (void)
                                     max_keycode - min_keycode,
                                     &keysyms_per_keycode);
 
+
+      /* GDK_ISO_Left_Tab, as usually configured through XKB, really messes
+       * up the whole idea of "consumed modifiers" because shift is consumed.
+       * However, <shift>Tab is not usually GDK_ISO_Left_Tab without XKB,
+       * we we fudge the map here.
+       */
+      keycode = min_keycode;
+      while (keycode < max_keycode)
+        {
+          KeySym *syms = keymap + (keycode - min_keycode) * keysyms_per_keycode;
+         /* Check both groups */
+         for (i = 0 ; i < 2 ; i++)
+           {
+             if (syms[KEYSYM_INDEX (i, 0)] == GDK_Tab)
+               syms[KEYSYM_INDEX (i, 1)] = GDK_ISO_Left_Tab;
+           }
+          
+          ++keycode;
+        }
+
       mod_keymap = XGetModifierMapping (gdk_display);
 
 
@@ -609,10 +635,9 @@ gdk_keymap_lookup_key (GdkKeymap          *keymap,
   else
 #endif
     {
-      update_keymaps ();
-      
-      return XKeycodeToKeysym (gdk_display, key->keycode,
-                               key->group * keysyms_per_keycode + key->level);
+      const KeySym *map = get_keymap ();
+      const KeySym *syms = map + (key->keycode - min_keycode) * keysyms_per_keycode;
+      return syms [KEYSYM_INDEX (key->group, key->level)];
     }
 }
 
@@ -809,40 +834,68 @@ gdk_keymap_translate_keyboard_state (GdkKeymap       *keymap,
   else
 #endif
     {
+      const KeySym *map = get_keymap ();
+      const KeySym *syms;
       gint shift_level;
+      gboolean ignore_shift = FALSE;
+      gboolean ignore_group = FALSE;
       
-      update_keymaps ();
-
       if ((state & GDK_SHIFT_MASK) &&
           (state & GDK_LOCK_MASK))
-        shift_level = 0; /* shift disables shift lock */
+       shift_level = 0; /* shift disables shift lock */
       else if ((state & GDK_SHIFT_MASK) ||
                (state & GDK_LOCK_MASK))
-        shift_level = 1;
+       shift_level = 1;
       else
-        shift_level = 0;
+       shift_level = 0;
+
+      syms = map + (hardware_keycode - min_keycode) * keysyms_per_keycode;
+
+#define SYM(g,l) syms[KEYSYM_INDEX (g,l)]
+
+      /* Drop group and shift if there are no keysymbols on
+       * the specified key.
+       */
+      if (!SYM (group, shift_level) && SYM (group, 0))
+       {
+         shift_level = 0;
+         ignore_shift = TRUE;
+       }
+      if (!SYM (group, shift_level) && SYM (0, shift_level))
+       {
+         group = 0;
+         ignore_group = TRUE;
+       }
+      if (!SYM (group, shift_level) && SYM (0, 0))
+       {
+         shift_level = 0;
+         group = 0;
+         ignore_group = TRUE;
+         ignore_shift = TRUE;
+       }
+
+      /* See whether the group and shift level actually mattered
+       * to know what to put in consumed_modifiers
+       */
+      if (!SYM (group, 1) ||
+         SYM (group, 0) == SYM (group, 1))
+       ignore_shift = TRUE;
+
+      if (!SYM (1, shift_level) ||
+         SYM (0, shift_level) == SYM (1, shift_level))
+       ignore_group = TRUE;
+
+      tmp_keyval = SYM (group, shift_level);
+
+      tmp_modifiers = ignore_group ? 0 : group_switch_mask;
+      tmp_modifiers |= ignore_shift ? 0 : (GDK_SHIFT_MASK | GDK_LOCK_MASK);
 
-      tmp_keyval = XKeycodeToKeysym (gdk_display, hardware_keycode,
-                                     group * keysyms_per_keycode + shift_level);
-      
-      tmp_modifiers = GDK_SHIFT_MASK | GDK_LOCK_MASK | group_switch_mask;
-      
       if (effective_group)
-        *effective_group = (state & group_switch_mask) ? 1 : 0;
+        *effective_group = group;
 
       if (level)
         *level = shift_level;
-    }
-
-  /* GDK_ISO_Left_Tab, as usually configured through XKB, really messes
-   * up the whole idea of "consumed modifiers" because shift is consumed.
-   * However, <shift>Tab is not _consistently_ GDK_ISO_Left_Tab, so people
-   * can't bind to GDK_ISO_Left_Tab instead. So, we force consistency here.
-   */
-  if (tmp_keyval == GDK_Tab && (tmp_modifiers & GDK_SHIFT_MASK) == 0)
-    {
-      tmp_keyval = GDK_ISO_Left_Tab;
-      tmp_modifiers |= GDK_SHIFT_MASK;
+#undef SYM       
     }
 
   if (consumed_modifiers)
@@ -911,3 +964,19 @@ gdk_keyval_convert_case (guint symbol,
     *upper = xupper;
 }  
 #endif /* HAVE_XCONVERTCASE */
+
+gint
+_gdk_x11_get_group_for_state (GdkModifierType state)
+{
+#ifdef HAVE_XKB
+  if (_gdk_use_xkb)
+    {
+      return XkbGroupForCoreState (state);
+    }
+  else
+#endif
+    {
+      update_keymaps ();
+      return (state & group_switch_mask) ? 1 : 0;
+    }
+}
index 2035e2066f7443dff63ba5dd7e44daedfbefa2e6..b7bb8a6b6bf895a8c597576fa7904dd72071846f 100644 (file)
@@ -160,6 +160,7 @@ void     _gdk_moveresize_handle_event      (XEvent *event);
 void     _gdk_moveresize_configure_done    (void);
 
 void     _gdk_keymap_state_changed         (void);
+gint     _gdk_x11_get_group_for_state      (GdkModifierType state);
 
 GC _gdk_x11_gc_flush (GdkGC *gc);