summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPierre Le Marre <dev@wismill.eu>2023-07-04 09:23:23 +0200
committerWismill <dev@wismill.eu>2023-07-14 09:22:24 +0200
commite811743ff2f28085be74a28b57dfe684a320936e (patch)
treec32715751137b2a64e1020ccf44b1d76fd04ea56 /src
parent0d01a933bba047c7e4a3312fd2c8c6accc563823 (diff)
downloadlibxkbcommon-e811743ff2f28085be74a28b57dfe684a320936e.tar.gz
libxkbcommon-e811743ff2f28085be74a28b57dfe684a320936e.tar.bz2
libxkbcommon-e811743ff2f28085be74a28b57dfe684a320936e.zip
Add XKB_KEYSYM_MIN and XKB_KEYSYM_MAX
Keysyms are 32-bit integers with the 3 most significant bits always set to zero. See: Appendix A “KEYSYM Encoding” of the X Window System Protocol at https://www.x.org/releases/current/doc/xproto/x11protocol.html#keysym_encoding. Add a new constants XKB_KEYSYM_MIN and XKB_KEYSYM_MAX to make the interval of valid keysyms more obvious in the code.
Diffstat (limited to 'src')
-rw-r--r--src/keysym.c2
-rw-r--r--src/keysym.h8
2 files changed, 9 insertions, 1 deletions
diff --git a/src/keysym.c b/src/keysym.c
index 989ae7c..788b7a2 100644
--- a/src/keysym.c
+++ b/src/keysym.c
@@ -64,7 +64,7 @@ get_name(const struct name_keysym *entry)
XKB_EXPORT int
xkb_keysym_get_name(xkb_keysym_t ks, char *buffer, size_t size)
{
- if ((ks & ((unsigned long) ~0x1fffffff)) != 0) {
+ if (ks > XKB_KEYSYM_MAX) {
snprintf(buffer, size, "Invalid");
return -1;
}
diff --git a/src/keysym.h b/src/keysym.h
index 2633963..e636746 100644
--- a/src/keysym.h
+++ b/src/keysym.h
@@ -50,6 +50,14 @@
#ifndef KEYSYM_H
#define KEYSYM_H
+/*
+ * NOTE: this is not defined in xkbcommon.h, because if we did, it may add
+ * overhead for library user: when handling keysyms they would also need to
+ * check min keysym when previously there was no reason to.
+ */
+/** Minimum keysym value */
+#define XKB_KEYSYM_MIN 0x00000000
+
bool
xkb_keysym_is_lower(xkb_keysym_t keysym);