Author: yamakenz
Date: Mon Sep 17 05:00:12 2007
New Revision: 4975

Added:
   trunk/uim/uim-x-kana-input-hack.c
   trunk/uim/uim-x-util.h
Modified:
   trunk/configure.ac
   trunk/gtk/Makefile.am
   trunk/gtk/key-util-gtk.c
   trunk/uim/Makefile.am
   trunk/xim/Makefile.am
   trunk/xim/ximserver.cpp

Log:
* This commit make the kana-input hack Japanese-keysym independent. A
  reporter said that xkeyboard-config 1.0 will make the previous hack
  unworking. So I rewrite the hack to be capable of any Japanese
  keyboard mapping

* uim/uim-x-util.h
  - (uim_x_kana_input_hack_translate_key, uim_x_kana_input_hack_init):
    New function decl
* uim/uim-x-kana-input-hack.c
  - New file
  - (enum KeySymIndex): New type
  - (is_japanese_keyboard, kana_RO_keycode, yen_sign_keycode): New
    static variable
  - (uim_x_kana_input_hack_translate_key, uim_x_kana_input_hack_init):
    New function
* uim/Makefile.am
  - (noinst_LTLIBRARIES): Add libuim-x-util.la
* gtk/key-util-gtk.c
  - Include uim-x-util.h
  - (UIM_GTK_USE_JAPANESE_KANA_KEYBOARD_HACK): New macro
  - (g_prolongedsound_keycode): Removed
  - (im_uim_convert_keyevent, im_uim_init_modifier_keys): Replace the
    hack with uim_x_kana_input_hack_*()
* gtk/Makefile.am
  - (im_uim_la_LIBADD): Add libuim-x-util.la
* xim/ximserver.cpp
  - Include uim-x-util.h
  - (gProlongedsoundKeyCode): Removed
  - (keyState::check_key, check_modifier): Replace the hack with
    uim_x_kana_input_hack_*()
* xim/Makefile.am
  - (uim_xim_LDADD): Add libuim-x-util.la
* configure.ac
  - Define AM_CONDITIONAL LIBUIM_X_UTIL


Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac  (original)
+++ trunk/configure.ac  Mon Sep 17 05:00:12 2007
@@ -954,6 +954,7 @@
 AM_CONDITIONAL(EB, test x$use_eb = xyes)
 AM_CONDITIONAL(LIBEDIT, test x$use_libedit = xyes)
 AM_CONDITIONAL(DEBUG, test x$enable_debug = xyes)
+AM_CONDITIONAL(LIBUIM_X_UTIL, test x$have_x = xyes)
 AM_CONDITIONAL(NEED_SETENV_C, test $ac_cv_func_setenv = no -o 
$ac_cv_func_unsetenv = no)
 AM_CONDITIONAL(NEED_STRSEP_C, test $ac_cv_func_strsep = no)
 AM_CONDITIONAL(GCC, test x$ac_cv_c_compiler_gnu = xyes)

Modified: trunk/gtk/Makefile.am
==============================================================================
--- trunk/gtk/Makefile.am       (original)
+++ trunk/gtk/Makefile.am       Mon Sep 17 05:00:12 2007
@@ -16,6 +16,9 @@
 im_uim_la_LDFLAGS = -module -avoid-version @GTK2_LIBS@
 im_uim_la_LIBADD = $(top_builddir)/uim/libuim-scm.la \
                   $(top_builddir)/uim/libuim.la $(EBLIB_LIBS)
+if LIBUIM_X_UTIL
+im_uim_la_LIBADD += $(top_builddir)/uim/libuim-x-util.la
+endif
 
 
 IM_UIM_SOURCES = \

Modified: trunk/gtk/key-util-gtk.c
==============================================================================
--- trunk/gtk/key-util-gtk.c    (original)
+++ trunk/gtk/key-util-gtk.c    Mon Sep 17 05:00:12 2007
@@ -46,7 +46,14 @@
 #include <X11/keysym.h>
 #endif
 
+#ifdef GDK_WINDOWING_X11
+#define UIM_GTK_USE_JAPANESE_KANA_KEYBOARD_HACK 1
+#endif
+
 #include "uim/uim.h"
+#if UIM_GTK_USE_JAPANESE_KANA_KEYBOARD_HACK
+#include "uim/uim-x-util.h"
+#endif
 
 #include "key-util-gtk.h"
 
@@ -54,7 +61,6 @@
 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;
-static KeyCode g_prolongedsound_keycode;
 #endif
 
 void
@@ -229,23 +235,9 @@
      break;
     }
   }
-#ifdef GDK_WINDOWING_X11
+#if UIM_GTK_USE_JAPANESE_KANA_KEYBOARD_HACK
   /* 1'. replace keysym for Japanese keyboard */
-  /*
-   * A hack to distinguish Japanese kana_RO key from yen sign key
-   * (both keys normally generates backslash on ASCII input). See
-   * [uim-en 11] and the follow messages for the discussion.
-   *
-   * This hack assumes that the xmodmap for the Japanese kana
-   * keyboard is defined as follows:
-   * 
-   * yen sign key: keycode X = backslash bar prolongedsound
-   * kana_RO key:  keycode Y = backslash underscore kana_RO
-   */
-  if (*ukey == '\\' &&
-      event->hardware_keycode == g_prolongedsound_keycode) {
-    *ukey = UKey_Yen;
-  }
+  *ukey = uim_x_kana_input_hack_translate_key(*ukey, event->hardware_keycode);
 #endif
 
   /* 2. check modifier */
@@ -394,7 +386,9 @@
   g_slist_free(mod5_list);
   XFreeModifiermap(map);
   XFree(sym);
-  /* setup keycode hack */
-  g_prolongedsound_keycode = XKeysymToKeycode(display, XK_prolongedsound);
+
+#if UIM_GTK_USE_JAPANESE_KANA_KEYBOARD_HACK
+  uim_x_kana_input_hack_init(display);
+#endif
 #endif
 }

Modified: trunk/uim/Makefile.am
==============================================================================
--- trunk/uim/Makefile.am       (original)
+++ trunk/uim/Makefile.am       Mon Sep 17 05:00:12 2007
@@ -11,6 +11,9 @@
 CFLAGS = @CFLAGS@ $(UIM_SCM_CFLAGS)
 
 lib_LTLIBRARIES = libuim-scm.la libuim.la libuim-custom.la libuim-bsdlook.la
+if LIBUIM_X_UTIL
+noinst_LTLIBRARIES = libuim-x-util.la
+endif
 
 # Although uim only needs *.so for the plugins, whether *.la is
 # installed or not is system-dependent and uim leaves it untouched. It
@@ -180,6 +183,11 @@
 libuim_custom_enabler_la_LIBADD = libuim-custom.la libuim-scm.la libuim.la
 libuim_custom_enabler_la_LDFLAGS = -rpath $(uim_plugindir) -avoid-version 
-module
 libuim_custom_enabler_la_CPPFLAGS = -I$(top_srcdir)
+
+if LIBUIM_X_UTIL
+libuim_x_util_la_SOURCES = uim-x-util.h uim-x-kana-input-hack.c
+libuim_x_util_la_CPPFLAGS = -I$(top_srcdir)
+endif
 
 
 bin_PROGRAMS = uim-sh uim-module-manager

Added: trunk/uim/uim-x-kana-input-hack.c
==============================================================================
--- (empty file)
+++ trunk/uim/uim-x-kana-input-hack.c   Mon Sep 17 05:00:12 2007
@@ -0,0 +1,119 @@
+/*
+
+  Copyright (c) 2007 uim Project http://code.google.com/p/uim/
+
+  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.
+
+*/
+
+/*
+ * A hack to distinguish Japanese kana_RO key from yen sign key (both
+ * keys normally generates backslash on ASCII input). See [uim-en 11]
+ * and the follow messages for the discussion.
+ *
+ * This hack assumes that the xmodmap for the Japanese kana keyboard
+ * is defined as follows:
+ * 
+ * yen sign key: keycode X = backslash bar
+ * kana_RO key:  keycode Y = backslash underscore
+ *
+ * And also assumes that Japanese kana_RO key is the only one key that
+ * has 'backslash underscore' modmap.
+ */
+
+#include <config.h>
+
+#include <X11/Xlib.h>
+#include <X11/keysym.h>
+
+#include "uim.h"
+#include "uim-x-util.h"
+
+enum KeySymIndex {
+  UNMODIFIED_KEYSYM_INDEX = 0,
+  SHIFTED_KEYSYM_INDEX = 1
+};
+
+static uim_bool is_japanese_keyboard;
+static KeyCode kana_RO_keycode, yen_sign_keycode;
+
+
+int
+uim_x_kana_input_hack_translate_key(int ukey, KeyCode hardware_keycode)
+{
+  if (ukey == '\\'
+      && is_japanese_keyboard
+      && hardware_keycode == yen_sign_keycode
+      && hardware_keycode != kana_RO_keycode)
+  {
+    ukey = UKey_Yen;
+  }
+
+  return ukey;
+}
+
+void
+uim_x_kana_input_hack_init(Display *display)
+{
+  int min_keycode, max_keycode, keysyms_per_keycode, keycode_count, i;
+  KeySym *map, *syms, unmodified, shifted;
+
+  /* To allow refreshing keyboard encoding configuration by call this
+   * function again, the global variables are explicitly initialized
+   * with zero here. */
+  is_japanese_keyboard = UIM_FALSE;
+  kana_RO_keycode = 0;
+
+  XDisplayKeycodes(display, &min_keycode, &max_keycode);
+  keycode_count = max_keycode - min_keycode + 1;
+  map = XGetKeyboardMapping(display,
+                           min_keycode, keycode_count, &keysyms_per_keycode);
+
+  if (keysyms_per_keycode >= SHIFTED_KEYSYM_INDEX + 1) {
+    for (i = 0, syms = map;
+        i <= keycode_count;
+        i++, syms += keysyms_per_keycode)
+    {
+      unmodified = syms[UNMODIFIED_KEYSYM_INDEX];
+      shifted = syms[SHIFTED_KEYSYM_INDEX];
+
+      /* Assumes that Japanese kana_RO key is the only one key that
+       * has 'backslash underscore' modmap. */
+      if (unmodified == XK_backslash) {
+       if (shifted == XK_underscore) {
+         is_japanese_keyboard = UIM_TRUE;
+         kana_RO_keycode = min_keycode + i;
+       } else if (shifted == XK_bar) {
+         yen_sign_keycode = min_keycode + i;
+       }
+      }
+    }
+  }
+
+  XFree(map);
+}

Added: trunk/uim/uim-x-util.h
==============================================================================
--- (empty file)
+++ trunk/uim/uim-x-util.h      Mon Sep 17 05:00:12 2007
@@ -0,0 +1,50 @@
+/*
+
+  Copyright (c) 2007 uim Project http://code.google.com/p/uim/
+
+  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.
+
+*/
+
+#ifndef _uim_x_util_included_
+#define _uim_x_util_included_
+
+#include <X11/Xlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int uim_x_kana_input_hack_translate_key(int ukey, KeyCode hardware_keycode);
+void uim_x_kana_input_hack_init(Display *display);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _uim_x_util_included_ */

Modified: trunk/xim/Makefile.am
==============================================================================
--- trunk/xim/Makefile.am       (original)
+++ trunk/xim/Makefile.am       Mon Sep 17 05:00:12 2007
@@ -5,7 +5,8 @@
 bin_PROGRAMS = uim-xim
 uim_xim_LDFLAGS =  @X_LIBS@
 uim_xim_LDADD =  -lXext -lX11 $(top_builddir)/uim/libuim-scm.la \
-                $(top_builddir)/uim/libuim.la
+                $(top_builddir)/uim/libuim.la \
+                $(top_builddir)/uim/libuim-x-util.la
 uim_xim_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir)
 uim_xim_CFLAGS = @X_CFLAGS@ -Wall
 uim_xim_CXXFLAGS = @X_CFLAGS@ -Wall

Modified: trunk/xim/ximserver.cpp
==============================================================================
--- trunk/xim/ximserver.cpp     (original)
+++ trunk/xim/ximserver.cpp     Mon Sep 17 05:00:12 2007
@@ -34,6 +34,8 @@
 # include <config.h>
 #endif
 
+#define UIM_XIM_USE_JAPANESE_KANA_KEYBOARD_HACK 1
+
 #include <stdio.h>
 #include <ctype.h>
 #include <locale.h>
@@ -60,6 +62,9 @@
 #include "uim/uim-helper.h"
 #include "uim/uim-im-switcher.h"
 #include "uim/uim-scm.h"
+#if UIM_XIM_USE_JAPANESE_KANA_KEYBOARD_HACK
+#include "uim/uim-x-util.h"
+#endif
 
 #ifndef XK_dead_horn
 #define XK_dead_horn   0xfe62
@@ -71,8 +76,6 @@
 # endif
 #endif
 
-#define UIM_XIM_USE_JAPANESE_KANA_KEYBOARD_HACK 1
-
 extern int lib_uim_fd;
 extern Atom xim_servers;
 InputContext *InputContext::mFocusedContext = NULL;
@@ -80,9 +83,6 @@
 static int check_modifier(std::list<KeySym> list);
 static int gMod1Mask, gMod2Mask, gMod3Mask, gMod4Mask, gMod5Mask;
 static int gXNumLockMask;
-#if UIM_XIM_USE_JAPANESE_KANA_KEYBOARD_HACK
-static unsigned int gProlongedsoundKeyCode;
-#endif
 
 
 void print_ustring(uString *s)
@@ -1102,18 +1102,7 @@
        mModifier |= (gMod5Mask & mPreModState);
 
 #if UIM_XIM_USE_JAPANESE_KANA_KEYBOARD_HACK
-    // A hack to distinguish Japanese kana_RO key from yen sign key
-    // (both keys normally generates backslash on ASCII input). See
-    // [uim-en 11] and the follow messages for the discussion.
-    //
-    // This hack assumes that the xmodmap for the Japanese kana
-    // keyboard is defined as follows:
-    // 
-    // yen sign key: keycode X = backslash bar prolongedsound
-    // kana_RO key:  keycode Y = backslash underscore kana_RO
-    if (x->key_sym == '\\' && x->ev.xkey.keycode == gProlongedsoundKeyCode)
-       mKey = UKey_Yen;
-    else
+    mKey = uim_x_kana_input_hack_translate_key(x->key_sym, x->ev.xkey.keycode);
 #endif
     if (x->key_sym < 128 && x->key_sym >= 32)
        mKey = x->key_sym;
@@ -1297,8 +1286,7 @@
 
 #if UIM_XIM_USE_JAPANESE_KANA_KEYBOARD_HACK
     // Init at here to sync with proper update timing although not a modifier.
-    gProlongedsoundKeyCode
-       = XKeysymToKeycode(XimServer::gDpy, XK_prolongedsound);
+    uim_x_kana_input_hack_init(XimServer::gDpy);
 #endif
 }
 

Reply via email to