[gnome-maps/wip/mlundblad/long-press-context-menu: 2/2] mapView: Open the context menu on long-press




commit 8f5d0af7568f145eae4b47bff947b52c941cc74f
Author: Marcus Lundblad <ml dfupdate se>
Date:   Wed Aug 31 23:26:42 2022 +0200

    mapView: Open the context menu on long-press
    
    Trigger the context menu also on long-press on
    touch.

 src/mapView.js | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index 37fde131..1bc55289 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -197,6 +197,11 @@ export class MapView extends Gtk.Overlay {
         this._clickGesture = new Gtk.GestureClick({ button: Gdk.BUTTON_SECONDARY });
         this._clickGesture.connect('pressed', this._onClickGesturePressed.bind(this));
         this.add_controller(this._clickGesture);
+
+        this._longPressGesture = new Gtk.GestureLongPress();;
+        this._longPressGesture.connect('pressed',
+                                       this._onLongPressGesturePressed.bind(this));
+        this.add_controller(this._longPressGesture);
     }
 
     vfunc_size_allocate(width, height, baseline) {
@@ -967,23 +972,32 @@ export class MapView extends Gtk.Overlay {
 
         let event = gesture.get_current_event();
         if (event.triggers_context_menu()) {
-            let viewport = this.map.viewport;
-            let rect = new Gdk.Rectangle({ x: x, y: y, width: 0, height: 0 });
+            this._showContextMenuAt(x, y);
+            gesture.set_state(Gtk.EventSequenceState.CLAIMED);
+        }
 
-            [this._latitude, this._longitude] = viewport.widget_coords_to_location(this, x, y);
+        gesture.set_state(Gtk.EventSequenceState.DENIED);
+    }
 
-            if (this.direction === Gtk.TextDirection.RTL) {
-                this._contextMenu.halign = Gtk.Align.END;
-            } else {
-                this._contextMenu.halign = Gtk.Align.START;
-            }
+    _onLongPressGesturePressed(gesture, x, y) {
+        this._showContextMenuAt(x, y);
+        gesture.set_state(Gtk.EventSequenceState.CLAIMED);
+    }
 
-            this._contextMenu.pointing_to = rect;
-            this._contextMenu.popup();
-            gesture.set_state(Gtk.EventSequenceState.CLAIMED);
+    _showContextMenuAt(x, y) {
+        let viewport = this.map.viewport;
+        let rect = new Gdk.Rectangle({ x: x, y: y, width: 0, height: 0 });
+
+        [this._latitude, this._longitude] = viewport.widget_coords_to_location(this, x, y);
+
+        if (this.direction === Gtk.TextDirection.RTL) {
+            this._contextMenu.halign = Gtk.Align.END;
+        } else {
+            this._contextMenu.halign = Gtk.Align.START;
         }
 
-        gesture.set_state(Gtk.EventSequenceState.DENIED);
+        this._contextMenu.pointing_to = rect;
+        this._contextMenu.popup();
     }
 
     _onRouteFromHereActivated() {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]