[gnome-shell] slider: React to touch events



commit dbbf4097a5c0a94e8ab3687b1bd7cbc5dbd2dc81
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Jul 22 12:37:06 2014 +0200

    slider: React to touch events
    
    The slider locks to the first interacting sequence, and ignores events from
    any other.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733633

 js/ui/slider.js |   48 ++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 42 insertions(+), 6 deletions(-)
---
diff --git a/js/ui/slider.js b/js/ui/slider.js
index b81af36..383dca4 100644
--- a/js/ui/slider.js
+++ b/js/ui/slider.js
@@ -24,6 +24,7 @@ const Slider = new Lang.Class({
                                           accessible_role: Atk.Role.SLIDER });
         this.actor.connect('repaint', Lang.bind(this, this._sliderRepaint));
         this.actor.connect('button-press-event', Lang.bind(this, this._startDragging));
+        this.actor.connect('touch-event', Lang.bind(this, this._touchDragging));
         this.actor.connect('scroll-event', Lang.bind(this, this._onScrollEvent));
         this.actor.connect('key-press-event', Lang.bind(this, this.onKeyPressEvent));
 
@@ -121,11 +122,21 @@ const Slider = new Lang.Class({
         this._dragging = true;
 
         let device = event.get_device();
-        device.grab(this.actor);
+        let sequence = event.get_event_sequence();
+
+        if (sequence != null)
+            device.sequence_grab(sequence, this.actor);
+        else
+            device.grab(this.actor);
+
         this._grabbedDevice = device;
+        this._grabbedSequence = sequence;
+
+        if (sequence == null) {
+            this._releaseId = this.actor.connect('button-release-event', Lang.bind(this, this._endDragging));
+            this._motionId = this.actor.connect('motion-event', Lang.bind(this, this._motionEvent));
+        }
 
-        this._releaseId = this.actor.connect('button-release-event', Lang.bind(this, this._endDragging));
-        this._motionId = this.actor.connect('motion-event', Lang.bind(this, this._motionEvent));
         let absX, absY;
         [absX, absY] = event.get_coords();
         this._moveHandle(absX, absY);
@@ -134,10 +145,17 @@ const Slider = new Lang.Class({
 
     _endDragging: function() {
         if (this._dragging) {
-            this.actor.disconnect(this._releaseId);
-            this.actor.disconnect(this._motionId);
+            if (this._releaseId)
+                this.actor.disconnect(this._releaseId);
+            if (this._motionId)
+                this.actor.disconnect(this._motionId);
+
+            if (this._grabbedSequence != null)
+                this._grabbedDevice.sequence_ungrab(this._grabbedSequence);
+            else
+                this._grabbedDevice.ungrab();
 
-            this._grabbedDevice.ungrab();
+            this._grabbedSequence = null;
             this._grabbedDevice = null;
             this._dragging = false;
 
@@ -146,6 +164,24 @@ const Slider = new Lang.Class({
         return Clutter.EVENT_STOP;
     },
 
+    _touchDragging: function(actor, event) {
+        let device = event.get_device();
+        let sequence = event.get_event_sequence();
+
+        if (!this._dragging &&
+            event.type() == Clutter.EventType.TOUCH_BEGIN) {
+            this.startDragging(event);
+            return Clutter.EVENT_STOP;
+        } else if (device.sequence_get_grabbed_actor(sequence) == actor) {
+            if (event.type() == Clutter.EventType.TOUCH_UPDATE)
+                return this._motionEvent(actor, event);
+            else if (event.type() == Clutter.EventType.TOUCH_END)
+                return this._endDragging();
+        }
+
+        return Clutter.EVENT_PROPAGATE;
+    },
+
     scroll: function(event) {
         let direction = event.get_scroll_direction();
         let delta;


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