| 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 | static void qt_UCSConvertCase(uint32_t code, xkb_keysym_t *lower, xkb_keysym_t *upper) | 
| 105 | { | 
| 106 |     *lower = QChar::toLower(ucs4: code); | 
| 107 |     *upper = QChar::toUpper(ucs4: code); | 
| 108 | } | 
| 109 |  | 
| 110 | void QXkbCommon::xkbcommon_XConvertCase(xkb_keysym_t sym, xkb_keysym_t *lower, xkb_keysym_t *upper) | 
| 111 | { | 
| 112 |     /* Latin 1 keysym */ | 
| 113 |     if (sym < 0x100) { | 
| 114 |         qt_UCSConvertCase(code: sym, lower, upper); | 
| 115 |         return; | 
| 116 |     } | 
| 117 |  | 
| 118 |     /* Unicode keysym */ | 
| 119 |     if ((sym & 0xff000000) == 0x01000000) { | 
| 120 |         qt_UCSConvertCase(code: (sym & 0x00ffffff), lower, upper); | 
| 121 |         *upper |= 0x01000000; | 
| 122 |         *lower |= 0x01000000; | 
| 123 |         return; | 
| 124 |     } | 
| 125 |  | 
| 126 |     /* Legacy keysym */ | 
| 127 |  | 
| 128 |     *lower = sym; | 
| 129 |     *upper = sym; | 
| 130 |  | 
| 131 |     switch (sym >> 8) { | 
| 132 |     case 1: /* Latin 2 */ | 
| 133 |         /* Assume the KeySym is a legal value (ignore discontinuities) */ | 
| 134 |         if (sym == XKB_KEY_Aogonek) | 
| 135 |             *lower = XKB_KEY_aogonek; | 
| 136 |         else if (sym >= XKB_KEY_Lstroke && sym <= XKB_KEY_Sacute) | 
| 137 |             *lower += (XKB_KEY_lstroke - XKB_KEY_Lstroke); | 
| 138 |         else if (sym >= XKB_KEY_Scaron && sym <= XKB_KEY_Zacute) | 
| 139 |             *lower += (XKB_KEY_scaron - XKB_KEY_Scaron); | 
| 140 |         else if (sym >= XKB_KEY_Zcaron && sym <= XKB_KEY_Zabovedot) | 
| 141 |             *lower += (XKB_KEY_zcaron - XKB_KEY_Zcaron); | 
| 142 |         else if (sym == XKB_KEY_aogonek) | 
| 143 |             *upper = XKB_KEY_Aogonek; | 
| 144 |         else if (sym >= XKB_KEY_lstroke && sym <= XKB_KEY_sacute) | 
| 145 |             *upper -= (XKB_KEY_lstroke - XKB_KEY_Lstroke); | 
| 146 |         else if (sym >= XKB_KEY_scaron && sym <= XKB_KEY_zacute) | 
| 147 |             *upper -= (XKB_KEY_scaron - XKB_KEY_Scaron); | 
| 148 |         else if (sym >= XKB_KEY_zcaron && sym <= XKB_KEY_zabovedot) | 
| 149 |             *upper -= (XKB_KEY_zcaron - XKB_KEY_Zcaron); | 
| 150 |         else if (sym >= XKB_KEY_Racute && sym <= XKB_KEY_Tcedilla) | 
| 151 |             *lower += (XKB_KEY_racute - XKB_KEY_Racute); | 
| 152 |         else if (sym >= XKB_KEY_racute && sym <= XKB_KEY_tcedilla) | 
| 153 |             *upper -= (XKB_KEY_racute - XKB_KEY_Racute); | 
| 154 |         break; | 
| 155 |     case 2: /* Latin 3 */ | 
| 156 |         /* Assume the KeySym is a legal value (ignore discontinuities) */ | 
| 157 |         if (sym >= XKB_KEY_Hstroke && sym <= XKB_KEY_Hcircumflex) | 
| 158 |             *lower += (XKB_KEY_hstroke - XKB_KEY_Hstroke); | 
| 159 |         else if (sym >= XKB_KEY_Gbreve && sym <= XKB_KEY_Jcircumflex) | 
| 160 |             *lower += (XKB_KEY_gbreve - XKB_KEY_Gbreve); | 
| 161 |         else if (sym >= XKB_KEY_hstroke && sym <= XKB_KEY_hcircumflex) | 
| 162 |             *upper -= (XKB_KEY_hstroke - XKB_KEY_Hstroke); | 
| 163 |         else if (sym >= XKB_KEY_gbreve && sym <= XKB_KEY_jcircumflex) | 
| 164 |             *upper -= (XKB_KEY_gbreve - XKB_KEY_Gbreve); | 
| 165 |         else if (sym >= XKB_KEY_Cabovedot && sym <= XKB_KEY_Scircumflex) | 
| 166 |             *lower += (XKB_KEY_cabovedot - XKB_KEY_Cabovedot); | 
| 167 |         else if (sym >= XKB_KEY_cabovedot && sym <= XKB_KEY_scircumflex) | 
| 168 |             *upper -= (XKB_KEY_cabovedot - XKB_KEY_Cabovedot); | 
| 169 |         break; | 
| 170 |     case 3: /* Latin 4 */ | 
| 171 |         /* Assume the KeySym is a legal value (ignore discontinuities) */ | 
| 172 |         if (sym >= XKB_KEY_Rcedilla && sym <= XKB_KEY_Tslash) | 
| 173 |             *lower += (XKB_KEY_rcedilla - XKB_KEY_Rcedilla); | 
| 174 |         else if (sym >= XKB_KEY_rcedilla && sym <= XKB_KEY_tslash) | 
| 175 |             *upper -= (XKB_KEY_rcedilla - XKB_KEY_Rcedilla); | 
| 176 |         else if (sym == XKB_KEY_ENG) | 
| 177 |             *lower = XKB_KEY_eng; | 
| 178 |         else if (sym == XKB_KEY_eng) | 
| 179 |             *upper = XKB_KEY_ENG; | 
| 180 |         else if (sym >= XKB_KEY_Amacron && sym <= XKB_KEY_Umacron) | 
| 181 |             *lower += (XKB_KEY_amacron - XKB_KEY_Amacron); | 
| 182 |         else if (sym >= XKB_KEY_amacron && sym <= XKB_KEY_umacron) | 
| 183 |             *upper -= (XKB_KEY_amacron - XKB_KEY_Amacron); | 
| 184 |         break; | 
| 185 |     case 6: /* Cyrillic */ | 
| 186 |         /* Assume the KeySym is a legal value (ignore discontinuities) */ | 
| 187 |         if (sym >= XKB_KEY_Serbian_DJE && sym <= XKB_KEY_Serbian_DZE) | 
| 188 |             *lower -= (XKB_KEY_Serbian_DJE - XKB_KEY_Serbian_dje); | 
| 189 |         else if (sym >= XKB_KEY_Serbian_dje && sym <= XKB_KEY_Serbian_dze) | 
| 190 |             *upper += (XKB_KEY_Serbian_DJE - XKB_KEY_Serbian_dje); | 
| 191 |         else if (sym >= XKB_KEY_Cyrillic_YU && sym <= XKB_KEY_Cyrillic_HARDSIGN) | 
| 192 |             *lower -= (XKB_KEY_Cyrillic_YU - XKB_KEY_Cyrillic_yu); | 
| 193 |         else if (sym >= XKB_KEY_Cyrillic_yu && sym <= XKB_KEY_Cyrillic_hardsign) | 
| 194 |             *upper += (XKB_KEY_Cyrillic_YU - XKB_KEY_Cyrillic_yu); | 
| 195 |         break; | 
| 196 |     case 7: /* Greek */ | 
| 197 |         /* Assume the KeySym is a legal value (ignore discontinuities) */ | 
| 198 |         if (sym >= XKB_KEY_Greek_ALPHAaccent && sym <= XKB_KEY_Greek_OMEGAaccent) | 
| 199 |             *lower += (XKB_KEY_Greek_alphaaccent - XKB_KEY_Greek_ALPHAaccent); | 
| 200 |         else if (sym >= XKB_KEY_Greek_alphaaccent && sym <= XKB_KEY_Greek_omegaaccent && | 
| 201 |              sym != XKB_KEY_Greek_iotaaccentdieresis && | 
| 202 |              sym != XKB_KEY_Greek_upsilonaccentdieresis) | 
| 203 |             *upper -= (XKB_KEY_Greek_alphaaccent - XKB_KEY_Greek_ALPHAaccent); | 
| 204 |         else if (sym >= XKB_KEY_Greek_ALPHA && sym <= XKB_KEY_Greek_OMEGA) | 
| 205 |             *lower += (XKB_KEY_Greek_alpha - XKB_KEY_Greek_ALPHA); | 
| 206 |         else if (sym >= XKB_KEY_Greek_alpha && sym <= XKB_KEY_Greek_omega && | 
| 207 |              sym != XKB_KEY_Greek_finalsmallsigma) | 
| 208 |             *upper -= (XKB_KEY_Greek_alpha - XKB_KEY_Greek_ALPHA); | 
| 209 |         break; | 
| 210 |     case 0x13: /* Latin 9 */ | 
| 211 |         if (sym == XKB_KEY_OE) | 
| 212 |             *lower = XKB_KEY_oe; | 
| 213 |         else if (sym == XKB_KEY_oe) | 
| 214 |             *upper = XKB_KEY_OE; | 
| 215 |         else if (sym == XKB_KEY_Ydiaeresis) | 
| 216 |             *lower = XKB_KEY_ydiaeresis; | 
| 217 |         break; | 
| 218 |     } | 
| 219 | } | 
| 220 |  |