[gnome-shell/wip/exalm/gestures: 38/47] workspacesView: Use SwipeTracker
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/exalm/gestures: 38/47] workspacesView: Use SwipeTracker
- Date: Mon, 5 Aug 2019 12:16:01 +0000 (UTC)
commit ba8bbfd53cd7ab051357241e8078bea0eef7dd8b
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Mon Jul 8 13:47:04 2019 +0500
workspacesView: Use SwipeTracker
Replace existing panning, touchpad scrolling and four-finger gesture by
SwipeTracker.
Change programmatic workspace animation to use easeOutCubic interpolator
to match the gesture.
Also change the dragging distance to always match the current monitor.
Fixes touchpad parts of https://gitlab.gnome.org/GNOME/gnome-shell/issues/1338
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/605
js/ui/workspacesView.js | 196 ++++++++++++++++++++++--------------------------
1 file changed, 88 insertions(+), 108 deletions(-)
---
diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js
index 7c4acb217..a4ecf4a5d 100644
--- a/js/ui/workspacesView.js
+++ b/js/ui/workspacesView.js
@@ -5,8 +5,8 @@ const { Clutter, Gio, GObject, Meta, Shell, St } = imports.gi;
const Signals = imports.signals;
const Main = imports.ui.main;
+const SwipeTracker = imports.ui.swipeTracker;
const Tweener = imports.ui.tweener;
-const WindowManager = imports.ui.windowManager;
const Workspace = imports.ui.workspace;
var WORKSPACE_SWITCH_TIME = 0.25;
@@ -83,7 +83,6 @@ var WorkspacesView = class extends WorkspacesViewBase {
super(monitorIndex);
this._animating = false; // tweening
- this._scrolling = false; // swipe-scrolling
this._gestureActive = false; // touch(pad) gestures
this._workspaces = [];
@@ -159,7 +158,7 @@ var WorkspacesView = class extends WorkspacesViewBase {
let workspaceManager = global.workspace_manager;
let active = workspaceManager.get_active_workspace_index();
- this.updateWorkspaceActors(true);
+ this.updateWorkspaceActors(!this._gestureActive);
}
// Update workspace actors parameters
@@ -186,7 +185,7 @@ var WorkspacesView = class extends WorkspacesViewBase {
if (showAnimation) {
let tweenParams = Object.assign(params, {
time: WORKSPACE_SWITCH_TIME,
- transition: 'easeOutQuad'
+ transition: 'easeOutCubic'
});
// we have to call _updateVisibility() once before the
// animation and once afterwards - it does not really
@@ -213,7 +212,7 @@ var WorkspacesView = class extends WorkspacesViewBase {
for (let w = 0; w < this._workspaces.length; w++) {
let workspace = this._workspaces[w];
- if (this._animating || this._scrolling || this._gestureActive) {
+ if (this._animating || this._gestureActive) {
workspace.actor.show();
} else {
if (this._inDrag)
@@ -263,17 +262,6 @@ var WorkspacesView = class extends WorkspacesViewBase {
workspaceManager.disconnect(this._reorderWorkspacesId);
}
- startSwipeScroll() {
- this._scrolling = true;
- }
-
- endSwipeScroll() {
- this._scrolling = false;
-
- // Make sure title captions etc are shown as necessary
- this._updateVisibility();
- }
-
startTouchGesture() {
this._gestureActive = true;
}
@@ -388,12 +376,6 @@ var ExtraWorkspaceView = class extends WorkspacesViewBase {
updateWorkspaceActors(_showAnimation) {
}
- startSwipeScroll() {
- }
-
- endSwipeScroll() {
- }
-
startTouchGesture() {
}
@@ -418,8 +400,6 @@ var WorkspacesDisplay = class {
this.actor.connect('notify::allocation', this._updateWorkspacesActualGeometry.bind(this));
this.actor.connect('parent-set', this._parentSet.bind(this));
- let workspaceManager = global.workspace_manager;
- let activeWorkspaceIndex = workspaceManager.get_active_workspace_index();
this._scrollAdjustment = adjustment;
this._scrollAdjustment.connect('notify::value',
@@ -441,50 +421,22 @@ var WorkspacesDisplay = class {
});
Main.overview.addAction(clickAction);
this.actor.bind_property('mapped', clickAction, 'enabled', GObject.BindingFlags.SYNC_CREATE);
-
- let panAction = new Clutter.PanAction({ trigger_edge: Clutter.TriggerEdge.AFTER });
- panAction.connect('pan', this._onPan.bind(this));
- panAction.connect('gesture-begin', () => {
- if (this._workspacesOnlyOnPrimary) {
- let event = Clutter.get_current_event();
- if (this._getMonitorIndexForEvent(event) != this._primaryIndex)
- return false;
- }
-
- this._startSwipeScroll();
- return true;
- });
- panAction.connect('gesture-cancel', () => {
- clickAction.release();
- this._endSwipeScroll();
- });
- panAction.connect('gesture-end', () => {
- clickAction.release();
- this._endSwipeScroll();
- });
- Main.overview.addAction(panAction);
- this.actor.bind_property('mapped', panAction, 'enabled', GObject.BindingFlags.SYNC_CREATE);
+ this._clickAction = clickAction;
let allowedModes = Shell.ActionMode.OVERVIEW;
- let switchGesture = new WindowManager.WorkspaceSwitchAction(allowedModes);
- switchGesture.connect('motion', this._onSwitchWorkspaceMotion.bind(this));
- switchGesture.connect('activated', this._onSwitchWorkspaceActivated.bind(this));
- switchGesture.connect('cancel', this._endTouchGesture.bind(this));
- Main.overview.addAction(switchGesture);
- this.actor.bind_property('mapped', switchGesture, 'enabled', GObject.BindingFlags.SYNC_CREATE);
-
- switchGesture = new WindowManager.TouchpadWorkspaceSwitchAction(global.stage, allowedModes);
- switchGesture.connect('motion', this._onSwitchWorkspaceMotion.bind(this));
- switchGesture.connect('activated', this._onSwitchWorkspaceActivated.bind(this));
- switchGesture.connect('cancel', this._endTouchGesture.bind(this));
+ let swipeTracker = new SwipeTracker.SwipeTracker(Main.layoutManager.overviewGroup, allowedModes);
+ swipeTracker.connect('begin', this._switchWorkspaceBegin.bind(this));
+ swipeTracker.connect('update', this._switchWorkspaceUpdate.bind(this));
+ swipeTracker.connect('end', this._switchWorkspaceEnd.bind(this));
this.actor.connect('notify::mapped', () => {
- switchGesture.enabled = this.actor.mapped;
+ swipeTracker.enabled = this.actor.mapped;
});
+ swipeTracker.enabled = this.actor.mapped;
+
this._primaryIndex = Main.layoutManager.primaryIndex;
this._workspacesViews = [];
- switchGesture.enabled = this.actor.mapped;
this._settings = new Gio.Settings({ schema_id: MUTTER_SCHEMA });
this._settings.connect('changed::workspaces-only-on-primary',
@@ -498,13 +450,12 @@ var WorkspacesDisplay = class {
this._fullGeometry = null;
- this._scrolling = false; // swipe-scrolling
this._gestureActive = false; // touch(pad) gestures
this._animatingScroll = false; // programmatically updating the adjustment
}
_activeWorkspaceChanged(_wm, _from, _to, _direction) {
- if (this._scrolling)
+ if (this._gestureActive)
return;
this._scrollToActive();
@@ -521,7 +472,7 @@ var WorkspacesDisplay = class {
}
_updateScrollAdjustment(index) {
- if (this._scrolling || this._gestureActive)
+ if (this._gestureActive)
return;
this._animatingScroll = true;
@@ -529,75 +480,103 @@ var WorkspacesDisplay = class {
Tweener.addTween(this._scrollAdjustment, {
value: index,
time: WORKSPACE_SWITCH_TIME,
- transition: 'easeOutQuad',
+ transition: 'easeOutCubic',
onComplete: () => {
this._animatingScroll = false;
}
});
}
- _onPan(action) {
- let [dist_, dx, dy] = action.get_motion_delta(0);
- let adjustment = this._scrollAdjustment;
+ _directionForProgress(progress) {
if (global.workspace_manager.layout_rows == -1)
- adjustment.value -= (dy / this.actor.height) * adjustment.page_size;
+ return (progress > 0) ? Meta.MotionDirection.DOWN : Meta.MotionDirection.UP;
else if (this.actor.text_direction == Clutter.TextDirection.RTL)
- adjustment.value += (dx / this.actor.width) * adjustment.page_size;
+ return (progress > 0) ? Meta.MotionDirection.LEFT : Meta.MotionDirection.RIGHT;
else
- adjustment.value -= (dx / this.actor.width) * adjustment.page_size;
- return false;
+ return (progress > 0) ? Meta.MotionDirection.RIGHT : Meta.MotionDirection.LEFT;
}
- _startSwipeScroll() {
- for (let i = 0; i < this._workspacesViews.length; i++)
- this._workspacesViews[i].startSwipeScroll();
- this._scrolling = true;
- }
+ _switchWorkspaceBegin(tracker, monitor) {
+ if (this._workspacesOnlyOnPrimary && monitor != this._primaryIndex)
+ return;
- _endSwipeScroll() {
- for (let i = 0; i < this._workspacesViews.length; i++)
- this._workspacesViews[i].endSwipeScroll();
- this._scrolling = false;
- this._scrollToActive();
- }
+ let adjustment = this._scrollAdjustment;
+ if (this._gestureActive)
+ Tweener.removeTweens(adjustment);
+
+ let horiz = (global.workspace_manager.layout_rows != -1);
+ tracker.orientation = horiz ? Clutter.Orientation.HORIZONTAL : Clutter.Orientation.VERTICAL;
- _startTouchGesture() {
for (let i = 0; i < this._workspacesViews.length; i++)
this._workspacesViews[i].startTouchGesture();
- this._gestureActive = true;
- }
- _endTouchGesture() {
- for (let i = 0; i < this._workspacesViews.length; i++)
- this._workspacesViews[i].endTouchGesture();
- this._gestureActive = false;
- this._scrollToActive();
- }
+ let workspaceManager = global.workspace_manager;
+ let activeWs = workspaceManager.get_active_workspace();
+
+ let monitors = Main.layoutManager.monitors;
+ let geometry = (monitor == this._primaryIndex) ? this._fullGeometry : monitors[monitor];
+ let distance = (global.workspace_manager.layout_rows == -1) ? geometry.height : geometry.width;
+
+ let progress = adjustment.value / adjustment.page_size - activeWs.index();
+ let points = [];
- _onSwitchWorkspaceMotion(action, xRel, yRel) {
- // We don't have a way to hook into start of touchpad actions,
- // luckily this is safe to call repeatedly.
- this._startTouchGesture();
+ let dir = this._directionForProgress(-1);
+ if (activeWs.get_neighbor(dir) != activeWs)
+ points.push(-1);
+ points.push(0);
+
+ dir = this._directionForProgress(1);
+ if (activeWs.get_neighbor(dir) != activeWs)
+ points.push(1);
+
+ tracker.confirmSwipe(distance, points, progress, 0);
+
+ this._gestureActive = true;
+ }
+
+ _switchWorkspaceUpdate(_tracker, progress) {
let workspaceManager = global.workspace_manager;
let active = workspaceManager.get_active_workspace_index();
let adjustment = this._scrollAdjustment;
- if (workspaceManager.layout_rows == -1)
- adjustment.value = (active - yRel / this.actor.height) * adjustment.page_size;
- else if (this.actor.text_direction == Clutter.TextDirection.RTL)
- adjustment.value = (active + xRel / this.actor.width) * adjustment.page_size;
- else
- adjustment.value = (active - xRel / this.actor.width) * adjustment.page_size;
+ adjustment.value = (active + progress) * adjustment.page_size;
}
- _onSwitchWorkspaceActivated(action, direction) {
+ _switchWorkspaceEnd(_tracker, duration, endProgress) {
+ this._clickAction.release();
+
let workspaceManager = global.workspace_manager;
let activeWorkspace = workspaceManager.get_active_workspace();
- let newWs = activeWorkspace.get_neighbor(direction);
- if (newWs != activeWorkspace)
- newWs.activate(global.get_current_time());
+ let newWs = activeWorkspace;
+ if (endProgress != 0) {
+ let direction = this._directionForProgress(endProgress);
+ newWs = activeWorkspace.get_neighbor(direction);
+ }
+
+ if (duration == 0) {
+ if (newWs != activeWorkspace)
+ newWs.activate(global.get_current_time());
+
+ this._endTouchGesture();
+ return;
+ }
+
+ let active = workspaceManager.get_active_workspace_index();
+ Tweener.addTween(this._scrollAdjustment,
+ { value: active + endProgress,
+ time: duration,
+ transition: 'easeOutCubic',
+ onComplete: () => {
+ if (newWs != activeWorkspace)
+ newWs.activate(global.get_current_time());
+ this._endTouchGesture();
+ } });
+ }
- this._endTouchGesture();
+ _endTouchGesture() {
+ for (let i = 0; i < this._workspacesViews.length; i++)
+ this._workspacesViews[i].endTouchGesture();
+ this._gestureActive = false;
}
navigateFocus(from, direction) {
@@ -677,8 +656,6 @@ var WorkspacesDisplay = class {
else
view = new WorkspacesView(i);
- view.actor.connect('scroll-event', this._onScrollEvent.bind(this));
-
// HACK: Avoid spurious allocation changes while updating views
view.actor.hide();
@@ -782,6 +759,9 @@ var WorkspacesDisplay = class {
}
_onScrollEvent(actor, event) {
+ if (event.get_scroll_source() == Clutter.ScrollSource.FINGER ||
event.get_source_device().get_device_type() == Clutter.InputDeviceType.TOUCHPAD_DEVICE) // TODO: remove this
and handle it in SwipeTracker too
+ return Clutter.EVENT_PROPAGATE;
+
if (!this.actor.mapped)
return Clutter.EVENT_PROPAGATE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]