From 93b4244cb6f585841d9f4350be735b31d17ffb1b Mon Sep 17 00:00:00 2001 From: Leo Date: Sun, 7 Jul 2024 14:41:34 +0900 Subject: [PATCH] DragDropAction: support touch (#1962) --- lib/DragDropAction.vala | 42 +++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/lib/DragDropAction.vala b/lib/DragDropAction.vala index b91c4f7b..240f64d9 100644 --- a/lib/DragDropAction.vala +++ b/lib/DragDropAction.vala @@ -109,6 +109,11 @@ namespace Gala { private InputDevice? grabbed_device = null; private ulong on_event_id = 0; + static construct { + sources = new Gee.HashMap> (); + destinations = new Gee.HashMap> (); + } + /** * Create a new DragDropAction * @@ -119,18 +124,12 @@ namespace Gala { */ public DragDropAction (DragDropActionType type, string id) { Object (drag_type : type, drag_id : id); - - if (sources == null) - sources = new Gee.HashMap> (); - - if (destinations == null) - destinations = new Gee.HashMap> (); - } ~DragDropAction () { - if (actor != null) + if (actor != null) { release_actor (actor); + } } public override void set_actor (Actor? new_actor) { @@ -197,6 +196,11 @@ namespace Gala { switch (event.get_type ()) { case EventType.BUTTON_PRESS: + case EventType.TOUCH_BEGIN: + if (!is_valid_touch_event (event)) { + return Clutter.EVENT_PROPAGATE; + } + if (grabbed_actor != null) { return Clutter.EVENT_PROPAGATE; } @@ -213,6 +217,11 @@ namespace Gala { return Clutter.EVENT_STOP; case EventType.BUTTON_RELEASE: + case EventType.TOUCH_END: + if (!is_valid_touch_event (event)) { + return Clutter.EVENT_PROPAGATE; + } + if (!dragging) { float x, y, ex, ey; event.get_coords (out ex, out ey); @@ -290,6 +299,11 @@ namespace Gala { } break; case EventType.MOTION: + case EventType.TOUCH_UPDATE: + if (!is_valid_touch_event (event)) { + return Clutter.EVENT_PROPAGATE; + } + float x, y; event.get_coords (out x, out y); @@ -447,5 +461,17 @@ namespace Gala { dragging = false; } + + private bool is_valid_touch_event (Clutter.Event event) { + var type = event.get_type (); + + return ( + type != Clutter.EventType.TOUCH_BEGIN && + type != Clutter.EventType.TOUCH_CANCEL && + type != Clutter.EventType.TOUCH_END && + type != Clutter.EventType.TOUCH_UPDATE || + Meta.Util.is_wayland_compositor () + ); + } } }