From 9d5b0106509f8a9fafac5539c499f3645af91fbe Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Tue, 13 Aug 2013 18:52:46 +0300 Subject: [PATCH libxkbcommon 1/3] keysym: add xkb_keysym_to_{lower,upper} This functions are needed later; they are not API functions. The capitalization is not locale sensitive. Signed-off-by: Ran Benita --- src/keysym.c | 20 ++++++++++++++++++++ src/keysym.h | 6 ++++++ test/keysym.c | 13 +++++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/keysym.c b/src/keysym.c index 1e92a4a..33b6491 100644 --- a/src/keysym.c +++ b/src/keysym.c @@ -242,6 +242,26 @@ xkb_keysym_is_upper(xkb_keysym_t ks) return (ks == upper ? true : false); } +xkb_keysym_t +xkb_keysym_to_lower(xkb_keysym_t ks) +{ + xkb_keysym_t lower, upper; + + XConvertCase(ks, &lower, &upper); + + return lower; +} + +xkb_keysym_t +xkb_keysym_to_upper(xkb_keysym_t ks) +{ + xkb_keysym_t lower, upper; + + XConvertCase(ks, &lower, &upper); + + return upper; +} + /* * The following is copied verbatim from libX11:src/KeyBind.c, commit * d45b3fc19fbe95c41afc4e51d768df6d42332010, with the following changes: diff --git a/src/keysym.h b/src/keysym.h index 6f2280b..e9374dc 100644 --- a/src/keysym.h +++ b/src/keysym.h @@ -59,4 +59,10 @@ xkb_keysym_is_upper(xkb_keysym_t keysym); bool xkb_keysym_is_keypad(xkb_keysym_t keysym); +xkb_keysym_t +xkb_keysym_to_upper(xkb_keysym_t ks); + +xkb_keysym_t +xkb_keysym_to_lower(xkb_keysym_t ks); + #endif diff --git a/test/keysym.c b/test/keysym.c index 46d70ac..439622c 100644 --- a/test/keysym.c +++ b/test/keysym.c @@ -183,5 +183,18 @@ main(void) assert(!xkb_keysym_is_keypad(XKB_KEY_1)); assert(!xkb_keysym_is_keypad(XKB_KEY_Return)); + assert(xkb_keysym_to_upper(XKB_KEY_a) == XKB_KEY_A); + assert(xkb_keysym_to_upper(XKB_KEY_A) == XKB_KEY_A); + assert(xkb_keysym_to_lower(XKB_KEY_a) == XKB_KEY_a); + assert(xkb_keysym_to_lower(XKB_KEY_A) == XKB_KEY_a); + assert(xkb_keysym_to_upper(XKB_KEY_Return) == XKB_KEY_Return); + assert(xkb_keysym_to_lower(XKB_KEY_Return) == XKB_KEY_Return); + assert(xkb_keysym_to_upper(XKB_KEY_Greek_lambda) == XKB_KEY_Greek_LAMBDA); + assert(xkb_keysym_to_upper(XKB_KEY_Greek_LAMBDA) == XKB_KEY_Greek_LAMBDA); + assert(xkb_keysym_to_lower(XKB_KEY_Greek_lambda) == XKB_KEY_Greek_lambda); + assert(xkb_keysym_to_lower(XKB_KEY_Greek_LAMBDA) == XKB_KEY_Greek_lambda); + assert(xkb_keysym_to_upper(XKB_KEY_eacute) == XKB_KEY_Eacute); + assert(xkb_keysym_to_lower(XKB_KEY_Eacute) == XKB_KEY_eacute); + return 0; } -- 1.8.3.4