@samitouri / QOSamiQemu / commits / 264cda6264

ui: move LED and key utilities to input.c, delete input-legacy.c

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 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. Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Marc-André Lureau committed Jun 8, 2026 at 13:29 UTC 264cda62641ef3dd04cc4daf8f527c55ba05ce50
5 files changed +70 -243
include/ui/console.h
-18
@@ -30,14 +30,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(QemuFixedTextConsole, QEMU_FIXED_TEXT_CONSOLE)
30 #define QEMU_IS_FIXED_TEXT_CONSOLE(c) \
31 object_dynamic_cast(OBJECT(c), TYPE_QEMU_FIXED_TEXT_CONSOLE)
32
33 -/* keyboard/mouse support */
34 -
35 -#define MOUSE_EVENT_LBUTTON 0x01
36 -#define MOUSE_EVENT_RBUTTON 0x02
37 -#define MOUSE_EVENT_MBUTTON 0x04
38 -#define MOUSE_EVENT_WHEELUP 0x08
39 -#define MOUSE_EVENT_WHEELDN 0x10
40 -
33 /* identical to the ps/2 keyboard bits */
34 #define QEMU_SCROLL_LOCK_LED (1 << 0)
35 #define QEMU_NUM_LOCK_LED (1 << 1)
@@ -62,20 +54,10 @@ enum qemu_color_names {
54 #define ATTR2CHTYPE(c, fg, bg, bold) \
55 ((bold) << 21 | (bg) << 11 | (fg) << 8 | (c))
56
65 -typedef void QEMUPutKBDEvent(void *opaque, int keycode);
57 typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
67 -typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
58
69 -typedef struct QEMUPutMouseEntry QEMUPutMouseEntry;
70 -typedef struct QEMUPutKbdEntry QEMUPutKbdEntry;
59 typedef struct QEMUPutLEDEntry QEMUPutLEDEntry;
60
73 -QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
74 - void *opaque, int absolute,
75 - const char *name);
76 -void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
77 -void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry);
78 -
61 QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque);
62 void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
63
ui/input-legacy.c deleted
-221
@@ -1,221 +0,0 @@
1 -/*
2 - * QEMU System Emulator
3 - *
4 - * Copyright (c) 2003-2008 Fabrice Bellard
5 - *
6 - * Permission is hereby granted, free of charge, to any person obtaining a copy
7 - * of this software and associated documentation files (the "Software"), to deal
8 - * in the Software without restriction, including without limitation the rights
9 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 - * copies of the Software, and to permit persons to whom the Software is
11 - * furnished to do so, subject to the following conditions:
12 - *
13 - * The above copyright notice and this permission notice shall be included in
14 - * all copies or substantial portions of the Software.
15 - *
16 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 - * THE SOFTWARE.
23 - */
24 -
25 -#include "qemu/osdep.h"
26 -#include "qemu/log.h"
27 -#include "qapi/qapi-commands-ui.h"
28 -#include "ui/console.h"
29 -#include "keymaps.h"
30 -#include "ui/input.h"
31 -
32 -struct QEMUPutMouseEntry {
33 - QEMUPutMouseEvent *qemu_put_mouse_event;
34 - void *qemu_put_mouse_event_opaque;
35 - int qemu_put_mouse_event_absolute;
36 -
37 - /* new input core */
38 - QemuInputHandler h;
39 - QemuInputHandlerState *s;
40 - int axis[INPUT_AXIS__MAX];
41 - int buttons;
42 -};
43 -
44 -struct QEMUPutKbdEntry {
45 - QEMUPutKBDEvent *put_kbd;
46 - void *opaque;
47 - QemuInputHandlerState *s;
48 -};
49 -
50 -struct QEMUPutLEDEntry {
51 - QEMUPutLEDEvent *put_led;
52 - void *opaque;
53 - QTAILQ_ENTRY(QEMUPutLEDEntry) next;
54 -};
55 -
56 -static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers =
57 - QTAILQ_HEAD_INITIALIZER(led_handlers);
58 -
59 -void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time,
60 - Error **errp)
61 -{
62 - KeyValueList *p;
63 - unsigned int *up = NULL;
64 - int count = 0;
65 -
66 - if (!has_hold_time) {
67 - hold_time = 0; /* use default */
68 - }
69 -
70 - for (p = keys; p != NULL; p = p->next) {
71 - up = g_realloc(up, sizeof(*up) * (count+1));
72 - up[count] = qemu_input_key_value_to_linux(p->value);
73 - qemu_input_event_send_key_linux(NULL, up[count], true);
74 - qemu_input_event_send_key_delay(hold_time);
75 - count++;
76 - }
77 - while (count) {
78 - count--;
79 - qemu_input_event_send_key_linux(NULL, up[count], false);
80 - qemu_input_event_send_key_delay(hold_time);
81 - }
82 - g_free(up);
83 -}
84 -
85 -static void legacy_mouse_event(DeviceState *dev, QemuConsole *src,
86 - QemuInputEvent *evt)
87 -{
88 - static const int bmap[INPUT_BUTTON__MAX] = {
89 - [INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON,
90 - [INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
91 - [INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON,
92 - };
93 - QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev;
94 -
95 - switch (evt->type) {
96 - case INPUT_EVENT_KIND_BTN:
97 - if (evt->btn.down) {
98 - s->buttons |= bmap[evt->btn.button];
99 - } else {
100 - s->buttons &= ~bmap[evt->btn.button];
101 - }
102 - if (evt->btn.down && evt->btn.button == INPUT_BUTTON_WHEEL_UP) {
103 - s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
104 - s->axis[INPUT_AXIS_X],
105 - s->axis[INPUT_AXIS_Y],
106 - -1,
107 - s->buttons);
108 - }
109 - if (evt->btn.down && evt->btn.button == INPUT_BUTTON_WHEEL_DOWN) {
110 - s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
111 - s->axis[INPUT_AXIS_X],
112 - s->axis[INPUT_AXIS_Y],
113 - 1,
114 - s->buttons);
115 - }
116 - if (evt->btn.down && evt->btn.button == INPUT_BUTTON_WHEEL_RIGHT) {
117 - s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
118 - s->axis[INPUT_AXIS_X],
119 - s->axis[INPUT_AXIS_Y],
120 - -2,
121 - s->buttons);
122 - }
123 - if (evt->btn.down && evt->btn.button == INPUT_BUTTON_WHEEL_LEFT) {
124 - s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
125 - s->axis[INPUT_AXIS_X],
126 - s->axis[INPUT_AXIS_Y],
127 - 2,
128 - s->buttons);
129 - }
130 - break;
131 - case INPUT_EVENT_KIND_ABS:
132 - s->axis[evt->abs.axis] = evt->abs.value;
133 - break;
134 - case INPUT_EVENT_KIND_REL:
135 - s->axis[evt->rel.axis] += evt->rel.value;
136 - break;
137 - default:
138 - break;
139 - }
140 -}
141 -
142 -static void legacy_mouse_sync(DeviceState *dev)
143 -{
144 - QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev;
145 -
146 - s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
147 - s->axis[INPUT_AXIS_X],
148 - s->axis[INPUT_AXIS_Y],
149 - 0,
150 - s->buttons);
151 -
152 - if (!s->qemu_put_mouse_event_absolute) {
153 - s->axis[INPUT_AXIS_X] = 0;
154 - s->axis[INPUT_AXIS_Y] = 0;
155 - }
156 -}
157 -
158 -QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
159 - void *opaque, int absolute,
160 - const char *name)
161 -{
162 - QEMUPutMouseEntry *s;
163 -
164 - s = g_new0(QEMUPutMouseEntry, 1);
165 -
166 - s->qemu_put_mouse_event = func;
167 - s->qemu_put_mouse_event_opaque = opaque;
168 - s->qemu_put_mouse_event_absolute = absolute;
169 -
170 - s->h.name = name;
171 - s->h.mask = INPUT_EVENT_MASK_BTN |
172 - (absolute ? INPUT_EVENT_MASK_ABS : INPUT_EVENT_MASK_REL);
173 - s->h.event = legacy_mouse_event;
174 - s->h.sync = legacy_mouse_sync;
175 - s->s = qemu_input_handler_register((DeviceState *)s,
176 - &s->h);
177 -
178 - return s;
179 -}
180 -
181 -void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry)
182 -{
183 - qemu_input_handler_activate(entry->s);
184 -}
185 -
186 -void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
187 -{
188 - qemu_input_handler_unregister(entry->s);
189 -
190 - g_free(entry);
191 -}
192 -
193 -QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func,
194 - void *opaque)
195 -{
196 - QEMUPutLEDEntry *s;
197 -
198 - s = g_new0(QEMUPutLEDEntry, 1);
199 -
200 - s->put_led = func;
201 - s->opaque = opaque;
202 - QTAILQ_INSERT_TAIL(&led_handlers, s, next);
203 - return s;
204 -}
205 -
206 -void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
207 -{
208 - if (entry == NULL)
209 - return;
210 - QTAILQ_REMOVE(&led_handlers, entry, next);
211 - g_free(entry);
212 -}
213 -
214 -void kbd_put_ledstate(int ledstate)
215 -{
216 - QEMUPutLEDEntry *cursor;
217 -
218 - QTAILQ_FOREACH(cursor, &led_handlers, next) {
219 - cursor->put_led(cursor->opaque, ledstate);
220 - }
221 -}
ui/input.c
+66
@@ -648,3 +648,69 @@ void qemu_input_touch_event(QemuConsole *con,
648 qemu_input_event_sync();
649 }
650 }
651 +
652 +struct QEMUPutLEDEntry {
653 + QEMUPutLEDEvent *put_led;
654 + void *opaque;
655 + QTAILQ_ENTRY(QEMUPutLEDEntry) next;
656 +};
657 +
658 +static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers =
659 + QTAILQ_HEAD_INITIALIZER(led_handlers);
660 +
661 +QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func,
662 + void *opaque)
663 +{
664 + QEMUPutLEDEntry *s;
665 +
666 + s = g_new0(QEMUPutLEDEntry, 1);
667 +
668 + s->put_led = func;
669 + s->opaque = opaque;
670 + QTAILQ_INSERT_TAIL(&led_handlers, s, next);
671 + return s;
672 +}
673 +
674 +void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
675 +{
676 + if (entry == NULL) {
677 + return;
678 + }
679 + QTAILQ_REMOVE(&led_handlers, entry, next);
680 + g_free(entry);
681 +}
682 +
683 +void kbd_put_ledstate(int ledstate)
684 +{
685 + QEMUPutLEDEntry *cursor;
686 +
687 + QTAILQ_FOREACH(cursor, &led_handlers, next) {
688 + cursor->put_led(cursor->opaque, ledstate);
689 + }
690 +}
691 +
692 +void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time,
693 + Error **errp)
694 +{
695 + KeyValueList *p;
696 + unsigned int *up = NULL;
697 + int count = 0;
698 +
699 + if (!has_hold_time) {
700 + hold_time = 0; /* use default */
701 + }
702 +
703 + for (p = keys; p != NULL; p = p->next) {
704 + up = g_realloc_n(up, count + 1, sizeof(*up));
705 + up[count] = qemu_input_key_value_to_linux(p->value);
706 + qemu_input_event_send_key_linux(NULL, up[count], true);
707 + qemu_input_event_send_key_delay(hold_time);
708 + count++;
709 + }
710 + while (count) {
711 + count--;
712 + qemu_input_event_send_key_linux(NULL, up[count], false);
713 + qemu_input_event_send_key_delay(hold_time);
714 + }
715 + g_free(up);
716 +}
ui/meson.build
-1
@@ -53,7 +53,6 @@ libui = static_library('qemuui', libui_sources + genh,
53 ui = declare_dependency(objects: libui.extract_all_objects(recursive: false), dependencies: [pixman])
54 system_ss.add(png)
55 system_ss.add(files(
56 - 'input-legacy.c',
56 'input-barrier.c',
57 'input.c',
58 'ui-hmp-cmds.c',
ui/ui-hmp-cmds.c
+4 -3
@@ -55,10 +55,11 @@ void hmp_mouse_move(Monitor *mon, const QDict *qdict)
55
56 void hmp_mouse_button(Monitor *mon, const QDict *qdict)
57 {
58 + /* HMP mouse_button bitmask: 1=L, 2=R, 4=M */
59 static uint32_t bmap[INPUT_BUTTON__MAX] = {
59 - [INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON,
60 - [INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
61 - [INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON,
60 + [INPUT_BUTTON_LEFT] = 0x01,
61 + [INPUT_BUTTON_MIDDLE] = 0x04,
62 + [INPUT_BUTTON_RIGHT] = 0x02,
63 };
64 int button_state = qdict_get_int(qdict, "button_state");
65