[gnome-shell/wip/jimmac/dash-icon-spacing: 37/72] workspacesView: Derive workspace mode from overview state




commit f780567099e08f21a09a48d2abb65b8c6eb357b7
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Jan 2 16:06:34 2021 -0300

    workspacesView: Derive workspace mode from overview state
    
    WorkspacesView uses the floating layout when the overview is in window
    picker mode, and the session layout when the overview is in app grid
    mode. Up until now, the snap axis adjustment was used to derive the
    workspace mode, but it is incomplete as it doesn't have the full range
    of workspace states.
    
    Make ViewSelector cascade the overview adjustment to WorkspacesDisplay,
    and use the overview adjustment itself to derive the workspace mode.
    
    Extra workspaces don't have to account for the snap axis, and thus are
    basically a clamp(state, 0, 1) of the overview state. However, don't
    call animateTo/FromOverview() anymore, since they ease the workspace
    mode adjustment.

 js/ui/viewSelector.js   | 10 +++++---
 js/ui/workspacesView.js | 67 +++++++++++++++++++++++++++++++++++++------------
 2 files changed, 58 insertions(+), 19 deletions(-)
---
diff --git a/js/ui/viewSelector.js b/js/ui/viewSelector.js
index 2c03a26712..774746923c 100644
--- a/js/ui/viewSelector.js
+++ b/js/ui/viewSelector.js
@@ -138,7 +138,12 @@ class AppsPageContainer extends St.Widget {
         });
 
         overviewAdjustment.connect('notify::value', () => {
-            this._adjustment.value = Math.max(overviewAdjustment.value - 1, 0);
+            const overviewState = overviewAdjustment.value;
+
+            this._appDisplay.visible =
+                overviewState >= OverviewControls.ControlsState.WINDOW_PICKER;
+            this._adjustment.value = Math.max(overviewAdjustment.value -
+                OverviewControls.ControlsState.WINDOW_PICKER, 0);
         });
 
         this._appDisplay = appDisplay;
@@ -158,7 +163,6 @@ class AppsPageContainer extends St.Widget {
         const progress = this._adjustment.value;
 
         this._appDisplay.opacity = progress * 255;
-        this._appDisplay.visible = progress !== 0;
 
         const { snapAdjustment } = this._workspacesDisplay;
         snapAdjustment.value = 1 - progress;
@@ -242,7 +246,7 @@ var ViewSelector = GObject.registerClass({
         this._capturedEventId = 0;
 
         this._workspacesDisplay =
-            new WorkspacesView.WorkspacesDisplay(workspaceAdjustment);
+            new WorkspacesView.WorkspacesDisplay(workspaceAdjustment, overviewAdjustment);
         this.appDisplay = new AppDisplay.AppDisplay();
 
         const appsContainer = new AppsPageContainer(
diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js
index fa8decd0a7..f1e434d1bf 100644
--- a/js/ui/workspacesView.js
+++ b/js/ui/workspacesView.js
@@ -5,6 +5,7 @@ const { Clutter, Gio, GLib, GObject, Meta, Shell, St } = imports.gi;
 
 const Main = imports.ui.main;
 const SwipeTracker = imports.ui.swipeTracker;
+const OverviewControls = imports.ui.overviewControls;
 const Workspace = imports.ui.workspace;
 
 var { ANIMATION_TIME } = imports.ui.overview;
@@ -22,7 +23,7 @@ const WORKSPACE_HOVER_SCALE = 0.98;
 var WorkspacesViewBase = GObject.registerClass({
     GTypeFlags: GObject.TypeFlags.ABSTRACT,
 }, class WorkspacesViewBase extends St.Widget {
-    _init(monitorIndex) {
+    _init(monitorIndex, overviewAdjustment) {
         super._init({
             style_class: 'workspaces-view',
             clip_to_allocation: true,
@@ -37,6 +38,11 @@ var WorkspacesViewBase = GObject.registerClass({
         this._inDrag = false;
         this._windowDragBeginId = Main.overview.connect('window-drag-begin', this._dragBegin.bind(this));
         this._windowDragEndId = Main.overview.connect('window-drag-end', this._dragEnd.bind(this));
+
+        this._overviewAdjustment = overviewAdjustment;
+        this._overviewId = overviewAdjustment.connect('notify::value', () => {
+            this._updateWorkspaceMode();
+        });
     }
 
     _onDestroy() {
@@ -50,6 +56,10 @@ var WorkspacesViewBase = GObject.registerClass({
             Main.overview.disconnect(this._windowDragEndId);
             this._windowDragEndId = 0;
         }
+        if (this._overviewId > 0) {
+            this._overviewAdjustment.disconnect(this._overviewId);
+            delete this._overviewId;
+        }
     }
 
     _dragBegin() {
@@ -60,6 +70,9 @@ var WorkspacesViewBase = GObject.registerClass({
         this._inDrag = false;
     }
 
+    _updateWorkspaceMode() {
+    }
+
     vfunc_allocate(box) {
         this.set_allocation(box);
 
@@ -78,10 +91,10 @@ var WorkspacesViewBase = GObject.registerClass({
 
 var WorkspacesView = GObject.registerClass(
 class WorkspacesView extends WorkspacesViewBase {
-    _init(monitorIndex, scrollAdjustment, snapAdjustment) {
+    _init(monitorIndex, scrollAdjustment, snapAdjustment, overviewAdjustment) {
         let workspaceManager = global.workspace_manager;
 
-        super._init(monitorIndex);
+        super._init(monitorIndex, overviewAdjustment);
         this.clip_to_allocation = true;
 
         this._snapAdjustment = snapAdjustment;
@@ -234,12 +247,26 @@ class WorkspacesView extends WorkspacesViewBase {
     }
 
     _updateWorkspacesState() {
+        const snapProgress = this._snapAdjustment.value;
+        const overviewState = this._overviewAdjustment.value;
+
+        const normalizedWorkspaceState = 1 - Math.min(1,
+            Math.abs(OverviewControls.ControlsState.WINDOW_PICKER - overviewState));
+        const workspaceMode = Math.interpolate(0, normalizedWorkspaceState, snapProgress);
+
         this._workspaces.forEach((w, index) => {
+            // Workspace mode
+            w.stateAdjustment.value = workspaceMode;
+
             // Fade and scale inactive workspaces
             this._updateWorkspacesScale(index);
         });
     }
 
+    _updateWorkspaceMode() {
+        this._updateWorkspacesState();
+    }
+
     vfunc_allocate(box) {
         this.set_allocation(box);
 
@@ -346,10 +373,6 @@ class WorkspacesView extends WorkspacesViewBase {
                     const index = this._workspaces.indexOf(workspace);
                     this._updateWorkspacesScale(index, true);
                 });
-
-                this._snapAdjustment.bind_property('value',
-                    workspace.stateAdjustment, 'value',
-                    GObject.BindingFlags.SYNC_CREATE);
             } else  {
                 workspace = this._workspaces[j];
 
@@ -431,22 +454,31 @@ class WorkspacesView extends WorkspacesViewBase {
 
 var ExtraWorkspaceView = GObject.registerClass(
 class ExtraWorkspaceView extends WorkspacesViewBase {
-    _init(monitorIndex) {
-        super._init(monitorIndex);
+    _init(monitorIndex, overviewAdjustment) {
+        super._init(monitorIndex, overviewAdjustment);
         this._workspace = new Workspace.Workspace(null, monitorIndex);
         this.add_actor(this._workspace);
     }
 
+    _updateWorkspaceMode() {
+        const overviewState = this._overviewAdjustment.value;
+
+        const progress = Math.clamp(overviewState,
+            OverviewControls.ControlsState.HIDDEN,
+            OverviewControls.ControlsState.WINDOW_PICKER);
+
+        this._workspace.stateAdjustment.value = progress;
+    }
+
     getActiveWorkspace() {
         return this._workspace;
     }
 
     animateToOverview() {
-        this._workspace.zoomToOverview();
     }
 
     animateFromOverview() {
-        this._workspace.zoomFromOverview();
+        this._workspace.prepareToLeaveOverview();
     }
 
     syncStacking(stackIndices) {
@@ -462,7 +494,7 @@ class ExtraWorkspaceView extends WorkspacesViewBase {
 
 var WorkspacesDisplay = GObject.registerClass(
 class WorkspacesDisplay extends St.Widget {
-    _init(scrollAdjustment) {
+    _init(scrollAdjustment, overviewAdjustment) {
         super._init({
             visible: false,
             y_expand: true,
@@ -470,6 +502,7 @@ class WorkspacesDisplay extends St.Widget {
             layout_manager: new Clutter.BinLayout(),
         });
 
+        this._overviewAdjustment = overviewAdjustment;
         this._snapAdjustment = new St.Adjustment({
             actor: this,
             value: Clutter.Orientation.VERTICAL,
@@ -770,10 +803,12 @@ class WorkspacesDisplay extends St.Widget {
         let monitors = Main.layoutManager.monitors;
         for (let i = 0; i < monitors.length; i++) {
             let view;
-            if (this._workspacesOnlyOnPrimary && i != this._primaryIndex)
-                view = new ExtraWorkspaceView(i);
-            else
-                view = new WorkspacesView(i, this._scrollAdjustment, this._snapAdjustment);
+            if (this._workspacesOnlyOnPrimary && i !== this._primaryIndex) {
+                view = new ExtraWorkspaceView(i, this._overviewAdjustment);
+            } else {
+                view = new WorkspacesView(i, this._scrollAdjustment,
+                    this._snapAdjustment, this._overviewAdjustment);
+            }
 
             this._workspacesViews.push(view);
 


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