On 10/6/26 12:56, Marc-André Lureau wrote:
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.
Signed-off-by: Marc-André Lureau <[email protected]>
---
include/ui/input.h | 5 +++++
ui/input.c | 49 +++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/include/ui/input.h b/include/ui/input.h
index 6df8ae3a8a3..66e5c1f4b06 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -151,4 +151,9 @@ 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[];
+void qemu_input_handler_set_led(QemuInputHandlerState *s, int ledstate);
+void qemu_input_led_notifier_add(Notifier *n);
+void qemu_input_led_notifier_remove(Notifier *n);
+int qemu_input_get_led(QemuConsole *con);
+
#endif /* INPUT_H */
diff --git a/ui/input.c b/ui/input.c
index 15affeabf44..99a1090f8c3 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -14,6 +14,7 @@ struct QemuInputHandlerState {
int id;
int events;
QemuConsole *con;
+ int ledstate;
In "hw/misc/led.h" we use 'bool is_emitting' which is clearer IMHO.
Now looking at kbd_put_ledstate(), 'int ledstate' is actually a bitmask
of:
/* identical to the ps/2 keyboard bits */
#define QEMU_SCROLL_LOCK_LED (1 << 0)
#define QEMU_NUM_LOCK_LED (1 << 1)
#define QEMU_CAPS_LOCK_LED (1 << 2)
Maybe rename as 'unsigned qemu_leds_bitmask' or 'uint32_t leds_bitmask'
or simply ledsmask? (notify_input_changed below uses uint32_t).
And:
qemu_input_handler_set_led() -> qemu_input_handler_set_leds_mask(u32)
int qemu_input_get_led() -> uint32_t qemu_input_get_leds_mask(const)
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 led_notifiers =
+ NOTIFIER_LIST_INITIALIZER(led_notifiers);
leds_notifiers (plural)
With the changes:
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>