From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Subject: [GIT PULL 09/27] ui/input: add LED state tracking to QemuInputHandlerState
Date: Wed, 17 Jun 2026 19:23:06 +0400 [thread overview]
Message-ID: <20260617-ui-input-v1-9-79e9aedc5899@redhat.com> (raw)
In-Reply-To: <20260617-ui-input-v1-0-79e9aedc5899@redhat.com>
Add per-handler LED state and a NotifierList for UI backends to
subscribe to LED changes.
Devices call qemu_input_handler_set_led() to store their LED state and
notify backends. Notify also on focus change, or list update.
Note: I considered conflating mouse-mode & led-state changes, but those
are quite different events (from different source kinds etc) and we may
want to improve the internal implementation.
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
include/ui/input.h | 11 +++++++++++
ui/input.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 57 insertions(+), 5 deletions(-)
diff --git a/include/ui/input.h b/include/ui/input.h
index 6df8ae3a8a3..11146c92bd4 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -151,4 +151,15 @@ extern const guint16 qemu_input_map_xorgxwin_to_linux[];
extern const guint qemu_input_map_osx_to_linux_len;
extern const guint16 qemu_input_map_osx_to_linux[];
+/**
+ * qemu_input_get_leds_mask() - get the LED mask for the given console
+ * @con: a QemuConsole or NULL
+ *
+ * If @con is NULL, returns the LED state mask for the default console.
+ */
+uint32_t qemu_input_get_leds_mask(const QemuConsole *con);
+void qemu_input_handler_set_leds_mask(QemuInputHandlerState *s, uint32_t leds_mask);
+void qemu_input_led_notifier_add(Notifier *n);
+void qemu_input_led_notifier_remove(Notifier *n);
+
#endif /* INPUT_H */
diff --git a/ui/input.c b/ui/input.c
index 15affeabf44..3e362c05787 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -14,6 +14,7 @@ struct QemuInputHandlerState {
int id;
int events;
QemuConsole *con;
+ uint32_t leds_mask;
QTAILQ_ENTRY(QemuInputHandlerState) node;
};
@@ -38,6 +39,8 @@ static QTAILQ_HEAD(, QemuInputHandlerState) handlers =
QTAILQ_HEAD_INITIALIZER(handlers);
static NotifierList mouse_mode_notifiers =
NOTIFIER_LIST_INITIALIZER(mouse_mode_notifiers);
+static NotifierList leds_notifiers =
+ NOTIFIER_LIST_INITIALIZER(leds_notifiers);
static QemuInputEventQueueHead kbd_queue = QTAILQ_HEAD_INITIALIZER(kbd_queue);
static QEMUTimer *kbd_timer;
@@ -45,6 +48,14 @@ static uint32_t kbd_default_delay_ms = 10;
static uint32_t queue_count;
static uint32_t queue_limit = 1024;
+static void notify_input_changed(uint32_t mask)
+{
+ notifier_list_notify(&mouse_mode_notifiers, NULL);
+ if (mask & INPUT_EVENT_MASK_KEY) {
+ notifier_list_notify(&leds_notifiers, NULL);
+ }
+}
+
QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev,
const QemuInputHandler *handler)
{
@@ -55,8 +66,8 @@ QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev,
s->handler = handler;
s->id = id++;
QTAILQ_INSERT_TAIL(&handlers, s, node);
+ notify_input_changed(handler->mask);
- notifier_list_notify(&mouse_mode_notifiers, NULL);
return s;
}
@@ -64,21 +75,23 @@ void qemu_input_handler_activate(QemuInputHandlerState *s)
{
QTAILQ_REMOVE(&handlers, s, node);
QTAILQ_INSERT_HEAD(&handlers, s, node);
- notifier_list_notify(&mouse_mode_notifiers, NULL);
+ notify_input_changed(s->handler->mask);
}
void qemu_input_handler_deactivate(QemuInputHandlerState *s)
{
QTAILQ_REMOVE(&handlers, s, node);
QTAILQ_INSERT_TAIL(&handlers, s, node);
- notifier_list_notify(&mouse_mode_notifiers, NULL);
+ notify_input_changed(s->handler->mask);
}
void qemu_input_handler_unregister(QemuInputHandlerState *s)
{
+ uint32_t mask = s->handler->mask;
+
QTAILQ_REMOVE(&handlers, s, node);
g_free(s);
- notifier_list_notify(&mouse_mode_notifiers, NULL);
+ notify_input_changed(mask);
}
void qemu_input_handler_bind(QemuInputHandlerState *s,
@@ -98,7 +111,7 @@ void qemu_input_handler_bind(QemuInputHandlerState *s,
}
static QemuInputHandlerState*
-qemu_input_find_handler(uint32_t mask, QemuConsole *con)
+qemu_input_find_handler(uint32_t mask, const QemuConsole *con)
{
QemuInputHandlerState *s;
@@ -122,6 +135,23 @@ qemu_input_find_handler(uint32_t mask, QemuConsole *con)
return NULL;
}
+void qemu_input_handler_set_leds_mask(QemuInputHandlerState *s, uint32_t leds_mask)
+{
+ assert(s->handler->mask & INPUT_EVENT_MASK_KEY);
+ s->leds_mask = leds_mask;
+ notifier_list_notify(&leds_notifiers, NULL);
+}
+
+void qemu_input_led_notifier_add(Notifier *n)
+{
+ notifier_list_add(&leds_notifiers, n);
+}
+
+void qemu_input_led_notifier_remove(Notifier *n)
+{
+ notifier_remove(n);
+}
+
void qmp_input_send_event(const char *device,
bool has_head, int64_t head,
InputEventList *events, Error **errp)
@@ -445,6 +475,17 @@ bool qemu_input_is_absolute(QemuConsole *con)
return (s != NULL) && (s->handler->mask & INPUT_EVENT_MASK_ABS);
}
+uint32_t qemu_input_get_leds_mask(const QemuConsole *con)
+{
+ QemuInputHandlerState *s;
+
+ s = qemu_input_find_handler(INPUT_EVENT_MASK_KEY, con);
+ if (s) {
+ return s->leds_mask;
+ }
+ return 0;
+}
+
int qemu_input_scale_axis(int value,
int min_in, int max_in,
int min_out, int max_out)
--
2.54.0
next prev parent reply other threads:[~2026-06-17 15:24 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 15:22 [GIT PULL 00/27] UI patches for 2026-06-17 Marc-André Lureau
2026-06-17 15:22 ` [GIT PULL 01/27] hmp-commands.hx: fix button_state doc Marc-André Lureau
2026-06-17 15:22 ` [GIT PULL 02/27] ui/hmp: move index_from_key() where it is used Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 03/27] hw/i386/vmmouse: convert to QemuInputHandler API Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 04/27] hw/usb/dev-wacom: convert to modern " Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 05/27] ui: move LED and key utilities to input.c, delete input-legacy.c Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 06/27] hw/input: replace fprint with LOG_GUEST_ERROR Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 07/27] ui/input: remove double-notification on qemu_mouse_set() Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 08/27] ui/input: remove dead declaration Marc-André Lureau
2026-06-17 15:23 ` Marc-André Lureau [this message]
2026-06-17 15:23 ` [GIT PULL 10/27] hw/input/ps2: keep QemuInputHandlerState in PS2State Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 11/27] hw/arm: keep QemuInputHandlerState in musicpal Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 12/27] hw/input: keep QemuInputHandlerState in adb-kbd Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 13/27] hw/input: keep QemuInputHandlerState in stellaris Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 14/27] hw/m68k: keep QemuInputHandlerState in next-kbd Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 15/27] ui/input: qemu_input_handler_register to warn for unused result Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 16/27] hw/input/ps2: use qemu_input_handler_set_leds_mask() for LED state Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 17/27] hw/input/hid: " Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 18/27] hw/input/virtio-input-hid: " Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 19/27] ui/vnc: switch LED handling to Notifier-based input API Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 20/27] ui/spice: " Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 21/27] ui/dbus: " Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 22/27] ui/input: remove old LED handler broadcast queue Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 23/27] tools/qemu-vnc: Have console_get_mouse/keyboard take const QemuConsole Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 24/27] ui/input: Have qemu_input_is_absolute() take a " Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 25/27] ui/pixman: fix zero rowstride in qemu_pixman_image_new_shareable() Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 26/27] ui/sdl2: Explicitly specify EGL platform Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 27/27] ui/sdl2: Set GL ES profile before creating initial GL context Marc-André Lureau
2026-06-18 17:53 ` [GIT PULL 00/27] UI patches for 2026-06-17 Stefan Hajnoczi
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=20260617-ui-input-v1-9-79e9aedc5899@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.