The function uses input.c functions to provide a simpler abstraction for touch events. Let's move it from the already overloaded console.c, and to avoid some unnecessary dependency from console.c on input.c.
Signed-off-by: Marc-André Lureau <[email protected]> --- include/ui/console.h | 14 ----------- include/ui/input.h | 15 ++++++++++++ ui/console.c | 65 ---------------------------------------------------- ui/dbus-console.c | 6 ++--- ui/gtk.c | 8 +++---- ui/input.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 87 insertions(+), 86 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index f8163ef96a8..6968a1e35f3 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -111,20 +111,6 @@ void qemu_text_console_put_keysym(QemuTextConsole *s, int keysym); bool qemu_text_console_put_qcode(QemuTextConsole *s, int qcode, bool ctrl); void qemu_text_console_put_string(QemuTextConsole *s, const char *str, int len); -/* Touch devices */ -typedef struct touch_slot { - int x; - int y; - int tracking_id; -} touch_slot; - -void console_handle_touch_event(QemuConsole *con, - struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX], - uint64_t num_slot, - int width, int height, - double x, double y, - InputMultiTouchType type, - Error **errp); /* consoles */ struct QemuConsoleClass { diff --git a/include/ui/input.h b/include/ui/input.h index 8f9aac562ed..52c164bde57 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -70,6 +70,21 @@ void qemu_input_queue_mtt_abs(QemuConsole *src, InputAxis axis, int value, int min_in, int max_in, int slot, int tracking_id); +/* Touch devices */ +typedef struct touch_slot { + int x; + int y; + int tracking_id; +} touch_slot; + +void qemu_input_touch_event(QemuConsole *con, + struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX], + uint64_t num_slot, + int width, int height, + double x, double y, + 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); diff --git a/ui/console.c b/ui/console.c index 05c72e19c02..d1079348970 100644 --- a/ui/console.c +++ b/ui/console.c @@ -550,71 +550,6 @@ static bool console_compatible_with(QemuConsole *con, return true; } -void console_handle_touch_event(QemuConsole *con, - struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX], - uint64_t num_slot, - int width, int height, - double x, double y, - InputMultiTouchType type, - Error **errp) -{ - struct touch_slot *slot; - bool needs_sync = false; - int update; - int i; - - if (num_slot >= INPUT_EVENT_SLOTS_MAX) { - error_setg(errp, - "Unexpected touch slot number: % " PRId64" >= %d", - num_slot, INPUT_EVENT_SLOTS_MAX); - return; - } - - slot = &touch_slots[num_slot]; - slot->x = x; - slot->y = y; - - if (type == INPUT_MULTI_TOUCH_TYPE_BEGIN) { - slot->tracking_id = num_slot; - } - - for (i = 0; i < INPUT_EVENT_SLOTS_MAX; ++i) { - if (i == num_slot) { - update = type; - } else { - update = INPUT_MULTI_TOUCH_TYPE_UPDATE; - } - - slot = &touch_slots[i]; - - if (slot->tracking_id == -1) { - continue; - } - - if (update == INPUT_MULTI_TOUCH_TYPE_END) { - slot->tracking_id = -1; - qemu_input_queue_mtt(con, update, i, slot->tracking_id); - needs_sync = true; - } else { - qemu_input_queue_mtt(con, update, i, slot->tracking_id); - qemu_input_queue_btn(con, INPUT_BUTTON_TOUCH, true); - qemu_input_queue_mtt_abs(con, - INPUT_AXIS_X, (int) slot->x, - 0, width, - i, slot->tracking_id); - qemu_input_queue_mtt_abs(con, - INPUT_AXIS_Y, (int) slot->y, - 0, height, - i, slot->tracking_id); - needs_sync = true; - } - } - - if (needs_sync) { - qemu_input_event_sync(); - } -} - void qemu_console_set_display_gl_ctx(QemuConsole *con, DisplayGLCtx *gl) { /* display has opengl support */ diff --git a/ui/dbus-console.c b/ui/dbus-console.c index 88f58e88efb..b8e5c57b148 100644 --- a/ui/dbus-console.c +++ b/ui/dbus-console.c @@ -423,9 +423,9 @@ dbus_touch_send_event(DBusDisplayConsole *ddc, width = qemu_console_get_width(ddc->dcl.con, 0); height = qemu_console_get_height(ddc->dcl.con, 0); - console_handle_touch_event(ddc->dcl.con, touch_slots, - num_slot, width, height, - x, y, kind, &error); + qemu_input_touch_event(ddc->dcl.con, touch_slots, + num_slot, width, height, + x, y, kind, &error); if (error != NULL) { g_dbus_method_invocation_return_error( invocation, DBUS_DISPLAY_ERROR, diff --git a/ui/gtk.c b/ui/gtk.c index bcb67db7ee7..3b84224d8e8 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -1201,10 +1201,10 @@ static gboolean gd_touch_event(GtkWidget *widget, GdkEventTouch *touch, return FALSE; } - console_handle_touch_event(vc->gfx.dcl.con, touch_slots, - num_slot, surface_width(vc->gfx.ds), - surface_height(vc->gfx.ds), touch->x, - touch->y, type, &err); + qemu_input_touch_event(vc->gfx.dcl.con, touch_slots, + num_slot, surface_width(vc->gfx.ds), + surface_height(vc->gfx.ds), touch->x, + touch->y, type, &err); if (err) { warn_report_err(err); } diff --git a/ui/input.c b/ui/input.c index 147e69c1c3c..57e7817878a 100644 --- a/ui/input.c +++ b/ui/input.c @@ -609,3 +609,68 @@ bool qemu_mouse_set(int index, Error **errp) notifier_list_notify(&mouse_mode_notifiers, NULL); return true; } + +void qemu_input_touch_event(QemuConsole *con, + struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX], + uint64_t num_slot, + int width, int height, + double x, double y, + InputMultiTouchType type, + Error **errp) +{ + struct touch_slot *slot; + bool needs_sync = false; + int update; + int i; + + if (num_slot >= INPUT_EVENT_SLOTS_MAX) { + error_setg(errp, + "Unexpected touch slot number: % " PRId64" >= %d", + num_slot, INPUT_EVENT_SLOTS_MAX); + return; + } + + slot = &touch_slots[num_slot]; + slot->x = x; + slot->y = y; + + if (type == INPUT_MULTI_TOUCH_TYPE_BEGIN) { + slot->tracking_id = num_slot; + } + + for (i = 0; i < INPUT_EVENT_SLOTS_MAX; ++i) { + if (i == num_slot) { + update = type; + } else { + update = INPUT_MULTI_TOUCH_TYPE_UPDATE; + } + + slot = &touch_slots[i]; + + if (slot->tracking_id == -1) { + continue; + } + + if (update == INPUT_MULTI_TOUCH_TYPE_END) { + slot->tracking_id = -1; + qemu_input_queue_mtt(con, update, i, slot->tracking_id); + needs_sync = true; + } else { + qemu_input_queue_mtt(con, update, i, slot->tracking_id); + qemu_input_queue_btn(con, INPUT_BUTTON_TOUCH, true); + qemu_input_queue_mtt_abs(con, + INPUT_AXIS_X, (int) slot->x, + 0, width, + i, slot->tracking_id); + qemu_input_queue_mtt_abs(con, + INPUT_AXIS_Y, (int) slot->y, + 0, height, + i, slot->tracking_id); + needs_sync = true; + } + } + + if (needs_sync) { + qemu_input_event_sync(); + } +} -- 2.53.0
