@samitouri / QOSamiQemu / commits / fb7c3fe607

ui/console: move console_handle_touch_event() to input

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

Marc-André Lureau committed Mar 11, 2026 at 13:29 UTC fb7c3fe607afcb1b0e6deb5ecbc4c93c9d957bb8
6 files changed +87 -86
include/ui/console.h
-14
@@ -111,20 +111,6 @@ void qemu_text_console_put_keysym(QemuTextConsole *s, int keysym);
111 bool qemu_text_console_put_qcode(QemuTextConsole *s, int qcode, bool ctrl);
112 void qemu_text_console_put_string(QemuTextConsole *s, const char *str, int len);
113
114 -/* Touch devices */
115 -typedef struct touch_slot {
116 - int x;
117 - int y;
118 - int tracking_id;
119 -} touch_slot;
120 -
121 -void console_handle_touch_event(QemuConsole *con,
122 - struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX],
123 - uint64_t num_slot,
124 - int width, int height,
125 - double x, double y,
126 - InputMultiTouchType type,
127 - Error **errp);
114 /* consoles */
115
116 struct QemuConsoleClass {
include/ui/input.h
+15
@@ -70,6 +70,21 @@ void qemu_input_queue_mtt_abs(QemuConsole *src, InputAxis axis, int value,
70 int min_in, int max_in,
71 int slot, int tracking_id);
72
73 +/* Touch devices */
74 +typedef struct touch_slot {
75 + int x;
76 + int y;
77 + int tracking_id;
78 +} touch_slot;
79 +
80 +void qemu_input_touch_event(QemuConsole *con,
81 + struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX],
82 + uint64_t num_slot,
83 + int width, int height,
84 + double x, double y,
85 + InputMultiTouchType type,
86 + Error **errp);
87 +
88 void qemu_input_check_mode_change(void);
89 void qemu_add_mouse_mode_change_notifier(Notifier *notify);
90 void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
ui/console.c
-65
@@ -548,71 +548,6 @@ static bool console_compatible_with(QemuConsole *con,
548 return true;
549 }
550
551 -void console_handle_touch_event(QemuConsole *con,
552 - struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX],
553 - uint64_t num_slot,
554 - int width, int height,
555 - double x, double y,
556 - InputMultiTouchType type,
557 - Error **errp)
558 -{
559 - struct touch_slot *slot;
560 - bool needs_sync = false;
561 - int update;
562 - int i;
563 -
564 - if (num_slot >= INPUT_EVENT_SLOTS_MAX) {
565 - error_setg(errp,
566 - "Unexpected touch slot number: % " PRId64" >= %d",
567 - num_slot, INPUT_EVENT_SLOTS_MAX);
568 - return;
569 - }
570 -
571 - slot = &touch_slots[num_slot];
572 - slot->x = x;
573 - slot->y = y;
574 -
575 - if (type == INPUT_MULTI_TOUCH_TYPE_BEGIN) {
576 - slot->tracking_id = num_slot;
577 - }
578 -
579 - for (i = 0; i < INPUT_EVENT_SLOTS_MAX; ++i) {
580 - if (i == num_slot) {
581 - update = type;
582 - } else {
583 - update = INPUT_MULTI_TOUCH_TYPE_UPDATE;
584 - }
585 -
586 - slot = &touch_slots[i];
587 -
588 - if (slot->tracking_id == -1) {
589 - continue;
590 - }
591 -
592 - if (update == INPUT_MULTI_TOUCH_TYPE_END) {
593 - slot->tracking_id = -1;
594 - qemu_input_queue_mtt(con, update, i, slot->tracking_id);
595 - needs_sync = true;
596 - } else {
597 - qemu_input_queue_mtt(con, update, i, slot->tracking_id);
598 - qemu_input_queue_btn(con, INPUT_BUTTON_TOUCH, true);
599 - qemu_input_queue_mtt_abs(con,
600 - INPUT_AXIS_X, (int) slot->x,
601 - 0, width,
602 - i, slot->tracking_id);
603 - qemu_input_queue_mtt_abs(con,
604 - INPUT_AXIS_Y, (int) slot->y,
605 - 0, height,
606 - i, slot->tracking_id);
607 - needs_sync = true;
608 - }
609 - }
610 -
611 - if (needs_sync) {
612 - qemu_input_event_sync();
613 - }
614 -}
615 -
551 void qemu_console_set_display_gl_ctx(QemuConsole *con, DisplayGLCtx *gl)
552 {
553 /* display has opengl support */
ui/dbus-console.c
+3 -3
@@ -424,9 +424,9 @@ dbus_touch_send_event(DBusDisplayConsole *ddc,
424 width = qemu_console_get_width(ddc->dcl.con, 0);
425 height = qemu_console_get_height(ddc->dcl.con, 0);
426
427 - console_handle_touch_event(ddc->dcl.con, touch_slots,
428 - num_slot, width, height,
429 - x, y, kind, &error);
427 + qemu_input_touch_event(ddc->dcl.con, touch_slots,
428 + num_slot, width, height,
429 + x, y, kind, &error);
430 if (error != NULL) {
431 g_dbus_method_invocation_return_error(
432 invocation, DBUS_DISPLAY_ERROR,
ui/gtk.c
+4 -4
@@ -1201,10 +1201,10 @@ static gboolean gd_touch_event(GtkWidget *widget, GdkEventTouch *touch,
1201 return FALSE;
1202 }
1203
1204 - console_handle_touch_event(vc->gfx.dcl.con, touch_slots,
1205 - num_slot, surface_width(vc->gfx.ds),
1206 - surface_height(vc->gfx.ds), touch->x,
1207 - touch->y, type, &err);
1204 + qemu_input_touch_event(vc->gfx.dcl.con, touch_slots,
1205 + num_slot, surface_width(vc->gfx.ds),
1206 + surface_height(vc->gfx.ds), touch->x,
1207 + touch->y, type, &err);
1208 if (err) {
1209 warn_report_err(err);
1210 }
ui/input.c
+65
@@ -609,3 +609,68 @@ bool qemu_mouse_set(int index, Error **errp)
609 notifier_list_notify(&mouse_mode_notifiers, NULL);
610 return true;
611 }
612 +
613 +void qemu_input_touch_event(QemuConsole *con,
614 + struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX],
615 + uint64_t num_slot,
616 + int width, int height,
617 + double x, double y,
618 + InputMultiTouchType type,
619 + Error **errp)
620 +{
621 + struct touch_slot *slot;
622 + bool needs_sync = false;
623 + int update;
624 + int i;
625 +
626 + if (num_slot >= INPUT_EVENT_SLOTS_MAX) {
627 + error_setg(errp,
628 + "Unexpected touch slot number: % " PRId64" >= %d",
629 + num_slot, INPUT_EVENT_SLOTS_MAX);
630 + return;
631 + }
632 +
633 + slot = &touch_slots[num_slot];
634 + slot->x = x;
635 + slot->y = y;
636 +
637 + if (type == INPUT_MULTI_TOUCH_TYPE_BEGIN) {
638 + slot->tracking_id = num_slot;
639 + }
640 +
641 + for (i = 0; i < INPUT_EVENT_SLOTS_MAX; ++i) {
642 + if (i == num_slot) {
643 + update = type;
644 + } else {
645 + update = INPUT_MULTI_TOUCH_TYPE_UPDATE;
646 + }
647 +
648 + slot = &touch_slots[i];
649 +
650 + if (slot->tracking_id == -1) {
651 + continue;
652 + }
653 +
654 + if (update == INPUT_MULTI_TOUCH_TYPE_END) {
655 + slot->tracking_id = -1;
656 + qemu_input_queue_mtt(con, update, i, slot->tracking_id);
657 + needs_sync = true;
658 + } else {
659 + qemu_input_queue_mtt(con, update, i, slot->tracking_id);
660 + qemu_input_queue_btn(con, INPUT_BUTTON_TOUCH, true);
661 + qemu_input_queue_mtt_abs(con,
662 + INPUT_AXIS_X, (int) slot->x,
663 + 0, width,
664 + i, slot->tracking_id);
665 + qemu_input_queue_mtt_abs(con,
666 + INPUT_AXIS_Y, (int) slot->y,
667 + 0, height,
668 + i, slot->tracking_id);
669 + needs_sync = true;
670 + }
671 + }
672 +
673 + if (needs_sync) {
674 + qemu_input_event_sync();
675 + }
676 +}