ui: retire input-legacy.c
v2 cover ui: retire input-legacy.c
Hi
This series cleans up the QEMU input subsystem by converting the last legacy mouse API consumers and reworking how keyboard LED state (Caps Lock, Num Lock, Scroll Lock) flows from emulated devices to UI backends.
The first patches are preparatory cleanups and fixes. Then legacy mouse API consummers are converted. The second half introduces per-handler LED state tracking in QemuInputHandlerState, convert the users, and drop the old broadcast queue in the final patch.
---
Changes in v2:
- warn on qemu_input_handler_register() unused result, suggested by
Philippe Mathieu-Daudé
- related extra fixes
- rebased, collect patch trailers
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]
To: [email protected]
Cc: Philippe Mathieu-Daudé <[email protected]>
Cc: "Dr. David Alan Gilbert" <[email protected]>
Cc: Marc-André Lureau <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Gerd Hoffmann <[email protected]>
Cc: Jan Kiszka <[email protected]>
Cc: Peter Maydell <[email protected]>
Cc: [email protected]
Cc: Mark Cave-Ayland <[email protected]>
Cc: [email protected]
Cc: Thomas Huth <[email protected]>
---
Marc-André Lureau (22):
hmp-commands.hx: fix button_state doc
ui/hmp: move index_from_key() where it is used hw/i386/vmmouse: convert to QemuInputHandler API hw/usb/dev-wacom: convert to modern QemuInputHandler API
ui: move LED and key utilities to input.c, delete input-legacy.c hw/input: replace fprint with LOG_GUEST_ERROR
ui/input: remove double-notification on qemu_mouse_set() ui/input: remove dead declaration
ui/input: add LED state tracking to QemuInputHandlerState hw/input/ps2: keep QemuInputHandlerState in PS2State
hw/arm: keep QemuInputHandlerState in musicpal
hw/input: keep QemuInputHandlerState in adb-kbd
hw/input: keep QemuInputHandlerState in stellaris
hw/m68k: keep QemuInputHandlerState in next-kbd
ui/input: qemu_input_handler_register to warn for unused result hw/input/ps2: use qemu_input_handler_set_led() for LED state hw/input/hid: use qemu_input_handler_set_led() for LED state hw/input/virtio-input-hid: use qemu_input_handler_set_led() for LED state ui/vnc: switch LED handling to Notifier-based input API ui/spice: switch LED handling to Notifier-based input API ui/dbus: switch LED handling to Notifier-based input API ui/input: remove old LED handler broadcast queue
include/hw/input/ps2.h | 2 + include/hw/input/stellaris_gamepad.h | 2 + include/ui/console.h | 30 ----- include/ui/input.h | 7 +- ui/vnc.h | 2 +- hw/arm/musicpal.c | 13 +- hw/i386/vmmouse.c | 115 ++++++++++++----- hw/input/adb-kbd.c | 17 ++- hw/input/hid.c | 3 +- hw/input/ps2.c | 28 ++++- hw/input/stellaris_gamepad.c | 12 +- hw/input/virtio-input-hid.c | 15 ++- hw/m68k/next-kbd.c | 11 +- hw/usb/dev-wacom.c | 155 ++++++++++++++--------- tools/qemu-vnc/input.c | 49 +++----- ui/dbus-console.c | 11 +- ui/input-legacy.c | 236 ----------------------------------- ui/input.c | 76 ++++++++++- ui/spice-input.c | 10 +- ui/ui-hmp-cmds.c | 22 +++- ui/vnc.c | 11 +- hmp-commands.hx | 4 +- hw/i386/trace-events | 2 +- ui/meson.build | 1 - 24 files changed, 404 insertions(+), 430 deletions(-)
---
base-commit: cc329c491768b2d91eb0b0984f3baa0bf805776d
change-id: 20260609-ui-input-f4b63f6d6af3
Best regards,
Signature · 1 line
Marc-André Lureau <[email protected]>
PATCH v2 1/22 hmp-commands.hx: fix button_state doc
Right & middle buttons are inverted (see hmp_mouse_button)
--- hmp-commands.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hmp-commands.hx +2 -2
@@ -752,13 +752,13 @@ ERST .name = "mouse_button", .args_type = "button_state:i", .params = "state", - .help = "change mouse button state (1=L, 2=M, 4=R)", + .help = "change mouse button state (1=L, 2=R, 4=M)", .cmd = hmp_mouse_button, }, SRST ``mouse_button`` *val* - Change the active mouse button state *val* (1=L, 2=M, 4=R). + Change the active mouse button state *val* (1=L, 2=R, 4=M). ERST {
Signature · 1 line
2.54.0
Re: [PATCH v2 01/22] hmp-commands.hx: fix button_state doc
Quoted 7 lines · Marc-André Lureau
Right & middle buttons are inverted (see
hmp_mouse_button)Signed-off-by Marc-André Lureau <[email protected]>--- hmp-commands.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
PATCH v2 2/22 ui/hmp: move index_from_key() where it is used
In reply to Marc-André Lureau--- include/ui/console.h | 3 --- ui/input-legacy.c | 15 --------------- ui/ui-hmp-cmds.c | 15 +++++++++++++++ 3 files changed, 15 insertions(+), 18 deletions(-)
include/ui/console.h +0 -3
@@ -450,9 +450,6 @@ bool vnc_display_reload_certs(const char *id, Error **errp);bool vnc_display_update (DisplayUpdateOptionsVNC *arg,Error **errp);void vnc_cleanup (void ); -/* input.c */ -int index_from_key (const char *key,size_t key_length); -#ifdef CONFIG_LINUX /* udmabuf.c */ int udmabuf_fd (void );
ui/input-legacy.c +0 -15
@@ -56,21 +56,6 @@ struct QEMUPutLEDEntry { static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers =QTAILQ_HEAD_INITIALIZER (led_handlers); -int index_from_key (const char *key,size_t key_length) -{ -int i; - -for (i =0 ; i <Q_KEY_CODE__MAX ; i++) { -if (!strncmp (key,QKeyCode_str (i), key_length) && - !QKeyCode_str (i)[key_length]) { -break ; - } - } - -/* Return Q_KEY_CODE__MAX if the key is invalid */ -return i; -} -void qmp_send_key (KeyValueList *keys,bool has_hold_time,int64_t hold_time,Error **errp) {
ui/ui-hmp-cmds.c +15 -0
@@ -350,6 +350,21 @@ void hmp_change_vnc(Monitor *mon, const char *device, const char *target, }#endif +static int index_from_key (const char *key,size_t key_length) +{ +int i; + +for (i =0 ; i <Q_KEY_CODE__MAX ; i++) { +if (!strncmp (key,QKeyCode_str (i), key_length) && + !QKeyCode_str (i)[key_length]) { +break ; + } + } + +/* Return Q_KEY_CODE__MAX if the key is invalid */ +return i; +} +void hmp_sendkey (Monitor *mon,const QDict *qdict) {const char *keys =qdict_get_str (qdict,"keys" );
Signature · 1 line
2.54.0
PATCH v2 3/22 hw/i386/vmmouse: convert to QemuInputHandler API
In reply to Marc-André LureauReplace the legacy QEMUPutMouseEvent callback with a proper QemuInputHandler registration. This eliminates one of the two remaining users of the legacy input adapter in ui/input-legacy.c.
--- hw/i386/vmmouse.c | 115 +++++++++++++++++++++++++++++++++++++-------------- hw/i386/trace-events | 2 +- 2 files changed, 85 insertions(+), 32 deletions(-)
hw/i386/vmmouse.c +84 -31
@@ -68,7 +68,10 @@ struct VMMouseState {uint16_t nb_queue;uint16_t status;uint8_t absolute; -QEMUPutMouseEntry *entry; +QemuInputHandlerState *hs; +int axis[INPUT_AXIS__MAX ]; +int dz; +bool btns[INPUT_BUTTON__MAX ];ISAKBDState *i8042; };
@@ -99,39 +102,78 @@ static uint32_t vmmouse_get_status(VMMouseState *s)return (s->status <<16 ) | s->nb_queue; } -static void vmmouse_mouse_event (void *opaque,int x,int y,int dz,int buttons_state) +static void vmmouse_input_event (DeviceState *dev,QemuConsole *src, +QemuInputEvent *evt) { -VMMouseState *s = opaque; +VMMouseState *s =VMMOUSE (dev); + +switch (evt->type) { +case INPUT_EVENT_KIND_BTN : +if (evt->btn.down) { +if (evt->btn.button ==INPUT_BUTTON_WHEEL_UP ) { + s->dz--; + }else if (evt->btn.button ==INPUT_BUTTON_WHEEL_DOWN ) { + s->dz++; + } + } + s->btns[evt->btn.button] = evt->btn.down; +break ; +case INPUT_EVENT_KIND_ABS : +if (evt->abs.axis ==INPUT_AXIS_X ) { + s->axis[INPUT_AXIS_X ] = +qemu_input_scale_axis (evt->abs.value, +INPUT_EVENT_ABS_MIN ,INPUT_EVENT_ABS_MAX , +VMMOUSE_MIN_X ,VMMOUSE_MAX_X ); + }else if (evt->abs.axis ==INPUT_AXIS_Y ) { + s->axis[INPUT_AXIS_Y ] = +qemu_input_scale_axis (evt->abs.value, +INPUT_EVENT_ABS_MIN ,INPUT_EVENT_ABS_MAX , +VMMOUSE_MIN_Y ,VMMOUSE_MAX_Y ); + } +break ; +case INPUT_EVENT_KIND_REL : + s->axis[evt->rel.axis] += evt->rel.value; +break ; +default : +break ; + } +} + +static void vmmouse_input_sync (DeviceState *dev) +{ +VMMouseState *s =VMMOUSE (dev);int buttons =0 ; -if (s->nb_queue > (VMMOUSE_QUEUE_SIZE -4 )) +if (s->nb_queue > (VMMOUSE_QUEUE_SIZE -4 )) {return ; + } -trace_vmmouse_mouse_event (x, y, dz, buttons_state); - -if ((buttons_state &MOUSE_EVENT_LBUTTON )) +if (s->btns[INPUT_BUTTON_LEFT ]) { buttons |=VMMOUSE_LEFT_BUTTON ; -if ((buttons_state &MOUSE_EVENT_RBUTTON )) + } +if (s->btns[INPUT_BUTTON_RIGHT ]) { buttons |=VMMOUSE_RIGHT_BUTTON ; -if ((buttons_state &MOUSE_EVENT_MBUTTON )) + } +if (s->btns[INPUT_BUTTON_MIDDLE ]) { buttons |=VMMOUSE_MIDDLE_BUTTON ; - -if (s->absolute) { - x =qemu_input_scale_axis (x, -INPUT_EVENT_ABS_MIN ,INPUT_EVENT_ABS_MAX , -VMMOUSE_MIN_X ,VMMOUSE_MAX_X ); - y =qemu_input_scale_axis (y, -INPUT_EVENT_ABS_MIN ,INPUT_EVENT_ABS_MAX , -VMMOUSE_MIN_Y ,VMMOUSE_MAX_Y ); - }else { -/* add for guest vmmouse driver to judge this is a relative packet. */ + } +if (!s->absolute) { buttons |=VMMOUSE_RELATIVE_PACKET ; } +trace_vmmouse_queue_event (s->axis[INPUT_AXIS_X ], s->axis[INPUT_AXIS_Y ], + s->dz, buttons); + s->queue[s->nb_queue++] = buttons; - s->queue[s->nb_queue++] = x; - s->queue[s->nb_queue++] = y; - s->queue[s->nb_queue++] = dz; + s->queue[s->nb_queue++] = s->axis[INPUT_AXIS_X ]; + s->queue[s->nb_queue++] = s->axis[INPUT_AXIS_Y ]; + s->queue[s->nb_queue++] = s->dz; + s->dz =0 ; + +if (!s->absolute) { + s->axis[INPUT_AXIS_X ] =0 ; + s->axis[INPUT_AXIS_Y ] =0 ; + }/* need to still generate PS2 events to notify driver to read from queue */
@@ -140,14 +182,25 @@ static void vmmouse_mouse_event(void *opaque, int x, int y, int dz, int buttons_static void vmmouse_remove_handler (VMMouseState *s) { -if (s->entry) { -qemu_remove_mouse_event_handler (s->entry); - s->entry =NULL ; - } +g_clear_pointer (&s->hs, qemu_input_handler_unregister); }static void vmmouse_update_handler (VMMouseState *s,int absolute) { +static const QemuInputHandler vmmouse_abs_handler = { + .name ="vmmouse" , + .mask =INPUT_EVENT_MASK_BTN |INPUT_EVENT_MASK_ABS , + .event = vmmouse_input_event, + .sync = vmmouse_input_sync, + }; + +static const QemuInputHandler vmmouse_rel_handler = { + .name ="vmmouse" , + .mask =INPUT_EVENT_MASK_BTN |INPUT_EVENT_MASK_REL , + .event = vmmouse_input_event, + .sync = vmmouse_input_sync, + }; +if (s->status !=0 ) {return ; }
@@ -155,11 +208,11 @@ static void vmmouse_update_handler(VMMouseState *s, int absolute) s->absolute = absolute;vmmouse_remove_handler (s); } -if (s->entry ==NULL ) { - s->entry =qemu_add_mouse_event_handler (vmmouse_mouse_event, - s, s->absolute, -"vmmouse" ); -qemu_activate_mouse_event_handler (s->entry); +if (s->hs ==NULL ) { +const QemuInputHandler *h = s->absolute ? + &vmmouse_abs_handler : &vmmouse_rel_handler; + s->hs =qemu_input_handler_register (DEVICE (s), h); +qemu_input_handler_activate (s->hs); } }
hw/i386/trace-events +1 -1
@@ -133,7 +133,7 @@ port92_write(uint8_t val) "port92: write 0x%02x" # vmmouse.c vmmouse_get_status(void) "" -vmmouse_mouse_event(int x, int y, int dz, int buttons_state) "event: x=%d y=%d dz=%d state=%d" +vmmouse_queue_event(int x, int y, int dz, int buttons_state) "event: x=%d y=%d dz=%d state=%d" vmmouse_init(void) "" vmmouse_read_id(void) "" vmmouse_request_relative(void) ""
Signature · 1 line
2.54.0
Re: [PATCH v2 03/22] hw/i386/vmmouse: convert to QemuInputHandler API
Hi
Quoted 6 lines · Marc-André Lureau
Replace the legacy QEMUPutMouseEvent callback with a proper QemuInputHandler registration. This eliminates one of the two remaining users of the legacy input adapter in
ui/input-legacy.c.Signed-off-by Marc-André Lureau <[email protected]>
One of the 2 patches missing ack/review in this series, thanks
Quoted 186 lines
--- hw/i386/vmmouse.c | 115 +++++++++++++++++++++++++++++++++++++-------------- hw/i386/trace-events | 2 +- 2 files changed, 85 insertions(+), 32 deletions(-)hw/i386/vmmouse.c +84
-31@@ -68,7 +68,10 @@ struct VMMouseState {uint16_t nb_queue;uint16_t status;uint8_t absolute; -QEMUPutMouseEntry *entry; +QemuInputHandlerState *hs; +int axis[INPUT_AXIS__MAX ]; +int dz; +bool btns[INPUT_BUTTON__MAX ];ISAKBDState *i8042; };@@ -99,39 +102,78 @@ static uint32_t vmmouse_get_status(VMMouseState *s)return (s->status <<16 ) | s->nb_queue; } -static void vmmouse_mouse_event (void *opaque,int x,int y,int dz,int buttons_state) +static void vmmouse_input_event (DeviceState *dev,QemuConsole *src, +QemuInputEvent *evt) { -VMMouseState *s = opaque; +VMMouseState *s =VMMOUSE (dev); + +switch (evt->type) { +case INPUT_EVENT_KIND_BTN : +if (evt->btn.down) { +if (evt->btn.button ==INPUT_BUTTON_WHEEL_UP ) { + s->dz--; + }else if (evt->btn.button ==INPUT_BUTTON_WHEEL_DOWN ) { + s->dz++; + } + } + s->btns[evt->btn.button] = evt->btn.down; +break ; +case INPUT_EVENT_KIND_ABS : +if (evt->abs.axis ==INPUT_AXIS_X ) { + s->axis[INPUT_AXIS_X ] = +qemu_input_scale_axis (evt->abs.value, +INPUT_EVENT_ABS_MIN ,INPUT_EVENT_ABS_MAX , +VMMOUSE_MIN_X ,VMMOUSE_MAX_X ); + }else if (evt->abs.axis ==INPUT_AXIS_Y ) { + s->axis[INPUT_AXIS_Y ] = +qemu_input_scale_axis (evt->abs.value, +INPUT_EVENT_ABS_MIN ,INPUT_EVENT_ABS_MAX , +VMMOUSE_MIN_Y ,VMMOUSE_MAX_Y ); + } +break ; +case INPUT_EVENT_KIND_REL : + s->axis[evt->rel.axis] += evt->rel.value; +break ; +default : +break ; + } +} + +static void vmmouse_input_sync (DeviceState *dev) +{ +VMMouseState *s =VMMOUSE (dev);int buttons =0 ; -if (s->nb_queue > (VMMOUSE_QUEUE_SIZE -4 )) +if (s->nb_queue > (VMMOUSE_QUEUE_SIZE -4 )) {return ; + } -trace_vmmouse_mouse_event (x, y, dz, buttons_state); - -if ((buttons_state &MOUSE_EVENT_LBUTTON )) +if (s->btns[INPUT_BUTTON_LEFT ]) { buttons |=VMMOUSE_LEFT_BUTTON ; -if ((buttons_state &MOUSE_EVENT_RBUTTON )) + } +if (s->btns[INPUT_BUTTON_RIGHT ]) { buttons |=VMMOUSE_RIGHT_BUTTON ; -if ((buttons_state &MOUSE_EVENT_MBUTTON )) + } +if (s->btns[INPUT_BUTTON_MIDDLE ]) { buttons |=VMMOUSE_MIDDLE_BUTTON ; - -if (s->absolute) { - x =qemu_input_scale_axis (x, -INPUT_EVENT_ABS_MIN ,INPUT_EVENT_ABS_MAX , -VMMOUSE_MIN_X ,VMMOUSE_MAX_X ); - y =qemu_input_scale_axis (y, -INPUT_EVENT_ABS_MIN ,INPUT_EVENT_ABS_MAX , -VMMOUSE_MIN_Y ,VMMOUSE_MAX_Y ); - }else { -/* add for guest vmmouse driver to judge this is a relative packet. */ + } +if (!s->absolute) { buttons |=VMMOUSE_RELATIVE_PACKET ; } +trace_vmmouse_queue_event (s->axis[INPUT_AXIS_X ], s->axis[INPUT_AXIS_Y ], + s->dz, buttons); + s->queue[s->nb_queue++] = buttons; - s->queue[s->nb_queue++] = x; - s->queue[s->nb_queue++] = y; - s->queue[s->nb_queue++] = dz; + s->queue[s->nb_queue++] = s->axis[INPUT_AXIS_X ]; + s->queue[s->nb_queue++] = s->axis[INPUT_AXIS_Y ]; + s->queue[s->nb_queue++] = s->dz; + s->dz =0 ; + +if (!s->absolute) { + s->axis[INPUT_AXIS_X ] =0 ; + s->axis[INPUT_AXIS_Y ] =0 ; + }/* need to still generate PS2 events to notify driver to read from queue */ @@ -140,14 +182,25 @@ static void vmmouse_mouse_event(void *opaque, int x, int y, int dz, int buttons_static void vmmouse_remove_handler (VMMouseState *s) { -if (s->entry) { -qemu_remove_mouse_event_handler (s->entry); - s->entry =NULL ; - } +g_clear_pointer (&s->hs, qemu_input_handler_unregister); }static void vmmouse_update_handler (VMMouseState *s,int absolute) { +static const QemuInputHandler vmmouse_abs_handler = { + .name ="vmmouse" , + .mask =INPUT_EVENT_MASK_BTN |INPUT_EVENT_MASK_ABS , + .event = vmmouse_input_event, + .sync = vmmouse_input_sync, + }; + +static const QemuInputHandler vmmouse_rel_handler = { + .name ="vmmouse" , + .mask =INPUT_EVENT_MASK_BTN |INPUT_EVENT_MASK_REL , + .event = vmmouse_input_event, + .sync = vmmouse_input_sync, + }; +if (s->status !=0 ) {return ; }@@ -155,11 +208,11 @@ static void vmmouse_update_handler(VMMouseState *s, int absolute) s->absolute = absolute;vmmouse_remove_handler (s); } -if (s->entry ==NULL ) { - s->entry =qemu_add_mouse_event_handler (vmmouse_mouse_event, - s, s->absolute, -"vmmouse" ); -qemu_activate_mouse_event_handler (s->entry); +if (s->hs ==NULL ) { +const QemuInputHandler *h = s->absolute ? + &vmmouse_abs_handler : &vmmouse_rel_handler; + s->hs =qemu_input_handler_register (DEVICE (s), h); +qemu_input_handler_activate (s->hs); } }hw/i386/trace-events +1
-2@@ -133,7 +133,7 @@ port92_write(uint8_t val) "port92: write 0x%02x" # vmmouse.c vmmouse_get_status(void) "" -vmmouse_mouse_event(int x, int y, int dz, int buttons_state) "event: x=%d y=%d dz=%d state=%d" +vmmouse_queue_event(int x, int y, int dz, int buttons_state) "event: x=%d y=%d dz=%d state=%d" vmmouse_init(void) "" vmmouse_read_id(void) "" vmmouse_request_relative(void) "" --2.54.0
Gerd Hoffmann
Acked-byRe: [PATCH v2 03/22] hw/i386/vmmouse: convert to QemuInputHandler API
Quoted 5 lines · Marc-André Lureau
Hi
Quoted 1 line · Marc-André Lureau
Quoted 8 lines
Quoted 5 lines
Replace the legacy QEMUPutMouseEvent callback with a proper QemuInputHandler registration. This eliminates one of the two remaining users of the legacy input adapter in
ui/input-legacy.c.Signed-off-by Marc-André Lureau <[email protected]>One of the 2 patches missing ack/review in this series, thanks
take care,
Gerd
PATCH v2 4/22 hw/usb/dev-wacom: convert to modern QemuInputHandler API
In reply to Marc-André LureauReplace the legacy QEMUPutMouseEvent callbacks with a proper QemuInputHandler registration. The device now receives typed input events (BTN/ABS/REL) directly.
--- hw/usb/dev-wacom.c | 155 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 94 insertions(+), 61 deletions(-)
hw/usb/dev-wacom.c +94 -61
@@ -42,10 +42,10 @@struct USBWacomState {USBDevice dev;USBEndpoint *intr; -QEMUPutMouseEntry *eh_entry; -int dx, dy, dz, buttons_state; -int x, y; -int mouse_grabbed; +QemuInputHandlerState *hs; +int axis[INPUT_AXIS__MAX ]; +int dz; +bool btns[INPUT_BUTTON__MAX ];enum {WACOM_MODE_HID =1 ,WACOM_MODE_WACOM =2 ,
@@ -188,29 +188,37 @@ static const USBDesc desc_wacom = { .str = desc_strings, }; -static void usb_mouse_event (void *opaque, -int dx1,int dy1,int dz1,int buttons_state) +static void usb_wacom_input_event (DeviceState *dev,QemuConsole *src, +QemuInputEvent *evt) { -USBWacomState *s = opaque; +USBWacomState *s =USB_WACOM (dev); - s->dx += dx1; - s->dy += dy1; - s->dz += dz1; - s->buttons_state = buttons_state; - s->changed =1 ; -usb_wakeup (s->intr,0 ); +switch (evt->type) { +case INPUT_EVENT_KIND_BTN : +if (evt->btn.down) { +if (evt->btn.button ==INPUT_BUTTON_WHEEL_UP ) { + s->dz--; + }else if (evt->btn.button ==INPUT_BUTTON_WHEEL_DOWN ) { + s->dz++; + } + } + s->btns[evt->btn.button] = evt->btn.down; +break ; +case INPUT_EVENT_KIND_ABS : + s->axis[evt->abs.axis] = evt->abs.value; +break ; +case INPUT_EVENT_KIND_REL : + s->axis[evt->rel.axis] += evt->rel.value; +break ; +default : +break ; + } } -static void usb_wacom_event (void *opaque, -int x,int y,int dz,int buttons_state) +static void usb_wacom_input_sync (DeviceState *dev) { -USBWacomState *s = opaque; +USBWacomState *s =USB_WACOM (dev); -/* scale to Penpartner resolution */ - s->x = (x *5040 /0x7FFF ); - s->y = (y *3780 /0x7FFF ); - s->dz += dz; - s->buttons_state = buttons_state; s->changed =1 ;usb_wakeup (s->intr,0 ); }
@@ -225,32 +233,57 @@ static inline int int_clamp(int val, int vmin, int vmax)return val; } +static void usb_wacom_register_input_handler (USBWacomState *s,bool absolute) +{ +static const QemuInputHandler usb_wacom_abs_handler = { + .name ="QEMU PenPartner tablet" , + .mask =INPUT_EVENT_MASK_BTN |INPUT_EVENT_MASK_ABS , + .event = usb_wacom_input_event, + .sync = usb_wacom_input_sync, + }; + +static const QemuInputHandler usb_wacom_rel_handler = { + .name ="QEMU PenPartner tablet" , + .mask =INPUT_EVENT_MASK_BTN |INPUT_EVENT_MASK_REL , + .event = usb_wacom_input_event, + .sync = usb_wacom_input_sync, + }; + +const QemuInputHandler *h = absolute ? + &usb_wacom_abs_handler : &usb_wacom_rel_handler; + +g_clear_pointer (&s->hs, qemu_input_handler_unregister); + + s->hs =qemu_input_handler_register (DEVICE (s), h); +qemu_input_handler_activate (s->hs); +} +static int usb_mouse_poll (USBWacomState *s,uint8_t *buf,int len) {int dx, dy, dz, b, l; -if (!s->mouse_grabbed) { - s->eh_entry =qemu_add_mouse_event_handler (usb_mouse_event, s,0 , -"QEMU PenPartner tablet" ); -qemu_activate_mouse_event_handler (s->eh_entry); - s->mouse_grabbed =1 ; +if (!s->hs) { +usb_wacom_register_input_handler (s, false); } - dx =int_clamp (s->dx,-128 ,127 ); - dy =int_clamp (s->dy,-128 ,127 ); + dx =int_clamp (s->axis[INPUT_AXIS_X ],-128 ,127 ); + dy =int_clamp (s->axis[INPUT_AXIS_Y ],-128 ,127 ); dz =int_clamp (s->dz,-128 ,127 ); - s->dx -= dx; - s->dy -= dy; + s->axis[INPUT_AXIS_X ] -= dx; + s->axis[INPUT_AXIS_Y ] -= dy; s->dz -= dz; b =0 ; -if (s->buttons_state &MOUSE_EVENT_LBUTTON ) +if (s->btns[INPUT_BUTTON_LEFT ]) { b |=0x01 ; -if (s->buttons_state &MOUSE_EVENT_RBUTTON ) + } +if (s->btns[INPUT_BUTTON_RIGHT ]) { b |=0x02 ; -if (s->buttons_state &MOUSE_EVENT_MBUTTON ) + } +if (s->btns[INPUT_BUTTON_MIDDLE ]) { b |=0x04 ; + } buf[0 ] = b; buf[1 ] = dx;
@@ -265,32 +298,40 @@ static int usb_mouse_poll(USBWacomState *s, uint8_t *buf, int len)static int usb_wacom_poll (USBWacomState *s,uint8_t *buf,int len) { -int b; +int b, x, y; -if (!s->mouse_grabbed) { - s->eh_entry =qemu_add_mouse_event_handler (usb_wacom_event, s,1 , -"QEMU PenPartner tablet" ); -qemu_activate_mouse_event_handler (s->eh_entry); - s->mouse_grabbed =1 ; +if (!s->hs) { +usb_wacom_register_input_handler (s, true); } b =0 ; -if (s->buttons_state &MOUSE_EVENT_LBUTTON ) +if (s->btns[INPUT_BUTTON_LEFT ]) { b |=0x01 ; -if (s->buttons_state &MOUSE_EVENT_RBUTTON ) + } +if (s->btns[INPUT_BUTTON_RIGHT ]) { b |=0x40 ; -if (s->buttons_state &MOUSE_EVENT_MBUTTON ) + } +if (s->btns[INPUT_BUTTON_MIDDLE ]) { b |=0x20 ;/* eraser */ + } -if (len <7 ) +if (len <7 ) {return 0 ; + } + + x =qemu_input_scale_axis (s->axis[INPUT_AXIS_X ], +INPUT_EVENT_ABS_MIN ,INPUT_EVENT_ABS_MAX , +0 ,5040 ); + y =qemu_input_scale_axis (s->axis[INPUT_AXIS_Y ], +INPUT_EVENT_ABS_MIN ,INPUT_EVENT_ABS_MAX , +0 ,3780 ); buf[0 ] = s->mode; buf[5 ] =0x00 | (b &0xf0 ); - buf[1 ] = s->x &0xff ; - buf[2 ] = s->x >>8 ; - buf[3 ] = s->y &0xff ; - buf[4 ] = s->y >>8 ; + buf[1 ] = x &0xff ; + buf[2 ] = x >>8 ; + buf[3 ] = y &0xff ; + buf[4 ] = y >>8 ;if (b &0x3f ) { buf[6 ] =0 ; }else {
@@ -302,15 +343,13 @@ static int usb_wacom_poll(USBWacomState *s, uint8_t *buf, int len)static void usb_wacom_handle_reset (USBDevice *dev) { -USBWacomState *s = (USBWacomState *) dev; +USBWacomState *s =USB_WACOM (dev); - s->dx =0 ; - s->dy =0 ; +memset (s->axis,0 ,sizeof (s->axis)); +memset (s->btns,0 ,sizeof (s->btns)); s->dz =0 ; - s->x =0 ; - s->y =0 ; - s->buttons_state =0 ; s->mode =WACOM_MODE_HID ; +g_clear_pointer (&s->hs, qemu_input_handler_unregister); } static void usb_wacom_handle_control(USBDevice *dev, USBPacket *p,
@@ -337,10 +376,7 @@ static void usb_wacom_handle_control(USBDevice *dev, USBPacket *p, }break ;case WACOM_SET_REPORT : -if (s->mouse_grabbed) { -qemu_remove_mouse_event_handler (s->eh_entry); - s->mouse_grabbed =0 ; - } +g_clear_pointer (&s->hs, qemu_input_handler_unregister); s->mode = data[0 ];break ;case WACOM_GET_REPORT :
@@ -400,10 +436,7 @@ static void usb_wacom_unrealize(USBDevice *dev) {USBWacomState *s = (USBWacomState *) dev; -if (s->mouse_grabbed) { -qemu_remove_mouse_event_handler (s->eh_entry); - s->mouse_grabbed =0 ; - } +g_clear_pointer (&s->hs, qemu_input_handler_unregister); }static void usb_wacom_realize (USBDevice *dev,Error **errp)
Signature · 1 line
2.54.0
Re: [PATCH v2 04/22] hw/usb/dev-wacom: convert to modern QemuInputHandler API
Hi
Quoted 6 lines · Marc-André Lureau
Replace the legacy QEMUPutMouseEvent callbacks with a proper QemuInputHandler registration. The device now receives typed input events (BTN/ABS/REL) directly.
Signed-off-by Marc-André Lureau <[email protected]>
One of the 2 patches missing ack/review in this series,
thanks
Quoted 252 lines
--- hw/usb/dev-wacom.c | 155 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 94 insertions(+), 61 deletions(-)hw/usb/dev-wacom.c +94
-62@@ -42,10 +42,10 @@struct USBWacomState {USBDevice dev;USBEndpoint *intr; -QEMUPutMouseEntry *eh_entry; -int dx, dy, dz, buttons_state; -int x, y; -int mouse_grabbed; +QemuInputHandlerState *hs; +int axis[INPUT_AXIS__MAX ]; +int dz; +bool btns[INPUT_BUTTON__MAX ];enum {WACOM_MODE_HID =1 ,WACOM_MODE_WACOM =2 ,@@ -188,29 +188,37 @@ static const USBDesc desc_wacom = { .str = desc_strings, }; -static void usb_mouse_event (void *opaque, -int dx1,int dy1,int dz1,int buttons_state) +static void usb_wacom_input_event (DeviceState *dev,QemuConsole *src, +QemuInputEvent *evt) { -USBWacomState *s = opaque; +USBWacomState *s =USB_WACOM (dev); - s->dx += dx1; - s->dy += dy1; - s->dz += dz1; - s->buttons_state = buttons_state; - s->changed =1 ; -usb_wakeup (s->intr,0 ); +switch (evt->type) { +case INPUT_EVENT_KIND_BTN : +if (evt->btn.down) { +if (evt->btn.button ==INPUT_BUTTON_WHEEL_UP ) { + s->dz--; + }else if (evt->btn.button ==INPUT_BUTTON_WHEEL_DOWN ) { + s->dz++; + } + } + s->btns[evt->btn.button] = evt->btn.down; +break ; +case INPUT_EVENT_KIND_ABS : + s->axis[evt->abs.axis] = evt->abs.value; +break ; +case INPUT_EVENT_KIND_REL : + s->axis[evt->rel.axis] += evt->rel.value; +break ; +default : +break ; + } } -static void usb_wacom_event (void *opaque, -int x,int y,int dz,int buttons_state) +static void usb_wacom_input_sync (DeviceState *dev) { -USBWacomState *s = opaque; +USBWacomState *s =USB_WACOM (dev); -/* scale to Penpartner resolution */ - s->x = (x *5040 /0x7FFF ); - s->y = (y *3780 /0x7FFF ); - s->dz += dz; - s->buttons_state = buttons_state; s->changed =1 ;usb_wakeup (s->intr,0 ); }@@ -225,32 +233,57 @@ static inline int int_clamp(int val, int vmin, int vmax)return val; } +static void usb_wacom_register_input_handler (USBWacomState *s,bool absolute) +{ +static const QemuInputHandler usb_wacom_abs_handler = { + .name ="QEMU PenPartner tablet" , + .mask =INPUT_EVENT_MASK_BTN |INPUT_EVENT_MASK_ABS , + .event = usb_wacom_input_event, + .sync = usb_wacom_input_sync, + }; + +static const QemuInputHandler usb_wacom_rel_handler = { + .name ="QEMU PenPartner tablet" , + .mask =INPUT_EVENT_MASK_BTN |INPUT_EVENT_MASK_REL , + .event = usb_wacom_input_event, + .sync = usb_wacom_input_sync, + }; + +const QemuInputHandler *h = absolute ? + &usb_wacom_abs_handler : &usb_wacom_rel_handler; + +g_clear_pointer (&s->hs, qemu_input_handler_unregister); + + s->hs =qemu_input_handler_register (DEVICE (s), h); +qemu_input_handler_activate (s->hs); +} +static int usb_mouse_poll (USBWacomState *s,uint8_t *buf,int len) {int dx, dy, dz, b, l; -if (!s->mouse_grabbed) { - s->eh_entry =qemu_add_mouse_event_handler (usb_mouse_event, s,0 , -"QEMU PenPartner tablet" ); -qemu_activate_mouse_event_handler (s->eh_entry); - s->mouse_grabbed =1 ; +if (!s->hs) { +usb_wacom_register_input_handler (s, false); } - dx =int_clamp (s->dx,-128 ,127 ); - dy =int_clamp (s->dy,-128 ,127 ); + dx =int_clamp (s->axis[INPUT_AXIS_X ],-128 ,127 ); + dy =int_clamp (s->axis[INPUT_AXIS_Y ],-128 ,127 ); dz =int_clamp (s->dz,-128 ,127 ); - s->dx -= dx; - s->dy -= dy; + s->axis[INPUT_AXIS_X ] -= dx; + s->axis[INPUT_AXIS_Y ] -= dy; s->dz -= dz; b =0 ; -if (s->buttons_state &MOUSE_EVENT_LBUTTON ) +if (s->btns[INPUT_BUTTON_LEFT ]) { b |=0x01 ; -if (s->buttons_state &MOUSE_EVENT_RBUTTON ) + } +if (s->btns[INPUT_BUTTON_RIGHT ]) { b |=0x02 ; -if (s->buttons_state &MOUSE_EVENT_MBUTTON ) + } +if (s->btns[INPUT_BUTTON_MIDDLE ]) { b |=0x04 ; + } buf[0 ] = b; buf[1 ] = dx;@@ -265,32 +298,40 @@ static int usb_mouse_poll(USBWacomState *s, uint8_t *buf, int len)static int usb_wacom_poll (USBWacomState *s,uint8_t *buf,int len) { -int b; +int b, x, y; -if (!s->mouse_grabbed) { - s->eh_entry =qemu_add_mouse_event_handler (usb_wacom_event, s,1 , -"QEMU PenPartner tablet" ); -qemu_activate_mouse_event_handler (s->eh_entry); - s->mouse_grabbed =1 ; +if (!s->hs) { +usb_wacom_register_input_handler (s, true); } b =0 ; -if (s->buttons_state &MOUSE_EVENT_LBUTTON ) +if (s->btns[INPUT_BUTTON_LEFT ]) { b |=0x01 ; -if (s->buttons_state &MOUSE_EVENT_RBUTTON ) + } +if (s->btns[INPUT_BUTTON_RIGHT ]) { b |=0x40 ; -if (s->buttons_state &MOUSE_EVENT_MBUTTON ) + } +if (s->btns[INPUT_BUTTON_MIDDLE ]) { b |=0x20 ;/* eraser */ + } -if (len <7 ) +if (len <7 ) {return 0 ; + } + + x =qemu_input_scale_axis (s->axis[INPUT_AXIS_X ], +INPUT_EVENT_ABS_MIN ,INPUT_EVENT_ABS_MAX , +0 ,5040 ); + y =qemu_input_scale_axis (s->axis[INPUT_AXIS_Y ], +INPUT_EVENT_ABS_MIN ,INPUT_EVENT_ABS_MAX , +0 ,3780 ); buf[0 ] = s->mode; buf[5 ] =0x00 | (b &0xf0 ); - buf[1 ] = s->x &0xff ; - buf[2 ] = s->x >>8 ; - buf[3 ] = s->y &0xff ; - buf[4 ] = s->y >>8 ; + buf[1 ] = x &0xff ; + buf[2 ] = x >>8 ; + buf[3 ] = y &0xff ; + buf[4 ] = y >>8 ;if (b &0x3f ) { buf[6 ] =0 ; }else {@@ -302,15 +343,13 @@ static int usb_wacom_poll(USBWacomState *s, uint8_t *buf, int len)static void usb_wacom_handle_reset (USBDevice *dev) { -USBWacomState *s = (USBWacomState *) dev; +USBWacomState *s =USB_WACOM (dev); - s->dx =0 ; - s->dy =0 ; +memset (s->axis,0 ,sizeof (s->axis)); +memset (s->btns,0 ,sizeof (s->btns)); s->dz =0 ; - s->x =0 ; - s->y =0 ; - s->buttons_state =0 ; s->mode =WACOM_MODE_HID ; +g_clear_pointer (&s->hs, qemu_input_handler_unregister); } static void usb_wacom_handle_control(USBDevice *dev, USBPacket *p,@@ -337,10 +376,7 @@ static void usb_wacom_handle_control(USBDevice *dev, USBPacket *p, }break ;case WACOM_SET_REPORT : -if (s->mouse_grabbed) { -qemu_remove_mouse_event_handler (s->eh_entry); - s->mouse_grabbed =0 ; - } +g_clear_pointer (&s->hs, qemu_input_handler_unregister); s->mode = data[0 ];break ;case WACOM_GET_REPORT :@@ -400,10 +436,7 @@ static void usb_wacom_unrealize(USBDevice *dev) {USBWacomState *s = (USBWacomState *) dev; -if (s->mouse_grabbed) { -qemu_remove_mouse_event_handler (s->eh_entry); - s->mouse_grabbed =0 ; - } +g_clear_pointer (&s->hs, qemu_input_handler_unregister); }static void usb_wacom_realize (USBDevice *dev,Error **errp) --2.54.0
Gerd Hoffmann
Acked-byRe: [PATCH v2 04/22] hw/usb/dev-wacom: convert to modern QemuInputHandler API
Quoted 9 lines · Marc-André Lureau
Hi
Quoted 5 lines · Marc-André Lureau
Replace the legacy QEMUPutMouseEvent callbacks with a proper QemuInputHandler registration. The device now receives typed input events (BTN/ABS/REL) directly.
Quoted 5 lines
Quoted 1 line
Signed-off-by Marc-André Lureau <[email protected]>One of the 2 patches missing ack/review in this series,
thanks
take care,
Gerd
PATCH v2 5/22 ui: move LED and key utilities to input.c, delete input-legacy.c
In reply to Marc-André LureauWith both legacy mouse API consumers converted, the remaining code in input-legacy.c (LED broadcast, index_from_key, qmp_send_key) is not legacy-specific. Move it to ui/input.c and delete the file.
Clean up include/ui/console.h by removing the now-unused legacy mouse API declarations (QEMUPutMouseEvent, QEMUPutMouseEntry, QEMUPutKBDEvent, QEMUPutKbdEntry) and MOUSE_EVENT_* constants.
--- include/ui/console.h | 18 ----- ui/input-legacy.c | 221 --------------------------------------------------- ui/input.c | 66 +++++++++++++++ ui/ui-hmp-cmds.c | 7 +- ui/meson.build | 1 - 5 files changed, 70 insertions(+), 243 deletions(-)
include/ui/console.h +0 -18
@@ -30,14 +30,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(QemuFixedTextConsole, QEMU_FIXED_TEXT_CONSOLE)#define QEMU_IS_FIXED_TEXT_CONSOLE (c) \ object_dynamic_cast(OBJECT(c), TYPE_QEMU_FIXED_TEXT_CONSOLE) -/* keyboard/mouse support */ - -#define MOUSE_EVENT_LBUTTON 0x01 -#define MOUSE_EVENT_RBUTTON 0x02 -#define MOUSE_EVENT_MBUTTON 0x04 -#define MOUSE_EVENT_WHEELUP 0x08 -#define MOUSE_EVENT_WHEELDN 0x10 -/* identical to the ps/2 keyboard bits */ #define QEMU_SCROLL_LOCK_LED (1 << 0)#define QEMU_NUM_LOCK_LED (1 << 1)
@@ -62,20 +54,10 @@ enum qemu_color_names {#define ATTR2CHTYPE (c, fg, bg, bold) \ ((bold) << 21 | (bg) << 11 | (fg) << 8 | (c)) -typedef void QEMUPutKBDEvent (void *opaque,int keycode);typedef void QEMUPutLEDEvent (void *opaque,int ledstate); -typedef void QEMUPutMouseEvent (void *opaque,int dx,int dy,int dz,int buttons_state); -typedef struct QEMUPutMouseEntry QEMUPutMouseEntry ; -typedef struct QEMUPutKbdEntry QEMUPutKbdEntry ;typedef struct QEMUPutLEDEntry QEMUPutLEDEntry ; -QEMUPutMouseEntry *qemu_add_mouse_event_handler (QEMUPutMouseEvent *func, -void *opaque,int absolute, -const char *name); -void qemu_remove_mouse_event_handler (QEMUPutMouseEntry *entry); -void qemu_activate_mouse_event_handler (QEMUPutMouseEntry *entry); -QEMUPutLEDEntry *qemu_add_led_event_handler (QEMUPutLEDEvent *func,void *opaque);void qemu_remove_led_event_handler (QEMUPutLEDEntry *entry);
ui/input-legacy.c deleted +0 -221
221 lines not on this page · raw message
ui/input.c +66 -0
69 lines not on this page · raw message
ui/ui-hmp-cmds.c +4 -3
@@ -55,10 +55,11 @@ void hmp_mouse_move(Monitor *mon, const QDict *qdict)void hmp_mouse_button (Monitor *mon,const QDict *qdict) { +/* HMP mouse_button bitmask: 1=L, 2=R, 4=M */ static uint32_t bmap[INPUT_BUTTON__MAX ] = { - [INPUT_BUTTON_LEFT ] =MOUSE_EVENT_LBUTTON , - [INPUT_BUTTON_MIDDLE ] =MOUSE_EVENT_MBUTTON , - [INPUT_BUTTON_RIGHT ] =MOUSE_EVENT_RBUTTON , + [INPUT_BUTTON_LEFT ] =0x01 , + [INPUT_BUTTON_MIDDLE ] =0x04 , + [INPUT_BUTTON_RIGHT ] =0x02 , };int button_state =qdict_get_int (qdict,"button_state" );
ui/meson.build +0 -1
@@ -53,7 +53,6 @@ libui = static_library('qemuui', libui_sources + genh, ui = declare_dependency(objects: libui.extract_all_objects(recursive: false), dependencies: [pixman]) system_ss.add(png) system_ss.add(files( - 'input-legacy.c', 'input-barrier.c', 'input.c', 'ui-hmp-cmds.c',
Signature · 1 line
2.54.0
Re: [PATCH v2 05/22] ui: move LED and key utilities to input.c, delete input-legacy.c
Quoted 8 lines · Marc-André Lureau
With both legacy mouse API consumers converted, the remaining code in
input-legacy.c(LED broadcast,index_from_key,qmp_send_key) is not legacy-specific. Move it toui/input.cand delete the file.Clean up
include/ui/console.hby removing the now-unused legacy mouse API declarations (QEMUPutMouseEvent, QEMUPutMouseEntry, QEMUPutKBDEvent, QEMUPutKbdEntry) and MOUSE_EVENT_* constants.
Quoted 8 lines
Signed-off-by Marc-André Lureau <[email protected]>--- include/ui/console.h | 18 ----- ui/input-legacy.c | 221 --------------------------------------------------- ui/input.c | 66 +++++++++++++++ ui/ui-hmp-cmds.c | 7 +- ui/meson.build | 1 - 5 files changed, 70 insertions(+), 243 deletions(-)
PATCH v2 6/22 hw/input: replace fprint with LOG_GUEST_ERROR
In reply to Marc-André Lureau--- hw/input/virtio-input-hid.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
hw/input/virtio-input-hid.c +7 -5
@@ -6,6 +6,7 @@#include "qemu/osdep.h" #include "qemu/iov.h" +#include "qemu/log.h" #include "qemu/module.h" #include "hw/virtio/virtio.h"
@@ -107,9 +108,9 @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src,virtio_input_send (vinput, &event); }else {if (evt->btn.down) { -fprintf (stderr,"%s: unmapped button: %d [%s]\n" , __func__, - evt->btn.button, -InputButton_str (evt->btn.button)); +qemu_log_mask (LOG_GUEST_ERROR , +"%s: unmapped button: %d [%s]\n" , __func__, + evt->btn.button,InputButton_str (evt->btn.button)); } }break ;
@@ -210,8 +211,9 @@ static void virtio_input_hid_handle_status(VirtIOInput *vinput,kbd_put_ledstate (vhid->ledstate);break ;default : -fprintf (stderr,"%s: unknown type %d\n" , __func__, -le16_to_cpu (event->type)); +qemu_log_mask (LOG_GUEST_ERROR , +"%s: unknown type %d\n" , __func__, +le16_to_cpu (event->type));break ; } }
Signature · 1 line
2.54.0
PATCH v2 7/22 ui/input: remove double-notification on qemu_mouse_set()
In reply to Marc-André Lureauqemu_input_handler_activate() already notifies.
--- ui/input.c | 1 - 1 file changed, 1 deletion(-)
ui/input.c +0 -1
@@ -580,7 +580,6 @@ bool qemu_mouse_set(int index, Error **errp) }qemu_input_handler_activate (s); -notifier_list_notify (&mouse_mode_notifiers,NULL );return true; }
Signature · 1 line
2.54.0
Re: [PATCH v2 07/22] ui/input: remove double-notification on qemu_mouse_set()
Quoted 6 lines · Marc-André Lureau
qemu_input_handler_activate()already notifies.Signed-off-by Marc-André Lureau <[email protected]>--- ui/input.c | 1 - 1 file changed, 1 deletion(-)
PATCH v2 8/22 ui/input: remove dead declaration
In reply to Marc-André Lureau--- include/ui/input.h | 1 - 1 file changed, 1 deletion(-)
include/ui/input.h +0 -1
@@ -100,7 +100,6 @@ void qemu_input_touch_event(QemuConsole *con,InputMultiTouchType type, Error **errp); -void qemu_input_check_mode_change (void );void qemu_add_mouse_mode_change_notifier (Notifier *notify);void qemu_remove_mouse_mode_change_notifier (Notifier *notify);
Signature · 1 line
2.54.0
PATCH v2 9/22 ui/input: add LED state tracking to QemuInputHandlerState
In reply to Marc-André LureauAdd 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.
--- include/ui/input.h | 5 +++++ ui/input.c | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 4 deletions(-)
include/ui/input.h +5 -0
@@ -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 */
ui/input.c +45 -4
104 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v2 09/22] ui/input: add LED state tracking to QemuInputHandlerState
Quoted 35 lines · Marc-André Lureau
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(-)include/ui/input.h +5
-0@@ -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 */ ui/input.c +0
-0
ui/input.c struct QemuInputHandlerState { · line 17
Quoted 4 lines
ui/input.c +1
-0@@ -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)
ui/input.c static QTAILQ_HEAD(, QemuInputHandlerState) handlers = · line 43
Quoted 9 lines
ui/input.c +2
-0QTAILQ_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:
Re: [PATCH v2 09/22] ui/input: add LED state tracking to QemuInputHandlerState
Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Marc-André Lureau
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(-)
Quoted 12 lines
include/ui/input.h extern const guint16 · line 157
Quoted 12 lines
include/ui/input.h +4
-0@@ -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);
Can @con be NULL?
Please add some trivial docstring.
Quoted 44 lines
ui/input.c struct QemuInputHandlerState { · line 17
Quoted 11 lines
include/ui/input.h +1
-0+ #endif /* INPUT_H */ui/input.c +1
-0@@ -14,6 +14,7 @@ struct QemuInputHandlerState { int id; int events; QemuConsole *con; + int ledstate;In "
hw/misc/led.h" we use 'boolis_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 */
#defineQEMU_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_tleds_bitmask' or simply ledsmask? (notify_input_changedbelow usesuint32_t).And:
qemu_input_handler_set_led()->qemu_input_handler_set_leds_mask(u32)intqemu_input_get_led()->uint32_tqemu_input_get_leds_mask(const)Quoted 8 lines
ui/input.c +0
-0QTAILQ_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 NotifierListled_notifiers=
+NOTIFIER_LIST_INITIALIZER(led_notifiers);
leds_notifiers(plural)With the changes:
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Re: [PATCH v2 09/22] ui/input: add LED state tracking to QemuInputHandlerState
In reply to Marc-André LureauQuoted 17 lines · Marc-André Lureau
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(-)
ui/input.c bool qemu_input_is_absolute(QemuConsole *con) · line 482
Quoted 5 lines
ui/input.c +5
-0+int qemu_input_get_led (QemuConsole *con) +{ +QemuInputHandlerState *s; + + s =qemu_input_find_handler (INPUT_EVENT_MASK_KEY , con);
Hmm can @con be NULL?
In SPICE (patch 20) you do:
int ledstate = qemu_input_get_led(NULL);
Quoted 5 lines
ui/input.c +5
-0+if (s) { +return s->ledstate; + } +return 0 ; +}
PATCH v2 10/22 hw/input/ps2: keep QemuInputHandlerState in PS2State
In reply to Marc-André LureauTrack the input handled state, and dispose it on unrealize.
--- include/hw/input/ps2.h | 2 ++ hw/input/ps2.c | 24 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-)
include/hw/input/ps2.h +2 -0
@@ -26,6 +26,7 @@#define HW_PS2_H #include "hw/core/sysbus.h" +#include "ui/input.h" #define PS2_MOUSE_BUTTON_LEFT 0x01#define PS2_MOUSE_BUTTON_RIGHT 0x02
@@ -59,6 +60,7 @@ struct PS2State {PS2Queue queue;int32_t write_cmd;qemu_irq irq; +QemuInputHandlerState *hs; };#define TYPE_PS2_DEVICE "ps2-device"
hw/input/ps2.c +22 -2
@@ -1233,7 +1233,16 @@ static const QemuInputHandler ps2_keyboard_handler = {static void ps2_kbd_realize (DeviceState *dev,Error **errp) { -qemu_input_handler_register (dev, &ps2_keyboard_handler); +PS2State *s =PS2_DEVICE (dev); + + s->hs =qemu_input_handler_register (dev, &ps2_keyboard_handler); +} + +static void ps2_kbd_unrealize (DeviceState *dev) +{ +PS2State *s =PS2_DEVICE (dev); + +g_clear_pointer (&s->hs, qemu_input_handler_unregister); }static const QemuInputHandler ps2_mouse_handler = {
@@ -1245,7 +1254,16 @@ static const QemuInputHandler ps2_mouse_handler = {static void ps2_mouse_realize (DeviceState *dev,Error **errp) { -qemu_input_handler_register (dev, &ps2_mouse_handler); +PS2State *s =PS2_DEVICE (dev); + + s->hs =qemu_input_handler_register (dev, &ps2_mouse_handler); +} + +static void ps2_mouse_unrealize (DeviceState *dev) +{ +PS2State *s =PS2_DEVICE (dev); + +g_clear_pointer (&s->hs, qemu_input_handler_unregister); }static void ps2_kbd_class_init (ObjectClass *klass,const void *data)
@@ -1255,6 +1273,7 @@ static void ps2_kbd_class_init(ObjectClass *klass, const void *data)PS2DeviceClass *ps2dc =PS2_DEVICE_CLASS (klass); dc->realize = ps2_kbd_realize; + dc->unrealize = ps2_kbd_unrealize;resettable_class_set_parent_phases (rc,NULL , ps2_kbd_reset_hold,NULL , &ps2dc->parent_phases); dc->vmsd = &vmstate_ps2_keyboard;
@@ -1274,6 +1293,7 @@ static void ps2_mouse_class_init(ObjectClass *klass, const void *data)PS2DeviceClass *ps2dc =PS2_DEVICE_CLASS (klass); dc->realize = ps2_mouse_realize; + dc->unrealize = ps2_mouse_unrealize;resettable_class_set_parent_phases (rc,NULL , ps2_mouse_reset_hold,NULL , &ps2dc->parent_phases); dc->vmsd = &vmstate_ps2_mouse;
Signature · 1 line
2.54.0
PATCH v2 11/22 hw/arm: keep QemuInputHandlerState in musicpal
In reply to Marc-André LureauTrack the input handled state, and dispose it on unrealize.
--- hw/arm/musicpal.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
hw/arm/musicpal.c +12 -1
@@ -1062,6 +1062,7 @@ struct musicpal_key_state {SysBusDevice parent_obj;/*< public >*/ +QemuInputHandlerState *hs;uint32_t pressed_keys;qemu_irq out[8 ]; };
@@ -1158,7 +1159,16 @@ static const QemuInputHandler musicpal_key_handler = {static void musicpal_key_realize (DeviceState *dev,Error **errp) { -qemu_input_handler_register (dev, &musicpal_key_handler); +musicpal_key_state *s =MUSICPAL_KEY (dev); + + s->hs =qemu_input_handler_register (dev, &musicpal_key_handler); +} + +static void musicpal_key_unrealize (DeviceState *dev) +{ +musicpal_key_state *s =MUSICPAL_KEY (dev); + +g_clear_pointer (&s->hs, qemu_input_handler_unregister); }static const VMStateDescription musicpal_key_vmsd = {
@@ -1177,6 +1187,7 @@ static void musicpal_key_class_init(ObjectClass *klass, const void *data) dc->vmsd = &musicpal_key_vmsd; dc->realize = musicpal_key_realize; + dc->unrealize = musicpal_key_unrealize; }static const TypeInfo musicpal_key_info = {
Signature · 1 line
2.54.0
Re: [PATCH v2 11/22] hw/arm: keep QemuInputHandlerState in musicpal
Quoted 6 lines · Marc-André Lureau
Track the input handled state, and dispose it on unrealize.
Signed-off-by Marc-André Lureau <[email protected]>--- hw/arm/musicpal.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
PATCH v2 12/22 hw/input: keep QemuInputHandlerState in adb-kbd
In reply to Marc-André LureauTrack the input handled state, and dispose it on unrealize.
--- hw/input/adb-kbd.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
hw/input/adb-kbd.c +16 -1
@@ -40,6 +40,7 @@ struct KBDState {ADBDevice parent_obj;/*< public >*/ +QemuInputHandlerState *hs;uint8_t data[128 ];int rptr, wptr, count; };
@@ -51,6 +52,7 @@ struct ADBKeyboardClass {/*< public >*/ DeviceRealize parent_realize; +DeviceUnrealize parent_unrealize; };/* The adb keyboard doesn't have every key imaginable */
@@ -361,9 +363,20 @@ static const QemuInputHandler adb_keyboard_handler = {static void adb_kbd_realizefn (DeviceState *dev,Error **errp) { +KBDState *s =ADB_KEYBOARD (dev);ADBKeyboardClass *akc =ADB_KEYBOARD_GET_CLASS (dev); + akc->parent_realize (dev, errp); -qemu_input_handler_register (dev, &adb_keyboard_handler); + s->hs =qemu_input_handler_register (dev, &adb_keyboard_handler); +} + +static void adb_kbd_unrealizefn (DeviceState *dev) +{ +KBDState *s =ADB_KEYBOARD (dev); +ADBKeyboardClass *akc =ADB_KEYBOARD_GET_CLASS (dev); + +g_clear_pointer (&s->hs, qemu_input_handler_unregister); + akc->parent_unrealize (dev); }static void adb_kbd_initfn (Object *obj)
@@ -381,6 +394,8 @@ static void adb_kbd_class_init(ObjectClass *oc, const void *data)device_class_set_parent_realize (dc, adb_kbd_realizefn, &akc->parent_realize); +device_class_set_parent_unrealize (dc, adb_kbd_unrealizefn, + &akc->parent_unrealize);set_bit (DEVICE_CATEGORY_INPUT , dc->categories); adc->devreq = adb_kbd_request;
Signature · 1 line
2.54.0
Re: [PATCH v2 12/22] hw/input: keep QemuInputHandlerState in adb-kbd
Quoted 6 lines · Marc-André Lureau
Track the input handled state, and dispose it on unrealize.
Signed-off-by Marc-André Lureau <[email protected]>--- hw/input/adb-kbd.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
PATCH v2 13/22 hw/input: keep QemuInputHandlerState in stellaris
In reply to Marc-André LureauTrack the input handled state, and dispose it on unrealize.
Also free some allocated fields during unrealize.
--- include/hw/input/stellaris_gamepad.h | 2 ++ hw/input/stellaris_gamepad.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-)
include/hw/input/stellaris_gamepad.h +2 -0
@@ -13,6 +13,7 @@#include "hw/core/sysbus.h" #include "qom/object.h" +#include "ui/input.h" /* * QEMU interface:
@@ -28,6 +29,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(StellarisGamepad, STELLARIS_GAMEPAD)struct StellarisGamepad {SysBusDevice parent_obj; +QemuInputHandlerState *hs;uint32_t num_buttons;qemu_irq *irqs;uint32_t *keycodes;
hw/input/stellaris_gamepad.c +11 -1
@@ -59,7 +59,16 @@ static void stellaris_gamepad_realize(DeviceState *dev, Error **errp) s->irqs =g_new0 (qemu_irq, s->num_buttons); s->pressed =g_new0 (uint8_t, s->num_buttons);qdev_init_gpio_out (dev, s->irqs, s->num_buttons); -qemu_input_handler_register (dev, &stellaris_gamepad_handler); + s->hs =qemu_input_handler_register (dev, &stellaris_gamepad_handler); +} + +static void stellaris_gamepad_unrealize (DeviceState *dev) +{ +StellarisGamepad *s =STELLARIS_GAMEPAD (dev); + +g_clear_pointer (&s->irqs, g_free); +g_clear_pointer (&s->pressed, g_free); +g_clear_pointer (&s->hs, qemu_input_handler_unregister); }static void stellaris_gamepad_reset_enter (Object *obj,ResetType type)
@@ -81,6 +90,7 @@ static void stellaris_gamepad_class_init(ObjectClass *klass, const void *data) rc->phases.enter = stellaris_gamepad_reset_enter; dc->realize = stellaris_gamepad_realize; + dc->unrealize = stellaris_gamepad_unrealize; dc->vmsd = &vmstate_stellaris_gamepad;device_class_set_props (dc, stellaris_gamepad_properties); }
Signature · 1 line
2.54.0
Re: [PATCH v2 13/22] hw/input: keep QemuInputHandlerState in stellaris
Quoted 9 lines · Marc-André Lureau
Track the input handled state, and dispose it on unrealize.
Also free some allocated fields during unrealize.
Signed-off-by Marc-André Lureau <[email protected]>--- include/hw/input/stellaris_gamepad.h | 2 ++ hw/input/stellaris_gamepad.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-)
I'd rather a preliminary patch adding stellaris_gamepad_unrealize() to free the current leaks.
PATCH v2 14/22 hw/m68k: keep QemuInputHandlerState in next-kbd
In reply to Marc-André LureauTrack the input handled state, and dispose it on unrealize.
--- hw/m68k/next-kbd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
hw/m68k/next-kbd.c +10 -1
@@ -65,6 +65,7 @@ typedef struct {struct NextKBDState {SysBusDevice sbd;MemoryRegion mr; +QemuInputHandlerState *hs;KBDQueue queue;uint16_t shift; };
@@ -304,7 +305,14 @@ static void nextkbd_realize(DeviceState *dev, Error **errp)memory_region_init_io (&s->mr,OBJECT (dev), &kbd_ops, s,"next.kbd" ,0x1000 );sysbus_init_mmio (SYS_BUS_DEVICE (dev), &s->mr); -qemu_input_handler_register (dev, &nextkbd_handler); + s->hs =qemu_input_handler_register (dev, &nextkbd_handler); +} + +static void nextkbd_unrealize (DeviceState *dev) +{ +NextKBDState *s =NEXTKBD (dev); + +g_clear_pointer (&s->hs, qemu_input_handler_unregister); }static const VMStateDescription nextkbd_vmstate = {
@@ -319,6 +327,7 @@ static void nextkbd_class_init(ObjectClass *oc, const void *data)set_bit (DEVICE_CATEGORY_INPUT , dc->categories); dc->vmsd = &nextkbd_vmstate; dc->realize = nextkbd_realize; + dc->unrealize = nextkbd_unrealize;device_class_set_legacy_reset (dc, nextkbd_reset); }
Signature · 1 line
2.54.0
Re: [PATCH v2 14/22] hw/m68k: keep QemuInputHandlerState in next-kbd
Quoted 6 lines · Marc-André Lureau
Track the input handled state, and dispose it on unrealize.
Signed-off-by Marc-André Lureau <[email protected]>--- hw/m68k/next-kbd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
PATCH v2 15/22 ui/input: qemu_input_handler_register to warn for unused result
In reply to Marc-André Lureau--- include/ui/input.h | 1 + 1 file changed, 1 insertion(+)
include/ui/input.h +1 -0
@@ -45,6 +45,7 @@ struct QemuInputHandler {QemuInputHandlerSync sync; }; +G_GNUC_WARN_UNUSED_RESULT QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev,const QemuInputHandler *handler);void qemu_input_handler_activate (QemuInputHandlerState *s);
Signature · 1 line
2.54.0
Re: [PATCH v2 15/22] ui/input: qemu_input_handler_register to warn for unused result
Quoted 5 lines · Marc-André Lureau
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Marc-André Lureau <[email protected]>--- include/ui/input.h | 1 + 1 file changed, 1 insertion(+)
PATCH v2 16/22 hw/input/ps2: use qemu_input_handler_set_led() for LED state
In reply to Marc-André Lureau--- hw/input/ps2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/input/ps2.c +2 -2
@@ -577,7 +577,7 @@ static void ps2_set_ledstate(PS2KbdState *s, int ledstate) {trace_ps2_set_ledstate (s, ledstate); s->ledstate = ledstate; -kbd_put_ledstate (ledstate); +qemu_input_handler_set_led (PS2_DEVICE (s)->hs, ledstate); }static void ps2_reset_keyboard (PS2KbdState *s)
@@ -1108,7 +1108,7 @@ static int ps2_kbd_ledstate_post_load(void *opaque, int version_id) {PS2KbdState *s = opaque; -kbd_put_ledstate (s->ledstate); +qemu_input_handler_set_led (PS2_DEVICE (s)->hs, s->ledstate);return 0 ; }
Signature · 1 line
2.54.0
Re: [PATCH v2 16/22] hw/input/ps2: use qemu_input_handler_set_led() for LED state
Quoted 4 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- hw/input/ps2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
PATCH v2 17/22 hw/input/hid: use qemu_input_handler_set_led() for LED state
In reply to Marc-André Lureau--- hw/input/hid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/input/hid.c +2 -1
@@ -25,6 +25,7 @@#include "qemu/osdep.h" #include "ui/console.h" +#include "ui/input.h" #include "qemu/timer.h" #include "hw/input/hid.h" #include "migration/vmstate.h"
@@ -470,7 +471,7 @@ int hid_keyboard_write(HIDState *hs, uint8_t *buf, int len)if (hs->kbd.leds &0x02 ) { ledstate |=QEMU_CAPS_LOCK_LED ; } -kbd_put_ledstate (ledstate); +qemu_input_handler_set_led (hs->s, ledstate);return 1 ; }return 0 ;
Signature · 1 line
2.54.0
Re: [PATCH v2 17/22] hw/input/hid: use qemu_input_handler_set_led() for LED state
Quoted 4 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- hw/input/hid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
PATCH v2 18/22 hw/input/virtio-input-hid: use qemu_input_handler_set_led() for LED state
In reply to Marc-André Lureau--- hw/input/virtio-input-hid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/input/virtio-input-hid.c +2 -1
@@ -12,6 +12,7 @@#include "hw/virtio/virtio.h" #include "hw/core/qdev-properties.h" #include "hw/virtio/virtio-input.h" +#include "ui/input.h" #include "ui/console.h"
@@ -208,7 +209,7 @@ static void virtio_input_hid_handle_status(VirtIOInput *vinput, }else { vhid->ledstate &= ~ledbit; } -kbd_put_ledstate (vhid->ledstate); +qemu_input_handler_set_led (vhid->hs, vhid->ledstate);break ;default : qemu_log_mask(LOG_GUEST_ERROR,
Signature · 1 line
2.54.0
Re: [PATCH v2 18/22] hw/input/virtio-input-hid: use qemu_input_handler_set_led() for LED state
Quoted 4 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- hw/input/virtio-input-hid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
PATCH v2 19/22 ui/vnc: switch LED handling to Notifier-based input API
In reply to Marc-André LureauReplace QEMUPutLEDEntry with an embedded Notifier in VncDisplay. Use qemu_input_led_notifier_add/remove instead of the old qemu_add/remove_led_event_handler.
--- ui/vnc.h | 2 +- tools/qemu-vnc/input.c | 49 +++++++++++++++++-------------------------------- ui/vnc.c | 11 ++++++----- 3 files changed, 24 insertions(+), 38 deletions(-)
ui/vnc.h +1 -1
@@ -147,7 +147,7 @@ struct VncDisplayDisplayChangeListener dcl;kbd_layout_t *kbd_layout;int lock_key_sync; -QEMUPutLEDEntry *led; +Notifier led_notifier;int ledstate;QKbdState *kbd;QemuMutex mutex;
tools/qemu-vnc/input.c +17 -32
75 lines not on this page · raw message
ui/vnc.c +6 -5
@@ -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_led (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 ;
Signature · 1 line
2.54.0
Re: [PATCH v2 19/22] ui/vnc: switch LED handling to Notifier-based input API
Quoted 5 lines · Marc-André Lureau
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.
Signed-off-by Marc-André Lureau <[email protected]>
Quoted 8 lines
--- ui/vnc.h | 2 +- tools/qemu-vnc/input.c | 49 +++++++++++++++++-------------------------------- ui/vnc.c | 11 ++++++----- 3 files changed, 24 insertions(+), 38 deletions(-)+int
qemu_input_get_led(QemuConsole *con)
unsigned, const; otherwise:
Quoted 8 lines
{tools/qemu-vnc/input.c +1
-5-if (!entry) { -return ; - } -QTAILQ_REMOVE (&led_handlers, entry, next); -g_free (entry); +return modifiers; }
PATCH v2 20/22 ui/spice: switch LED handling to Notifier-based input API
In reply to Marc-André Lureau--- ui/spice-input.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
ui/spice-input.c +7 -3
@@ -33,6 +33,7 @@ typedef struct QemuSpiceKbd {int ledstate;bool emul0;size_t pauseseq; +Notifier led_notifier; } QemuSpiceKbd;static void kbd_push_key (SpiceKbdInstance *sin,uint8_t frag);
@@ -86,9 +87,11 @@ static uint8_t kbd_get_leds(SpiceKbdInstance *sin)return kbd->ledstate; } -static void kbd_leds (void *opaque,int ledstate) +static void kbd_leds (Notifier *notifier,void *data) { -QemuSpiceKbd *kbd = opaque; +QemuSpiceKbd *kbd =container_of (notifier, QemuSpiceKbd, led_notifier); +/* spice has no associated console support */ +int ledstate =qemu_input_get_led (NULL ); kbd->ledstate =0 ;if (ledstate &QEMU_SCROLL_LOCK_LED ) {
@@ -247,7 +250,8 @@ void qemu_spice_input_init(void) kbd =g_malloc0 (sizeof (*kbd)); kbd->sin.base.sif = &kbd_interface.base; qemu_spice.add_interface (&kbd->sin.base); -qemu_add_led_event_handler (kbd_leds, kbd); + kbd->led_notifier.notify = kbd_leds; +qemu_input_led_notifier_add (&kbd->led_notifier); pointer =g_malloc0 (sizeof (*pointer)); pointer->mouse.base.sif = &mouse_interface.base;
Signature · 1 line
2.54.0
Re: [PATCH v2 20/22] ui/spice: switch LED handling to Notifier-based input API
Quoted 18 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- ui/spice-input.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)ui/spice-input.c +1
-0@@ -33,6 +33,7 @@ typedef struct QemuSpiceKbd {int ledstate;bool emul0;size_t pauseseq; +Notifier led_notifier; } QemuSpiceKbd;static void kbd_push_key (SpiceKbdInstance *sin,uint8_t frag);
ui/spice-input.c static uint8_t kbd_get_leds(SpiceKbdInstance *sin) · line 94
Quoted 10 lines
ui/spice-input.c +4
-2@@ -86,9 +87,11 @@ static uint8_t kbd_get_leds(SpiceKbdInstance *sin)return kbd->ledstate; } -static void kbd_leds (void *opaque,int ledstate) +static void kbd_leds (Notifier *notifier,void *data) { -QemuSpiceKbd *kbd = opaque; +QemuSpiceKbd *kbd =container_of (notifier, QemuSpiceKbd, led_notifier); +/* spice has no associated console support */ +int ledstate =qemu_input_get_led (NULL );
unsigned leds_mask? At least would help to differentiate from QemuSpiceKbd::ledstate. Anyhow,
Quoted 9 lines
ui/spice-input.c +2
-1kbd->ledstate =0 ;if (ledstate &QEMU_SCROLL_LOCK_LED ) {@@ -247,7 +250,8 @@ void qemu_spice_input_init(void) kbd =g_malloc0 (sizeof (*kbd)); kbd->sin.base.sif = &kbd_interface.base; qemu_spice.add_interface (&kbd->sin.base); -qemu_add_led_event_handler (kbd_leds, kbd); + kbd->led_notifier.notify = kbd_leds; +qemu_input_led_notifier_add (&kbd->led_notifier);
PATCH v2 21/22 ui/dbus: switch LED handling to Notifier-based input API
In reply to Marc-André Lureau--- ui/dbus-console.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
ui/dbus-console.c +8 -3
@@ -46,6 +46,7 @@ struct _DBusDisplayConsole {QemuDBusDisplay1Keyboard *iface_kbd;QKbdState *kbd; +Notifier led_notifier;QemuDBusDisplay1Mouse *iface_mouse;QemuDBusDisplay1MultiTouch *iface_touch;
@@ -150,6 +151,7 @@ dbus_display_console_dispose(GObject *object) {DBusDisplayConsole *ddc =DBUS_DISPLAY_CONSOLE (object); +qemu_input_led_notifier_remove (&ddc->led_notifier);qemu_console_unregister_listener (&ddc->dcl);g_clear_object (&ddc->iface_touch);g_clear_object (&ddc->iface_mouse);
@@ -367,9 +369,11 @@ dbus_kbd_release(DBusDisplayConsole *ddc, }static void -dbus_kbd_qemu_leds_updated (void *data,int ledstate) +dbus_kbd_qemu_leds_updated (Notifier *notifier,void *data) { -DBusDisplayConsole *ddc =DBUS_DISPLAY_CONSOLE (data); +DBusDisplayConsole *ddc =container_of (notifier, DBusDisplayConsole, + led_notifier); +int ledstate =qemu_input_get_led (ddc->dcl.con);qemu_dbus_display1_keyboard_set_modifiers (ddc->iface_kbd, ledstate); }
@@ -577,7 +581,8 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con) ddc->kbd =qkbd_state_init (con); ddc->iface_kbd =qemu_dbus_display1_keyboard_skeleton_new (); -qemu_add_led_event_handler (dbus_kbd_qemu_leds_updated, ddc); + ddc->led_notifier.notify = dbus_kbd_qemu_leds_updated; +qemu_input_led_notifier_add (&ddc->led_notifier); g_object_connect(ddc->iface_kbd, "swapped-signal::handle-press", dbus_kbd_press, ddc, "swapped-signal::handle-release", dbus_kbd_release, ddc,
Signature · 1 line
2.54.0
Re: [PATCH v2 21/22] ui/dbus: switch LED handling to Notifier-based input API
Quoted 4 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- ui/dbus-console.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
PATCH v2 22/22 ui/input: remove old LED handler broadcast queue
In reply to Marc-André Lureau--- include/ui/console.h | 9 --------- ui/input.c | 40 ---------------------------------------- 2 files changed, 49 deletions(-)
include/ui/console.h +0 -9
@@ -54,15 +54,6 @@ enum qemu_color_names {#define ATTR2CHTYPE (c, fg, bg, bold) \ ((bold) << 21 | (bg) << 11 | (fg) << 8 | (c)) -typedef void QEMUPutLEDEvent (void *opaque,int ledstate); - -typedef struct QEMUPutLEDEntry QEMUPutLEDEntry ; - -QEMUPutLEDEntry *qemu_add_led_event_handler (QEMUPutLEDEvent *func,void *opaque); -void qemu_remove_led_event_handler (QEMUPutLEDEntry *entry); - -void kbd_put_ledstate (int ledstate); -bool qemu_mouse_set (int index,Error **errp);/* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
ui/input.c +0 -40
@@ -689,46 +689,6 @@ void qemu_input_touch_event(QemuConsole *con, } } -struct QEMUPutLEDEntry { -QEMUPutLEDEvent *put_led; -void *opaque; -QTAILQ_ENTRY (QEMUPutLEDEntry) next; -}; - -static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers = -QTAILQ_HEAD_INITIALIZER (led_handlers); - -QEMUPutLEDEntry *qemu_add_led_event_handler (QEMUPutLEDEvent *func, -void *opaque) -{ -QEMUPutLEDEntry *s; - - s =g_new0 (QEMUPutLEDEntry,1 ); - - s->put_led = func; - s->opaque = opaque; -QTAILQ_INSERT_TAIL (&led_handlers, s, next); -return s; -} - -void qemu_remove_led_event_handler (QEMUPutLEDEntry *entry) -{ -if (entry ==NULL ) { -return ; - } -QTAILQ_REMOVE (&led_handlers, entry, next); -g_free (entry); -} - -void kbd_put_ledstate (int ledstate) -{ -QEMUPutLEDEntry *cursor; - - QTAILQ_FOREACH(cursor, &led_handlers, next) { - cursor->put_led (cursor->opaque, ledstate); - } -} -void qmp_send_key (KeyValueList *keys,bool has_hold_time,int64_t hold_time,Error **errp) {
Signature · 1 line
2.54.0
Re: [PATCH v2 22/22] ui/input: remove old LED handler broadcast queue
Quoted 5 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- include/ui/console.h | 9 --------- ui/input.c | 40 ---------------------------------------- 2 files changed, 49 deletions(-)