mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-10 11:04:58 -06:00
hw/input/adb-mouse: convert to use QemuInputHandler
Update the ADB mouse implementation to use QemuInputHandler instead of the legacy qemu_add_mouse_event_handler() function. Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20240907173700.348818-1-mark.cave-ayland@ilande.co.uk> [PMD: Add comment about .sync handler] Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
parent
34acb67f03
commit
118e151918
1 changed files with 52 additions and 11 deletions
|
@ -38,6 +38,7 @@ struct MouseState {
|
||||||
ADBDevice parent_obj;
|
ADBDevice parent_obj;
|
||||||
/*< private >*/
|
/*< private >*/
|
||||||
|
|
||||||
|
QemuInputHandlerState *hs;
|
||||||
int buttons_state, last_buttons_state;
|
int buttons_state, last_buttons_state;
|
||||||
int dx, dy, dz;
|
int dx, dy, dz;
|
||||||
};
|
};
|
||||||
|
@ -51,17 +52,57 @@ struct ADBMouseClass {
|
||||||
DeviceRealize parent_realize;
|
DeviceRealize parent_realize;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void adb_mouse_event(void *opaque,
|
#define ADB_MOUSE_BUTTON_LEFT 0x01
|
||||||
int dx1, int dy1, int dz1, int buttons_state)
|
#define ADB_MOUSE_BUTTON_RIGHT 0x02
|
||||||
{
|
|
||||||
MouseState *s = opaque;
|
|
||||||
|
|
||||||
s->dx += dx1;
|
static void adb_mouse_handle_event(DeviceState *dev, QemuConsole *src,
|
||||||
s->dy += dy1;
|
InputEvent *evt)
|
||||||
s->dz += dz1;
|
{
|
||||||
s->buttons_state = buttons_state;
|
MouseState *s = (MouseState *)dev;
|
||||||
|
InputMoveEvent *move;
|
||||||
|
InputBtnEvent *btn;
|
||||||
|
static const int bmap[INPUT_BUTTON__MAX] = {
|
||||||
|
[INPUT_BUTTON_LEFT] = ADB_MOUSE_BUTTON_LEFT,
|
||||||
|
[INPUT_BUTTON_RIGHT] = ADB_MOUSE_BUTTON_RIGHT,
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (evt->type) {
|
||||||
|
case INPUT_EVENT_KIND_REL:
|
||||||
|
move = evt->u.rel.data;
|
||||||
|
if (move->axis == INPUT_AXIS_X) {
|
||||||
|
s->dx += move->value;
|
||||||
|
} else if (move->axis == INPUT_AXIS_Y) {
|
||||||
|
s->dy += move->value;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case INPUT_EVENT_KIND_BTN:
|
||||||
|
btn = evt->u.btn.data;
|
||||||
|
if (bmap[btn->button]) {
|
||||||
|
if (btn->down) {
|
||||||
|
s->buttons_state |= bmap[btn->button];
|
||||||
|
} else {
|
||||||
|
s->buttons_state &= ~bmap[btn->button];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
/* keep gcc happy */
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const QemuInputHandler adb_mouse_handler = {
|
||||||
|
.name = "QEMU ADB Mouse",
|
||||||
|
.mask = INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_REL,
|
||||||
|
.event = adb_mouse_handle_event,
|
||||||
|
/*
|
||||||
|
* We do not need the .sync handler because unlike e.g. PS/2 where async
|
||||||
|
* mouse events are sent over the serial port, an ADB mouse is constantly
|
||||||
|
* polled by the host via the adb_mouse_poll() callback.
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf)
|
static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf)
|
||||||
{
|
{
|
||||||
|
@ -94,10 +135,10 @@ static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf)
|
||||||
dx &= 0x7f;
|
dx &= 0x7f;
|
||||||
dy &= 0x7f;
|
dy &= 0x7f;
|
||||||
|
|
||||||
if (!(s->buttons_state & MOUSE_EVENT_LBUTTON)) {
|
if (!(s->buttons_state & ADB_MOUSE_BUTTON_LEFT)) {
|
||||||
dy |= 0x80;
|
dy |= 0x80;
|
||||||
}
|
}
|
||||||
if (!(s->buttons_state & MOUSE_EVENT_RBUTTON)) {
|
if (!(s->buttons_state & ADB_MOUSE_BUTTON_RIGHT)) {
|
||||||
dx |= 0x80;
|
dx |= 0x80;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +277,7 @@ static void adb_mouse_realizefn(DeviceState *dev, Error **errp)
|
||||||
|
|
||||||
amc->parent_realize(dev, errp);
|
amc->parent_realize(dev, errp);
|
||||||
|
|
||||||
qemu_add_mouse_event_handler(adb_mouse_event, s, 0, "QEMU ADB Mouse");
|
s->hs = qemu_input_handler_register(dev, &adb_mouse_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void adb_mouse_initfn(Object *obj)
|
static void adb_mouse_initfn(Object *obj)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue