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