[uim-commit] r2938 - in trunk: gtk helper

ekato at freedesktop.org ekato at freedesktop.org
Wed Jan 18 07:38:56 PST 2006


Author: ekato
Date: 2006-01-18 07:38:52 -0800 (Wed, 18 Jan 2006)
New Revision: 2938

Added:
   trunk/gtk/key-util-gtk.c
   trunk/gtk/key-util-gtk.h
Modified:
   trunk/gtk/Makefile.am
   trunk/gtk/gtk-im-uim.c
   trunk/helper/Makefile.am
   trunk/helper/pref-gtk-custom-widgets.c
   trunk/helper/pref-gtk.c
Log:
* gtk/gtk-im-uim.c : Include "key-util-gtk.h" for converting gdk's
  key to uim's key.
(convert_keyval) : Removed.
(convert_modifier) : Ditto.
(filter_keypress) : Use im_uim_convert_keyevent() instead of
  convert_keyval() and convert_modifier().
(uim_key_snoop) : Ditto.
(im_module_init) : Initialize modifier mappings with
  im_uim_init_modifier_keys().
* gtk/key-util-gtk.c : New file.
(im_uim_convert_keyevent) : New.  Reorganized from
  convert_keyval() and convert_modifier() in gtk-im-uim.c.  If
  compiled with gdk-x11, it treats MOD[1-5] modifier keys
  according to X11's keysym.
(check_modifier) : Utility for converting X keysym to uim's
  modifier key.
(im_uim_init_modifier_keys) : New.  Initialize modifier mappings
  if compiled with gdk-x11.
* gtk/key-util-gtk.h : New file.
* gtk/Makefile.am : Add key-util-gtk.c and key-util-gtk.h into
  IM_UIM_SOURCES.

* helper/pref-gtk.c : Include "key-util-gtk.h" for using
  im_uim_init_modifier_keys().
(main) : Initialize modifier key mappings.
* helper/pref-gtk-custom-widgets.c : Include "key-util-gtk.h" for
  converting gdk's key to uim's key.
(KeyPrefWin) : Change types of grabbed_key_val and
  grabbed_key_state from guint to gint.
(key_pref_set_value) : Change argument as uim's key value and
  modifier value instead of gdk's values, and handle "Meta",
  "Super", and "Hyper" modifiers.
(grab_win_key_press_cb) : Convert gdk's key into uim's key and
  put these values into key_pref_win.grabbed_key_{val,state}.
(grab_win_key_release_cb) : Call im_uim_convert_keyevent() on
  key release event.
(key_choose_entry_key_press_cb) : Convert gdk's key to uim's
  before key_pref_set_value().
(key_choose_entry_key_release_cb) : New.  Call
  im_uim_convert_keyevent() on key release.
(choose_key_clicked_cb) : Connect key release event of key_entry.
* helper/Makefile.am : Add gtk/key-util-gtk.{c,h} into
  uim_pref_gtk_SOURCES.


Modified: trunk/gtk/Makefile.am
===================================================================
--- trunk/gtk/Makefile.am	2006-01-18 02:27:17 UTC (rev 2937)
+++ trunk/gtk/Makefile.am	2006-01-18 15:38:52 UTC (rev 2938)
@@ -16,7 +16,7 @@
 
 
 IM_UIM_SOURCES = \
-	gtk-im-uim.c \
+	gtk-im-uim.c key-util-gtk.c key-util-gtk.h \
 	uim-cand-win-gtk.c uim-cand-win-gtk.h \
 	caret-state-indicator.c caret-state-indicator.h
 

Modified: trunk/gtk/gtk-im-uim.c
===================================================================
--- trunk/gtk/gtk-im-uim.c	2006-01-18 02:27:17 UTC (rev 2937)
+++ trunk/gtk/gtk-im-uim.c	2006-01-18 15:38:52 UTC (rev 2938)
@@ -52,8 +52,10 @@
 #include "uim/uim-im-switcher.h"
 #include "uim/gettext.h"
 #include "uim/uim-compat-scm.h"
+
 #include "uim-cand-win-gtk.h"
 #include "caret-state-indicator.h"
+#include "key-util-gtk.h"
 
 /* exported symbols */
 GtkIMContext *im_module_create(const gchar *context_id);
@@ -232,78 +234,6 @@
   uic->prev_preedit_len = preedit_len;
 }
 
-static int
-convert_keyval(int key)
-{
-  switch (key) {
-  case GDK_BackSpace: return UKey_Backspace;
-  case GDK_Delete: return UKey_Delete;
-  case GDK_Escape: return UKey_Escape;
-  case GDK_Tab: return UKey_Tab;
-  case GDK_Return: return UKey_Return;
-  case GDK_Left: return UKey_Left;
-  case GDK_Up: return UKey_Up;
-  case GDK_Right: return UKey_Right;
-  case GDK_Down: return UKey_Down;
-  case GDK_Prior: return UKey_Prior;
-  case GDK_Next: return UKey_Next;
-  case GDK_Home: return UKey_Home;
-  case GDK_End: return UKey_End;
-  case GDK_Kanji:
-  case GDK_Zenkaku_Hankaku: return UKey_Zenkaku_Hankaku;
-  case GDK_Multi_key: return UKey_Multi_key;
-  case GDK_Mode_switch: return UKey_Mode_switch;
-  case GDK_Henkan_Mode: return UKey_Henkan_Mode;
-  case GDK_Muhenkan: return UKey_Muhenkan;
-  case GDK_Shift_L: return UKey_Shift_key;
-  case GDK_Shift_R: return UKey_Shift_key;
-  case GDK_Control_L: return UKey_Control_key;
-  case GDK_Control_R: return UKey_Control_key;
-  case GDK_Alt_L: return UKey_Alt_key;
-  case GDK_Alt_R: return UKey_Alt_key;
-  case GDK_Meta_L: return UKey_Meta_key;
-  case GDK_Meta_R: return UKey_Meta_key;
-  case GDK_Super_L: return UKey_Super_key;
-  case GDK_Super_R: return UKey_Super_key;
-  case GDK_Hyper_L: return UKey_Hyper_key;
-  case GDK_Hyper_R: return UKey_Hyper_key;
-  }
-
-  if (key >= GDK_F1 && key <= GDK_F35)
-    return key - GDK_F1 + UKey_F1;
-
-  if (key >= GDK_KP_0 && key <= GDK_KP_9)
-    return key - GDK_KP_0 + UKey_0;
-
-  if (key < 256)
-    return key;
-
-  return UKey_Other;
-}
-
-static int
-convert_modifier(int mod)
-{
-  int rv = 0;
-
-  if (mod & GDK_SHIFT_MASK)
-    rv |= UMod_Shift;
-
-  if (mod & GDK_CONTROL_MASK)
-    rv |= UMod_Control;
-
-  if (mod & GDK_MOD1_MASK)
-    rv |= UMod_Alt;
-
-  if (mod & GDK_MOD3_MASK)  /* assuming mod3 */
-    rv |= UMod_Super;
-
-  if (mod & GDK_MOD4_MASK)  /* assuming mod4 */
-    rv |= UMod_Hyper;
-
-  return rv;
-}
-
 /*
  * KEY EVENT HANDLER
  */
@@ -314,10 +244,10 @@
 
   /* Hack for combination of xchat + GTK+ 2.6 */
   if (snooper_installed == FALSE) {
-    int rv;
-    int kv = convert_keyval(key->keyval);
-    int mod = convert_modifier(key->state);
+    int rv, kv, mod;
 
+    im_uim_convert_keyevent(key, &kv, &mod);
+
     if (key->type == GDK_KEY_RELEASE)
       rv = uim_release_key(uic->uc, kv, mod);
     else
@@ -1145,10 +1075,10 @@
 uim_key_snoop(GtkWidget *grab_widget, GdkEventKey *key, gpointer data)
 {
   if (focused_context) {
-    int rv;
-    int kv = convert_keyval(key->keyval);
-    int mod = convert_modifier(key->state);
+    int rv, kv, mod;
 
+    im_uim_convert_keyevent(key, &kv, &mod);
+
     if (key->type == GDK_KEY_RELEASE)
       rv = uim_release_key(focused_context->uc, kv, mod);
     else
@@ -1177,6 +1107,8 @@
   /* XXX:This is not recommended way!! */
   snooper_id = gtk_key_snooper_install((GtkKeySnoopFunc)uim_key_snoop, NULL );
   snooper_installed = TRUE;
+
+  im_uim_init_modifier_keys();
 }
 
 void

Added: trunk/gtk/key-util-gtk.c
===================================================================
--- trunk/gtk/key-util-gtk.c	2006-01-18 02:27:17 UTC (rev 2937)
+++ trunk/gtk/key-util-gtk.c	2006-01-18 15:38:52 UTC (rev 2938)
@@ -0,0 +1,350 @@
+/*
+
+  Copyright (c) 2003-2006 uim Project http://uim.freedesktop.org/
+
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+  3. Neither the name of authors nor the names of its contributors
+     may be used to endorse or promote products derived from this software
+     without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  SUCH DAMAGE.
+
+*/
+
+/*
+ * key conversion utility for uim-gtk
+ */
+
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+#include <gdk/gdkx.h>
+
+#ifdef GDK_WINDOWING_X11
+#include <X11/Xlib.h>
+#include <X11/keysym.h>
+#endif
+
+#include "config.h"
+#include "uim/uim.h"
+
+#include "key-util-gtk.h"
+
+#ifdef GDK_WINDOWING_X11
+static guint g_mod1_mask, g_mod2_mask, g_mod3_mask, g_mod4_mask, g_mod5_mask;
+static gint g_numlock_mask;
+static guint g_modifier_state, g_pre_modifier_state;
+#endif
+
+void
+im_uim_convert_keyevent(GdkEventKey *event, int *ukey, int *umod)
+{
+  int keyval = event->keyval;
+  int mod = event->state;
+
+  *umod = 0;
+#ifdef GDK_WINDOWING_X11
+  if (event->type == GDK_KEY_PRESS) {
+    if (!mod || mod == GDK_LOCK_MASK ||
+	mod == g_numlock_mask)
+      g_modifier_state = 0;
+  }
+  g_pre_modifier_state = g_modifier_state; 
+#endif
+
+  /* 1. check key */
+  if (keyval >= GDK_F1 && keyval <= GDK_F35)
+    *ukey = keyval - GDK_F1 + UKey_F1;
+  else if (keyval >= GDK_KP_0 && keyval <= GDK_KP_9)
+    *ukey = keyval - GDK_KP_0 + UKey_0;
+  else if (keyval < 256)
+    *ukey = keyval;
+  else {
+    switch (keyval) {
+    case GDK_BackSpace:
+      *ukey = UKey_Backspace;
+      break;
+    case GDK_Delete:
+      *ukey = UKey_Delete;
+      break;
+    case GDK_Insert:
+      *ukey = UKey_Insert;
+      break;
+    case GDK_Escape:
+      *ukey = UKey_Escape;
+      break;
+    case GDK_Tab:
+    case GDK_ISO_Left_Tab:
+      *ukey = UKey_Tab;
+      break;
+    case GDK_Return:
+      *ukey = UKey_Return;
+      break;
+    case GDK_Left:
+      *ukey = UKey_Left;
+      break;
+    case GDK_Up:
+      *ukey = UKey_Up;
+      break;
+    case GDK_Right:
+      *ukey = UKey_Right;
+      break;
+    case GDK_Down:
+      *ukey = UKey_Down;
+      break;
+    case GDK_Prior:
+      *ukey = UKey_Prior;
+      break;
+    case GDK_Next:
+      *ukey = UKey_Next;
+      break;
+    case GDK_Home:
+      *ukey = UKey_Home;
+      break;
+    case GDK_End:
+      *ukey = UKey_End;
+      break;
+    case GDK_Kanji:
+    case GDK_Zenkaku_Hankaku:
+      *ukey = UKey_Zenkaku_Hankaku;
+      break;
+    case GDK_Multi_key:
+      *ukey = UKey_Multi_key;
+      break;
+    case GDK_Mode_switch:
+      *ukey = UKey_Mode_switch;
+      break;
+    case GDK_Henkan_Mode:
+      *ukey = UKey_Henkan_Mode;
+      break;
+    case GDK_Muhenkan:
+      *ukey = UKey_Muhenkan;
+      break;
+    case GDK_Shift_L:
+    case GDK_Shift_R:
+#ifdef GDK_WINDOWING_X11
+      if (event->type == GDK_KEY_PRESS)
+	g_modifier_state |= UMod_Shift;
+      else
+	g_modifier_state &= ~UMod_Shift;
+#endif
+      *ukey = UKey_Shift_key;
+      break;
+    case GDK_Control_L:
+    case GDK_Control_R:
+#ifdef GDK_WINDOWING_X11
+      if (event->type == GDK_KEY_PRESS)
+	g_modifier_state |= UMod_Control;
+      else
+	g_modifier_state &= ~UMod_Control;
+#endif
+      *ukey = UKey_Control_key;
+      break;
+    case GDK_Alt_L:
+    case GDK_Alt_R:
+#ifdef GDK_WINDOWING_X11
+      if (event->type == GDK_KEY_PRESS)
+	g_modifier_state |= UMod_Alt;
+      else
+	g_modifier_state &= ~UMod_Alt;
+#endif
+      *ukey = UKey_Alt_key;
+      break;
+    case GDK_Meta_L:
+    case GDK_Meta_R:
+#ifdef GDK_WINDOWING_X11
+      if (event->type == GDK_KEY_PRESS)
+	g_modifier_state |= UMod_Meta;
+      else
+	g_modifier_state &= ~UMod_Meta;
+#endif
+      *ukey = UKey_Meta_key;
+      break;
+    case GDK_Super_L:
+    case GDK_Super_R:
+#ifdef GDK_WINDOWING_X11
+      if (event->type == GDK_KEY_PRESS)
+	g_modifier_state |= UMod_Super;
+      else
+	g_modifier_state &= ~UMod_Super;
+#endif
+      *ukey = UKey_Super_key;
+      break;
+    case GDK_Hyper_L:
+    case GDK_Hyper_R:
+#ifdef GDK_WINDOWING_X11
+      if (event->type == GDK_KEY_PRESS)
+	g_modifier_state |= UMod_Hyper;
+      else
+	g_modifier_state &= ~UMod_Hyper;
+#endif
+      *ukey = UKey_Hyper_key;
+      break;
+    default:
+      *ukey = UKey_Other;
+     break;
+    }
+  }
+
+  /* 2. check modifier */
+  if (mod & GDK_SHIFT_MASK)
+    *umod |= UMod_Shift;
+  if (mod & GDK_CONTROL_MASK)
+    *umod |= UMod_Control;
+#ifdef GDK_WINDOWING_X11
+  if (mod & GDK_MOD1_MASK)
+    *umod |= (g_mod1_mask & g_pre_modifier_state);
+  if (mod & GDK_MOD2_MASK)
+    *umod |= (g_mod2_mask & g_pre_modifier_state);
+  if (mod & GDK_MOD3_MASK)
+    *umod |= (g_mod3_mask & g_pre_modifier_state);
+  if (mod & GDK_MOD4_MASK)
+    *umod |= (g_mod4_mask & g_pre_modifier_state);
+  if (mod & GDK_MOD5_MASK)
+    *umod |= (g_mod5_mask & g_pre_modifier_state);
+#else
+  if (mod & GDK_MOD1_MASK)
+    *umod |= UMod_Alt;
+  if (mod & GDK_MOD3_MASK)  /* assuming mod3 */
+    *umod |= UMod_Super;
+  if (mod & GDK_MOD4_MASK)  /* assuming mod4 */
+    *umod |= UMod_Hyper;
+#endif
+}
+
+#ifdef GDK_WINDOWING_X11
+static int
+check_modifier(GSList *slist)
+{
+  int ret;
+  GSList *tmp_list;
+
+  ret = 0;
+  for (tmp_list = slist; tmp_list; tmp_list = tmp_list->next) {
+    switch (GPOINTER_TO_UINT(tmp_list->data)) {
+    case XK_Shift_L:
+    case XK_Shift_R:
+      ret |= UMod_Shift;
+      break;
+    case XK_Control_L:
+    case XK_Control_R:
+      ret |= UMod_Control;
+      break;
+    case XK_Meta_L:
+    case XK_Meta_R:
+      ret |= UMod_Meta;
+      break;
+    case XK_Alt_L:
+    case XK_Alt_R:
+      ret |= UMod_Alt;
+      break;
+    case XK_Super_L:
+    case XK_Super_R:
+      ret |= UMod_Super;
+      break;
+    case XK_Hyper_L:
+    case XK_Hyper_R:
+      ret |= UMod_Hyper;
+      break;
+    default:
+      break;
+    }
+  }
+  return ret;
+}
+#endif
+
+void
+im_uim_init_modifier_keys()
+{
+#ifdef GDK_WINDOWING_X11
+  int i, k = 0;
+  int min_keycode, max_keycode, keysyms_per_keycode = 0;
+  Display *display;
+  GSList *mod1_list, *mod2_list, *mod3_list, *mod4_list, *mod5_list; 
+  XModifierKeymap *map;
+  KeySym *sym;
+
+  g_modifier_state = 0;
+  g_numlock_mask = 0;
+
+  mod1_list = mod2_list = mod3_list = mod4_list = mod5_list = NULL;
+
+  display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
+  map = XGetModifierMapping(display);
+  XDisplayKeycodes(display, &min_keycode, &max_keycode);
+  sym = XGetKeyboardMapping(display, min_keycode,
+		  	    (max_keycode - min_keycode + 1),
+			    &keysyms_per_keycode);
+  for (i = 0; i < 8; i++) {
+    int j;
+    for (j = 0; j < map->max_keypermod; j++) {
+      if (map->modifiermap[k]) {
+	KeySym ks;
+	int index = 0;
+	char *nm;
+	do {
+	  ks = XKeycodeToKeysym(display, map->modifiermap[k], index);
+	  index++;
+	} while (!ks && index < keysyms_per_keycode);
+
+	nm = XKeysymToString(ks);
+	switch (i) {
+	case ShiftMapIndex:
+	  break;
+	case LockMapIndex:
+	  break;
+	case ControlMapIndex:
+	  break;
+	case Mod1MapIndex:
+	  mod1_list = g_slist_prepend(mod1_list, GUINT_TO_POINTER(ks));
+	  g_mod1_mask = check_modifier(mod1_list);
+	  break;
+	case Mod2MapIndex:
+	  mod2_list = g_slist_prepend(mod2_list, GUINT_TO_POINTER(ks));
+	  g_mod2_mask = check_modifier(mod2_list);
+	  break;
+	case Mod3MapIndex:
+	  mod3_list = g_slist_prepend(mod3_list, GUINT_TO_POINTER(ks));
+	  g_mod3_mask = check_modifier(mod3_list);
+	  break;
+	case Mod4MapIndex:
+	  mod4_list = g_slist_prepend(mod4_list, GUINT_TO_POINTER(ks));
+	  g_mod4_mask = check_modifier(mod4_list);
+	  break;
+	case Mod5MapIndex:
+	  mod5_list = g_slist_prepend(mod5_list, GUINT_TO_POINTER(ks));
+	  g_mod5_mask = check_modifier(mod5_list);
+	  break;
+	default:
+	  break;
+	}
+	if (ks == XK_Num_Lock)
+	  g_numlock_mask |= (1 << i);
+      }
+      k++;
+    }
+  }
+  XFreeModifiermap(map);
+  XFree(sym);
+#endif
+}

Added: trunk/gtk/key-util-gtk.h
===================================================================
--- trunk/gtk/key-util-gtk.h	2006-01-18 02:27:17 UTC (rev 2937)
+++ trunk/gtk/key-util-gtk.h	2006-01-18 15:38:52 UTC (rev 2938)
@@ -0,0 +1,54 @@
+/*
+
+  Copyright (c) 2003-2006 uim Project http://uim.freedesktop.org/
+
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+  3. Neither the name of authors nor the names of its contributors
+     may be used to endorse or promote products derived from this software
+     without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  SUCH DAMAGE.
+
+*/
+
+/*
+ * key utility for uim-gtk
+ */
+
+#ifndef _key_util_gtk_h_included_
+#define _key_util_gtk_h_included_
+
+#include <glib.h>
+
+/*
+ * Initialize modifier key mappings.
+ */
+void im_uim_init_modifier_keys(void);
+
+/*
+ * Get ukey and umod from gdk's GdkEventKey->keyval and GdkEventKey->state.
+ * This function should be called at both key press and release events.
+ */
+void im_uim_convert_keyevent(GdkEventKey *key, int *ukey, int *umod);
+
+#endif

Modified: trunk/helper/Makefile.am
===================================================================
--- trunk/helper/Makefile.am	2006-01-18 02:27:17 UTC (rev 2937)
+++ trunk/helper/Makefile.am	2006-01-18 15:38:52 UTC (rev 2938)
@@ -81,7 +81,9 @@
 uim_input_pad_ja_CFLAGS   = @GTK2_CFLAGS@ -Wall
 
 if GTK2_4
-uim_pref_gtk_SOURCES  = pref-gtk.c pref-gtk-custom-widgets.c pref-gtk-custom-widgets.h
+uim_pref_gtk_SOURCES  = pref-gtk.c \
+			pref-gtk-custom-widgets.c pref-gtk-custom-widgets.h \
+			../gtk/key-util-gtk.c ../gtk/key-util-gtk.h
 uim_pref_gtk_LDADD    = @GTK2_LIBS@ $(top_builddir)/uim/libuim-custom.la \
 			$(top_builddir)/uim/libuim.la
 uim_pref_gtk_CPPFLAGS = $(helper_defs) -I$(top_srcdir) -I$(top_builddir)

Modified: trunk/helper/pref-gtk-custom-widgets.c
===================================================================
--- trunk/helper/pref-gtk-custom-widgets.c	2006-01-18 02:27:17 UTC (rev 2937)
+++ trunk/helper/pref-gtk-custom-widgets.c	2006-01-18 15:38:52 UTC (rev 2938)
@@ -43,6 +43,8 @@
 #include "uim/uim-custom.h"
 #include "uim/gettext.h"
 
+#include "../gtk/key-util-gtk.h"
+
 #define OBJECT_DATA_UIM_CUSTOM_SYM    "uim-pref-gtk::uim-custom-sym"
 
 extern gboolean uim_pref_gtk_value_changed;
@@ -68,8 +70,8 @@
   GtkWidget *remove_button;
   GtkWidget *keycode_entry;
 
-  guint           grabbed_key_val;
-  GdkModifierType grabbed_key_state;
+  gint grabbed_key_val;
+  gint grabbed_key_state;
 } key_pref_win = {
   NULL, NULL, NULL, NULL, NULL, 0, 0,
 };
@@ -1308,7 +1310,7 @@
 }
 
 static void
-key_pref_set_value(guint keyval, GdkModifierType mod)
+key_pref_set_value(gint ukey, gint umod)
 {
   GString *keystr;
 
@@ -1318,111 +1320,112 @@
    * easy-to-recognize key configuration.  uim-custom performs
    * implicit shift key encoding/decoding appropriately.
    */
-  if (((keyval >= 256) || !g_ascii_isgraph(keyval)) &&
-		  (mod & GDK_SHIFT_MASK))
+  if (((ukey >= 256) || !g_ascii_isgraph(ukey)) &&
+		  (umod & UMod_Shift))
     g_string_append(keystr, "<Shift>");
-  if (mod & GDK_CONTROL_MASK)
+  if (umod & UMod_Control)
     g_string_append(keystr, "<Control>");
-  if (mod & GDK_MOD1_MASK)
+  if (umod & UMod_Alt)
     g_string_append(keystr, "<Alt>");
+  if (umod & UMod_Meta)
+    g_string_append(keystr, "<Meta>");
+  if (umod & UMod_Super)
+    g_string_append(keystr, "<Super>");
+  if (umod & UMod_Hyper)
+    g_string_append(keystr, "<Hyper>");
 
-  switch (keyval) {
-  case GDK_space:
+  switch (ukey) {
+  case 0x20:
     /*
      * "space" is not proper uim keysym and only exists for user
      * convenience. It is converted to " " by uim-custom
      */
     g_string_append(keystr, "space");
     break;
-  case GDK_BackSpace:
+  case UKey_Backspace:
     g_string_append(keystr, "backspace");
     break;
-  case GDK_Delete:
+  case UKey_Delete:
     g_string_append(keystr, "delete");
     break;
-  case GDK_Insert:
+  case UKey_Insert:
     g_string_append(keystr, "insert");
     break;
-  case GDK_Escape:
+  case UKey_Escape:
     g_string_append(keystr, "escape");
     break;
-  case GDK_Tab:
+  case UKey_Tab:
     g_string_append(keystr, "tab");
     break;
-  case GDK_Return:
+  case UKey_Return:
     g_string_append(keystr, "return");
     break;
-  case GDK_Left:
+  case UKey_Left:
     g_string_append(keystr, "left");
     break;
-  case GDK_Up:
+  case UKey_Up:
     g_string_append(keystr, "up");
     break;
-  case GDK_Right:
+  case UKey_Right:
     g_string_append(keystr, "right");
     break;
-  case GDK_Down:
+  case UKey_Down:
     g_string_append(keystr, "down");
     break;
-  case GDK_Prior:
+  case UKey_Prior:
     g_string_append(keystr, "prior");
     break;
-  case GDK_Next:
+  case UKey_Next:
     g_string_append(keystr, "next");
     break;
-  case GDK_Home:
+  case UKey_Home:
     g_string_append(keystr, "home");
     break;
-  case GDK_End:
+  case UKey_End:
     g_string_append(keystr, "end");
     break;
-  case GDK_Kanji:
-  case GDK_Zenkaku_Hankaku:
+  case UKey_Zenkaku_Hankaku:
     g_string_append(keystr, "zenkaku-hankaku");
     break;
-  case GDK_Multi_key:
+  case UKey_Multi_key:
     g_string_append(keystr, "Multi_key");
     break;
-  case GDK_Mode_switch:
+  case UKey_Mode_switch:
     g_string_append(keystr, "Mode_switch");
     break;
-  case GDK_Henkan_Mode:
+  case UKey_Henkan_Mode:
     g_string_append(keystr, "Henkan_Mode");
     break;
-  case GDK_Muhenkan:
+  case UKey_Muhenkan:
     g_string_append(keystr, "Muhenkan");
     break;
-  case GDK_Shift_L:
-  case GDK_Shift_R:
+  case UKey_Shift_key:
     g_string_append(keystr, "Shift_key");
     break;
-  case GDK_Control_L:
-  case GDK_Control_R:
+  case UKey_Control_key:
     g_string_append(keystr, "Control_key");
     break;
-  case GDK_Alt_L:
-  case GDK_Alt_R:
+  case UKey_Alt_key:
     g_string_append(keystr, "Alt_key");
     break;
-  case GDK_Meta_L:
-  case GDK_Meta_R:
+  case UKey_Meta_key:
     g_string_append(keystr, "Meta_key");
     break;
-  case GDK_Super_L:
-  case GDK_Super_R:
+  case UKey_Super_key:
     g_string_append(keystr, "Super_key");
     break;
-  case GDK_Hyper_L:
-  case GDK_Hyper_R:
+  case UKey_Hyper_key:
     g_string_append(keystr, "Hyper_key");
     break;
   default:
-    if (keyval >= GDK_F1 && keyval <= GDK_F35) {
-      g_string_append_printf(keystr, "F%d", keyval - GDK_F1 + 1);
-    } else if (keyval >= GDK_F1 && keyval <= GDK_F35) {
+    if (ukey >= UKey_F1 && ukey <= UKey_F35) {
+      g_string_append_printf(keystr, "F%d", ukey - UKey_F1 + 1);
+#if 0
+    } else if (keyval >= GDK_KP_0 && keyval <= GDK_KP_9) {
       g_string_append_printf(keystr, "%d", keyval - GDK_KP_0 + UKey_0);
-    } else if (keyval < 256) {
-      g_string_append_printf(keystr, "%c", keyval);
+#endif
+    } else if (ukey < 256) {
+      g_string_append_printf(keystr, "%c", ukey);
     } else {
       /* UKey_Other */
     }
@@ -1441,8 +1444,8 @@
 grab_win_key_press_cb (GtkWidget *widget, GdkEventKey *event,
 		       GtkEntry *key_entry)
 {
-  key_pref_win.grabbed_key_val   = event->keyval;
-  key_pref_win.grabbed_key_state = event->state;
+  im_uim_convert_keyevent(event, &key_pref_win.grabbed_key_val,
+				 &key_pref_win.grabbed_key_state);
 
   return TRUE;
 }
@@ -1454,6 +1457,9 @@
   key_pref_set_value(key_pref_win.grabbed_key_val,
 		     key_pref_win.grabbed_key_state);
 
+  im_uim_convert_keyevent(event, &key_pref_win.grabbed_key_val,
+				 &key_pref_win.grabbed_key_state);
+
   g_signal_handlers_disconnect_by_func(G_OBJECT(widget),
 				       (gpointer) grab_win_key_press_cb,
 				       key_entry);
@@ -1470,10 +1476,25 @@
 key_choose_entry_key_press_cb (GtkWidget *widget, GdkEventKey *event,
 			       GtkEntry *key_entry)
 {
-  key_pref_set_value(event->keyval, event->state);
+  int ukey, umod;
+
+  im_uim_convert_keyevent(event, &ukey, &umod);
+  key_pref_set_value(ukey, umod);
+
   return TRUE;
 }
 
+static gboolean
+key_choose_entry_key_release_cb (GtkWidget *widget, GdkEventKey *event,
+			       GtkEntry *key_entry)
+{
+  int ukey, umod;
+
+  im_uim_convert_keyevent(event, &ukey, &umod);
+
+  return TRUE;
+}
+
 static void
 choose_key_button_clicked_cb(GtkWidget *widget, GtkEntry *key_entry)
 {
@@ -1808,6 +1829,8 @@
 		   G_CALLBACK(key_val_entry_changed_cb), key_entry);
   g_signal_connect(G_OBJECT(entry), "key-press-event",
 		   G_CALLBACK(key_choose_entry_key_press_cb), key_entry);
+  g_signal_connect(G_OBJECT(entry), "key-release-event",
+		   G_CALLBACK(key_choose_entry_key_release_cb), key_entry);
   gtk_widget_show(entry);
 
   button = gtk_button_new_with_label(_("Grab..."));

Modified: trunk/helper/pref-gtk.c
===================================================================
--- trunk/helper/pref-gtk.c	2006-01-18 02:27:17 UTC (rev 2937)
+++ trunk/helper/pref-gtk.c	2006-01-18 15:38:52 UTC (rev 2938)
@@ -44,6 +44,7 @@
 #include "uim/uim-custom.h"
 #include "uim/gettext.h"
 #include "pref-gtk-custom-widgets.h"
+#include "../gtk/key-util-gtk.h"
 
 #define DEFAULT_WINDOW_WIDTH_MAX 800
 #define DEFAULT_WINDOW_HEIGHT_MAX 600
@@ -582,8 +583,10 @@
   if (uim_custom_enable()) {
     GtkWidget *pref;
 
+    im_uim_init_modifier_keys();
+  
     gtk_idle_add((GtkFunction) check_dot_uim_file, NULL);
-  
+
     pref = create_pref_window();
 
     gtk_widget_show_all(pref);



More information about the uim-commit mailing list