Rename KSIsLower/Upper and move to keysym.c

Seems like a more natural place, and allows to remove the src/misc.c
file.

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-07-13 18:55:10 +03:00
parent 0765064b35
commit 57374c3237
5 changed files with 134 additions and 138 deletions

View File

@ -78,7 +78,6 @@ libxkbcommon_la_SOURCES = \
src/keysym.c \
src/keysym-utf.c \
src/map.c \
src/misc.c \
src/state.c \
src/text.c \
src/text.h \

View File

@ -158,3 +158,122 @@ xkb_keysym_from_name(const char *s)
return XKB_KEY_NoSymbol;
}
enum keysym_case {
NONE,
LOWERCASE,
UPPERCASE,
};
static enum keysym_case
keysym_get_case(xkb_keysym_t ks)
{
unsigned set = (ks & (~0xff)) >> 8;
switch (set) {
case 0: /* latin 1 */
if ((ks >= XKB_KEY_A && ks <= XKB_KEY_Z) ||
(ks >= XKB_KEY_Agrave && ks <= XKB_KEY_THORN && ks != XKB_KEY_multiply))
return UPPERCASE;
if ((ks >= XKB_KEY_a && ks <= XKB_KEY_z) ||
(ks >= XKB_KEY_agrave && ks <= XKB_KEY_ydiaeresis))
return LOWERCASE;
break;
case 1: /* latin 2 */
if ((ks >= XKB_KEY_Aogonek && ks <= XKB_KEY_Zabovedot && ks != XKB_KEY_breve) ||
(ks >= XKB_KEY_Racute && ks<=XKB_KEY_Tcedilla))
return UPPERCASE;
if ((ks >= XKB_KEY_aogonek && ks <= XKB_KEY_zabovedot && ks != XKB_KEY_caron) ||
(ks >= XKB_KEY_racute && ks <= XKB_KEY_tcedilla))
return LOWERCASE;
break;
case 2: /* latin 3 */
if ((ks >= XKB_KEY_Hstroke && ks <= XKB_KEY_Jcircumflex) ||
(ks >= XKB_KEY_Cabovedot && ks <= XKB_KEY_Scircumflex))
return UPPERCASE;
if ((ks >= XKB_KEY_hstroke && ks <= XKB_KEY_jcircumflex) ||
(ks >= XKB_KEY_cabovedot && ks <= XKB_KEY_scircumflex))
return LOWERCASE;
break;
case 3: /* latin 4 */
if ((ks >= XKB_KEY_Rcedilla && ks <= XKB_KEY_Tslash) ||
(ks == XKB_KEY_ENG) ||
(ks >= XKB_KEY_Amacron && ks <= XKB_KEY_Umacron))
return UPPERCASE;
if ((ks >= XKB_KEY_rcedilla && ks <= XKB_KEY_tslash) ||
(ks == XKB_KEY_eng) ||
(ks >= XKB_KEY_amacron && ks <= XKB_KEY_umacron))
return LOWERCASE;
break;
case 6: /* Cyrillic */
if ((ks >= XKB_KEY_Serbian_DJE && ks <= XKB_KEY_Serbian_DZE) ||
(ks >= XKB_KEY_Cyrillic_YU && ks <= XKB_KEY_Cyrillic_HARDSIGN))
return UPPERCASE;
if ((ks >= XKB_KEY_Serbian_dje && ks <= XKB_KEY_Serbian_dze) ||
(ks >= XKB_KEY_Cyrillic_yu && ks <= XKB_KEY_Cyrillic_hardsign))
return LOWERCASE;
break;
case 7: /* Greek */
if ((ks >= XKB_KEY_Greek_ALPHAaccent &&
ks <= XKB_KEY_Greek_OMEGAaccent) ||
(ks >= XKB_KEY_Greek_ALPHA && ks <= XKB_KEY_Greek_OMEGA))
return UPPERCASE;
if ((ks >= XKB_KEY_Greek_alphaaccent &&
ks <= XKB_KEY_Greek_omegaaccent) ||
(ks >= XKB_KEY_Greek_alpha && ks <= XKB_KEY_Greek_OMEGA))
return LOWERCASE;
break;
case 18: /* latin 8 */
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))
return UPPERCASE;
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))
return LOWERCASE;
break;
case 19: /* latin 9 */
if (ks == XKB_KEY_OE || ks == XKB_KEY_Ydiaeresis)
return UPPERCASE;
if (ks == XKB_KEY_oe)
return LOWERCASE;
break;
}
return NONE;
}
bool
xkb_keysym_is_lower(xkb_keysym_t keysym)
{
return keysym_get_case(keysym) == LOWERCASE;
}
bool
xkb_keysym_is_upper(xkb_keysym_t keysym)
{
return keysym_get_case(keysym) == UPPERCASE;
}
bool
xkb_keysym_is_keypad(xkb_keysym_t keysym)
{
return keysym >= XKB_KEY_KP_Space && keysym <= XKB_KEY_KP_Equal;
}

View File

@ -1,124 +0,0 @@
/************************************************************
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.
********************************************************/
#include "xkb-priv.h"
#include "alloc.h"
unsigned
_XkbcKSCheckCase(xkb_keysym_t ks)
{
unsigned set = (ks & (~0xff)) >> 8;
unsigned rtrn = 0;
switch (set) {
case 0: /* latin 1 */
if ((ks >= XKB_KEY_A && ks <= XKB_KEY_Z) ||
(ks >= XKB_KEY_Agrave && ks <= XKB_KEY_THORN && ks != XKB_KEY_multiply))
rtrn |= _XkbKSUpper;
if ((ks >= XKB_KEY_a && ks <= XKB_KEY_z) ||
(ks >= XKB_KEY_agrave && ks <= XKB_KEY_ydiaeresis))
rtrn |= _XkbKSLower;
break;
case 1: /* latin 2 */
if ((ks >= XKB_KEY_Aogonek && ks <= XKB_KEY_Zabovedot && ks != XKB_KEY_breve) ||
(ks >= XKB_KEY_Racute && ks<=XKB_KEY_Tcedilla))
rtrn |= _XkbKSUpper;
if ((ks >= XKB_KEY_aogonek && ks <= XKB_KEY_zabovedot && ks != XKB_KEY_caron) ||
(ks >= XKB_KEY_racute && ks <= XKB_KEY_tcedilla))
rtrn |= _XkbKSLower;
break;
case 2: /* latin 3 */
if ((ks >= XKB_KEY_Hstroke && ks <= XKB_KEY_Jcircumflex) ||
(ks >= XKB_KEY_Cabovedot && ks <= XKB_KEY_Scircumflex))
rtrn |= _XkbKSUpper;
if ((ks >= XKB_KEY_hstroke && ks <= XKB_KEY_jcircumflex) ||
(ks >= XKB_KEY_cabovedot && ks <= XKB_KEY_scircumflex))
rtrn |= _XkbKSLower;
break;
case 3: /* latin 4 */
if ((ks >= XKB_KEY_Rcedilla && ks <= XKB_KEY_Tslash) ||
(ks == XKB_KEY_ENG) ||
(ks >= XKB_KEY_Amacron && ks <= XKB_KEY_Umacron))
rtrn |= _XkbKSUpper;
if ((ks >= XKB_KEY_rcedilla && ks <= XKB_KEY_tslash) ||
(ks == XKB_KEY_eng) ||
(ks >= XKB_KEY_amacron && ks <= XKB_KEY_umacron))
rtrn |= _XkbKSLower;
break;
case 6: /* Cyrillic */
if ((ks >= XKB_KEY_Serbian_DJE && ks <= XKB_KEY_Serbian_DZE) ||
(ks >= XKB_KEY_Cyrillic_YU && ks <= XKB_KEY_Cyrillic_HARDSIGN))
rtrn |= _XkbKSUpper;
if ((ks >= XKB_KEY_Serbian_dje && ks <= XKB_KEY_Serbian_dze) ||
(ks >= XKB_KEY_Cyrillic_yu && ks <= XKB_KEY_Cyrillic_hardsign))
rtrn |= _XkbKSLower;
break;
case 7: /* Greek */
if ((ks >= XKB_KEY_Greek_ALPHAaccent &&
ks <= XKB_KEY_Greek_OMEGAaccent) ||
(ks >= XKB_KEY_Greek_ALPHA && ks <= XKB_KEY_Greek_OMEGA))
rtrn |= _XkbKSUpper;
if ((ks >= XKB_KEY_Greek_alphaaccent &&
ks <= XKB_KEY_Greek_omegaaccent) ||
(ks >= XKB_KEY_Greek_alpha && ks <= XKB_KEY_Greek_OMEGA))
rtrn |= _XkbKSLower;
break;
case 18: /* latin 8 */
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))
rtrn |= _XkbKSUpper;
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))
rtrn |= _XkbKSLower;
break;
case 19: /* latin 9 */
if (ks == XKB_KEY_OE || ks == XKB_KEY_Ydiaeresis)
rtrn |= _XkbKSUpper;
if (ks == XKB_KEY_oe)
rtrn |= _XkbKSLower;
break;
}
return rtrn;
}

View File

@ -456,15 +456,13 @@ xkb_map_new_from_kccgst(struct xkb_context *ctx,
extern int
xkb_context_take_file_id(struct xkb_context *ctx);
extern unsigned
_XkbcKSCheckCase(xkb_keysym_t sym);
bool
xkb_keysym_is_lower(xkb_keysym_t keysym);
#define _XkbKSLower (1 << 0)
#define _XkbKSUpper (1 << 1)
bool
xkb_keysym_is_upper(xkb_keysym_t keysym);
#define XkbcKSIsLower(k) (_XkbcKSCheckCase(k) & _XkbKSLower)
#define XkbcKSIsUpper(k) (_XkbcKSCheckCase(k) & _XkbKSUpper)
#define XkbKSIsKeypad(k) (((k) >= XKB_KEY_KP_Space) && ((k) <= XKB_KEY_KP_Equal))
bool
xkb_keysym_is_keypad(xkb_keysym_t keysym);
#endif /* XKB_PRIV_H */

View File

@ -1670,11 +1670,13 @@ FindAutomaticType(struct xkb_keymap *keymap, int width,
}
else if (width == 2)
{
if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
if (syms && xkb_keysym_is_lower(syms[0]) &&
xkb_keysym_is_upper(syms[1]))
{
*typeNameRtrn = xkb_atom_intern(keymap->ctx, "ALPHABETIC");
}
else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
xkb_keysym_is_keypad(syms[1])))
{
*typeNameRtrn = xkb_atom_intern(keymap->ctx, "KEYPAD");
*autoType = true;
@ -1687,15 +1689,17 @@ FindAutomaticType(struct xkb_keymap *keymap, int width,
}
else if (width <= 4)
{
if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
if (syms && xkb_keysym_is_lower(syms[0]) &&
xkb_keysym_is_upper(syms[1]))
if (xkb_keysym_is_lower(syms[2]) && xkb_keysym_is_upper(syms[3]))
*typeNameRtrn =
xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_ALPHABETIC");
else
*typeNameRtrn = xkb_atom_intern(keymap->ctx,
"FOUR_LEVEL_SEMIALPHABETIC");
else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
xkb_keysym_is_keypad(syms[1])))
*typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_KEYPAD");
else
*typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL");