1 /*
2 
3   Copyright (c) 2007-2013 uim Project https://github.com/uim/uim
4 
5   All rights reserved.
6 
7   Redistribution and use in source and binary forms, with or without
8   modification, are permitted provided that the following conditions
9   are met:
10 
11   1. Redistributions of source code must retain the above copyright
12      notice, this list of conditions and the following disclaimer.
13   2. Redistributions in binary form must reproduce the above copyright
14      notice, this list of conditions and the following disclaimer in the
15      documentation and/or other materials provided with the distribution.
16   3. Neither the name of authors nor the names of its contributors
17      may be used to endorse or promote products derived from this software
18      without specific prior written permission.
19 
20   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
21   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
24   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26   OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29   OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30   SUCH DAMAGE.
31 
32 */
33 
34 #include <X11/Xlib.h>
35 #include <X11/keysym.h>
36 
37 #include "uim-x-util.h"
38 
39 int
uim_x_keysym2ukey(KeySym xkeysym)40 uim_x_keysym2ukey(KeySym xkeysym)
41 {
42     int ukey = UKey_Other;
43 
44     if (xkeysym < 256 && xkeysym >= 32)
45 	ukey = (int)(xkeysym);
46     else if (xkeysym >= XK_F1 && xkeysym <= XK_F35)
47 	ukey = (int)(xkeysym - XK_F1 + UKey_F1);
48     /* GTK+ and Qt don't support dead_stroke yet */
49     else if (xkeysym >= XK_dead_grave && xkeysym <= XK_dead_horn)
50 	ukey = (int)(xkeysym - XK_dead_grave + UKey_Dead_Grave);
51     else if (xkeysym >= XK_Kanji && xkeysym <= XK_Eisu_toggle)
52 	ukey = (int)(xkeysym - XK_Kanji + UKey_Kanji);
53     else if (xkeysym >= XK_Hangul && xkeysym <= XK_Hangul_Special)
54 	ukey = (int)(xkeysym - XK_Hangul + UKey_Hangul);
55     else if (xkeysym >= XK_kana_fullstop && xkeysym <= XK_semivoicedsound)
56 	ukey = (int)(xkeysym - XK_kana_fullstop + UKey_Kana_Fullstop);
57     else {
58 	switch (xkeysym) {
59 	case XK_yen: ukey = UKey_Yen; break;
60 	case XK_BackSpace: ukey = UKey_Backspace; break;
61 	case XK_Delete: ukey = UKey_Delete; break;
62 	case XK_Insert: ukey = UKey_Insert; break;
63 	case XK_Escape: ukey = UKey_Escape; break;
64 	case XK_Tab:
65 	case XK_ISO_Left_Tab: ukey = UKey_Tab; break;
66 	case XK_Return: ukey = UKey_Return; break;
67 	case XK_Left: ukey = UKey_Left; break;
68 	case XK_Up: ukey = UKey_Up; break;
69 	case XK_Right: ukey = UKey_Right; break;
70 	case XK_Down: ukey = UKey_Down; break;
71 	case XK_Prior: ukey = UKey_Prior; break;
72 	case XK_Next: ukey = UKey_Next; break;
73 	case XK_Home: ukey = UKey_Home; break;
74 	case XK_End: ukey = UKey_End; break;
75 	case XK_Multi_key: ukey = UKey_Multi_key; break;
76 	case XK_Codeinput: ukey = UKey_Codeinput; break;
77 	case XK_SingleCandidate: ukey = UKey_SingleCandidate; break;
78 	case XK_MultipleCandidate: ukey = UKey_MultipleCandidate; break;
79 	case XK_PreviousCandidate: ukey = UKey_PreviousCandidate; break;
80 	case XK_Mode_switch: ukey = UKey_Mode_switch; break;
81 	case XK_Shift_L: ukey = UKey_Shift_key; break;
82 	case XK_Shift_R: ukey = UKey_Shift_key; break;
83 	case XK_Control_L: ukey = UKey_Control_key; break;
84 	case XK_Control_R: ukey = UKey_Control_key; break;
85 	case XK_Alt_L: ukey = UKey_Alt_key; break;
86 	case XK_Alt_R: ukey = UKey_Alt_key; break;
87 	case XK_Meta_L: ukey = UKey_Meta_key; break;
88 	case XK_Meta_R: ukey = UKey_Meta_key; break;
89 	case XK_Super_L: ukey = UKey_Super_key; break;
90 	case XK_Super_R: ukey = UKey_Super_key; break;
91 	case XK_Hyper_L: ukey = UKey_Hyper_key; break;
92 	case XK_Hyper_R: ukey = UKey_Hyper_key; break;
93 	case XK_Caps_Lock: ukey = UKey_Caps_Lock; break;
94 	case XK_Num_Lock: ukey = UKey_Num_Lock; break;
95 	case XK_Scroll_Lock: ukey = UKey_Scroll_Lock; break;
96 	default:
97 	    ukey = UKey_Other;
98 	}
99     }
100 
101     return ukey;
102 }
103