mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:46:10 +00:00
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>
This commit is contained in:
@@ -1,221 +0,0 @@
|
||||
/*
|
||||
* QEMU System Emulator
|
||||
*
|
||||
* Copyright (c) 2003-2008 Fabrice Bellard
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/log.h"
|
||||
#include "qapi/qapi-commands-ui.h"
|
||||
#include "ui/console.h"
|
||||
#include "keymaps.h"
|
||||
#include "ui/input.h"
|
||||
|
||||
struct QEMUPutMouseEntry {
|
||||
QEMUPutMouseEvent *qemu_put_mouse_event;
|
||||
void *qemu_put_mouse_event_opaque;
|
||||
int qemu_put_mouse_event_absolute;
|
||||
|
||||
/* new input core */
|
||||
QemuInputHandler h;
|
||||
QemuInputHandlerState *s;
|
||||
int axis[INPUT_AXIS__MAX];
|
||||
int buttons;
|
||||
};
|
||||
|
||||
struct QEMUPutKbdEntry {
|
||||
QEMUPutKBDEvent *put_kbd;
|
||||
void *opaque;
|
||||
QemuInputHandlerState *s;
|
||||
};
|
||||
|
||||
struct QEMUPutLEDEntry {
|
||||
QEMUPutLEDEvent *put_led;
|
||||
void *opaque;
|
||||
QTAILQ_ENTRY(QEMUPutLEDEntry) next;
|
||||
};
|
||||
|
||||
static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers =
|
||||
QTAILQ_HEAD_INITIALIZER(led_handlers);
|
||||
|
||||
void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time,
|
||||
Error **errp)
|
||||
{
|
||||
KeyValueList *p;
|
||||
unsigned int *up = NULL;
|
||||
int count = 0;
|
||||
|
||||
if (!has_hold_time) {
|
||||
hold_time = 0; /* use default */
|
||||
}
|
||||
|
||||
for (p = keys; p != NULL; p = p->next) {
|
||||
up = g_realloc(up, sizeof(*up) * (count+1));
|
||||
up[count] = qemu_input_key_value_to_linux(p->value);
|
||||
qemu_input_event_send_key_linux(NULL, up[count], true);
|
||||
qemu_input_event_send_key_delay(hold_time);
|
||||
count++;
|
||||
}
|
||||
while (count) {
|
||||
count--;
|
||||
qemu_input_event_send_key_linux(NULL, up[count], false);
|
||||
qemu_input_event_send_key_delay(hold_time);
|
||||
}
|
||||
g_free(up);
|
||||
}
|
||||
|
||||
static void legacy_mouse_event(DeviceState *dev, QemuConsole *src,
|
||||
QemuInputEvent *evt)
|
||||
{
|
||||
static const int bmap[INPUT_BUTTON__MAX] = {
|
||||
[INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON,
|
||||
[INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
|
||||
[INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON,
|
||||
};
|
||||
QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev;
|
||||
|
||||
switch (evt->type) {
|
||||
case INPUT_EVENT_KIND_BTN:
|
||||
if (evt->btn.down) {
|
||||
s->buttons |= bmap[evt->btn.button];
|
||||
} else {
|
||||
s->buttons &= ~bmap[evt->btn.button];
|
||||
}
|
||||
if (evt->btn.down && evt->btn.button == INPUT_BUTTON_WHEEL_UP) {
|
||||
s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
|
||||
s->axis[INPUT_AXIS_X],
|
||||
s->axis[INPUT_AXIS_Y],
|
||||
-1,
|
||||
s->buttons);
|
||||
}
|
||||
if (evt->btn.down && evt->btn.button == INPUT_BUTTON_WHEEL_DOWN) {
|
||||
s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
|
||||
s->axis[INPUT_AXIS_X],
|
||||
s->axis[INPUT_AXIS_Y],
|
||||
1,
|
||||
s->buttons);
|
||||
}
|
||||
if (evt->btn.down && evt->btn.button == INPUT_BUTTON_WHEEL_RIGHT) {
|
||||
s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
|
||||
s->axis[INPUT_AXIS_X],
|
||||
s->axis[INPUT_AXIS_Y],
|
||||
-2,
|
||||
s->buttons);
|
||||
}
|
||||
if (evt->btn.down && evt->btn.button == INPUT_BUTTON_WHEEL_LEFT) {
|
||||
s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
|
||||
s->axis[INPUT_AXIS_X],
|
||||
s->axis[INPUT_AXIS_Y],
|
||||
2,
|
||||
s->buttons);
|
||||
}
|
||||
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 legacy_mouse_sync(DeviceState *dev)
|
||||
{
|
||||
QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev;
|
||||
|
||||
s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
|
||||
s->axis[INPUT_AXIS_X],
|
||||
s->axis[INPUT_AXIS_Y],
|
||||
0,
|
||||
s->buttons);
|
||||
|
||||
if (!s->qemu_put_mouse_event_absolute) {
|
||||
s->axis[INPUT_AXIS_X] = 0;
|
||||
s->axis[INPUT_AXIS_Y] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
|
||||
void *opaque, int absolute,
|
||||
const char *name)
|
||||
{
|
||||
QEMUPutMouseEntry *s;
|
||||
|
||||
s = g_new0(QEMUPutMouseEntry, 1);
|
||||
|
||||
s->qemu_put_mouse_event = func;
|
||||
s->qemu_put_mouse_event_opaque = opaque;
|
||||
s->qemu_put_mouse_event_absolute = absolute;
|
||||
|
||||
s->h.name = name;
|
||||
s->h.mask = INPUT_EVENT_MASK_BTN |
|
||||
(absolute ? INPUT_EVENT_MASK_ABS : INPUT_EVENT_MASK_REL);
|
||||
s->h.event = legacy_mouse_event;
|
||||
s->h.sync = legacy_mouse_sync;
|
||||
s->s = qemu_input_handler_register((DeviceState *)s,
|
||||
&s->h);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry)
|
||||
{
|
||||
qemu_input_handler_activate(entry->s);
|
||||
}
|
||||
|
||||
void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
|
||||
{
|
||||
qemu_input_handler_unregister(entry->s);
|
||||
|
||||
g_free(entry);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
66
ui/input.c
66
ui/input.c
@@ -648,3 +648,69 @@ void qemu_input_touch_event(QemuConsole *con,
|
||||
qemu_input_event_sync();
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
KeyValueList *p;
|
||||
unsigned int *up = NULL;
|
||||
int count = 0;
|
||||
|
||||
if (!has_hold_time) {
|
||||
hold_time = 0; /* use default */
|
||||
}
|
||||
|
||||
for (p = keys; p != NULL; p = p->next) {
|
||||
up = g_realloc_n(up, count + 1, sizeof(*up));
|
||||
up[count] = qemu_input_key_value_to_linux(p->value);
|
||||
qemu_input_event_send_key_linux(NULL, up[count], true);
|
||||
qemu_input_event_send_key_delay(hold_time);
|
||||
count++;
|
||||
}
|
||||
while (count) {
|
||||
count--;
|
||||
qemu_input_event_send_key_linux(NULL, up[count], false);
|
||||
qemu_input_event_send_key_delay(hold_time);
|
||||
}
|
||||
g_free(up);
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user