[gnome-shell/wip/exalm/gestures: 1/16] workspacesView: Use shared adjustment
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/exalm/gestures: 1/16] workspacesView: Use shared adjustment
- Date: Wed, 16 Oct 2019 07:34:51 +0000 (UTC)
commit b1d15151a04b150c04f9dc912623b7f6a12de30a
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Sun Jul 7 22:51:55 2019 +0500
workspacesView: Use shared adjustment
Instead of having a scroll adjustment in each WorkspacesView, and using the
one from primary screen in WorkspacesDisplay, have just one adjustment in
WorkspacesDisplay, and sync the changes between WorkspacesView.
This will allow to share the adjustment between WorkspacesDisplay and
ThumbnailsBox in the next commits.
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/605
js/ui/workspacesView.js | 179 +++++++++++++++++++++++++++---------------------
1 file changed, 102 insertions(+), 77 deletions(-)
---
diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js
index 172d2d4905..19076df0b1 100644
--- a/js/ui/workspacesView.js
+++ b/js/ui/workspacesView.js
@@ -84,31 +84,12 @@ var WorkspacesView = class extends WorkspacesViewBase {
this._animating = false; // tweening
this._scrolling = false; // swipe-scrolling
this._gestureActive = false; // touch(pad) gestures
- this._animatingScroll = false; // programmatically updating the adjustment
-
- let activeWorkspaceIndex = workspaceManager.get_active_workspace_index();
- this.scrollAdjustment = new St.Adjustment({ value: activeWorkspaceIndex,
- lower: 0,
- page_increment: 1,
- page_size: 1,
- step_increment: 0,
- upper: workspaceManager.n_workspaces });
- this.scrollAdjustment.connect('notify::value',
- this._onScroll.bind(this));
this._workspaces = [];
this._updateWorkspaces();
this._updateWorkspacesId =
workspaceManager.connect('notify::n-workspaces',
this._updateWorkspaces.bind(this));
- this._reorderWorkspacesId =
- workspaceManager.connect('workspaces-reordered', () => {
- this._workspaces.sort((a, b) => {
- return a.metaWorkspace.index() - b.metaWorkspace.index();
- });
- this._updateWorkspaceActors(false);
- });
-
this._overviewShownId =
Main.overview.connect('shown', () => {
@@ -116,9 +97,6 @@ var WorkspacesView = class extends WorkspacesViewBase {
this._fullGeometry.width, this._fullGeometry.height);
});
- this._switchWorkspaceNotifyId =
- global.window_manager.connect('switch-workspace',
- this._activeWorkspaceChanged.bind(this));
}
_setReservedSlot(window) {
@@ -149,7 +127,7 @@ var WorkspacesView = class extends WorkspacesViewBase {
else
this._workspaces[w].fadeToOverview();
}
- this._updateWorkspaceActors(false);
+ this.updateWorkspaceActors(false);
}
animateFromOverview(animationType) {
@@ -169,16 +147,12 @@ var WorkspacesView = class extends WorkspacesViewBase {
}
_scrollToActive() {
- let workspaceManager = global.workspace_manager;
- let active = workspaceManager.get_active_workspace_index();
-
- this._updateWorkspaceActors(true);
- this._updateScrollAdjustment(active);
+ this.updateWorkspaceActors(true);
}
// Update workspace actors parameters
// @showAnimation: iff %true, transition between states
- _updateWorkspaceActors(showAnimation) {
+ updateWorkspaceActors(showAnimation) {
let workspaceManager = global.workspace_manager;
let active = workspaceManager.get_active_workspace_index();
@@ -238,25 +212,10 @@ var WorkspacesView = class extends WorkspacesViewBase {
}
}
- _updateScrollAdjustment(index) {
- if (this._scrolling || this._gestureActive)
- return;
-
- this._animatingScroll = true;
-
- this.scrollAdjustment.ease(index, {
- mode: Clutter.AnimationMode.EASE_OUT_QUAD,
- duration: WORKSPACE_SWITCH_TIME,
- onComplete: () => (this._animatingScroll = false)
- });
- }
-
_updateWorkspaces() {
let workspaceManager = global.workspace_manager;
let newNumWorkspaces = workspaceManager.n_workspaces;
- this.scrollAdjustment.upper = newNumWorkspaces;
-
for (let j = 0; j < newNumWorkspaces; j++) {
let metaWorkspace = workspaceManager.get_workspace_by_index(j);
let workspace;
@@ -276,29 +235,19 @@ var WorkspacesView = class extends WorkspacesViewBase {
}
if (this._fullGeometry) {
- this._updateWorkspaceActors(false);
+ this.updateWorkspaceActors(false);
this._syncFullGeometry();
}
if (this._actualGeometry)
this._syncActualGeometry();
}
- _activeWorkspaceChanged(_wm, _from, _to, _direction) {
- if (this._scrolling)
- return;
-
- this._scrollToActive();
- }
-
_onDestroy() {
super._onDestroy();
- this.scrollAdjustment.run_dispose();
Main.overview.disconnect(this._overviewShownId);
- global.window_manager.disconnect(this._switchWorkspaceNotifyId);
let workspaceManager = global.workspace_manager;
workspaceManager.disconnect(this._updateWorkspacesId);
- workspaceManager.disconnect(this._reorderWorkspacesId);
}
startSwipeScroll() {
@@ -309,7 +258,6 @@ var WorkspacesView = class extends WorkspacesViewBase {
this._scrolling = false;
// Make sure title captions etc are shown as necessary
- this._scrollToActive();
this._updateVisibility();
}
@@ -321,16 +269,12 @@ var WorkspacesView = class extends WorkspacesViewBase {
this._gestureActive = false;
// Make sure title captions etc are shown as necessary
- this._scrollToActive();
this._updateVisibility();
}
// sync the workspaces' positions to the value of the scroll adjustment
// and change the active workspace if appropriate
- _onScroll(adj) {
- if (this._animatingScroll)
- return;
-
+ onScroll(adj) {
let workspaceManager = global.workspace_manager;
let active = workspaceManager.get_active_workspace_index();
let current = Math.round(adj.value);
@@ -384,6 +328,13 @@ var WorkspacesView = class extends WorkspacesViewBase {
}
}
}
+
+ workspacesReordered() {
+ this._workspaces.sort((a, b) => {
+ return a.metaWorkspace.index() - b.metaWorkspace.index();
+ });
+ this.updateWorkspaceActors(false);
+ }
};
Signals.addSignalMethods(WorkspacesView.prototype);
@@ -428,6 +379,9 @@ var ExtraWorkspaceView = class extends WorkspacesViewBase {
this._workspace.syncStacking(stackIndices);
}
+ updateWorkspaceActors(_showAnimation) {
+ }
+
startSwipeScroll() {
}
@@ -439,6 +393,12 @@ var ExtraWorkspaceView = class extends WorkspacesViewBase {
endTouchGesture() {
}
+
+ onScroll(_adj) {
+ }
+
+ workspacesReordered() {
+ }
};
var DelegateFocusNavigator = GObject.registerClass(
@@ -455,6 +415,27 @@ 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 = new St.Adjustment({ value: activeWorkspaceIndex,
+ lower: 0,
+ page_increment: 1,
+ page_size: 1,
+ step_increment: 0,
+ upper: workspaceManager.n_workspaces });
+
+ this._updateWorkspaces();
+ workspaceManager.connect('notify::n-workspaces',
+ this._updateWorkspaces.bind(this));
+ this._scrollAdjustment.connect('notify::value',
+ this._scrollValueChanged.bind(this));
+
+ global.window_manager.connect('switch-workspace',
+ this._activeWorkspaceChanged.bind(this));
+
+ workspaceManager.connect('workspaces-reordered',
+ this._workspacesReordered.bind(this));
+
let clickAction = new Clutter.ClickAction();
clickAction.connect('clicked', action => {
// Only switch to the workspace when there's no application
@@ -525,6 +506,10 @@ var WorkspacesDisplay = class {
this._fullGeometry = null;
+ this._scrolling = false; // swipe-scrolling
+ this._gestureActive = false; // touch(pad) gestures
+ this._animatingScroll = false; // programmatically updating the adjustment
+
this.actor.connect('destroy', this._onDestroy.bind(this));
}
@@ -542,6 +527,52 @@ var WorkspacesDisplay = class {
}
}
+ _updateWorkspaces() {
+ let workspaceManager = global.workspace_manager;
+ let newNumWorkspaces = workspaceManager.n_workspaces;
+
+ this._scrollAdjustment.upper = newNumWorkspaces;
+ }
+
+ _workspacesReordered() {
+ let workspaceManager = global.workspace_manager;
+
+ for (let i = 0; i < this._workspacesViews.length; i++)
+ this._workspacesViews[i].workspacesReordered();
+
+ this._scrollAdjustment.value = workspaceManager.get_active_workspace_index();
+ }
+
+ _activeWorkspaceChanged(_wm, _from, _to, _direction) {
+ if (this._scrolling)
+ return;
+
+ this._scrollToActive();
+ }
+
+ _scrollToActive() {
+ let workspaceManager = global.workspace_manager;
+ let active = workspaceManager.get_active_workspace_index();
+
+ for (let i = 0; i < this._workspacesViews.length; i++)
+ this._workspacesViews[i].updateWorkspaceActors(true);
+
+ this._updateScrollAdjustment(active);
+ }
+
+ _updateScrollAdjustment(index) {
+ if (this._scrolling || this._gestureActive)
+ return;
+
+ this._animatingScroll = true;
+
+ this._scrollAdjustment.ease(index, {
+ mode: Clutter.AnimationMode.EASE_OUT_QUAD,
+ duration: WORKSPACE_SWITCH_TIME,
+ onComplete: () => (this._animatingScroll = false)
+ });
+ }
+
_onPan(action) {
let [dist_, dx, dy] = action.get_motion_delta(0);
let adjustment = this._scrollAdjustment;
@@ -557,21 +588,27 @@ var WorkspacesDisplay = class {
_startSwipeScroll() {
for (let i = 0; i < this._workspacesViews.length; i++)
this._workspacesViews[i].startSwipeScroll();
+ this._scrolling = true;
}
_endSwipeScroll() {
for (let i = 0; i < this._workspacesViews.length; i++)
this._workspacesViews[i].endSwipeScroll();
+ this._scrolling = false;
+ this._scrollToActive();
}
_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();
}
_onSwitchWorkspaceMotion(action, xRel, yRel) {
@@ -678,11 +715,6 @@ var WorkspacesDisplay = class {
view = new WorkspacesView(i);
view.actor.connect('scroll-event', this._onScrollEvent.bind(this));
- if (i == this._primaryIndex) {
- this._scrollAdjustment = view.scrollAdjustment;
- this._scrollAdjustment.connect('notify::value',
- this._scrollValueChanged.bind(this));
- }
// HACK: Avoid spurious allocation changes while updating views
view.actor.hide();
@@ -698,18 +730,11 @@ var WorkspacesDisplay = class {
}
_scrollValueChanged() {
- for (let i = 0; i < this._workspacesViews.length; i++) {
- if (i == this._primaryIndex)
- continue;
-
- let adjustment = this._workspacesViews[i].scrollAdjustment;
- if (!adjustment)
- continue;
+ if (this._animatingScroll)
+ return;
- // the adjustments work in terms of workspaces, so the
- // values map directly
- adjustment.value = this._scrollAdjustment.value;
- }
+ for (let i = 0; i < this._workspacesViews.length; i++)
+ this._workspacesViews[i].onScroll(this._scrollAdjustment);
}
_getMonitorIndexForEvent(event) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]