ui/touch: Move event handling to a common helper
PATCH 1/2 ui/touch: Move event handling to a common helper
To share code between the GTK and DBus UI bakcends see the next commit for details
--- include/ui/console.h | 14 ++++++++++ ui/console.c | 65 ++++++++++++++++++++++++++++++++++++++++++++ ui/gtk.c | 62 ++++-------------------------------------- 3 files changed, 84 insertions(+), 57 deletions(-)
include/ui/console.h +14 -0
@@ -5,6 +5,7 @@#include "qom/object.h" #include "qemu/notify.h" #include "qapi/qapi-types-ui.h" +#include "ui/input.h" #ifdef CONFIG_OPENGL # include <epoxy/gl.h>
@@ -95,6 +96,19 @@ bool kbd_put_qcode_console(QemuConsole *s, int qcode, bool ctrl);void kbd_put_string_console (QemuConsole *s,const char *str,int len);void kbd_put_keysym (int keysym); +/* Touch devices */ +typedef struct touch_slot { +int x; +int y; +int tracking_id; +}touch_slot ; + +bool 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);/* consoles */ #define TYPE_QEMU_CONSOLE "qemu-console"
ui/console.c +65 -0
71 lines not on this page · raw message
ui/gtk.c +5 -57
88 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH 2/2 ui/dbus: Expose a touch device interface
So that clients making use of the DBus backend could send touch events through the new org.qemu.Display1.Touch interface
--- ui/dbus-console.c | 56 +++++++++++++++++++++++++++++++++++++++++++- ui/dbus-display1.xml | 38 ++++++++++++++++++++++++++++-- ui/trace-events | 1 + 3 files changed, 92 insertions(+), 3 deletions(-)
ui/dbus-console.c +55 -1
@@ -32,6 +32,8 @@#include "dbus.h" +static struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX ]; +struct _DBusDisplayConsole {GDBusObjectSkeleton parent_instance;DisplayChangeListener dcl;
@@ -44,6 +46,7 @@ struct _DBusDisplayConsole {QKbdState *kbd;QemuDBusDisplay1Mouse *iface_mouse; +QemuDBusDisplay1Touch *iface_touch;gboolean last_set;guint last_x;guint last_y;
@@ -345,6 +348,45 @@ dbus_mouse_rel_motion(DBusDisplayConsole *ddc,return DBUS_METHOD_INVOCATION_HANDLED ; } +static gboolean +dbus_touch_send_event (DBusDisplayConsole *ddc, +GDBusMethodInvocation *invocation, +guint kind,uint64_t num_slot, +double x,double y) +{ +int width, height; +gboolean ret; +trace_dbus_touch_send_event (kind, num_slot, x, y); + +if (kind !=INPUT_MULTI_TOUCH_TYPE_BEGIN && + kind !=INPUT_MULTI_TOUCH_TYPE_UPDATE && + kind !=INPUT_MULTI_TOUCH_TYPE_CANCEL && + kind !=INPUT_MULTI_TOUCH_TYPE_END ) + { +g_dbus_method_invocation_return_error ( + invocation,DBUS_DISPLAY_ERROR , +DBUS_DISPLAY_ERROR_INVALID , +"Invalid touch event kind" ); +return DBUS_METHOD_INVOCATION_HANDLED ; + } + width =qemu_console_get_width (ddc->dcl.con,0 ); + height =qemu_console_get_height (ddc->dcl.con,0 ); + + ret =console_handle_touch_event (ddc->dcl.con, touch_slots, + num_slot, width, height, + x, y, kind); +if (!ret) { +g_dbus_method_invocation_return_error ( + invocation,DBUS_DISPLAY_ERROR , +DBUS_DISPLAY_ERROR_INVALID , +"Unexpected touch slot number" ); + }else { +qemu_dbus_display1_touch_complete_send_event (ddc->iface_touch, + invocation); + } +return DBUS_METHOD_INVOCATION_HANDLED ; +} + static gboolean dbus_mouse_set_pos(DBusDisplayConsole *ddc, GDBusMethodInvocation *invocation,
@@ -440,7 +482,7 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con) g_autofree char *label = NULL;char device_addr[256 ] ="" ;DBusDisplayConsole *ddc; -int idx; +int idx, i;assert (display);assert (con);
@@ -495,6 +537,18 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con)g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (ddc),G_DBUS_INTERFACE_SKELETON (ddc->iface_mouse)); + ddc->iface_touch =qemu_dbus_display1_touch_skeleton_new (); +g_object_connect (ddc->iface_touch, +"swapped-signal::handle-send-event" , dbus_touch_send_event, ddc, +NULL ); +g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (ddc), +G_DBUS_INTERFACE_SKELETON (ddc->iface_touch)); + +for (i =0 ; i <INPUT_EVENT_SLOTS_MAX ; i++) { +struct touch_slot *slot = &touch_slots[i]; + slot->tracking_id =-1 ; + } +register_displaychangelistener (&ddc->dcl); ddc->mouse_mode_notifier.notify = dbus_mouse_mode_change;qemu_add_mouse_mode_change_notifier (&ddc->mouse_mode_notifier);
ui/dbus-display1.xml +36 -2
@@ -39,8 +39,9 @@ "Text" (see :dbus:prop:`Type` and other properties). Interactions with a console may be done with - :dbus:iface:`org.qemu.Display1.Keyboard` and - :dbus:iface:`org.qemu.Display1.Mouse` interfaces when available. + :dbus:iface:`org.qemu.Display1.Keyboard`, + :dbus:iface:`org.qemu.Display1.Mouse` and + :dbus:iface:`org.qemu.Display1.Touch` interfaces when available. --> <interface name="org.qemu.Display1.Console"> <!--
@@ -236,6 +237,39 @@ <property name="IsAbsolute" type="b" access="read"/> </interface> + <!-- + org.qemu.Display1.Touch: + + This interface in implemented on ``/org/qemu/Display1/Console_$id`` (see + :dbus:iface:`~org.qemu.Display1.Console` documentation). + + .. _dbus-kind-values: + + **Kind values**:: + + Begin = 0 + Update = 1 + End = 2 + Cancel = 3 + --> + <interface name="org.qemu.Display1.Touch"> + <!-- + SendEvent: + @kind: The touch event kind + @num_slot: The slot number. + @x: The x coordinates. + @y: The y coordinates. + + Send a touch gesture event. + --> + <method name="SendEvent"> + <arg type="u" name="kind" direction="in"/> + <arg type="t" name="num_slot" direction="in"/> + <arg type="d" name="x" direction="in"/> + <arg type="d" name="y" direction="in"/> + </method> + </interface> + <!-- org.qemu.Display1.Listener:
ui/trace-events +1 -0
@@ -154,6 +154,7 @@ dbus_mouse_press(unsigned int button) "button %u" dbus_mouse_release(unsigned int button) "button %u" dbus_mouse_set_pos(unsigned int x, unsigned int y) "x=%u, y=%u" dbus_mouse_rel_motion(int dx, int dy) "dx=%d, dy=%d" +dbus_touch_send_event(unsigned int kind, uint32_t num_slot, uint32_t x, uint32_t y) "kind=%u, num_slot=%u, x=%d, y=%d" dbus_update(int x, int y, int w, int h) "x=%d, y=%d, w=%d, h=%d" dbus_clipboard_grab_failed(void) "" dbus_clipboard_register(const char *bus_name) "peer %s"
Signature · 1 line
2.40.1
Re: [PATCH 2/2] ui/dbus: Expose a touch device interface
Hi Bilal
Quoted 55 lines · Bilal Elmoussaoui
So that clients making use of the DBus backend could send touch events through the new org.qemu.Display1.Touch interface
Signed-off-by Bilal Elmoussaoui <[email protected]>--- ui/dbus-console.c | 56 +++++++++++++++++++++++++++++++++++++++++++- ui/dbus-display1.xml | 38 ++++++++++++++++++++++++++++-- ui/trace-events | 1 + 3 files changed, 92 insertions(+), 3 deletions(-)ui/dbus-console.c +22
-0@@ -32,6 +32,8 @@#include "dbus.h" +static struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX ]; +struct _DBusDisplayConsole {GDBusObjectSkeleton parent_instance;DisplayChangeListener dcl;@@ -44,6 +46,7 @@ struct _DBusDisplayConsole {QKbdState *kbd;QemuDBusDisplay1Mouse *iface_mouse; +QemuDBusDisplay1Touch *iface_touch;gboolean last_set;guint last_x;guint last_y;@@ -345,6 +348,45 @@ dbus_mouse_rel_motion(DBusDisplayConsole *ddc,return DBUS_METHOD_INVOCATION_HANDLED ; } +static gboolean +dbus_touch_send_event (DBusDisplayConsole *ddc, +GDBusMethodInvocation *invocation, +guint kind,uint64_t num_slot, +double x,double y) +{ +int width, height; +gboolean ret; +trace_dbus_touch_send_event (kind, num_slot, x, y); + +if (kind !=INPUT_MULTI_TOUCH_TYPE_BEGIN && + kind !=INPUT_MULTI_TOUCH_TYPE_UPDATE && + kind !=INPUT_MULTI_TOUCH_TYPE_CANCEL && + kind !=INPUT_MULTI_TOUCH_TYPE_END ) + { +g_dbus_method_invocation_return_error ( + invocation,DBUS_DISPLAY_ERROR , +DBUS_DISPLAY_ERROR_INVALID , +"Invalid touch event kind" );
ui/dbus-console.c dbus_mouse_rel_motion(DBusDisplayConsole *ddc, · line 379
Quoted 10 lines
ui/dbus-console.c +9
-0+return DBUS_METHOD_INVOCATION_HANDLED ; + } + width =qemu_console_get_width (ddc->dcl.con,0 ); + height =qemu_console_get_height (ddc->dcl.con,0 ); + + ret =console_handle_touch_event (ddc->dcl.con, touch_slots, + num_slot, width, height, + x, y, kind); +if (!ret) {
+ g_dbus_method_invocation_return_error(
ui/dbus-console.c dbus_mouse_rel_motion(DBusDisplayConsole *ddc,
Quoted 5 lines
ui/dbus-console.c +3
-0+ invocation,DBUS_DISPLAY_ERROR , +DBUS_DISPLAY_ERROR_INVALID , + "Unexpected touch slot number");
With Error* usage, we won't have to "guess" the error
Quoted 86 lines
ui/dbus-console.c +8
-1+ }else { +qemu_dbus_display1_touch_complete_send_event (ddc->iface_touch, + invocation); + } +return DBUS_METHOD_INVOCATION_HANDLED ; +} + static gboolean dbus_mouse_set_pos(DBusDisplayConsole *ddc, GDBusMethodInvocation *invocation,@@ -440,7 +482,7 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con) g_autofree char *label = NULL;char device_addr[256 ] ="" ;DBusDisplayConsole *ddc; -int idx; +int idx, i;assert (display);assert(con);ui/dbus-console.c +12
-0@@ -495,6 +537,18 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con)g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (ddc ), G_DBUS_INTERFACE_SKELETON(ddc->iface_mouse)); + ddc->iface_touch =qemu_dbus_display1_touch_skeleton_new (); +g_object_connect (ddc->iface_touch, +"swapped-signal::handle-send-event" , dbus_touch_send_event, ddc, +NULL ); +g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (ddc), +G_DBUS_INTERFACE_SKELETON (ddc->iface_touch)); + +for (i =0 ; i <INPUT_EVENT_SLOTS_MAX ; i++) { +struct touch_slot *slot = &touch_slots[i]; + slot->tracking_id =-1 ; + } +register_displaychangelistener (&ddc->dcl); ddc->mouse_mode_notifier.notify = dbus_mouse_mode_change;qemu_add_mouse_mode_change_notifier(&ddc->mouse_mode_notifier);ui/dbus-display1.xml +7
-2@@ -39,8 +39,9 @@ "Text" (see :dbus:prop:`Type` and other properties). Interactions with a console may be done with - :dbus:iface:`org.qemu.Display1.Keyboard` and - :dbus:iface:`org.qemu.Display1.Mouse` interfaces when available. + :dbus:iface:`org.qemu.Display1.Keyboard`, + :dbus:iface:`org.qemu.Display1.Mouse` and + :dbus:iface:`org.qemu.Display1.Touch` interfaces when available. --> <interface name="org.qemu.Display1.Console"> <!--@@ -236,6 +237,39 @@ <property name="IsAbsolute" type="b" access="read"/> </interface> + <!-- + org.qemu.Display1.Touch: + + This interface in implemented on ``/org/qemu/Display1/Console_$id``(see
ui/dbus-display1.xml +17
-0+ :dbus:iface:`~org.qemu.Display1.Console` documentation). + + .. _dbus-kind-values: + + **Kind values**:: + + Begin = 0 + Update = 1 + End = 2 + Cancel = 3 + --> + <interface name="org.qemu.Display1.Touch"> + <!-- + SendEvent: + @kind: The touch event kind + @num_slot: The slot number. + @x: The x coordinates.
ui/dbus-display1.xml line 270
Quoted 10 lines
ui/dbus-display1.xml +10
-0+ @y: The y coordinates. + + Send a touch gesture event. + --> + <method name="SendEvent"> + <arg type="u" name="kind" direction="in"/> + <arg type="t" name="num_slot" direction="in"/> + <arg type="d" name="x" direction="in"/> + <arg type="d" name="y" direction="in"/> + </method>
We should expose a max-slots property.
+ </interface>
Quoted 22 lines
ui/dbus-display1.xml +1
-0+ <!-- org.qemu.Display1.Listener:ui/trace-events +1
-0@@ -154,6 +154,7 @@ dbus_mouse_press(unsigned int button) "button %u" dbus_mouse_release(unsigned int button) "button %u" dbus_mouse_set_pos(unsigned int x, unsigned int y) "x=%u, y=%u" dbus_mouse_rel_motion(int dx, int dy) "dx=%d, dy=%d" +dbus_touch_send_event(unsigned int kind, uint32_t num_slot, uint32_t x,
uint32_ty) "kind=%u, num_slot=%u, x=%d, y=%d"
dbus_update(int x, int y, int w, int h)"x=%d, y=%d, w=%d, h=%d"dbus_clipboard_grab_failed(void)""dbus_clipboard_register(const char *bus_name)"peer %s"
--
2.40.1
Signature · 1 line
Marc-André Lureau
Hi Bilal
Quoted 51 lines · Bilal Elmoussaoui
To share code between the GTK and DBus UI bakcends see the next commit for details
Signed-off-by Bilal Elmoussaoui <[email protected]>--- include/ui/console.h | 14 ++++++++++ ui/console.c | 65 ++++++++++++++++++++++++++++++++++++++++++++ ui/gtk.c | 62 ++++-------------------------------------- 3 files changed, 84 insertions(+), 57 deletions(-)include/ui/console.h +14
-0@@ -5,6 +5,7 @@#include "qom/object.h" #include "qemu/notify.h" #include "qapi/qapi-types-ui.h" +#include "ui/input.h" #ifdef CONFIG_OPENGL # include <epoxy/gl.h> @@ -95,6 +96,19 @@ bool kbd_put_qcode_console(QemuConsole *s, int qcode, bool ctrl);void kbd_put_string_console (QemuConsole *s,const char *str,int len);void kbd_put_keysym (int keysym); +/* Touch devices */ +typedef struct touch_slot { +int x; +int y; +int tracking_id; +}touch_slot ; + +bool 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);/* consoles */ #define
TYPE_QEMU_CONSOLE"qemu-console"ui/console.c +0
-0@@ -1635,6 +1635,71 @@ static bool console_compatible_with(QemuConsole *con, return true;
ui/console.c static bool console_compatible_with(QemuConsole · line 1646
Quoted 10 lines
ui/console.c +6
-0} +bool 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)
Better would be to use Error **errp.
+{
Quoted 158 lines
ui/console.c +58
-0+struct touch_slot *slot; +bool needs_sync = false; +int update; +int i; + +if (num_slot >=INPUT_EVENT_SLOTS_MAX ) { +warn_report ("unexpected touch slot number: % " PRId64" >= %d\n" , + num_slot,INPUT_EVENT_SLOTS_MAX ); +return FALSE; + } + + 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 (); + } + +return TRUE; +} +void qemu_console_set_display_gl_ctx (QemuConsole *con,DisplayGLCtx *gl) {/* display has opengl support */ ui/gtk.c +0
-20@@ -130,11 +130,6 @@ typedef struct VCChardev VCChardev;DECLARE_INSTANCE_CHECKER (VCChardev,VC_CHARDEV , TYPE_CHARDEV_VC) -struct touch_slot { -int x; -int y; -int tracking_id; -};static struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX ];bool gtk_use_gl_area;@@ -1068,27 +1063,12 @@ static gboolean gd_touch_event(GtkWidget *widget, GdkEventTouch *touch, void *opaque) {VirtualConsole *vc = opaque; -struct touch_slot *slot;uint64_t num_slot =GPOINTER_TO_UINT (touch->sequence); -bool needs_sync = false; -int update;int type =-1 ; -int i; - -if (num_slot >=INPUT_EVENT_SLOTS_MAX ) { - warn_report("gtk: unexpected touch slot number: % " PRId64" >= %d\n", - num_slot, INPUT_EVENT_SLOTS_MAX); -return FALSE; - } - - slot = &touch_slots[num_slot]; - slot->x = touch->x; - slot->y = touch->y; switch (touch->type) {case GDK_TOUCH_BEGIN : type =INPUT_MULTI_TOUCH_TYPE_BEGIN ; - slot->tracking_id = num_slot;break ;case GDK_TOUCH_UPDATE: type = INPUT_MULTI_TOUCH_TYPE_UPDATE;ui/gtk.c +4
-37@@ -1099,45 +1079,13 @@ static gboolean gd_touch_event(GtkWidget *widget,GdkEventTouch *touch, break;default :warn_report ("gtk: unexpected touch event type\n" ); +return FALSE; } -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 (vc->gfx.dcl.con, update, i, slot->tracking_id); - needs_sync = true; - }else { -qemu_input_queue_mtt (vc->gfx.dcl.con, update, i, slot->tracking_id); -qemu_input_queue_btn (vc->gfx.dcl.con,INPUT_BUTTON_TOUCH , true); -qemu_input_queue_mtt_abs (vc->gfx.dcl.con, -INPUT_AXIS_X , (int ) slot->x, -0 ,surface_width (vc->gfx.ds), - i, slot->tracking_id); -qemu_input_queue_mtt_abs (vc->gfx.dcl.con, -INPUT_AXIS_Y , (int ) slot->y, -0 ,surface_height (vc->gfx.ds), - i, slot->tracking_id); - needs_sync = true; - } - } - -if (needs_sync) { -qemu_input_event_sync (); - } - -return TRUE; + return console_handle_touch_event(vc->gfx.dcl.con, touch_slots, + num_slot, surface_width(vc->gfx.ds), + surface_height(vc->gfx.ds),
Quoted 3 lines
touch->x,
+touch->y, type);
Then we can call with &error_warn form here.
otherwise, lgtm
Signature · 1 line
Marc-André Lureau