systemd/0488-terminal-idev-add-help...

51 lines
1.9 KiB
Diff

From 884964a9639649422d3613500cdacea48a4ccc91 Mon Sep 17 00:00:00 2001
From: David Herrmann <dh.herrmann@gmail.com>
Date: Fri, 3 Oct 2014 13:11:08 +0200
Subject: [PATCH] terminal/idev: add helper to match keyboard shortcuts
Matching keyboard shortcuts on internationalized keyboards is actually
non-trivial. Matching the actual key is easy, but the modifiers can be
used by both, the matching and the translation step. Therefore, XKB
exports "consumed-modifiers" that we use to figure out whether a modifier
was already used by the translation step.
The new IDEV_KBDMATCH() helper can be used to match on any keyboard
shortcut and it will do the right thing.
---
src/libsystemd-terminal/idev.h | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/libsystemd-terminal/idev.h b/src/libsystemd-terminal/idev.h
index 0ae044cfd5..ea79bb6ab6 100644
--- a/src/libsystemd-terminal/idev.h
+++ b/src/libsystemd-terminal/idev.h
@@ -110,6 +110,28 @@ struct idev_data_keyboard {
uint32_t *codepoints;
};
+static inline bool idev_kbdmatch(idev_data_keyboard *kdata,
+ uint32_t mods, uint32_t n_syms,
+ const uint32_t *syms) {
+ const uint32_t significant = IDEV_KBDMOD_SHIFT |
+ IDEV_KBDMOD_CTRL |
+ IDEV_KBDMOD_ALT |
+ IDEV_KBDMOD_LINUX;
+ uint32_t real;
+
+ if (n_syms != kdata->n_syms)
+ return false;
+
+ real = kdata->mods & ~kdata->consumed_mods & significant;
+ if (real != (mods & ~kdata->consumed_mods))
+ return false;
+
+ return !memcmp(syms, kdata->keysyms, n_syms * sizeof(*syms));
+}
+
+#define IDEV_KBDMATCH(_kdata, _mods, _sym) \
+ idev_kbdmatch((_kdata), (_mods), 1, (const uint32_t[]){ (_sym) })
+
/*
* Data Packets
*/