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