2009-03-28 18:55:46 -06:00
|
|
|
/************************************************************
|
|
|
|
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and distribute this
|
|
|
|
software and its documentation for any purpose and without
|
|
|
|
fee is hereby granted, provided that the above copyright
|
|
|
|
notice appear in all copies and that both that copyright
|
|
|
|
notice and this permission notice appear in supporting
|
|
|
|
documentation, and that the name of Silicon Graphics not be
|
|
|
|
used in advertising or publicity pertaining to distribution
|
|
|
|
of the software without specific prior written permission.
|
|
|
|
Silicon Graphics makes no representation about the suitability
|
|
|
|
of this software for any purpose. It is provided "as is"
|
|
|
|
without any express or implied warranty.
|
|
|
|
|
|
|
|
SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
|
|
|
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
|
|
|
|
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
|
|
|
|
THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
|
|
********************************************************/
|
|
|
|
|
2012-05-08 05:52:23 -06:00
|
|
|
#include "xkb-priv.h"
|
|
|
|
#include "alloc.h"
|
|
|
|
|
2010-07-01 12:35:24 -06:00
|
|
|
static struct xkb_kt_map_entry map2Level[]= {
|
2012-05-22 01:59:46 -06:00
|
|
|
{
|
|
|
|
.active = true,
|
|
|
|
.level = ShiftMask,
|
|
|
|
.mods = {.mask = 1, .vmods = ShiftMask, .real_mods = 0 }
|
|
|
|
}
|
2009-03-28 18:55:46 -06:00
|
|
|
};
|
|
|
|
|
2010-07-01 12:35:24 -06:00
|
|
|
static struct xkb_kt_map_entry mapAlpha[]= {
|
2012-05-22 01:59:46 -06:00
|
|
|
{
|
|
|
|
.active = true,
|
|
|
|
.level = ShiftMask,
|
|
|
|
.mods = { .mask = 1, .vmods = ShiftMask, .real_mods = 0 }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.active = true,
|
|
|
|
.level = LockMask,
|
|
|
|
.mods = { .mask = 0, .vmods = LockMask, .real_mods = 0 }
|
|
|
|
}
|
2009-03-28 18:55:46 -06:00
|
|
|
};
|
|
|
|
|
2010-07-01 12:35:24 -06:00
|
|
|
static struct xkb_mods preAlpha[]= {
|
2012-05-22 01:59:46 -06:00
|
|
|
{ .mask = 0, .vmods = 0, .real_mods = 0 },
|
|
|
|
{ .mask = LockMask, .vmods = LockMask, .real_mods = 0 }
|
2009-03-28 18:55:46 -06:00
|
|
|
};
|
|
|
|
|
2009-03-28 19:17:34 -06:00
|
|
|
#define NL_VMOD_MASK 0
|
2012-05-22 01:59:46 -06:00
|
|
|
static struct xkb_kt_map_entry mapKeypad[]= {
|
|
|
|
{
|
|
|
|
.active = true,
|
|
|
|
.level = ShiftMask,
|
|
|
|
.mods = { .mask = 1, .vmods = ShiftMask, .real_mods = 0 }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.active = false,
|
|
|
|
.level = 0,
|
|
|
|
.mods = { .mask = 1, .vmods = 0, .real_mods = NL_VMOD_MASK }
|
|
|
|
}
|
2009-03-28 18:55:46 -06:00
|
|
|
};
|
|
|
|
|
2012-05-22 01:59:46 -06:00
|
|
|
static const struct xkb_key_type canonicalTypes[XkbNumRequiredTypes] = {
|
|
|
|
{
|
|
|
|
.mods = { .mask = 0, .vmods = 0, .real_mods = 0 },
|
|
|
|
.num_levels = 1,
|
|
|
|
.preserve = NULL,
|
|
|
|
.name = NULL,
|
|
|
|
.level_names = NULL
|
2009-03-28 19:17:34 -06:00
|
|
|
},
|
2012-05-22 01:59:46 -06:00
|
|
|
{
|
|
|
|
.mods = { .mask = ShiftMask, .vmods = ShiftMask, .real_mods = 0 },
|
|
|
|
.num_levels = 2,
|
|
|
|
.map = darray_lit(map2Level),
|
|
|
|
.preserve = NULL,
|
|
|
|
.name = NULL,
|
|
|
|
.level_names = NULL
|
2009-03-28 19:17:34 -06:00
|
|
|
},
|
2012-05-22 01:59:46 -06:00
|
|
|
{
|
|
|
|
.mods = { .mask = ShiftMask|LockMask, .vmods = ShiftMask|LockMask, .real_mods = 0 },
|
|
|
|
.num_levels = 2,
|
|
|
|
.map = darray_lit(mapAlpha),
|
|
|
|
.preserve = preAlpha,
|
|
|
|
.name = NULL,
|
|
|
|
.level_names = NULL
|
2009-03-28 19:17:34 -06:00
|
|
|
},
|
2012-05-22 01:59:46 -06:00
|
|
|
{
|
|
|
|
.mods = { .mask = ShiftMask, .vmods = ShiftMask, .real_mods = NL_VMOD_MASK },
|
|
|
|
.num_levels = 2,
|
|
|
|
.map = darray_lit(mapKeypad),
|
|
|
|
.preserve = NULL,
|
|
|
|
.name = NULL,
|
|
|
|
.level_names = NULL
|
2009-03-28 19:17:34 -06:00
|
|
|
}
|
2009-03-28 18:55:46 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
int
|
2012-05-09 08:15:30 -06:00
|
|
|
XkbcInitCanonicalKeyTypes(struct xkb_keymap *keymap, unsigned which,
|
|
|
|
int keypadVMod)
|
2009-03-28 18:55:46 -06:00
|
|
|
{
|
2010-07-01 12:35:24 -06:00
|
|
|
struct xkb_client_map * map;
|
2012-05-22 01:59:46 -06:00
|
|
|
const struct xkb_key_type *from;
|
2009-03-28 19:17:34 -06:00
|
|
|
int rtrn;
|
2009-03-28 18:55:46 -06:00
|
|
|
|
2012-05-09 08:15:30 -06:00
|
|
|
if (!keymap)
|
2009-03-28 19:17:34 -06:00
|
|
|
return BadMatch;
|
|
|
|
|
2012-05-09 08:15:30 -06:00
|
|
|
rtrn = XkbcAllocClientMap(keymap, XkbKeyTypesMask, XkbNumRequiredTypes);
|
2009-03-28 19:17:34 -06:00
|
|
|
if (rtrn != Success)
|
|
|
|
return rtrn;
|
|
|
|
|
2012-05-09 08:15:30 -06:00
|
|
|
map = keymap->map;
|
2009-03-28 19:17:34 -06:00
|
|
|
if ((which & XkbAllRequiredTypes) == 0)
|
|
|
|
return Success;
|
|
|
|
|
|
|
|
rtrn = Success;
|
|
|
|
from = canonicalTypes;
|
|
|
|
|
|
|
|
if (which & XkbOneLevelMask)
|
2012-05-21 23:07:52 -06:00
|
|
|
rtrn = XkbcCopyKeyType(&from[XkbOneLevelIndex],
|
|
|
|
&darray_item(map->types, XkbOneLevelIndex));
|
2009-03-28 19:17:34 -06:00
|
|
|
|
|
|
|
if ((which & XkbTwoLevelMask) && (rtrn == Success))
|
2012-05-21 23:07:52 -06:00
|
|
|
rtrn = XkbcCopyKeyType(&from[XkbTwoLevelIndex],
|
|
|
|
&darray_item(map->types, XkbTwoLevelIndex));
|
2009-03-28 19:17:34 -06:00
|
|
|
|
|
|
|
if ((which & XkbAlphabeticMask) && (rtrn == Success))
|
|
|
|
rtrn = XkbcCopyKeyType(&from[XkbAlphabeticIndex],
|
2012-05-21 23:07:52 -06:00
|
|
|
&darray_item(map->types, XkbAlphabeticIndex));
|
2009-03-28 19:17:34 -06:00
|
|
|
|
|
|
|
if ((which & XkbKeypadMask) && (rtrn == Success)) {
|
2010-07-01 12:35:24 -06:00
|
|
|
struct xkb_key_type * type;
|
2009-03-28 19:17:34 -06:00
|
|
|
|
2012-05-21 23:07:52 -06:00
|
|
|
rtrn = XkbcCopyKeyType(&from[XkbKeypadIndex],
|
|
|
|
&darray_item(map->types, XkbKeypadIndex));
|
|
|
|
type = &darray_item(map->types, XkbKeypadIndex);
|
2009-03-28 19:17:34 -06:00
|
|
|
|
|
|
|
if ((keypadVMod >= 0) && (keypadVMod < XkbNumVirtualMods) &&
|
|
|
|
(rtrn == Success)) {
|
2012-05-22 01:59:46 -06:00
|
|
|
struct xkb_kt_map_entry *entry;
|
2009-03-28 19:17:34 -06:00
|
|
|
type->mods.vmods = (1 << keypadVMod);
|
2012-05-22 01:59:46 -06:00
|
|
|
|
|
|
|
entry = &darray_item(type->map, 0);
|
|
|
|
entry->active = true;
|
|
|
|
entry->mods.mask = ShiftMask;
|
|
|
|
entry->mods.real_mods = ShiftMask;
|
|
|
|
entry->mods.vmods = 0;
|
|
|
|
entry->level = 1;
|
|
|
|
|
|
|
|
entry = &darray_item(type->map, 1);
|
|
|
|
entry->active = false;
|
|
|
|
entry->mods.mask = 0;
|
|
|
|
entry->mods.real_mods = 0;
|
|
|
|
entry->mods.vmods = (1 << keypadVMod);
|
|
|
|
entry->level = 1;
|
2009-03-28 19:17:34 -06:00
|
|
|
}
|
2009-03-28 18:55:46 -06:00
|
|
|
}
|
2009-03-28 19:17:34 -06:00
|
|
|
|
2009-03-28 18:55:46 -06:00
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
2009-03-28 20:21:18 -06:00
|
|
|
unsigned
|
2012-03-09 12:03:59 -07:00
|
|
|
_XkbcKSCheckCase(xkb_keysym_t ks)
|
2009-03-28 20:21:18 -06:00
|
|
|
{
|
2009-04-12 13:14:36 -06:00
|
|
|
unsigned set = (ks & (~0xff)) >> 8;
|
|
|
|
unsigned rtrn = 0;
|
2009-03-28 20:21:18 -06:00
|
|
|
|
|
|
|
switch (set) {
|
2009-04-12 13:14:36 -06:00
|
|
|
case 0: /* latin 1 */
|
2012-05-09 07:05:00 -06:00
|
|
|
if ((ks >= XKB_KEY_A && ks <= XKB_KEY_Z) ||
|
|
|
|
(ks >= XKB_KEY_Agrave && ks <= XKB_KEY_THORN && ks != XKB_KEY_multiply))
|
2009-04-12 13:14:36 -06:00
|
|
|
rtrn |= _XkbKSUpper;
|
2012-05-09 07:05:00 -06:00
|
|
|
if ((ks >= XKB_KEY_a && ks <= XKB_KEY_z) ||
|
|
|
|
(ks >= XKB_KEY_agrave && ks <= XKB_KEY_ydiaeresis))
|
2009-04-12 13:14:36 -06:00
|
|
|
rtrn |= _XkbKSLower;
|
|
|
|
break;
|
|
|
|
case 1: /* latin 2 */
|
2012-05-09 07:05:00 -06:00
|
|
|
if ((ks >= XKB_KEY_Aogonek && ks <= XKB_KEY_Zabovedot && ks != XKB_KEY_breve) ||
|
|
|
|
(ks >= XKB_KEY_Racute && ks<=XKB_KEY_Tcedilla))
|
2009-04-12 13:14:36 -06:00
|
|
|
rtrn |= _XkbKSUpper;
|
2012-05-09 07:05:00 -06:00
|
|
|
if ((ks >= XKB_KEY_aogonek && ks <= XKB_KEY_zabovedot && ks != XKB_KEY_caron) ||
|
|
|
|
(ks >= XKB_KEY_racute && ks <= XKB_KEY_tcedilla))
|
2009-04-12 13:14:36 -06:00
|
|
|
rtrn |= _XkbKSLower;
|
|
|
|
break;
|
|
|
|
case 2: /* latin 3 */
|
2012-05-09 07:05:00 -06:00
|
|
|
if ((ks >= XKB_KEY_Hstroke && ks <= XKB_KEY_Jcircumflex) ||
|
|
|
|
(ks >= XKB_KEY_Cabovedot && ks <= XKB_KEY_Scircumflex))
|
2009-04-12 13:14:36 -06:00
|
|
|
rtrn |= _XkbKSUpper;
|
2012-05-09 07:05:00 -06:00
|
|
|
if ((ks >= XKB_KEY_hstroke && ks <= XKB_KEY_jcircumflex) ||
|
|
|
|
(ks >= XKB_KEY_cabovedot && ks <= XKB_KEY_scircumflex))
|
2009-04-12 13:14:36 -06:00
|
|
|
rtrn |= _XkbKSLower;
|
|
|
|
break;
|
|
|
|
case 3: /* latin 4 */
|
2012-05-09 07:05:00 -06:00
|
|
|
if ((ks >= XKB_KEY_Rcedilla && ks <= XKB_KEY_Tslash) ||
|
|
|
|
(ks == XKB_KEY_ENG) ||
|
|
|
|
(ks >= XKB_KEY_Amacron && ks <= XKB_KEY_Umacron))
|
2009-04-12 13:14:36 -06:00
|
|
|
rtrn |= _XkbKSUpper;
|
2012-05-09 07:05:00 -06:00
|
|
|
if ((ks >= XKB_KEY_rcedilla && ks <= XKB_KEY_tslash) ||
|
|
|
|
(ks == XKB_KEY_eng) ||
|
|
|
|
(ks >= XKB_KEY_amacron && ks <= XKB_KEY_umacron))
|
2009-04-12 13:14:36 -06:00
|
|
|
rtrn |= _XkbKSLower;
|
|
|
|
break;
|
|
|
|
case 18: /* latin 8 */
|
2012-05-09 07:05:00 -06:00
|
|
|
if ((ks == XKB_KEY_Wcircumflex) ||
|
|
|
|
(ks == XKB_KEY_Ycircumflex) ||
|
|
|
|
(ks == XKB_KEY_Babovedot) ||
|
|
|
|
(ks == XKB_KEY_Dabovedot) ||
|
|
|
|
(ks == XKB_KEY_Fabovedot) ||
|
|
|
|
(ks == XKB_KEY_Mabovedot) ||
|
|
|
|
(ks == XKB_KEY_Pabovedot) ||
|
|
|
|
(ks == XKB_KEY_Sabovedot) ||
|
|
|
|
(ks == XKB_KEY_Tabovedot) ||
|
|
|
|
(ks == XKB_KEY_Wdiaeresis) ||
|
|
|
|
(ks == XKB_KEY_Ygrave))
|
2009-04-12 13:14:36 -06:00
|
|
|
rtrn |= _XkbKSUpper;
|
2012-05-09 07:05:00 -06:00
|
|
|
if ((ks == XKB_KEY_wcircumflex) ||
|
|
|
|
(ks == XKB_KEY_ycircumflex) ||
|
|
|
|
(ks == XKB_KEY_babovedot) ||
|
|
|
|
(ks == XKB_KEY_dabovedot) ||
|
|
|
|
(ks == XKB_KEY_fabovedot) ||
|
|
|
|
(ks == XKB_KEY_mabovedot) ||
|
|
|
|
(ks == XKB_KEY_pabovedot) ||
|
|
|
|
(ks == XKB_KEY_sabovedot) ||
|
|
|
|
(ks == XKB_KEY_tabovedot) ||
|
|
|
|
(ks == XKB_KEY_wdiaeresis) ||
|
|
|
|
(ks == XKB_KEY_ygrave))
|
2009-04-12 13:14:36 -06:00
|
|
|
rtrn |= _XkbKSLower;
|
|
|
|
break;
|
|
|
|
case 19: /* latin 9 */
|
2012-05-09 07:05:00 -06:00
|
|
|
if (ks == XKB_KEY_OE || ks == XKB_KEY_Ydiaeresis)
|
2009-04-12 13:14:36 -06:00
|
|
|
rtrn |= _XkbKSUpper;
|
2012-05-09 07:05:00 -06:00
|
|
|
if (ks == XKB_KEY_oe)
|
2009-04-12 13:14:36 -06:00
|
|
|
rtrn |= _XkbKSLower;
|
|
|
|
break;
|
2009-03-28 20:21:18 -06:00
|
|
|
}
|
2009-04-12 13:14:36 -06:00
|
|
|
|
2009-03-28 20:21:18 -06:00
|
|
|
return rtrn;
|
|
|
|
}
|
2012-05-25 10:05:39 -06:00
|
|
|
|
|
|
|
xkb_keycode_t
|
|
|
|
XkbcFindKeycodeByName(struct xkb_keymap *keymap, const char *name,
|
|
|
|
bool use_aliases)
|
|
|
|
{
|
|
|
|
struct xkb_key_alias *alias;
|
|
|
|
xkb_keycode_t i;
|
|
|
|
|
|
|
|
for (i = keymap->min_key_code; i <= keymap->max_key_code; i++) {
|
|
|
|
if (strncmp(darray_item(keymap->names->keys, i).name, name,
|
|
|
|
XkbKeyNameLength) == 0)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!use_aliases)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < darray_size(keymap->names->key_aliases); i++) {
|
|
|
|
alias = &darray_item(keymap->names->key_aliases, i);
|
|
|
|
if (strncmp(name, alias->alias, XkbKeyNameLength) == 0)
|
|
|
|
return XkbcFindKeycodeByName(keymap, alias->real, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|