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>
This commit is contained in:
Marc-André Lureau
2026-06-09 01:17:52 +04:00
parent 694635664a
commit 757397c0a2
3 changed files with 25 additions and 39 deletions

View File

@@ -13,58 +13,43 @@
#include "trace.h"
#include "qemu-vnc.h"
struct QEMUPutLEDEntry {
QEMUPutLEDEvent *put_led;
void *opaque;
QTAILQ_ENTRY(QEMUPutLEDEntry) next;
};
static NotifierList mouse_mode_notifiers =
NOTIFIER_LIST_INITIALIZER(mouse_mode_notifiers);
static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers =
QTAILQ_HEAD_INITIALIZER(led_handlers);
static NotifierList led_notifiers =
NOTIFIER_LIST_INITIALIZER(led_notifiers);
/* Track the target console for pending mouse events (used by sync) */
static QemuConsole *mouse_target;
QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func,
void *opaque)
{
QEMUPutLEDEntry *s;
/*
* The D-Bus Keyboard.Modifiers property uses the same
* bit layout as QEMU's LED constants.
*/
static guint modifiers;
s = g_new0(QEMUPutLEDEntry, 1);
s->put_led = func;
s->opaque = opaque;
QTAILQ_INSERT_TAIL(&led_handlers, s, next);
return s;
void qemu_input_led_notifier_add(Notifier *n)
{
notifier_list_add(&led_notifiers, n);
}
void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
void qemu_input_led_notifier_remove(Notifier *n)
{
if (!entry) {
return;
}
QTAILQ_REMOVE(&led_handlers, entry, next);
g_free(entry);
notifier_remove(n);
}
uint32_t qemu_input_get_leds_mask(const QemuConsole *con)
{
return modifiers;
}
static void
on_keyboard_modifiers_changed(GObject *gobject, GParamSpec *pspec,
gpointer user_data)
{
guint modifiers;
QEMUPutLEDEntry *cursor;
modifiers = qemu_dbus_display1_keyboard_get_modifiers(
QEMU_DBUS_DISPLAY1_KEYBOARD(gobject));
/*
* The D-Bus Keyboard.Modifiers property uses the same
* bit layout as QEMU's LED constants.
*/
QTAILQ_FOREACH(cursor, &led_handlers, next) {
cursor->put_led(cursor->opaque, modifiers);
}
notifier_list_notify(&led_notifiers, NULL);
}
void qemu_add_mouse_mode_change_notifier(Notifier *notify)

View File

@@ -1820,9 +1820,10 @@ static void vnc_led_state_change(VncState *vs)
vnc_flush(vs);
}
static void kbd_leds(void *opaque, int ledstate)
static void kbd_leds(Notifier *notifier, void *data)
{
VncDisplay *vd = opaque;
VncDisplay *vd = container_of(notifier, VncDisplay, led_notifier);
int ledstate = qemu_input_get_leds_mask(vd->dcl.con);
VncState *client;
trace_vnc_key_guest_leds((ledstate & QEMU_CAPS_LOCK_LED),
@@ -3489,8 +3490,7 @@ static void vnc_display_close(VncDisplay *vd)
g_free(vd->tlsauthzid);
vd->tlsauthzid = NULL;
if (vd->lock_key_sync) {
qemu_remove_led_event_handler(vd->led);
vd->led = NULL;
qemu_input_led_notifier_remove(&vd->led_notifier);
}
#ifdef CONFIG_VNC_SASL
if (vd->sasl.authz) {
@@ -4221,7 +4221,8 @@ static bool vnc_display_open(VncDisplay *vd, Error **errp)
#endif
vd->lock_key_sync = lock_key_sync;
if (lock_key_sync) {
vd->led = qemu_add_led_event_handler(kbd_leds, vd);
vd->led_notifier.notify = kbd_leds;
qemu_input_led_notifier_add(&vd->led_notifier);
}
vd->ledstate = 0;

View File

@@ -147,7 +147,7 @@ struct VncDisplay
DisplayChangeListener dcl;
kbd_layout_t *kbd_layout;
int lock_key_sync;
QEMUPutLEDEntry *led;
Notifier led_notifier;
int ledstate;
QKbdState *kbd;
QemuMutex mutex;