1 | // Copyright (C) 2019 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | /* Copyright 1985, 1987, 1990, 1998 The Open Group |
5 | |
6 | Permission is hereby granted, free of charge, to any person obtaining a |
7 | copy of this software and associated documentation files (the "Software"), |
8 | to deal in the Software without restriction, including without limitation |
9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
10 | and/or sell copies of the Software, and to permit persons to whom the |
11 | Software is furnished to do so, subject to the following conditions: |
12 | |
13 | The above copyright notice and this permission notice shall be included in |
14 | all copies or substantial portions of the Software. |
15 | |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 | |
23 | Except as contained in this notice, the names of the authors or their |
24 | institutions shall not be used in advertising or otherwise to promote the |
25 | sale, use or other dealings in this Software without prior written |
26 | authorization from the authors. |
27 | |
28 | |
29 | |
30 | Copyright © 2009 Dan Nicholson |
31 | |
32 | Permission is hereby granted, free of charge, to any person obtaining a |
33 | copy of this software and associated documentation files (the "Software"), |
34 | to deal in the Software without restriction, including without limitation |
35 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
36 | and/or sell copies of the Software, and to permit persons to whom the |
37 | Software is furnished to do so, subject to the following conditions: |
38 | |
39 | The above copyright notice and this permission notice (including the next |
40 | paragraph) shall be included in all copies or substantial portions of the |
41 | Software. |
42 | |
43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
46 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
48 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
49 | DEALINGS IN THE SOFTWARE. |
50 | */ |
51 | |
52 | /* |
53 | XConvertCase was copied from src/3rdparty/xkbcommon/src/keysym.c |
54 | The following code modifications were applied: |
55 | |
56 | XConvertCase() was renamed to xkbcommon_XConvertCase(), to not confuse it |
57 | with Xlib's XConvertCase(). |
58 | |
59 | UCSConvertCase() was renamed to qt_UCSConvertCase() and function's body was |
60 | replaced to use Qt APIs for doing case conversion, which should give us better |
61 | results instead of using the less complete version from keysym.c |
62 | */ |
63 | |
64 | #include "qxkbcommon_p.h" |
65 | |
66 | #include <QtCore/QChar> |
67 | |
68 | QT_BEGIN_NAMESPACE |
69 | |
70 | static void qt_UCSConvertCase(uint32_t code, xkb_keysym_t *lower, xkb_keysym_t *upper) |
71 | { |
72 | *lower = QChar::toLower(ucs4: code); |
73 | *upper = QChar::toUpper(ucs4: code); |
74 | } |
75 | |
76 | void QXkbCommon::xkbcommon_XConvertCase(xkb_keysym_t sym, xkb_keysym_t *lower, xkb_keysym_t *upper) |
77 | { |
78 | /* Latin 1 keysym */ |
79 | if (sym < 0x100) { |
80 | qt_UCSConvertCase(code: sym, lower, upper); |
81 | return; |
82 | } |
83 | |
84 | /* Unicode keysym */ |
85 | if ((sym & 0xff000000) == 0x01000000) { |
86 | qt_UCSConvertCase(code: (sym & 0x00ffffff), lower, upper); |
87 | *upper |= 0x01000000; |
88 | *lower |= 0x01000000; |
89 | return; |
90 | } |
91 | |
92 | /* Legacy keysym */ |
93 | |
94 | *lower = sym; |
95 | *upper = sym; |
96 | |
97 | switch (sym >> 8) { |
98 | case 1: /* Latin 2 */ |
99 | /* Assume the KeySym is a legal value (ignore discontinuities) */ |
100 | if (sym == XKB_KEY_Aogonek) |
101 | *lower = XKB_KEY_aogonek; |
102 | else if (sym >= XKB_KEY_Lstroke && sym <= XKB_KEY_Sacute) |
103 | *lower += (XKB_KEY_lstroke - XKB_KEY_Lstroke); |
104 | else if (sym >= XKB_KEY_Scaron && sym <= XKB_KEY_Zacute) |
105 | *lower += (XKB_KEY_scaron - XKB_KEY_Scaron); |
106 | else if (sym >= XKB_KEY_Zcaron && sym <= XKB_KEY_Zabovedot) |
107 | *lower += (XKB_KEY_zcaron - XKB_KEY_Zcaron); |
108 | else if (sym == XKB_KEY_aogonek) |
109 | *upper = XKB_KEY_Aogonek; |
110 | else if (sym >= XKB_KEY_lstroke && sym <= XKB_KEY_sacute) |
111 | *upper -= (XKB_KEY_lstroke - XKB_KEY_Lstroke); |
112 | else if (sym >= XKB_KEY_scaron && sym <= XKB_KEY_zacute) |
113 | *upper -= (XKB_KEY_scaron - XKB_KEY_Scaron); |
114 | else if (sym >= XKB_KEY_zcaron && sym <= XKB_KEY_zabovedot) |
115 | *upper -= (XKB_KEY_zcaron - XKB_KEY_Zcaron); |
116 | else if (sym >= XKB_KEY_Racute && sym <= XKB_KEY_Tcedilla) |
117 | *lower += (XKB_KEY_racute - XKB_KEY_Racute); |
118 | else if (sym >= XKB_KEY_racute && sym <= XKB_KEY_tcedilla) |
119 | *upper -= (XKB_KEY_racute - XKB_KEY_Racute); |
120 | break; |
121 | case 2: /* Latin 3 */ |
122 | /* Assume the KeySym is a legal value (ignore discontinuities) */ |
123 | if (sym >= XKB_KEY_Hstroke && sym <= XKB_KEY_Hcircumflex) |
124 | *lower += (XKB_KEY_hstroke - XKB_KEY_Hstroke); |
125 | else if (sym >= XKB_KEY_Gbreve && sym <= XKB_KEY_Jcircumflex) |
126 | *lower += (XKB_KEY_gbreve - XKB_KEY_Gbreve); |
127 | else if (sym >= XKB_KEY_hstroke && sym <= XKB_KEY_hcircumflex) |
128 | *upper -= (XKB_KEY_hstroke - XKB_KEY_Hstroke); |
129 | else if (sym >= XKB_KEY_gbreve && sym <= XKB_KEY_jcircumflex) |
130 | *upper -= (XKB_KEY_gbreve - XKB_KEY_Gbreve); |
131 | else if (sym >= XKB_KEY_Cabovedot && sym <= XKB_KEY_Scircumflex) |
132 | *lower += (XKB_KEY_cabovedot - XKB_KEY_Cabovedot); |
133 | else if (sym >= XKB_KEY_cabovedot && sym <= XKB_KEY_scircumflex) |
134 | *upper -= (XKB_KEY_cabovedot - XKB_KEY_Cabovedot); |
135 | break; |
136 | case 3: /* Latin 4 */ |
137 | /* Assume the KeySym is a legal value (ignore discontinuities) */ |
138 | if (sym >= XKB_KEY_Rcedilla && sym <= XKB_KEY_Tslash) |
139 | *lower += (XKB_KEY_rcedilla - XKB_KEY_Rcedilla); |
140 | else if (sym >= XKB_KEY_rcedilla && sym <= XKB_KEY_tslash) |
141 | *upper -= (XKB_KEY_rcedilla - XKB_KEY_Rcedilla); |
142 | else if (sym == XKB_KEY_ENG) |
143 | *lower = XKB_KEY_eng; |
144 | else if (sym == XKB_KEY_eng) |
145 | *upper = XKB_KEY_ENG; |
146 | else if (sym >= XKB_KEY_Amacron && sym <= XKB_KEY_Umacron) |
147 | *lower += (XKB_KEY_amacron - XKB_KEY_Amacron); |
148 | else if (sym >= XKB_KEY_amacron && sym <= XKB_KEY_umacron) |
149 | *upper -= (XKB_KEY_amacron - XKB_KEY_Amacron); |
150 | break; |
151 | case 6: /* Cyrillic */ |
152 | /* Assume the KeySym is a legal value (ignore discontinuities) */ |
153 | if (sym >= XKB_KEY_Serbian_DJE && sym <= XKB_KEY_Serbian_DZE) |
154 | *lower -= (XKB_KEY_Serbian_DJE - XKB_KEY_Serbian_dje); |
155 | else if (sym >= XKB_KEY_Serbian_dje && sym <= XKB_KEY_Serbian_dze) |
156 | *upper += (XKB_KEY_Serbian_DJE - XKB_KEY_Serbian_dje); |
157 | else if (sym >= XKB_KEY_Cyrillic_YU && sym <= XKB_KEY_Cyrillic_HARDSIGN) |
158 | *lower -= (XKB_KEY_Cyrillic_YU - XKB_KEY_Cyrillic_yu); |
159 | else if (sym >= XKB_KEY_Cyrillic_yu && sym <= XKB_KEY_Cyrillic_hardsign) |
160 | *upper += (XKB_KEY_Cyrillic_YU - XKB_KEY_Cyrillic_yu); |
161 | break; |
162 | case 7: /* Greek */ |
163 | /* Assume the KeySym is a legal value (ignore discontinuities) */ |
164 | if (sym >= XKB_KEY_Greek_ALPHAaccent && sym <= XKB_KEY_Greek_OMEGAaccent) |
165 | *lower += (XKB_KEY_Greek_alphaaccent - XKB_KEY_Greek_ALPHAaccent); |
166 | else if (sym >= XKB_KEY_Greek_alphaaccent && sym <= XKB_KEY_Greek_omegaaccent && |
167 | sym != XKB_KEY_Greek_iotaaccentdieresis && |
168 | sym != XKB_KEY_Greek_upsilonaccentdieresis) |
169 | *upper -= (XKB_KEY_Greek_alphaaccent - XKB_KEY_Greek_ALPHAaccent); |
170 | else if (sym >= XKB_KEY_Greek_ALPHA && sym <= XKB_KEY_Greek_OMEGA) |
171 | *lower += (XKB_KEY_Greek_alpha - XKB_KEY_Greek_ALPHA); |
172 | else if (sym >= XKB_KEY_Greek_alpha && sym <= XKB_KEY_Greek_omega && |
173 | sym != XKB_KEY_Greek_finalsmallsigma) |
174 | *upper -= (XKB_KEY_Greek_alpha - XKB_KEY_Greek_ALPHA); |
175 | break; |
176 | case 0x13: /* Latin 9 */ |
177 | if (sym == XKB_KEY_OE) |
178 | *lower = XKB_KEY_oe; |
179 | else if (sym == XKB_KEY_oe) |
180 | *upper = XKB_KEY_OE; |
181 | else if (sym == XKB_KEY_Ydiaeresis) |
182 | *lower = XKB_KEY_ydiaeresis; |
183 | break; |
184 | } |
185 | } |
186 | |
187 | QT_END_NAMESPACE |
188 | |