From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: programmingkidx@gmail.com, berrange@redhat.com,
peter.maydell@linaro.org, Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [RFC PATCH 2/5] kbd-state: add hotkey registry
Date: Wed, 21 Feb 2018 18:08:17 +0100 [thread overview]
Message-ID: <20180221170820.15365-3-kraxel@redhat.com> (raw)
In-Reply-To: <20180221170820.15365-1-kraxel@redhat.com>
Add support to register hotkeys and to check whenever a given QKeyCode
combined with the current modifier state is a hotkey. A hotkey can be
any key combined with up to three modifier keys.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
include/ui/kbd-state.h | 27 +++++++++++++++++++++++++++
ui/kbd-state.c | 41 +++++++++++++++++++++++++++++++++++++----
2 files changed, 64 insertions(+), 4 deletions(-)
diff --git a/include/ui/kbd-state.h b/include/ui/kbd-state.h
index c961da45b2..3f13649b63 100644
--- a/include/ui/kbd-state.h
+++ b/include/ui/kbd-state.h
@@ -20,3 +20,30 @@ bool kbd_state_key_get(KbdState *kbd, QKeyCode qcode);
void kbd_state_key_event(KbdState *kbd, QKeyCode qcode, bool down);
void kbd_state_lift_all_keys(KbdState *kbd);
KbdState *kbd_state_init(QemuConsole *con);
+
+/* ------------------------------------------------------------------ */
+
+typedef enum KbdHotkey KbdHotkey;
+
+enum KbdHotkey {
+ KBD_HOTKEY_NONE = 0,
+
+ KBD_HOTKEY_GRAB,
+ KBD_HOTKEY_FULLSCREEN,
+ KBD_HOTKEY_REDRAW,
+
+ KBD_HOTKEY_CONSOLE_1,
+ KBD_HOTKEY_CONSOLE_2,
+ KBD_HOTKEY_CONSOLE_3,
+ KBD_HOTKEY_CONSOLE_4,
+ KBD_HOTKEY_CONSOLE_5,
+ KBD_HOTKEY_CONSOLE_6,
+ KBD_HOTKEY_CONSOLE_7,
+ KBD_HOTKEY_CONSOLE_8,
+ KBD_HOTKEY_CONSOLE_9,
+};
+
+void kbd_state_hotkey_register(KbdState *kbd, KbdHotkey, QKeyCode qcode,
+ KbdModifier mod1, KbdModifier mod2,
+ KbdModifier mod3);
+KbdHotkey kbd_state_hotkey_get(KbdState *kbd, QKeyCode qcode);
diff --git a/ui/kbd-state.c b/ui/kbd-state.c
index 7a9fe268c2..812cb368e3 100644
--- a/ui/kbd-state.c
+++ b/ui/kbd-state.c
@@ -6,20 +6,20 @@
#include "ui/input.h"
#include "ui/kbd-state.h"
-typedef struct KbdHotkey KbdHotkey;
+typedef struct KbdHotkeyEntry KbdHotkeyEntry;
-struct KbdHotkey {
+struct KbdHotkeyEntry {
uint32_t id;
QKeyCode qcode;
DECLARE_BITMAP(mods, KBD_MOD__MAX);
- QTAILQ_ENTRY(KbdHotkey) next;
+ QTAILQ_ENTRY(KbdHotkeyEntry) next;
};
struct KbdState {
QemuConsole *con;
DECLARE_BITMAP(keys, Q_KEY_CODE__MAX);
DECLARE_BITMAP(mods, KBD_MOD__MAX);
- QTAILQ_HEAD(,KbdHotkey) hotkeys;
+ QTAILQ_HEAD(, KbdHotkeyEntry) hotkeys;
};
static void kbd_state_modifier_update(KbdState *kbd,
@@ -117,3 +117,36 @@ KbdState *kbd_state_init(QemuConsole *con)
return kbd;
}
+
+void kbd_state_hotkey_register(KbdState *kbd, KbdHotkey id, QKeyCode qcode,
+ KbdModifier mod1, KbdModifier mod2,
+ KbdModifier mod3)
+{
+ KbdHotkeyEntry *hotkey = g_new0(KbdHotkeyEntry, 1);
+
+ hotkey->id = id;
+ hotkey->qcode = qcode;
+ if (mod1 != KBD_MOD_NONE) {
+ set_bit(mod1, hotkey->mods);
+ }
+ if (mod2 != KBD_MOD_NONE) {
+ set_bit(mod2, hotkey->mods);
+ }
+ if (mod3 != KBD_MOD_NONE) {
+ set_bit(mod3, hotkey->mods);
+ }
+ QTAILQ_INSERT_TAIL(&kbd->hotkeys, hotkey, next);
+}
+
+KbdHotkey kbd_state_hotkey_get(KbdState *kbd, QKeyCode qcode)
+{
+ KbdHotkeyEntry *hotkey;
+
+ QTAILQ_FOREACH(hotkey, &kbd->hotkeys, next) {
+ if (qcode == hotkey->qcode &&
+ bitmap_equal(kbd->mods, hotkey->mods, KBD_MOD__MAX)) {
+ return hotkey->id;
+ }
+ }
+ return KBD_HOTKEY_NONE;
+}
--
2.9.3
next prev parent reply other threads:[~2018-02-21 17:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-21 17:08 [Qemu-devel] [RFC PATCH 0/5] ui: add keyboard state and hotkey tracker Gerd Hoffmann
2018-02-21 17:08 ` [Qemu-devel] [RFC PATCH 1/5] kbd-state: add keyboard state tracker Gerd Hoffmann
2018-02-21 17:08 ` Gerd Hoffmann [this message]
2018-06-01 19:05 ` [Qemu-devel] [RFC PATCH 2/5] kbd-state: add hotkey registry Programmingkid
2018-06-05 10:20 ` Gerd Hoffmann
2018-06-05 14:37 ` Programmingkid
2018-02-21 17:08 ` [Qemu-devel] [RFC PATCH 3/5] kbd-state: use state tracker for sdl2 Gerd Hoffmann
2018-02-21 17:08 ` [Qemu-devel] [RFC PATCH 4/5] kbd-state: register sdl2 hotkeys Gerd Hoffmann
2018-02-21 17:08 ` [Qemu-devel] [RFC PATCH 5/5] sdl2: use only QKeyCode in sdl2_process_key() Gerd Hoffmann
2018-02-22 14:14 ` [Qemu-devel] [RFC PATCH 0/5] ui: add keyboard state and hotkey tracker no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180221170820.15365-3-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=berrange@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=programmingkidx@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).