Back to index

im-sdk  12.3.91
KeyMap.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1997 by Sun Microsystems, Inc.
00003  */
00004  
00005 #ifndef XK_KATAKANA
00006 #define XK_KATAKANA
00007 #endif
00008 
00009 #include <ctype.h>
00010 #include <X11/Xlib.h>
00011 #include <X11/Xutil.h>
00012 #include <X11/keysym.h>
00013 #include <X11/Sunkeysym.h>
00014 #include <X11/Xmd.h>
00015 
00016 /*
00017 #include "KeyMap.h"
00018 */
00019 
00020 #define kana_table 1 /* for japanese kana support */
00021 
00022 typedef struct KEYMAP_ENTRY {
00023     long awtKey;
00024     KeySym x11Key;
00025     Bool printable;
00026 } KeymapEntry;
00027 
00028 #if kana_table
00029 typedef struct KEYMAP_ENTRY2 {
00030     long awtKey;
00031     KeySym x11Key;
00032     KeySym alt_x11Key;
00033     int keychar;
00034     Bool printable;
00035     KeyCode keycode;
00036 } KeymapEntry2;
00037 #endif
00038 
00039 static int awt_MetaMask = 0;
00040 static int awt_AltMask = 0;
00041 static int awt_NumLockMask = 0;
00042 static int awt_KanaLockMask = 0;
00043 
00044 #ifdef linux
00045 #include <X11/Xatom.h>
00046 static int KanaMode = -1;
00047 static Atom kanawin_atom = 0;
00048 static Atom kanaflag_atom = 0;
00049 static Window kana_w = 0;
00050 #endif /* linux */
00051 
00052 /* extract the definitions below from java header files */
00053 #undef java_awt_event_KeyEvent_COMPONENT_EVENT_MASK
00054 #define java_awt_event_KeyEvent_COMPONENT_EVENT_MASK 1LL
00055 #undef java_awt_event_KeyEvent_CONTAINER_EVENT_MASK
00056 #define java_awt_event_KeyEvent_CONTAINER_EVENT_MASK 2LL
00057 #undef java_awt_event_KeyEvent_FOCUS_EVENT_MASK
00058 #define java_awt_event_KeyEvent_FOCUS_EVENT_MASK 4LL
00059 #undef java_awt_event_KeyEvent_KEY_EVENT_MASK
00060 #define java_awt_event_KeyEvent_KEY_EVENT_MASK 8LL
00061 #undef java_awt_event_KeyEvent_MOUSE_EVENT_MASK
00062 #define java_awt_event_KeyEvent_MOUSE_EVENT_MASK 16LL
00063 #undef java_awt_event_KeyEvent_MOUSE_MOTION_EVENT_MASK
00064 #define java_awt_event_KeyEvent_MOUSE_MOTION_EVENT_MASK 32LL
00065 #undef java_awt_event_KeyEvent_WINDOW_EVENT_MASK
00066 #define java_awt_event_KeyEvent_WINDOW_EVENT_MASK 64LL
00067 #undef java_awt_event_KeyEvent_ACTION_EVENT_MASK
00068 #define java_awt_event_KeyEvent_ACTION_EVENT_MASK 128LL
00069 #undef java_awt_event_KeyEvent_ADJUSTMENT_EVENT_MASK
00070 #define java_awt_event_KeyEvent_ADJUSTMENT_EVENT_MASK 256LL
00071 #undef java_awt_event_KeyEvent_ITEM_EVENT_MASK
00072 #define java_awt_event_KeyEvent_ITEM_EVENT_MASK 512LL
00073 #undef java_awt_event_KeyEvent_TEXT_EVENT_MASK
00074 #define java_awt_event_KeyEvent_TEXT_EVENT_MASK 1024LL
00075 #undef java_awt_event_KeyEvent_RESERVED_ID_MAX
00076 #define java_awt_event_KeyEvent_RESERVED_ID_MAX 1999L
00077 #undef java_awt_event_KeyEvent_serialVersionUID
00078 #define java_awt_event_KeyEvent_serialVersionUID -1825314779160409405LL
00079 #undef java_awt_event_KeyEvent_COMPONENT_FIRST
00080 #define java_awt_event_KeyEvent_COMPONENT_FIRST 100L
00081 #undef java_awt_event_KeyEvent_COMPONENT_LAST
00082 #define java_awt_event_KeyEvent_COMPONENT_LAST 103L
00083 #undef java_awt_event_KeyEvent_COMPONENT_MOVED
00084 #define java_awt_event_KeyEvent_COMPONENT_MOVED 100L
00085 #undef java_awt_event_KeyEvent_COMPONENT_RESIZED
00086 #define java_awt_event_KeyEvent_COMPONENT_RESIZED 101L
00087 #undef java_awt_event_KeyEvent_COMPONENT_SHOWN
00088 #define java_awt_event_KeyEvent_COMPONENT_SHOWN 102L
00089 #undef java_awt_event_KeyEvent_COMPONENT_HIDDEN
00090 #define java_awt_event_KeyEvent_COMPONENT_HIDDEN 103L
00091 #undef java_awt_event_KeyEvent_serialVersionUID
00092 #define java_awt_event_KeyEvent_serialVersionUID 8101406823902992965LL
00093 #undef java_awt_event_KeyEvent_SHIFT_MASK
00094 #define java_awt_event_KeyEvent_SHIFT_MASK 1L
00095 #undef java_awt_event_KeyEvent_CTRL_MASK
00096 #define java_awt_event_KeyEvent_CTRL_MASK 2L
00097 #undef java_awt_event_KeyEvent_META_MASK
00098 #define java_awt_event_KeyEvent_META_MASK 4L
00099 #undef java_awt_event_KeyEvent_ALT_MASK
00100 #define java_awt_event_KeyEvent_ALT_MASK 8L
00101 #undef java_awt_event_KeyEvent_BUTTON1_MASK
00102 #define java_awt_event_KeyEvent_BUTTON1_MASK 16L
00103 #undef java_awt_event_KeyEvent_BUTTON2_MASK
00104 #define java_awt_event_KeyEvent_BUTTON2_MASK 8L
00105 #undef java_awt_event_KeyEvent_BUTTON3_MASK
00106 #define java_awt_event_KeyEvent_BUTTON3_MASK 4L
00107 #undef java_awt_event_KeyEvent_KEY_FIRST
00108 #define java_awt_event_KeyEvent_KEY_FIRST 400L
00109 #undef java_awt_event_KeyEvent_KEY_LAST
00110 #define java_awt_event_KeyEvent_KEY_LAST 402L
00111 #undef java_awt_event_KeyEvent_KEY_TYPED
00112 #define java_awt_event_KeyEvent_KEY_TYPED 400L
00113 #undef java_awt_event_KeyEvent_KEY_PRESSED
00114 #define java_awt_event_KeyEvent_KEY_PRESSED 401L
00115 #undef java_awt_event_KeyEvent_KEY_RELEASED
00116 #define java_awt_event_KeyEvent_KEY_RELEASED 402L
00117 #undef java_awt_event_KeyEvent_VK_ENTER
00118 #define java_awt_event_KeyEvent_VK_ENTER 10L
00119 #undef java_awt_event_KeyEvent_VK_BACK_SPACE
00120 #define java_awt_event_KeyEvent_VK_BACK_SPACE 8L
00121 #undef java_awt_event_KeyEvent_VK_TAB
00122 #define java_awt_event_KeyEvent_VK_TAB 9L
00123 #undef java_awt_event_KeyEvent_VK_CANCEL
00124 #define java_awt_event_KeyEvent_VK_CANCEL 3L
00125 #undef java_awt_event_KeyEvent_VK_CLEAR
00126 #define java_awt_event_KeyEvent_VK_CLEAR 12L
00127 #undef java_awt_event_KeyEvent_VK_SHIFT
00128 #define java_awt_event_KeyEvent_VK_SHIFT 16L
00129 #undef java_awt_event_KeyEvent_VK_CONTROL
00130 #define java_awt_event_KeyEvent_VK_CONTROL 17L
00131 #undef java_awt_event_KeyEvent_VK_ALT
00132 #define java_awt_event_KeyEvent_VK_ALT 18L
00133 #undef java_awt_event_KeyEvent_VK_PAUSE
00134 #define java_awt_event_KeyEvent_VK_PAUSE 19L
00135 #undef java_awt_event_KeyEvent_VK_CAPS_LOCK
00136 #define java_awt_event_KeyEvent_VK_CAPS_LOCK 20L
00137 #undef java_awt_event_KeyEvent_VK_ESCAPE
00138 #define java_awt_event_KeyEvent_VK_ESCAPE 27L
00139 #undef java_awt_event_KeyEvent_VK_SPACE
00140 #define java_awt_event_KeyEvent_VK_SPACE 32L
00141 #undef java_awt_event_KeyEvent_VK_PAGE_UP
00142 #define java_awt_event_KeyEvent_VK_PAGE_UP 33L
00143 #undef java_awt_event_KeyEvent_VK_PAGE_DOWN
00144 #define java_awt_event_KeyEvent_VK_PAGE_DOWN 34L
00145 #undef java_awt_event_KeyEvent_VK_END
00146 #define java_awt_event_KeyEvent_VK_END 35L
00147 #undef java_awt_event_KeyEvent_VK_HOME
00148 #define java_awt_event_KeyEvent_VK_HOME 36L
00149 #undef java_awt_event_KeyEvent_VK_LEFT
00150 #define java_awt_event_KeyEvent_VK_LEFT 37L
00151 #undef java_awt_event_KeyEvent_VK_UP
00152 #define java_awt_event_KeyEvent_VK_UP 38L
00153 #undef java_awt_event_KeyEvent_VK_RIGHT
00154 #define java_awt_event_KeyEvent_VK_RIGHT 39L
00155 #undef java_awt_event_KeyEvent_VK_DOWN
00156 #define java_awt_event_KeyEvent_VK_DOWN 40L
00157 #undef java_awt_event_KeyEvent_VK_COMMA
00158 #define java_awt_event_KeyEvent_VK_COMMA 44L
00159 #undef java_awt_event_KeyEvent_VK_PERIOD
00160 #define java_awt_event_KeyEvent_VK_PERIOD 46L
00161 #undef java_awt_event_KeyEvent_VK_MINUS
00162 #define java_awt_event_KeyEvent_VK_MINUS 0x2D
00163 #undef java_awt_event_KeyEvent_VK_SLASH
00164 #define java_awt_event_KeyEvent_VK_SLASH 47L
00165 #undef java_awt_event_KeyEvent_VK_0
00166 #define java_awt_event_KeyEvent_VK_0 48L
00167 #undef java_awt_event_KeyEvent_VK_1
00168 #define java_awt_event_KeyEvent_VK_1 49L
00169 #undef java_awt_event_KeyEvent_VK_2
00170 #define java_awt_event_KeyEvent_VK_2 50L
00171 #undef java_awt_event_KeyEvent_VK_3
00172 #define java_awt_event_KeyEvent_VK_3 51L
00173 #undef java_awt_event_KeyEvent_VK_4
00174 #define java_awt_event_KeyEvent_VK_4 52L
00175 #undef java_awt_event_KeyEvent_VK_5
00176 #define java_awt_event_KeyEvent_VK_5 53L
00177 #undef java_awt_event_KeyEvent_VK_6
00178 #define java_awt_event_KeyEvent_VK_6 54L
00179 #undef java_awt_event_KeyEvent_VK_7
00180 #define java_awt_event_KeyEvent_VK_7 55L
00181 #undef java_awt_event_KeyEvent_VK_8
00182 #define java_awt_event_KeyEvent_VK_8 56L
00183 #undef java_awt_event_KeyEvent_VK_9
00184 #define java_awt_event_KeyEvent_VK_9 57L
00185 #undef java_awt_event_KeyEvent_VK_SEMICOLON
00186 #define java_awt_event_KeyEvent_VK_SEMICOLON 59L
00187 #undef java_awt_event_KeyEvent_VK_EQUALS
00188 #define java_awt_event_KeyEvent_VK_EQUALS 61L
00189 #undef java_awt_event_KeyEvent_VK_A
00190 #define java_awt_event_KeyEvent_VK_A 65L
00191 #undef java_awt_event_KeyEvent_VK_B
00192 #define java_awt_event_KeyEvent_VK_B 66L
00193 #undef java_awt_event_KeyEvent_VK_C
00194 #define java_awt_event_KeyEvent_VK_C 67L
00195 #undef java_awt_event_KeyEvent_VK_D
00196 #define java_awt_event_KeyEvent_VK_D 68L
00197 #undef java_awt_event_KeyEvent_VK_E
00198 #define java_awt_event_KeyEvent_VK_E 69L
00199 #undef java_awt_event_KeyEvent_VK_F
00200 #define java_awt_event_KeyEvent_VK_F 70L
00201 #undef java_awt_event_KeyEvent_VK_G
00202 #define java_awt_event_KeyEvent_VK_G 71L
00203 #undef java_awt_event_KeyEvent_VK_H
00204 #define java_awt_event_KeyEvent_VK_H 72L
00205 #undef java_awt_event_KeyEvent_VK_I
00206 #define java_awt_event_KeyEvent_VK_I 73L
00207 #undef java_awt_event_KeyEvent_VK_J
00208 #define java_awt_event_KeyEvent_VK_J 74L
00209 #undef java_awt_event_KeyEvent_VK_K
00210 #define java_awt_event_KeyEvent_VK_K 75L
00211 #undef java_awt_event_KeyEvent_VK_L
00212 #define java_awt_event_KeyEvent_VK_L 76L
00213 #undef java_awt_event_KeyEvent_VK_M
00214 #define java_awt_event_KeyEvent_VK_M 77L
00215 #undef java_awt_event_KeyEvent_VK_N
00216 #define java_awt_event_KeyEvent_VK_N 78L
00217 #undef java_awt_event_KeyEvent_VK_O
00218 #define java_awt_event_KeyEvent_VK_O 79L
00219 #undef java_awt_event_KeyEvent_VK_P
00220 #define java_awt_event_KeyEvent_VK_P 80L
00221 #undef java_awt_event_KeyEvent_VK_Q
00222 #define java_awt_event_KeyEvent_VK_Q 81L
00223 #undef java_awt_event_KeyEvent_VK_R
00224 #define java_awt_event_KeyEvent_VK_R 82L
00225 #undef java_awt_event_KeyEvent_VK_S
00226 #define java_awt_event_KeyEvent_VK_S 83L
00227 #undef java_awt_event_KeyEvent_VK_T
00228 #define java_awt_event_KeyEvent_VK_T 84L
00229 #undef java_awt_event_KeyEvent_VK_U
00230 #define java_awt_event_KeyEvent_VK_U 85L
00231 #undef java_awt_event_KeyEvent_VK_V
00232 #define java_awt_event_KeyEvent_VK_V 86L
00233 #undef java_awt_event_KeyEvent_VK_W
00234 #define java_awt_event_KeyEvent_VK_W 87L
00235 #undef java_awt_event_KeyEvent_VK_X
00236 #define java_awt_event_KeyEvent_VK_X 88L
00237 #undef java_awt_event_KeyEvent_VK_Y
00238 #define java_awt_event_KeyEvent_VK_Y 89L
00239 #undef java_awt_event_KeyEvent_VK_Z
00240 #define java_awt_event_KeyEvent_VK_Z 90L
00241 #undef java_awt_event_KeyEvent_VK_OPEN_BRACKET
00242 #define java_awt_event_KeyEvent_VK_OPEN_BRACKET 91L
00243 #undef java_awt_event_KeyEvent_VK_BACK_SLASH
00244 #define java_awt_event_KeyEvent_VK_BACK_SLASH 92L
00245 #undef java_awt_event_KeyEvent_VK_CLOSE_BRACKET
00246 #define java_awt_event_KeyEvent_VK_CLOSE_BRACKET 93L
00247 #undef java_awt_event_KeyEvent_VK_NUMPAD0
00248 #define java_awt_event_KeyEvent_VK_NUMPAD0 96L
00249 #undef java_awt_event_KeyEvent_VK_NUMPAD1
00250 #define java_awt_event_KeyEvent_VK_NUMPAD1 97L
00251 #undef java_awt_event_KeyEvent_VK_NUMPAD2
00252 #define java_awt_event_KeyEvent_VK_NUMPAD2 98L
00253 #undef java_awt_event_KeyEvent_VK_NUMPAD3
00254 #define java_awt_event_KeyEvent_VK_NUMPAD3 99L
00255 #undef java_awt_event_KeyEvent_VK_NUMPAD4
00256 #define java_awt_event_KeyEvent_VK_NUMPAD4 100L
00257 #undef java_awt_event_KeyEvent_VK_NUMPAD5
00258 #define java_awt_event_KeyEvent_VK_NUMPAD5 101L
00259 #undef java_awt_event_KeyEvent_VK_NUMPAD6
00260 #define java_awt_event_KeyEvent_VK_NUMPAD6 102L
00261 #undef java_awt_event_KeyEvent_VK_NUMPAD7
00262 #define java_awt_event_KeyEvent_VK_NUMPAD7 103L
00263 #undef java_awt_event_KeyEvent_VK_NUMPAD8
00264 #define java_awt_event_KeyEvent_VK_NUMPAD8 104L
00265 #undef java_awt_event_KeyEvent_VK_NUMPAD9
00266 #define java_awt_event_KeyEvent_VK_NUMPAD9 105L
00267 #undef java_awt_event_KeyEvent_VK_MULTIPLY
00268 #define java_awt_event_KeyEvent_VK_MULTIPLY 106L
00269 #undef java_awt_event_KeyEvent_VK_ADD
00270 #define java_awt_event_KeyEvent_VK_ADD 107L
00271 #undef java_awt_event_KeyEvent_VK_SEPARATER
00272 #define java_awt_event_KeyEvent_VK_SEPARATER 108L
00273 #undef java_awt_event_KeyEvent_VK_SUBTRACT
00274 #define java_awt_event_KeyEvent_VK_SUBTRACT 109L
00275 #undef java_awt_event_KeyEvent_VK_DECIMAL
00276 #define java_awt_event_KeyEvent_VK_DECIMAL 110L
00277 #undef java_awt_event_KeyEvent_VK_DIVIDE
00278 #define java_awt_event_KeyEvent_VK_DIVIDE 111L
00279 #undef java_awt_event_KeyEvent_VK_F1
00280 #define java_awt_event_KeyEvent_VK_F1 112L
00281 #undef java_awt_event_KeyEvent_VK_F2
00282 #define java_awt_event_KeyEvent_VK_F2 113L
00283 #undef java_awt_event_KeyEvent_VK_F3
00284 #define java_awt_event_KeyEvent_VK_F3 114L
00285 #undef java_awt_event_KeyEvent_VK_F4
00286 #define java_awt_event_KeyEvent_VK_F4 115L
00287 #undef java_awt_event_KeyEvent_VK_F5
00288 #define java_awt_event_KeyEvent_VK_F5 116L
00289 #undef java_awt_event_KeyEvent_VK_F6
00290 #define java_awt_event_KeyEvent_VK_F6 117L
00291 #undef java_awt_event_KeyEvent_VK_F7
00292 #define java_awt_event_KeyEvent_VK_F7 118L
00293 #undef java_awt_event_KeyEvent_VK_F8
00294 #define java_awt_event_KeyEvent_VK_F8 119L
00295 #undef java_awt_event_KeyEvent_VK_F9
00296 #define java_awt_event_KeyEvent_VK_F9 120L
00297 #undef java_awt_event_KeyEvent_VK_F10
00298 #define java_awt_event_KeyEvent_VK_F10 121L
00299 #undef java_awt_event_KeyEvent_VK_F11
00300 #define java_awt_event_KeyEvent_VK_F11 122L
00301 #undef java_awt_event_KeyEvent_VK_F12
00302 #define java_awt_event_KeyEvent_VK_F12 123L
00303 #undef java_awt_event_KeyEvent_VK_DELETE
00304 #define java_awt_event_KeyEvent_VK_DELETE 127L
00305 #undef java_awt_event_KeyEvent_VK_NUM_LOCK
00306 #define java_awt_event_KeyEvent_VK_NUM_LOCK 144L
00307 #undef java_awt_event_KeyEvent_VK_SCROLL_LOCK
00308 #define java_awt_event_KeyEvent_VK_SCROLL_LOCK 145L
00309 #undef java_awt_event_KeyEvent_VK_PRINTSCREEN
00310 #define java_awt_event_KeyEvent_VK_PRINTSCREEN 154L
00311 #undef java_awt_event_KeyEvent_VK_INSERT
00312 #define java_awt_event_KeyEvent_VK_INSERT 155L
00313 #undef java_awt_event_KeyEvent_VK_HELP
00314 #define java_awt_event_KeyEvent_VK_HELP 156L
00315 #undef java_awt_event_KeyEvent_VK_META
00316 #define java_awt_event_KeyEvent_VK_META 157L
00317 #undef java_awt_event_KeyEvent_VK_BACK_QUOTE
00318 #define java_awt_event_KeyEvent_VK_BACK_QUOTE 192L
00319 #undef java_awt_event_KeyEvent_VK_QUOTE
00320 #define java_awt_event_KeyEvent_VK_QUOTE 222L
00321 #undef java_awt_event_KeyEvent_VK_FINAL
00322 #define java_awt_event_KeyEvent_VK_FINAL 24L
00323 #undef java_awt_event_KeyEvent_VK_CONVERT
00324 #define java_awt_event_KeyEvent_VK_CONVERT 28L
00325 #undef java_awt_event_KeyEvent_VK_NONCONVERT
00326 #define java_awt_event_KeyEvent_VK_NONCONVERT 29L
00327 #undef java_awt_event_KeyEvent_VK_ACCEPT
00328 #define java_awt_event_KeyEvent_VK_ACCEPT 30L
00329 #undef java_awt_event_KeyEvent_VK_MODECHANGE
00330 #define java_awt_event_KeyEvent_VK_MODECHANGE 31L
00331 #undef java_awt_event_KeyEvent_VK_KANA
00332 #define java_awt_event_KeyEvent_VK_KANA 21L
00333 #undef java_awt_event_KeyEvent_VK_KANJI
00334 #define java_awt_event_KeyEvent_VK_KANJI 25L
00335 #undef java_awt_event_KeyEvent_VK_UNDEFINED
00336 #define java_awt_event_KeyEvent_VK_UNDEFINED 0L
00337 #undef java_awt_event_KeyEvent_CHAR_UNDEFINED
00338 #define java_awt_event_KeyEvent_CHAR_UNDEFINED 0L
00339 
00340 #undef java_awt_event_KeyEvent_VK_CUT
00341 #define java_awt_event_KeyEvent_VK_CUT                      0xFFD1
00342 #undef java_awt_event_KeyEvent_VK_COPY
00343 #define java_awt_event_KeyEvent_VK_COPY                     0xFFCD
00344 #undef java_awt_event_KeyEvent_VK_PASTE
00345 #define java_awt_event_KeyEvent_VK_PASTE                    0xFFCF
00346 #undef java_awt_event_KeyEvent_VK_UNDO
00347 #define java_awt_event_KeyEvent_VK_UNDO                     0xFFCB
00348 #undef java_awt_event_KeyEvent_VK_AGAIN
00349 #define java_awt_event_KeyEvent_VK_AGAIN                    0xFFC9
00350 #undef java_awt_event_KeyEvent_VK_FIND
00351 #define java_awt_event_KeyEvent_VK_FIND                     0xFFD0
00352 #undef java_awt_event_KeyEvent_VK_PROPS
00353 #define java_awt_event_KeyEvent_VK_PROPS                    0xFFCA
00354 #undef java_awt_event_KeyEvent_VK_STOP
00355 #define java_awt_event_KeyEvent_VK_STOP                     0xFFC8
00356 
00357 #undef java_awt_event_KeyEvent_VK_AT
00358 #define java_awt_event_KeyEvent_VK_AT                       0x0200
00359 
00360 #undef java_awt_event_InputEvent_SHIFT_MASK
00361 #define java_awt_event_InputEvent_SHIFT_MASK 1L
00362 #undef java_awt_event_InputEvent_CTRL_MASK
00363 #define java_awt_event_InputEvent_CTRL_MASK 2L
00364 #undef java_awt_event_InputEvent_META_MASK
00365 #define java_awt_event_InputEvent_META_MASK 4L
00366 #undef java_awt_event_InputEvent_ALT_MASK
00367 #define java_awt_event_InputEvent_ALT_MASK 8L
00368 #undef java_awt_event_InputEvent_BUTTON1_MASK
00369 #define java_awt_event_InputEvent_BUTTON1_MASK 16L
00370 #undef java_awt_event_InputEvent_BUTTON2_MASK
00371 #define java_awt_event_InputEvent_BUTTON2_MASK 8L
00372 #undef java_awt_event_InputEvent_BUTTON3_MASK
00373 #define java_awt_event_InputEvent_BUTTON3_MASK 4L
00374 
00375 typedef       enum {
00376     FALSE = 0,
00377     TRUE = 1
00378 } bool_t;
00379 
00380 typedef unsigned short unicode;
00381 
00382 #if kana_table
00383 static KeymapEntry2 kana_normal_keymapTable[] = {
00384     { java_awt_event_KeyEvent_VK_1, XK_kana_NU, XK_1, 0xff87, TRUE, 0 },
00385     { java_awt_event_KeyEvent_VK_2, XK_kana_FU, XK_2, 0xff8c, TRUE, 0 },
00386     { java_awt_event_KeyEvent_VK_3, XK_kana_A, XK_3, 0xff71, TRUE, 0 },
00387     { java_awt_event_KeyEvent_VK_4, XK_kana_U, XK_4, 0xff73, TRUE, 0 },
00388     { java_awt_event_KeyEvent_VK_5, XK_kana_E, XK_5, 0xff74, TRUE, 0 },
00389     { java_awt_event_KeyEvent_VK_6, XK_kana_O, XK_6, 0xff75, TRUE, 0 },
00390     { java_awt_event_KeyEvent_VK_7, XK_kana_YA, XK_7, 0xff94, TRUE, 0 },
00391     { java_awt_event_KeyEvent_VK_8, XK_kana_YU, XK_8, 0xff95, TRUE, 0 },
00392     { java_awt_event_KeyEvent_VK_9, XK_kana_YO, XK_9, 0xff96, TRUE, 0 },
00393     { java_awt_event_KeyEvent_VK_0, XK_kana_WA, XK_0, 0xff9c, TRUE, 0 },
00394     { '-',                      XK_kana_HO, XK_minus, 0xff8e, TRUE, 0 },
00395     { '~',                      XK_kana_HE, XK_asciicircum, 0xff8d, TRUE, 0 },
00396     { java_awt_event_KeyEvent_VK_Q, XK_kana_TA, XK_q, 0xff80, TRUE, 0 },
00397     { java_awt_event_KeyEvent_VK_W, XK_kana_TE, XK_w, 0xff83, TRUE, 0 },
00398     { java_awt_event_KeyEvent_VK_E, XK_kana_I, XK_e, 0xff72, TRUE, 0 },
00399     { java_awt_event_KeyEvent_VK_R, XK_kana_SU, XK_r, 0xff7d, TRUE, 0 },
00400     { java_awt_event_KeyEvent_VK_T, XK_kana_KA, XK_t, 0xff76, TRUE, 0 },
00401     { java_awt_event_KeyEvent_VK_Y, XK_kana_N, XK_y, 0xff9d, TRUE, 0 },
00402     { java_awt_event_KeyEvent_VK_U, XK_kana_NA, XK_u, 0xff85, TRUE, 0 },
00403     { java_awt_event_KeyEvent_VK_I, XK_kana_NI, XK_i, 0xff86, TRUE, 0 },
00404     { java_awt_event_KeyEvent_VK_O, XK_kana_RA, XK_o, 0xff97, TRUE, 0 },
00405     { java_awt_event_KeyEvent_VK_P, XK_kana_SE, XK_p, 0xff7e, TRUE, 0 },
00406     { java_awt_event_KeyEvent_VK_AT, XK_voicedsound, XK_at, 0xff9e, TRUE, 0 },
00407     { java_awt_event_KeyEvent_VK_OPEN_BRACKET, XK_semivoicedsound, XK_bracketleft, 0xff9f, TRUE, 0 },
00408     { java_awt_event_KeyEvent_VK_A, XK_kana_CHI, XK_a, 0xff81, TRUE, 0 },
00409     { java_awt_event_KeyEvent_VK_S, XK_kana_TO, XK_s, 0xff84, TRUE, 0 },
00410     { java_awt_event_KeyEvent_VK_D, XK_kana_SHI, XK_d, 0xff7c, TRUE, 0 },
00411     { java_awt_event_KeyEvent_VK_F, XK_kana_HA, XK_f, 0xff8a, TRUE, 0 },
00412     { java_awt_event_KeyEvent_VK_G, XK_kana_KI, XK_g, 0xff77, TRUE, 0 },
00413     { java_awt_event_KeyEvent_VK_H, XK_kana_KU, XK_h, 0xff78, TRUE, 0 },
00414     { java_awt_event_KeyEvent_VK_J, XK_kana_MA, XK_j, 0xff8f, TRUE, 0 },
00415     { java_awt_event_KeyEvent_VK_K, XK_kana_NO, XK_k, 0xff89, TRUE, 0 },
00416     { java_awt_event_KeyEvent_VK_L, XK_kana_RI, XK_l, 0xff98, TRUE, 0 },
00417     { java_awt_event_KeyEvent_VK_SEMICOLON, XK_kana_RE, XK_semicolon, 0xff9a, TRUE, 0 },
00418     { ':',                             XK_kana_KE, XK_colon, 0xff79, TRUE, 0 },
00419     { java_awt_event_KeyEvent_VK_CLOSE_BRACKET, XK_kana_MU, XK_bracketright, 0xff91, TRUE, 0 },
00420     { java_awt_event_KeyEvent_VK_Z, XK_kana_TSU, XK_z, 0xff82, TRUE, 0 },
00421     { java_awt_event_KeyEvent_VK_X, XK_kana_SA, XK_x, 0xff7b, TRUE, 0 },
00422     { java_awt_event_KeyEvent_VK_C, XK_kana_SO, XK_c, 0xff7f, TRUE, 0 },
00423     { java_awt_event_KeyEvent_VK_V, XK_kana_HI, XK_v, 0xff8b, TRUE, 0 },
00424     { java_awt_event_KeyEvent_VK_B, XK_kana_KO, XK_b, 0xff7a, TRUE, 0 },
00425     { java_awt_event_KeyEvent_VK_N, XK_kana_MI, XK_n, 0xff90, TRUE, 0 },
00426     { java_awt_event_KeyEvent_VK_M, XK_kana_MO, XK_m, 0xff93, TRUE, 0 },
00427     { java_awt_event_KeyEvent_VK_COMMA, XK_kana_NE, XK_comma, 0xff88, TRUE, 0 },
00428     { java_awt_event_KeyEvent_VK_PERIOD, XK_kana_RU, XK_period, 0xff99, TRUE , 0},
00429     { java_awt_event_KeyEvent_VK_SLASH, XK_kana_ME, XK_slash, 0xff92, TRUE, 0 },
00430     /* hack to japanese keyboard */
00431     /* backslash is duplicate for RO and prolongedsound */
00432     { java_awt_event_KeyEvent_VK_BACK_SLASH, XK_kana_RO, XK_underscore, 0xff9b, TRUE, 0 },
00433     { java_awt_event_KeyEvent_VK_BACK_SLASH, XK_prolongedsound, XK_bar, 0xff70, TRUE, 0 },
00434     { 0, 0, 0 }
00435 };
00436 
00437 static KeymapEntry2 kana_shift_keymapTable[] = {
00438     { java_awt_event_KeyEvent_VK_3, XK_kana_a, XK_numbersign, 0xff67, TRUE, 0 },
00439     { java_awt_event_KeyEvent_VK_4, XK_kana_u, XK_dollar, 0xff69, TRUE, 0 },
00440     { java_awt_event_KeyEvent_VK_5, XK_kana_e, XK_percent, 0xff6a, TRUE, 0 },
00441     { java_awt_event_KeyEvent_VK_6, XK_kana_o, XK_ampersand, 0xff6b, TRUE, 0 },
00442     { java_awt_event_KeyEvent_VK_7, XK_kana_ya, XK_apostrophe, 0xff6c, TRUE, 0 },
00443     { java_awt_event_KeyEvent_VK_8, XK_kana_yu, XK_parenleft, 0xff6d, TRUE, 0 },
00444     { java_awt_event_KeyEvent_VK_9, XK_kana_yo, XK_parenright, 0xff6e, TRUE, 0 },
00445     { java_awt_event_KeyEvent_VK_0, XK_kana_WO, XK_asciitilde, 0xff66, TRUE, 0 },
00446     { java_awt_event_KeyEvent_VK_E, XK_kana_i, XK_E, 0xff68, TRUE, 0 },
00447     { java_awt_event_KeyEvent_VK_OPEN_BRACKET, XK_kana_openingbracket, XK_braceleft, 0xff62, TRUE, 0 },
00448     { java_awt_event_KeyEvent_VK_CLOSE_BRACKET, XK_kana_closingbracket, XK_braceright, 0xff63, TRUE, 0 },
00449     { java_awt_event_KeyEvent_VK_Z, XK_kana_tsu, XK_Z, 0xff6f, TRUE, 0 },
00450     /* XK_less does not return correct keycode on VineLinux 1.1 */
00451     { java_awt_event_KeyEvent_VK_COMMA, XK_kana_comma, XK_comma, 0xff64, TRUE, 0 },
00452     { java_awt_event_KeyEvent_VK_PERIOD, XK_kana_fullstop, XK_greater, 0xff61, TRUE,0 },
00453     { java_awt_event_KeyEvent_VK_SLASH, XK_kana_conjunctive, XK_question, 0xff65, TRUE,0 },
00454     { 0, 0, 0 }
00455 };
00456 #endif
00457 
00458 static KeymapEntry keymapTable[] = {
00459     { java_awt_event_KeyEvent_VK_A, XK_a, TRUE },
00460     { java_awt_event_KeyEvent_VK_B, XK_b, TRUE },
00461     { java_awt_event_KeyEvent_VK_C, XK_c, TRUE },
00462     { java_awt_event_KeyEvent_VK_D, XK_d, TRUE },
00463     { java_awt_event_KeyEvent_VK_E, XK_e, TRUE },
00464     { java_awt_event_KeyEvent_VK_F, XK_f, TRUE },
00465     { java_awt_event_KeyEvent_VK_G, XK_g, TRUE },
00466     { java_awt_event_KeyEvent_VK_H, XK_h, TRUE },
00467     { java_awt_event_KeyEvent_VK_I, XK_i, TRUE },
00468     { java_awt_event_KeyEvent_VK_J, XK_j, TRUE },
00469     { java_awt_event_KeyEvent_VK_K, XK_k, TRUE },
00470     { java_awt_event_KeyEvent_VK_L, XK_l, TRUE },
00471     { java_awt_event_KeyEvent_VK_M, XK_m, TRUE },
00472     { java_awt_event_KeyEvent_VK_N, XK_n, TRUE },
00473     { java_awt_event_KeyEvent_VK_O, XK_o, TRUE },
00474     { java_awt_event_KeyEvent_VK_P, XK_p, TRUE },
00475     { java_awt_event_KeyEvent_VK_Q, XK_q, TRUE },
00476     { java_awt_event_KeyEvent_VK_R, XK_r, TRUE },
00477     { java_awt_event_KeyEvent_VK_S, XK_s, TRUE },
00478     { java_awt_event_KeyEvent_VK_T, XK_t, TRUE },
00479     { java_awt_event_KeyEvent_VK_U, XK_u, TRUE },
00480     { java_awt_event_KeyEvent_VK_V, XK_v, TRUE },
00481     { java_awt_event_KeyEvent_VK_W, XK_w, TRUE },
00482     { java_awt_event_KeyEvent_VK_X, XK_x, TRUE },
00483     { java_awt_event_KeyEvent_VK_Y, XK_y, TRUE },
00484     { java_awt_event_KeyEvent_VK_Z, XK_z, TRUE },
00485 
00486     { java_awt_event_KeyEvent_VK_ENTER, XK_Return, TRUE },
00487     { java_awt_event_KeyEvent_VK_ENTER, XK_KP_Enter, TRUE },
00488     { java_awt_event_KeyEvent_VK_ENTER, XK_Linefeed, TRUE },
00489 
00490     { java_awt_event_KeyEvent_VK_BACK_SPACE, XK_BackSpace, TRUE },
00491     { java_awt_event_KeyEvent_VK_TAB, XK_Tab, TRUE },
00492     { java_awt_event_KeyEvent_VK_TAB, XK_ISO_Left_Tab, TRUE },
00493     { java_awt_event_KeyEvent_VK_CANCEL, XK_Cancel, FALSE },
00494     { java_awt_event_KeyEvent_VK_CLEAR, XK_Clear, FALSE },
00495     { java_awt_event_KeyEvent_VK_SHIFT, XK_Shift_L, FALSE },
00496     { java_awt_event_KeyEvent_VK_SHIFT, XK_Shift_R, FALSE }, 
00497     { java_awt_event_KeyEvent_VK_CONTROL, XK_Control_L, FALSE },
00498     { java_awt_event_KeyEvent_VK_CONTROL, XK_Control_R, FALSE }, 
00499     { java_awt_event_KeyEvent_VK_ALT, XK_Alt_L, FALSE },
00500     { java_awt_event_KeyEvent_VK_ALT, XK_Alt_R, FALSE },
00501     { java_awt_event_KeyEvent_VK_META, XK_Meta_L, FALSE },
00502     { java_awt_event_KeyEvent_VK_META, XK_Meta_R, FALSE }, 
00503     { java_awt_event_KeyEvent_VK_PAUSE, XK_Pause, FALSE },
00504     { java_awt_event_KeyEvent_VK_CAPS_LOCK, XK_Caps_Lock, FALSE },
00505     { java_awt_event_KeyEvent_VK_ESCAPE, XK_Escape, TRUE },
00506     { java_awt_event_KeyEvent_VK_SPACE, XK_space, TRUE },
00507 
00508     { java_awt_event_KeyEvent_VK_PAGE_UP, XK_Page_Up, FALSE },
00509     { java_awt_event_KeyEvent_VK_PAGE_UP, XK_R9, FALSE },
00510     { java_awt_event_KeyEvent_VK_PAGE_UP, XK_Prior, FALSE },
00511     { java_awt_event_KeyEvent_VK_PAGE_UP, XK_F29, FALSE },
00512     { java_awt_event_KeyEvent_VK_PAGE_DOWN, XK_Page_Down, FALSE },
00513     { java_awt_event_KeyEvent_VK_PAGE_DOWN, XK_R15, FALSE },
00514     { java_awt_event_KeyEvent_VK_PAGE_DOWN, XK_Next, FALSE },
00515     { java_awt_event_KeyEvent_VK_PAGE_DOWN, XK_F35, FALSE },
00516     { java_awt_event_KeyEvent_VK_END, XK_End, FALSE },
00517     { java_awt_event_KeyEvent_VK_END, XK_R13, FALSE },
00518     { java_awt_event_KeyEvent_VK_HOME, XK_Home, FALSE },
00519     { java_awt_event_KeyEvent_VK_HOME, XK_R7, FALSE },
00520     { java_awt_event_KeyEvent_VK_HOME, XK_F27, FALSE },
00521 
00522     { java_awt_event_KeyEvent_VK_LEFT, XK_Left, FALSE },
00523     { java_awt_event_KeyEvent_VK_UP, XK_Up, FALSE },
00524     { java_awt_event_KeyEvent_VK_RIGHT, XK_Right, FALSE },
00525     { java_awt_event_KeyEvent_VK_DOWN, XK_Down, FALSE },
00526     { java_awt_event_KeyEvent_VK_INSERT, XK_Insert, FALSE },
00527     { java_awt_event_KeyEvent_VK_HELP, XK_Help, FALSE },
00528 
00529     { java_awt_event_KeyEvent_VK_0, XK_0, TRUE },
00530     { java_awt_event_KeyEvent_VK_1, XK_1, TRUE },
00531     { java_awt_event_KeyEvent_VK_2, XK_2, TRUE },
00532     { java_awt_event_KeyEvent_VK_3, XK_3, TRUE },
00533     { java_awt_event_KeyEvent_VK_4, XK_4, TRUE },
00534     { java_awt_event_KeyEvent_VK_5, XK_5, TRUE },
00535     { java_awt_event_KeyEvent_VK_6, XK_6, TRUE },
00536     { java_awt_event_KeyEvent_VK_7, XK_7, TRUE },
00537     { java_awt_event_KeyEvent_VK_8, XK_8, TRUE },
00538     { java_awt_event_KeyEvent_VK_9, XK_9, TRUE },
00539 
00540     { java_awt_event_KeyEvent_VK_EQUALS, XK_equal, TRUE },
00541     { java_awt_event_KeyEvent_VK_BACK_SLASH, XK_backslash, TRUE },
00542     { java_awt_event_KeyEvent_VK_BACK_QUOTE, XK_grave, TRUE },
00543     { java_awt_event_KeyEvent_VK_OPEN_BRACKET, XK_bracketleft, TRUE },
00544     { java_awt_event_KeyEvent_VK_CLOSE_BRACKET, XK_bracketright, TRUE },
00545     { java_awt_event_KeyEvent_VK_SEMICOLON, XK_semicolon, TRUE },
00546     { java_awt_event_KeyEvent_VK_QUOTE, XK_apostrophe, TRUE },
00547     { java_awt_event_KeyEvent_VK_MINUS, XK_minus, TRUE },
00548     { java_awt_event_KeyEvent_VK_COMMA, XK_comma, TRUE },
00549     { java_awt_event_KeyEvent_VK_PERIOD, XK_period, TRUE },
00550     { java_awt_event_KeyEvent_VK_SLASH, XK_slash, TRUE },
00551 
00552     { java_awt_event_KeyEvent_VK_NUMPAD0, XK_KP_0, TRUE },
00553     { java_awt_event_KeyEvent_VK_NUMPAD1, XK_KP_1, TRUE },
00554     { java_awt_event_KeyEvent_VK_NUMPAD2, XK_KP_2, TRUE },
00555     { java_awt_event_KeyEvent_VK_NUMPAD3, XK_KP_3, TRUE },
00556     { java_awt_event_KeyEvent_VK_NUMPAD4, XK_KP_4, TRUE },
00557     { java_awt_event_KeyEvent_VK_NUMPAD5, XK_KP_5, TRUE },
00558     { java_awt_event_KeyEvent_VK_NUMPAD6, XK_KP_6, TRUE },
00559     { java_awt_event_KeyEvent_VK_NUMPAD7, XK_KP_7, TRUE },
00560     { java_awt_event_KeyEvent_VK_NUMPAD8, XK_KP_8, TRUE },
00561     { java_awt_event_KeyEvent_VK_NUMPAD9, XK_KP_9, TRUE },
00562     { java_awt_event_KeyEvent_VK_MULTIPLY, XK_KP_Multiply, TRUE },
00563     { java_awt_event_KeyEvent_VK_ADD, XK_KP_Add, TRUE },
00564     { java_awt_event_KeyEvent_VK_SUBTRACT, XK_KP_Subtract, TRUE },
00565     { java_awt_event_KeyEvent_VK_DECIMAL, XK_KP_Decimal, TRUE },
00566     { java_awt_event_KeyEvent_VK_DIVIDE, XK_KP_Divide, TRUE },
00567     { java_awt_event_KeyEvent_VK_EQUALS, XK_KP_Equal, TRUE },
00568     { java_awt_event_KeyEvent_VK_INSERT, XK_KP_Insert, FALSE },
00569     { java_awt_event_KeyEvent_VK_ENTER, XK_KP_Enter, FALSE },
00570 
00571     { java_awt_event_KeyEvent_VK_F1, XK_F1, FALSE },
00572     { java_awt_event_KeyEvent_VK_F2, XK_F2, FALSE },
00573     { java_awt_event_KeyEvent_VK_F3, XK_F3, FALSE },
00574     { java_awt_event_KeyEvent_VK_F4, XK_F4, FALSE },
00575     { java_awt_event_KeyEvent_VK_F5, XK_F5, FALSE },
00576     { java_awt_event_KeyEvent_VK_F6, XK_F6, FALSE },
00577     { java_awt_event_KeyEvent_VK_F7, XK_F7, FALSE },
00578     { java_awt_event_KeyEvent_VK_F8, XK_F8, FALSE },
00579     { java_awt_event_KeyEvent_VK_F9, XK_F9, FALSE },
00580     { java_awt_event_KeyEvent_VK_F10, XK_F10, FALSE },
00581     /* next two entries for for 4173902 */
00582     { java_awt_event_KeyEvent_VK_F11, SunXK_F36, FALSE },
00583     { java_awt_event_KeyEvent_VK_F12, SunXK_F37, FALSE },
00584     { java_awt_event_KeyEvent_VK_F11, XK_F11, FALSE },
00585     { java_awt_event_KeyEvent_VK_F12, XK_F12, FALSE },
00586 
00587     { java_awt_event_KeyEvent_VK_DELETE, XK_Delete, TRUE },
00588     { java_awt_event_KeyEvent_VK_DELETE, XK_KP_Delete, TRUE },
00589 
00590     { java_awt_event_KeyEvent_VK_NUM_LOCK, XK_Num_Lock, FALSE },
00591     { java_awt_event_KeyEvent_VK_SCROLL_LOCK, XK_Scroll_Lock, FALSE },
00592     { java_awt_event_KeyEvent_VK_PRINTSCREEN, XK_Print, FALSE },
00593 
00594     { java_awt_event_KeyEvent_VK_ACCEPT, XK_Execute, FALSE },
00595 
00596 #ifdef JAVA_12_BUG
00597     /* bugs in Java2 4124396
00598 
00599        - Convert key (right of Space key): generates VK_KANJI,
00600               should generate VK_CONVERT.
00601        - Nihongo On-Off key (right of Convert key): generates VK_CONVERT,
00602               should generate VK_KANJI.
00603 
00604     */
00605 
00606     { java_awt_event_KeyEvent_VK_CONVERT, XK_Henkan_Mode, FALSE },
00607     { java_awt_event_KeyEvent_VK_KANJI, XK_Kanji, FALSE },
00608 #else
00609     { java_awt_event_KeyEvent_VK_KANJI, XK_Henkan_Mode, FALSE },
00610     { java_awt_event_KeyEvent_VK_CONVERT, XK_Kanji, FALSE },
00611 #endif
00612 
00613     { java_awt_event_KeyEvent_VK_NONCONVERT, XK_Muhenkan, FALSE },
00614 
00615     { java_awt_event_KeyEvent_VK_KANA, XK_Katakana, FALSE },
00616     { java_awt_event_KeyEvent_VK_KANA, XK_kana_switch, FALSE },
00617 
00618     { java_awt_event_KeyEvent_VK_CUT, XK_F20, FALSE },
00619     { java_awt_event_KeyEvent_VK_COPY, XK_F16, FALSE },
00620     { java_awt_event_KeyEvent_VK_PASTE, XK_F18, FALSE },
00621     { java_awt_event_KeyEvent_VK_UNDO, XK_F14, FALSE },
00622     { java_awt_event_KeyEvent_VK_FIND, XK_F19, FALSE },
00623     { java_awt_event_KeyEvent_VK_PROPS, XK_F13, FALSE },
00624 
00625     { 0, 0, 0 }
00626 };
00627 
00628 static KeySym getX11KeySym(long awtKey) 
00629 {
00630     int i;
00631     for (i = 0; keymapTable[i].awtKey != 0; i++) {
00632         if (keymapTable[i].awtKey == awtKey) {
00633          /* stop checking printable or not, otherwise
00634             arrow keys won't work
00635            if (keymapTable[i].printable == FALSE) return 0;
00636            */
00637          return keymapTable[i].x11Key;
00638         }
00639     }
00640     return 0;
00641 }
00642 
00643 static long getAWTKeyCode(long keysym) 
00644 {
00645     int i;
00646     for (i = 0; keymapTable[i].awtKey != 0; i++) {
00647         if (keymapTable[i].x11Key == keysym) {
00648          return keymapTable[i].awtKey;
00649         }
00650     }
00651     return 0;
00652 }
00653 
00654 /* for kana */
00655 #if kana_table
00656 static void getAWTKeyCode2(long keysym, int *keycode, int *keychar) 
00657 {
00658     int i;
00659          *keycode = 0;
00660          *keychar = 0;
00661 
00662     for (i = 0; kana_normal_keymapTable[i].awtKey != 0; i++) {
00663         if (kana_normal_keymapTable[i].x11Key == keysym) {
00664          *keycode = kana_normal_keymapTable[i].awtKey;
00665          *keychar = kana_normal_keymapTable[i].keychar;
00666          return;
00667         }
00668     }
00669     for (i = 0; kana_shift_keymapTable[i].awtKey != 0; i++) {
00670         if (kana_shift_keymapTable[i].x11Key == keysym) {
00671          *keycode = kana_shift_keymapTable[i].awtKey;
00672          *keychar = kana_shift_keymapTable[i].keychar;
00673          return;
00674         }
00675     }
00676     return;
00677 }
00678 #endif
00679 
00680 static void
00681 set_mod_mask(int modnum, int *mask) {
00682     switch(modnum) {
00683       case 1: 
00684        *mask = Mod1Mask;
00685        break;               
00686       case 2: 
00687        *mask = Mod2Mask;
00688        break;        
00689       case 3: 
00690        *mask = Mod3Mask;
00691        break;               
00692       case 4: 
00693        *mask = Mod4Mask;
00694        break; 
00695       case 5:
00696        *mask = Mod5Mask;
00697        break;
00698       default:
00699        *mask = 0;
00700     }
00701 }
00702 
00703 static void
00704 setup_modifier_map(Display *disp)
00705 {
00706     XModifierKeymap *modmap; 
00707     int i, k, nkeys;
00708     KeyCode keycode, metaL, metaR, altL, altR, numLock, Mode_switch;
00709 
00710     metaL = XKeysymToKeycode(disp, XK_Meta_L);
00711     metaR = XKeysymToKeycode(disp, XK_Meta_R);
00712     altR = XKeysymToKeycode(disp, XK_Alt_R);
00713     altL = XKeysymToKeycode(disp, XK_Alt_L);
00714     numLock = XKeysymToKeycode(disp, XK_Num_Lock);
00715     Mode_switch = XKeysymToKeycode(disp, XK_Mode_switch);
00716 
00717     modmap = XGetModifierMapping(disp);
00718     nkeys = modmap->max_keypermod;
00719     for(i = 3*nkeys; 
00720        i < (nkeys*8) && (awt_MetaMask == 0 || awt_AltMask == 0 || awt_NumLockMask == 0 || awt_KanaLockMask ==0);
00721             i++) {
00722        keycode = modmap->modifiermap[i];
00723        k = (i/nkeys) - 2;
00724        if (awt_MetaMask == 0 && (keycode == metaL || keycode == metaR)) {
00725            set_mod_mask(k, &awt_MetaMask);
00726        } else if (awt_AltMask == 0 && (keycode == altL || keycode == altR)) {
00727            set_mod_mask(k, &awt_AltMask);
00728        } else if (awt_NumLockMask == 0 && keycode == numLock) {
00729             set_mod_mask(k, &awt_NumLockMask);
00730        } else if (awt_KanaLockMask == 0 && keycode == Mode_switch) {
00731             set_mod_mask(k, &awt_KanaLockMask);
00732         }
00733     }
00734     XFreeModifiermap(modmap);
00735 
00736 #ifdef linux
00737     /* hack for Linux XFree86 */
00738     if (getenv("HTT_USES_LINUX_XKEYSYM")){
00739            for (i = 0; keymapTable[i].awtKey != 0; i++) {
00740               if (keymapTable[i].x11Key == XK_Henkan_Mode) {
00741                 keymapTable[i].x11Key = XK_Zenkaku_Hankaku;
00742                 break;
00743               }
00744            }
00745            for (i = 0; keymapTable[i].awtKey != 0; i++) {
00746               if (keymapTable[i].x11Key == XK_Kanji) {
00747                 keymapTable[i].x11Key = XK_Henkan_Mode;
00748                 break;
00749               }
00750            }
00751            for (i = 0; keymapTable[i].awtKey != 0; i++) {
00752               if (keymapTable[i].x11Key == XK_Execute) {
00753                 keymapTable[i].x11Key = XK_Muhenkan;
00754                 break;
00755               }
00756            }
00757     }
00758 
00759     /* hack for Linux XFree86 */
00760     if (getenv("HTT_GENERATES_KANAKEY")){
00761        KanaMode = 0;
00762     } else {
00763        return;
00764     }
00765 
00766     /* Get Keycodes for Kana keys */
00767     for (i = 0; kana_normal_keymapTable[i].awtKey != 0; i++) {
00768        kana_normal_keymapTable[i].keycode = XKeysymToKeycode(disp,
00769                                           kana_normal_keymapTable[i].x11Key);
00770        if (kana_normal_keymapTable[i].keycode == 0) {
00771               kana_normal_keymapTable[i].keycode = XKeysymToKeycode(disp,
00772                                           kana_normal_keymapTable[i].alt_x11Key);
00773        }
00774 #ifdef DEBUG
00775        printf("xkey=%x(%x) -> %x\n", kana_normal_keymapTable[i].x11Key,
00776                                    kana_normal_keymapTable[i].keychar,
00777                                    kana_normal_keymapTable[i].keycode);
00778 #endif
00779     }
00780     for (i = 0; kana_shift_keymapTable[i].awtKey != 0; i++) {
00781        kana_shift_keymapTable[i].keycode = XKeysymToKeycode(disp,
00782                                           kana_shift_keymapTable[i].x11Key);
00783        if (kana_shift_keymapTable[i].keycode == 0) {
00784               kana_shift_keymapTable[i].keycode = XKeysymToKeycode(disp,
00785                                           kana_shift_keymapTable[i].alt_x11Key);
00786        }
00787 #ifdef DEBUG
00788        printf("xkey=%x(%x) -> %x\n", kana_shift_keymapTable[i].x11Key,
00789                                    kana_shift_keymapTable[i].keychar,
00790                                    kana_shift_keymapTable[i].keycode);
00791 #endif
00792     }
00793 
00794     if (!kanawin_atom) {
00795        kanawin_atom = XInternAtom(disp, "HTT_KANA_WIN", False);
00796        kanaflag_atom = XInternAtom(disp, "HTT_KANA_FLAG", False);
00797     }
00798 
00799     kana_w = XGetSelectionOwner(disp, kanawin_atom);
00800 
00801     if (kana_w == None) {
00802        kana_w = XCreateSimpleWindow(disp, RootWindow(disp, 0),
00803                      0, 0, 1, 1, 0, 0, 0);
00804 
00805        XSetSelectionOwner(disp, kanawin_atom, kana_w, CurrentTime);
00806 
00807        XChangeProperty(disp, kana_w, kanaflag_atom, XA_WINDOW, 32,
00808                             PropModeReplace,
00809                             &KanaMode, sizeof(KanaMode));
00810     }
00811 
00812     GetKanaFlag(disp);
00813 #endif /* linux */
00814 }
00815 
00816 #ifdef linux
00817 GetKanaFlag(Display *disp)
00818 {
00819     Atom            ret_type;
00820     int             ret_format;
00821     unsigned long   nitems, bytes_left;
00822     unsigned long  *tmp;
00823 
00824     XGetWindowProperty(disp, kana_w,
00825                      kanaflag_atom, 0, 4, False, XA_WINDOW,
00826                      &ret_type, &ret_format,
00827                      &nitems, &bytes_left, &tmp);
00828 
00829     if (ret_type == XA_WINDOW) {
00830        KanaMode = *tmp;
00831     }
00832 }
00833 #endif /* linux */
00834 
00835 /*
00836        XKeysymToKeycode() does not return correct keycode for XK_Delete.
00837        So we store and keep the value of KeyCode at the first key typed,
00838        then use in modify_Event()
00839 */
00840 
00841 static long keyCode_XK_Delete = 0;
00842 
00843 static void
00844 modify_Event(XEvent *xevent, long keyCode, unicode keyChar, long modifiers)
00845 {
00846     KeySym keysym = 0;
00847 
00848     if (xevent->type != KeyPress && xevent->type != KeyRelease)
00849         return;
00850 
00851     switch(keyCode) {
00852       case java_awt_event_KeyEvent_VK_ENTER:
00853       case java_awt_event_KeyEvent_VK_BACK_SPACE:
00854       case java_awt_event_KeyEvent_VK_TAB:
00855       case java_awt_event_KeyEvent_VK_ESCAPE:
00856       case java_awt_event_KeyEvent_VK_MULTIPLY:
00857       case java_awt_event_KeyEvent_VK_ADD:
00858       case java_awt_event_KeyEvent_VK_SUBTRACT:
00859       case java_awt_event_KeyEvent_VK_DIVIDE:
00860       case java_awt_event_KeyEvent_VK_EQUALS:
00861       case java_awt_event_KeyEvent_VK_DECIMAL:
00862           keysym = getX11KeySym(keyCode);
00863           break;
00864       default:
00865           if ((keyChar != 0 && keyChar < 256)
00866              || (keyChar >= 0xff61 && keyChar <= 0xff9f)) {
00867               keysym = keyChar;
00868           } else {
00869               keysym = getX11KeySym(keyCode);
00870           }
00871           break;
00872     }
00873 
00874     if (keysym != 0) {
00875        if (modifiers & java_awt_event_InputEvent_CTRL_MASK) {
00876            switch (keysym + 64) {
00877              case '[':
00878              case ']':
00879              case '\\':
00880              case '_':
00881               keysym += 64;
00882               break;
00883              default:
00884               if (keysym < 254) {
00885                 if (modifiers & java_awt_event_InputEvent_SHIFT_MASK) {
00886                   if (isalpha(keysym + 'A' - 1)) {
00887                     keysym += ('A' - 1);
00888                   }
00889                 } else {
00890                   if (isalpha(keysym + 'a' - 1)) {
00891                     keysym += ('a' - 1);
00892                   }
00893                 }
00894               }
00895               break;
00896            }
00897        }
00898 
00899        /*
00900         * 0xff61 is Unicode value of first XK_kana_fullstop.
00901         * We need X Keysym to Unicode map in post1.1 release
00902         * to support more intenational keyboard.
00903         */
00904        /*
00905         * 0xff63 is duplicate with INSERT
00906         */
00907        if (keyCode != java_awt_event_KeyEvent_VK_INSERT &&
00908            keyCode != java_awt_event_KeyEvent_VK_ACCEPT &&
00909            keyCode != java_awt_event_KeyEvent_VK_ENTER &&
00910            (keysym >= 0xff61 && keysym <= 0xff9f)) {
00911            keysym = keysym - 0xff61 + XK_kana_fullstop;
00912 
00913            /*
00914             * modifier needs to be set
00915             */
00916            xevent->xkey.state |= awt_KanaLockMask;
00917        }
00918 
00919        /* workaround, do we have to set NumLock mask for
00920           all KP_ keysym??? */
00921        if(keysym == XK_KP_Decimal){
00922            xevent->xkey.state |= awt_NumLockMask;
00923         }
00924 
00925        if (xevent->xany.display)
00926            xevent->xkey.keycode = XKeysymToKeycode(xevent->xany.display,
00927                                               keysym);
00928        else
00929            xevent->xkey.keycode = keysym; /* hack */
00930 
00931        /* workaround for XKeysymToKeycode() */
00932        if (keyCode == java_awt_event_KeyEvent_VK_DELETE){
00933            xevent->xkey.keycode = keyCode_XK_Delete;
00934        }
00935     }
00936 
00937     if (keysym >= 'A' && keysym <= 'Z') {
00938        xevent->xkey.state |= ShiftMask;
00939     }
00940     if (modifiers & java_awt_event_InputEvent_SHIFT_MASK) {
00941        xevent->xkey.state |= ShiftMask;
00942     }
00943     if (modifiers & java_awt_event_InputEvent_CTRL_MASK) {
00944        xevent->xkey.state |= ControlMask;
00945     }
00946     if (modifiers & java_awt_event_InputEvent_META_MASK) {
00947        xevent->xkey.state |= awt_MetaMask;
00948     }
00949     if (modifiers & java_awt_event_InputEvent_ALT_MASK) {
00950        xevent->xkey.state |= awt_AltMask;
00951     }
00952     if (modifiers & java_awt_event_InputEvent_BUTTON1_MASK) {
00953         xevent->xkey.state |= Button1Mask;
00954     }
00955     if (modifiers & java_awt_event_InputEvent_BUTTON2_MASK) {
00956         xevent->xkey.state |= Button2Mask;
00957     }
00958     if (modifiers & java_awt_event_InputEvent_BUTTON3_MASK) {
00959         xevent->xkey.state |= Button3Mask;
00960     }
00961 }
00962 
00963 static int first_call = True;
00964 
00965 void
00966 VirtualKeyToXKeyEvent(CARD32 keyCode, CARD32 keyChar,
00967                     CARD32 state, XKeyEvent *kev) {
00968 
00969     if (first_call && kev->display != (Display*)0) {
00970        setup_modifier_map(kev->display);
00971     }
00972     first_call = False;
00973     modify_Event((XEvent*)kev, keyCode, keyChar, state);
00974     return;
00975 }
00976 
00977 /*
00978   KeyEventToVirtualKey() :
00979      Convert X KeyEvent to IIIMP keyCode, keyChar, state values
00980  */
00981 Bool
00982 KeyEventToVirtualKey(XKeyEvent *ev, int *keycode_ret,
00983                    int *keychar_ret, int *state_ret) {
00984   KeySym keysym;
00985   char buf[64];
00986   int len = sizeof(buf);
00987   int state;
00988   int i;
00989 
00990   *keychar_ret = 0;
00991   *keycode_ret = 0;
00992 
00993   if (first_call && ev->display != (Display*)0) {
00994      setup_modifier_map(ev->display);
00995   }
00996   first_call = False;
00997 
00998   state = ev->state;
00999 
01000   /* LockMask, NumLockMask, KanaLockMask should be ignored for
01001      Java Client compatibility */
01002   if(state & LockMask){
01003     state -= LockMask;
01004   }
01005   if(state & awt_NumLockMask){
01006     state -= awt_NumLockMask;
01007   }
01008   if(state & awt_KanaLockMask){
01009     state -= awt_KanaLockMask;
01010   }
01011 
01012   /* IIIMP's control_mask(1<<1) and X's control_mask(1<<2)is
01013        different, so it should be changed */
01014   if (state & ControlMask) {
01015     state -= (1<<2);
01016     state |= (1<<1);
01017   }
01018 
01019   *state_ret = state;
01020 
01021   len = XLookupString(ev, buf, len - 1, &keysym, NULL);
01022 
01023 #ifdef  linux
01024    /* Linux generates XK_Mode_switch at Shift + Henkan_Mode */
01025    if (getenv("HTT_USES_LINUX_XKEYSYM")&&
01026         ((state & ShiftMask) && keysym == XK_Mode_switch)){
01027         keysym = XK_Henkan_Mode;
01028    } else
01029 #endif /* linux */
01030   if (IsModifierKey(keysym)) {
01031        return False;
01032   }
01033 
01034 #ifdef linux
01035   if (KanaMode != -1){
01036        if (keysym == XK_Hiragana_Katakana){
01037 #ifdef DEBUG
01038               printf("Kanakey is pressed\n");
01039 #endif
01040               if (KanaMode == 1){
01041                      KanaMode = 0;
01042 #ifdef DEBUG
01043               printf("      off\n");
01044 #endif
01045               } else {
01046                      KanaMode = 1;
01047 #ifdef DEBUG
01048               printf("      on\n");
01049 #endif
01050               }
01051               XChangeProperty(ev->display, kana_w, kanaflag_atom,
01052                             XA_WINDOW, 32,
01053                             PropModeReplace,
01054                             &KanaMode, sizeof(KanaMode));
01055               return False;
01056        }
01057   }
01058 
01059   if (KanaMode != -1){
01060        GetKanaFlag(ev->display);
01061   }     
01062 
01063   if (KanaMode == 1) {
01064        if (ev->state & ShiftMask) {
01065               /* check kana_shift_keymapTable first is ShiftMask */
01066               for (i = 0; kana_shift_keymapTable[i].awtKey != 0; i++) {
01067                      if (kana_shift_keymapTable[i].keycode == ev->keycode) {
01068                             getAWTKeyCode2(kana_shift_keymapTable[i].x11Key, keycode_ret, keychar_ret);
01069                             if (*keycode_ret) {
01070                                    return True;
01071                             }
01072                             break;
01073                      }
01074               }
01075        }
01076 
01077        for (i = 0; kana_normal_keymapTable[i].awtKey != 0; i++) {
01078               if (kana_normal_keymapTable[i].keycode == ev->keycode) {
01079                      getAWTKeyCode2(kana_normal_keymapTable[i].x11Key, keycode_ret, keychar_ret);
01080                      if (*keycode_ret) {
01081                             return True;
01082                      }
01083                      break;
01084               }
01085        }
01086 
01087        for (i = 0; kana_shift_keymapTable[i].awtKey != 0; i++) {
01088               if (kana_shift_keymapTable[i].keycode == ev->keycode) {
01089                      getAWTKeyCode2(kana_shift_keymapTable[i].x11Key, keycode_ret, keychar_ret);
01090                      if (*keycode_ret) {
01091                             return True;
01092                      }
01093                      break;
01094               }
01095        }
01096    }
01097 #endif /* linux */
01098 
01099   /* store keycode for XK_Delete */
01100   if(keysym == XK_Delete && keyCode_XK_Delete == 0){
01101        keyCode_XK_Delete = ev->keycode;
01102   }
01103 
01104   if (keysym < 256) {
01105     if ((ev->state & ControlMask)) {
01106        if (isalpha(keysym)) {
01107          keysym = toupper(keysym);
01108        }
01109     }
01110     *keycode_ret = getAWTKeyCode(keysym);
01111     if (*keycode_ret == 0 && (ev->state & ShiftMask)) {
01112        /* when Shift key is pressed, need to get the normal keysym,
01113           then get the AWT keycode */
01114        if (ev->display != (Display*)0) {
01115           *keycode_ret = getAWTKeyCode(XKeycodeToKeysym(ev->display,
01116                                                  ev->keycode, 0));
01117        }
01118     }
01119     if (*keycode_ret == 0) {
01120         *keycode_ret = keysym;
01121     }
01122     *keychar_ret = keysym;
01123     return True;
01124   } else {
01125     *keycode_ret = getAWTKeyCode(keysym);
01126     switch (keysym) {
01127     case XK_KP_Decimal:
01128       *keychar_ret = '.';
01129       break;
01130     case XK_KP_Add:
01131       *keychar_ret = '+';
01132       break;
01133     case XK_KP_Subtract:
01134       *keychar_ret = '-';
01135       break;
01136     case XK_KP_Divide:
01137       *keychar_ret = '/';
01138       break;
01139     case XK_KP_Multiply:
01140       *keychar_ret = '*';
01141       break;
01142     case XK_KP_0:
01143       *keychar_ret = '0';
01144       break;
01145     case XK_KP_1:
01146       *keychar_ret = '1';
01147       break;
01148     case XK_KP_2:
01149       *keychar_ret = '2';
01150       break;
01151     case XK_KP_3:
01152       *keychar_ret = '3';
01153       break;
01154     case XK_KP_4:
01155       *keychar_ret = '4';
01156       break;
01157     case XK_KP_5:
01158       *keychar_ret = '5';
01159       break;
01160     case XK_KP_6:
01161       *keychar_ret = '6';
01162       break;
01163     case XK_KP_7:
01164       *keychar_ret = '7';
01165       break;
01166     case XK_KP_8:
01167       *keychar_ret = '8';
01168       break;
01169     case XK_KP_9:
01170       *keychar_ret = '9';
01171       break;
01172     }
01173     if(*keycode_ret) {
01174         return True;
01175     }
01176 
01177     /* get Kana code */
01178     getAWTKeyCode2(keysym, keycode_ret, keychar_ret);
01179 
01180     if (*keycode_ret) {
01181         return True;
01182     }
01183 
01184     if (*keycode_ret == 0 && (ev->state & ShiftMask)) {
01185         /* when Shift key is pressed, need to get the normal keysym,
01186           then get the AWT keycode */
01187        *keycode_ret = getAWTKeyCode(XKeycodeToKeysym(ev->display,
01188                                                  ev->keycode, 0));
01189     }
01190 
01191     if (*keycode_ret) {
01192         return True;
01193     }
01194   }
01195   return False;
01196 }