| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2018 The Qt Company Ltd. |
| 4 |
** Contact: https://www.qt.io/licensing/ |
| 5 |
** |
| 6 |
** This file is part of the plugins of the Qt Toolkit. |
| 7 |
** |
| 8 |
** $QT_BEGIN_LICENSE:LGPL$ |
| 9 |
** Commercial License Usage |
| 10 |
** Licensees holding valid commercial Qt licenses may use this file in |
| 11 |
** accordance with the commercial license agreement provided with the |
| 12 |
** Software or, alternatively, in accordance with the terms contained in |
| 13 |
** a written agreement between you and The Qt Company. For licensing terms |
| 14 |
** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 |
** information use the contact form at https://www.qt.io/contact-us. |
| 16 |
** |
| 17 |
** GNU Lesser General Public License Usage |
| 18 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 |
** General Public License version 3 as published by the Free Software |
| 20 |
** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 |
** packaging of this file. Please review the following information to |
| 22 |
** ensure the GNU Lesser General Public License version 3 requirements |
| 23 |
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 |
** |
| 25 |
** GNU General Public License Usage |
| 26 |
** Alternatively, this file may be used under the terms of the GNU |
| 27 |
** General Public License version 2.0 or (at your option) the GNU General |
| 28 |
** Public license version 3 or any later version approved by the KDE Free |
| 29 |
** Qt Foundation. The licenses are as published by the Free Software |
| 30 |
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 |
** included in the packaging of this file. Please review the following |
| 32 |
** information to ensure the GNU General Public License requirements will |
| 33 |
** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 |
** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 |
** |
| 36 |
** $QT_END_LICENSE$ |
| 37 |
** |
| 38 |
****************************************************************************/ |
| 39 |
|
| 40 |
/* XConvertCase was copied from src/3rdparty/xkbcommon/src/keysym.c, |
| 41 |
which contains the following license information: |
| 42 |
|
| 43 |
Copyright 1985, 1987, 1990, 1998 The Open Group |
| 44 |
|
| 45 |
Permission is hereby granted, free of charge, to any person obtaining a |
| 46 |
copy of this software and associated documentation files (the "Software"), |
| 47 |
to deal in the Software without restriction, including without limitation |
| 48 |
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 49 |
and/or sell copies of the Software, and to permit persons to whom the |
| 50 |
Software is furnished to do so, subject to the following conditions: |
| 51 |
|
| 52 |
The above copyright notice and this permission notice shall be included in |
| 53 |
all copies or substantial portions of the Software. |
| 54 |
|
| 55 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 56 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 57 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 58 |
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 59 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 60 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 61 |
|
| 62 |
Except as contained in this notice, the names of the authors or their |
| 63 |
institutions shall not be used in advertising or otherwise to promote the |
| 64 |
sale, use or other dealings in this Software without prior written |
| 65 |
authorization from the authors. |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
Copyright © 2009 Dan Nicholson |
| 70 |
|
| 71 |
Permission is hereby granted, free of charge, to any person obtaining a |
| 72 |
copy of this software and associated documentation files (the "Software"), |
| 73 |
to deal in the Software without restriction, including without limitation |
| 74 |
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 75 |
and/or sell copies of the Software, and to permit persons to whom the |
| 76 |
Software is furnished to do so, subject to the following conditions: |
| 77 |
|
| 78 |
The above copyright notice and this permission notice (including the next |
| 79 |
paragraph) shall be included in all copies or substantial portions of the |
| 80 |
Software. |
| 81 |
|
| 82 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 83 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 84 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 85 |
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 86 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 87 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 88 |
DEALINGS IN THE SOFTWARE. |
| 89 |
*/ |
| 90 |
|
| 91 |
/* |
| 92 |
The following code modifications were applied: |
| 93 |
|
| 94 |
XConvertCase() was renamed to xkbcommon_XConvertCase(), to not confuse it |
| 95 |
with Xlib's XConvertCase(). |
| 96 |
|
| 97 |
UCSConvertCase() was renamed to qt_UCSConvertCase() and function's body was |
| 98 |
replaced to use Qt APIs for doing case conversion, which should give us better |
| 99 |
results instead of using the less complete version from keysym.c |
| 100 |
*/ |
| 101 |
|
| 102 |
#include <xkbcommon/xkbcommon.h> |
| 103 |
#include <QtCore/QChar> |
| 104 |
|
| 105 |
QT_BEGIN_NAMESPACE |
| 106 |
|
| 107 |
static void qt_UCSConvertCase(uint32_t code, xkb_keysym_t *lower, xkb_keysym_t *upper) |
| 108 |
{ |
| 109 |
*lower = QChar::toLower(code); |
| 110 |
*upper = QChar::toUpper(code); |
| 111 |
} |
| 112 |
|
| 113 |
void xkbcommon_XConvertCase(xkb_keysym_t sym, xkb_keysym_t *lower, xkb_keysym_t *upper) |
| 114 |
{ |
| 115 |
/* Latin 1 keysym */ |
| 116 |
if (sym < 0x100) { |
| 117 |
qt_UCSConvertCase(sym, lower, upper); |
| 118 |
return; |
| 119 |
} |
| 120 |
|
| 121 |
/* Unicode keysym */ |
| 122 |
if ((sym & 0xff000000) == 0x01000000) { |
| 123 |
qt_UCSConvertCase((sym & 0x00ffffff), lower, upper); |
| 124 |
*upper |= 0x01000000; |
| 125 |
*lower |= 0x01000000; |
| 126 |
return; |
| 127 |
} |
| 128 |
|
| 129 |
/* Legacy keysym */ |
| 130 |
|
| 131 |
*lower = sym; |
| 132 |
*upper = sym; |
| 133 |
|
| 134 |
switch (sym >> 8) { |
| 135 |
case 1: /* Latin 2 */ |
| 136 |
/* Assume the KeySym is a legal value (ignore discontinuities) */ |
| 137 |
if (sym == XKB_KEY_Aogonek) |
| 138 |
*lower = XKB_KEY_aogonek; |
| 139 |
else if (sym >= XKB_KEY_Lstroke && sym <= XKB_KEY_Sacute) |
| 140 |
*lower += (XKB_KEY_lstroke - XKB_KEY_Lstroke); |
| 141 |
else if (sym >= XKB_KEY_Scaron && sym <= XKB_KEY_Zacute) |
| 142 |
*lower += (XKB_KEY_scaron - XKB_KEY_Scaron); |
| 143 |
else if (sym >= XKB_KEY_Zcaron && sym <= XKB_KEY_Zabovedot) |
| 144 |
*lower += (XKB_KEY_zcaron - XKB_KEY_Zcaron); |
| 145 |
else if (sym == XKB_KEY_aogonek) |
| 146 |
*upper = XKB_KEY_Aogonek; |
| 147 |
else if (sym >= XKB_KEY_lstroke && sym <= XKB_KEY_sacute) |
| 148 |
*upper -= (XKB_KEY_lstroke - XKB_KEY_Lstroke); |
| 149 |
else if (sym >= XKB_KEY_scaron && sym <= XKB_KEY_zacute) |
| 150 |
*upper -= (XKB_KEY_scaron - XKB_KEY_Scaron); |
| 151 |
else if (sym >= XKB_KEY_zcaron && sym <= XKB_KEY_zabovedot) |
| 152 |
*upper -= (XKB_KEY_zcaron - XKB_KEY_Zcaron); |
| 153 |
else if (sym >= XKB_KEY_Racute && sym <= XKB_KEY_Tcedilla) |
| 154 |
*lower += (XKB_KEY_racute - XKB_KEY_Racute); |
| 155 |
else if (sym >= XKB_KEY_racute && sym <= XKB_KEY_tcedilla) |
| 156 |
*upper -= (XKB_KEY_racute - XKB_KEY_Racute); |
| 157 |
break; |
| 158 |
case 2: /* Latin 3 */ |
| 159 |
/* Assume the KeySym is a legal value (ignore discontinuities) */ |
| 160 |
if (sym >= XKB_KEY_Hstroke && sym <= XKB_KEY_Hcircumflex) |
| 161 |
*lower += (XKB_KEY_hstroke - XKB_KEY_Hstroke); |
| 162 |
else if (sym >= XKB_KEY_Gbreve && sym <= XKB_KEY_Jcircumflex) |
| 163 |
*lower += (XKB_KEY_gbreve - XKB_KEY_Gbreve); |
| 164 |
else if (sym >= XKB_KEY_hstroke && sym <= XKB_KEY_hcircumflex) |
| 165 |
*upper -= (XKB_KEY_hstroke - XKB_KEY_Hstroke); |
| 166 |
else if (sym >= XKB_KEY_gbreve && sym <= XKB_KEY_jcircumflex) |
| 167 |
*upper -= (XKB_KEY_gbreve - XKB_KEY_Gbreve); |
| 168 |
else if (sym >= XKB_KEY_Cabovedot && sym <= XKB_KEY_Scircumflex) |
| 169 |
*lower += (XKB_KEY_cabovedot - XKB_KEY_Cabovedot); |
| 170 |
else if (sym >= XKB_KEY_cabovedot && sym <= XKB_KEY_scircumflex) |
| 171 |
*upper -= (XKB_KEY_cabovedot - XKB_KEY_Cabovedot); |
| 172 |
break; |
| 173 |
case 3: /* Latin 4 */ |
| 174 |
/* Assume the KeySym is a legal value (ignore discontinuities) */ |
| 175 |
if (sym >= XKB_KEY_Rcedilla && sym <= XKB_KEY_Tslash) |
| 176 |
*lower += (XKB_KEY_rcedilla - XKB_KEY_Rcedilla); |
| 177 |
else if (sym >= XKB_KEY_rcedilla && sym <= XKB_KEY_tslash) |
| 178 |
*upper -= (XKB_KEY_rcedilla - XKB_KEY_Rcedilla); |
| 179 |
else if (sym == XKB_KEY_ENG) |
| 180 |
*lower = XKB_KEY_eng; |
| 181 |
else if (sym == XKB_KEY_eng) |
| 182 |
*upper = XKB_KEY_ENG; |
| 183 |
else if (sym >= XKB_KEY_Amacron && sym <= XKB_KEY_Umacron) |
| 184 |
*lower += (XKB_KEY_amacron - XKB_KEY_Amacron); |
| 185 |
else if (sym >= XKB_KEY_amacron && sym <= XKB_KEY_umacron) |
| 186 |
*upper -= (XKB_KEY_amacron - XKB_KEY_Amacron); |
| 187 |
break; |
| 188 |
case 6: /* Cyrillic */ |
| 189 |
/* Assume the KeySym is a legal value (ignore discontinuities) */ |
| 190 |
if (sym >= XKB_KEY_Serbian_DJE && sym <= XKB_KEY_Serbian_DZE) |
| 191 |
*lower -= (XKB_KEY_Serbian_DJE - XKB_KEY_Serbian_dje); |
| 192 |
else if (sym >= XKB_KEY_Serbian_dje && sym <= XKB_KEY_Serbian_dze) |
| 193 |
*upper += (XKB_KEY_Serbian_DJE - XKB_KEY_Serbian_dje); |
| 194 |
else if (sym >= XKB_KEY_Cyrillic_YU && sym <= XKB_KEY_Cyrillic_HARDSIGN) |
| 195 |
*lower -= (XKB_KEY_Cyrillic_YU - XKB_KEY_Cyrillic_yu); |
| 196 |
else if (sym >= XKB_KEY_Cyrillic_yu && sym <= XKB_KEY_Cyrillic_hardsign) |
| 197 |
*upper += (XKB_KEY_Cyrillic_YU - XKB_KEY_Cyrillic_yu); |
| 198 |
break; |
| 199 |
case 7: /* Greek */ |
| 200 |
/* Assume the KeySym is a legal value (ignore discontinuities) */ |
| 201 |
if (sym >= XKB_KEY_Greek_ALPHAaccent && sym <= XKB_KEY_Greek_OMEGAaccent) |
| 202 |
*lower += (XKB_KEY_Greek_alphaaccent - XKB_KEY_Greek_ALPHAaccent); |
| 203 |
else if (sym >= XKB_KEY_Greek_alphaaccent && sym <= XKB_KEY_Greek_omegaaccent && |
| 204 |
sym != XKB_KEY_Greek_iotaaccentdieresis && |
| 205 |
sym != XKB_KEY_Greek_upsilonaccentdieresis) |
| 206 |
*upper -= (XKB_KEY_Greek_alphaaccent - XKB_KEY_Greek_ALPHAaccent); |
| 207 |
else if (sym >= XKB_KEY_Greek_ALPHA && sym <= XKB_KEY_Greek_OMEGA) |
| 208 |
*lower += (XKB_KEY_Greek_alpha - XKB_KEY_Greek_ALPHA); |
| 209 |
else if (sym >= XKB_KEY_Greek_alpha && sym <= XKB_KEY_Greek_omega && |
| 210 |
sym != XKB_KEY_Greek_finalsmallsigma) |
| 211 |
*upper -= (XKB_KEY_Greek_alpha - XKB_KEY_Greek_ALPHA); |
| 212 |
break; |
| 213 |
case 0x13: /* Latin 9 */ |
| 214 |
if (sym == XKB_KEY_OE) |
| 215 |
*lower = XKB_KEY_oe; |
| 216 |
else if (sym == XKB_KEY_oe) |
| 217 |
*upper = XKB_KEY_OE; |
| 218 |
else if (sym == XKB_KEY_Ydiaeresis) |
| 219 |
*lower = XKB_KEY_ydiaeresis; |
| 220 |
break; |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
xkb_keysym_t xkbcommon_xkb_keysym_to_upper(xkb_keysym_t ks) |
| 225 |
{ |
| 226 |
xkb_keysym_t lower, upper; |
| 227 |
|
| 228 |
xkbcommon_XConvertCase(ks, &lower, &upper); |
| 229 |
|
| 230 |
return upper; |
| 231 |
} |
| 232 |
|
| 233 |
QT_END_NAMESPACE |