@samitouri / QOSamiQemu / commits / 757397c0a2

ui/vnc: switch LED handling to Notifier-based input API

Replace QEMUPutLEDEntry with an embedded Notifier in VncDisplay. Use qemu_input_led_notifier_add/remove instead of the old qemu_add/remove_led_event_handler. Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Marc-André Lureau committed Jun 9, 2026 at 01:17 UTC 757397c0a2175a51d8d38f53723632ff023328e6
3 files changed +24 -38
tools/qemu-vnc/input.c
+17 -32
@@ -13,58 +13,43 @@
13 #include "trace.h"
14 #include "qemu-vnc.h"
15
16 -struct QEMUPutLEDEntry {
17 - QEMUPutLEDEvent *put_led;
18 - void *opaque;
19 - QTAILQ_ENTRY(QEMUPutLEDEntry) next;
20 -};
21 -
16 static NotifierList mouse_mode_notifiers =
17 NOTIFIER_LIST_INITIALIZER(mouse_mode_notifiers);
24 -static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers =
25 - QTAILQ_HEAD_INITIALIZER(led_handlers);
18 +static NotifierList led_notifiers =
19 + NOTIFIER_LIST_INITIALIZER(led_notifiers);
20
21 /* Track the target console for pending mouse events (used by sync) */
22 static QemuConsole *mouse_target;
23
30 -QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func,
31 - void *opaque)
24 +/*
25 + * The D-Bus Keyboard.Modifiers property uses the same
26 + * bit layout as QEMU's LED constants.
27 + */
28 +static guint modifiers;
29 +
30 +void qemu_input_led_notifier_add(Notifier *n)
31 {
33 - QEMUPutLEDEntry *s;
32 + notifier_list_add(&led_notifiers, n);
33 +}
34
35 - s = g_new0(QEMUPutLEDEntry, 1);
36 - s->put_led = func;
37 - s->opaque = opaque;
38 - QTAILQ_INSERT_TAIL(&led_handlers, s, next);
39 - return s;
35 +void qemu_input_led_notifier_remove(Notifier *n)
36 +{
37 + notifier_remove(n);
38 }
39
42 -void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
40 +uint32_t qemu_input_get_leds_mask(const QemuConsole *con)
41 {
44 - if (!entry) {
45 - return;
46 - }
47 - QTAILQ_REMOVE(&led_handlers, entry, next);
48 - g_free(entry);
42 + return modifiers;
43 }
44
45 static void
46 on_keyboard_modifiers_changed(GObject *gobject, GParamSpec *pspec,
47 gpointer user_data)
48 {
55 - guint modifiers;
56 - QEMUPutLEDEntry *cursor;
57 -
49 modifiers = qemu_dbus_display1_keyboard_get_modifiers(
50 QEMU_DBUS_DISPLAY1_KEYBOARD(gobject));
51
61 - /*
62 - * The D-Bus Keyboard.Modifiers property uses the same
63 - * bit layout as QEMU's LED constants.
64 - */
65 - QTAILQ_FOREACH(cursor, &led_handlers, next) {
66 - cursor->put_led(cursor->opaque, modifiers);
67 - }
52 + notifier_list_notify(&led_notifiers, NULL);
53 }
54
55 void qemu_add_mouse_mode_change_notifier(Notifier *notify)
ui/vnc.c
+6 -5
@@ -1820,9 +1820,10 @@ static void vnc_led_state_change(VncState *vs)
1820 vnc_flush(vs);
1821 }
1822
1823 -static void kbd_leds(void *opaque, int ledstate)
1823 +static void kbd_leds(Notifier *notifier, void *data)
1824 {
1825 - VncDisplay *vd = opaque;
1825 + VncDisplay *vd = container_of(notifier, VncDisplay, led_notifier);
1826 + int ledstate = qemu_input_get_leds_mask(vd->dcl.con);
1827 VncState *client;
1828
1829 trace_vnc_key_guest_leds((ledstate & QEMU_CAPS_LOCK_LED),
@@ -3489,8 +3490,7 @@ static void vnc_display_close(VncDisplay *vd)
3490 g_free(vd->tlsauthzid);
3491 vd->tlsauthzid = NULL;
3492 if (vd->lock_key_sync) {
3492 - qemu_remove_led_event_handler(vd->led);
3493 - vd->led = NULL;
3493 + qemu_input_led_notifier_remove(&vd->led_notifier);
3494 }
3495 #ifdef CONFIG_VNC_SASL
3496 if (vd->sasl.authz) {
@@ -4221,7 +4221,8 @@ static bool vnc_display_open(VncDisplay *vd, Error **errp)
4221 #endif
4222 vd->lock_key_sync = lock_key_sync;
4223 if (lock_key_sync) {
4224 - vd->led = qemu_add_led_event_handler(kbd_leds, vd);
4224 + vd->led_notifier.notify = kbd_leds;
4225 + qemu_input_led_notifier_add(&vd->led_notifier);
4226 }
4227 vd->ledstate = 0;
4228
ui/vnc.h
+1 -1
@@ -147,7 +147,7 @@ struct VncDisplay
147 DisplayChangeListener dcl;
148 kbd_layout_t *kbd_layout;
149 int lock_key_sync;
150 - QEMUPutLEDEntry *led;
150 + Notifier led_notifier;
151 int ledstate;
152 QKbdState *kbd;
153 QemuMutex mutex;