[gnome-shell/wip/exalm/gestures-part-3: 24/31] workspaceThumbnail: Sync indicator with WorkspacesDisplay



commit 63c1371d8c165788be9b15a7a977511148f14c91
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Jul 8 13:03:20 2019 +0500

    workspaceThumbnail: Sync indicator with WorkspacesDisplay
    
    Now that both ThumbnailsBox and WorkspacesDisplay use single adjustments for
    controlling indicator and scrolling, create the adjustment in OverviewControls
    and pass it to both objects, effectively syncing indicator to scrolling.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/821

 js/ui/overviewControls.js   | 29 +++++++++++++++++++++++++++--
 js/ui/viewSelector.js       |  5 +++--
 js/ui/workspaceThumbnail.js | 39 +++++----------------------------------
 js/ui/workspacesView.js     | 22 ++--------------------
 4 files changed, 37 insertions(+), 58 deletions(-)
---
diff --git a/js/ui/overviewControls.js b/js/ui/overviewControls.js
index 687dc78887..d32ec124a6 100644
--- a/js/ui/overviewControls.js
+++ b/js/ui/overviewControls.js
@@ -436,11 +436,27 @@ class ControlsManager extends St.Widget {
         this._dashSpacer = new DashSpacer();
         this._dashSpacer.setDashActor(this._dashSlider);
 
-        this._thumbnailsBox = new WorkspaceThumbnail.ThumbnailsBox();
+        let workspaceManager = global.workspace_manager;
+        let activeWorkspaceIndex = workspaceManager.get_active_workspace_index();
+
+        this._workspaceAdjustment = 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._thumbnailsBox =
+            new WorkspaceThumbnail.ThumbnailsBox(this._workspaceAdjustment);
         this._thumbnailsSlider = new ThumbnailsSlider(this._thumbnailsBox);
 
         this.viewSelector = new ViewSelector.ViewSelector(searchEntry,
-                                                          this.dash.showAppsButton);
+            this._workspaceAdjustment, this.dash.showAppsButton);
         this.viewSelector.connect('page-changed', this._setVisibility.bind(this));
         this.viewSelector.connect('page-empty', this._onPageEmpty.bind(this));
 
@@ -459,6 +475,15 @@ class ControlsManager extends St.Widget {
         Main.overview.connect('showing', this._updateSpacerVisibility.bind(this));
     }
 
+    _updateWorkspaces() {
+        let workspaceManager = global.workspace_manager;
+        let newNumWorkspaces = workspaceManager.n_workspaces;
+
+        this._workspaceAdjustment.upper = newNumWorkspaces;
+        this._workspaceAdjustment.value =
+            workspaceManager.get_active_workspace_index();
+    }
+
     _updateWorkspacesGeometry() {
         let [x, y] = this.get_transformed_position();
         let [width, height] = this.get_transformed_size();
diff --git a/js/ui/viewSelector.js b/js/ui/viewSelector.js
index 3be94df24d..8acea0c03d 100644
--- a/js/ui/viewSelector.js
+++ b/js/ui/viewSelector.js
@@ -128,7 +128,7 @@ var ViewSelector = GObject.registerClass({
         'page-empty': {},
     },
 }, class ViewSelector extends Shell.Stack {
-    _init(searchEntry, showAppsButton) {
+    _init(searchEntry, workspaceAdjustment, showAppsButton) {
         super._init({
             name: 'viewSelector',
             x_expand: true,
@@ -171,7 +171,8 @@ var ViewSelector = GObject.registerClass({
         this._iconClickedId = 0;
         this._capturedEventId = 0;
 
-        this._workspacesDisplay = new WorkspacesView.WorkspacesDisplay();
+        this._workspacesDisplay =
+            new WorkspacesView.WorkspacesDisplay(workspaceAdjustment);
         this._workspacesPage = this._addPage(this._workspacesDisplay,
                                              _("Windows"), 'focus-windows-symbolic');
 
diff --git a/js/ui/workspaceThumbnail.js b/js/ui/workspaceThumbnail.js
index 53cd513c9e..382d6874dd 100644
--- a/js/ui/workspaceThumbnail.js
+++ b/js/ui/workspaceThumbnail.js
@@ -7,7 +7,6 @@ const Background = imports.ui.background;
 const DND = imports.ui.dnd;
 const Main = imports.ui.main;
 const Workspace = imports.ui.workspace;
-const WorkspacesView = imports.ui.workspacesView;
 
 // The maximum size of a thumbnail is 1/10 the width and height of the screen
 let MAX_THUMBNAIL_SCALE = 1 / 10.;
@@ -628,7 +627,7 @@ var ThumbnailsBox = GObject.registerClass({
             0, Infinity, 0),
     },
 }, class ThumbnailsBox extends St.Widget {
-    _init() {
+    _init(scrollAdjustment) {
         super._init({ reactive: true,
                       style_class: 'workspace-thumbnails',
                       request_mode: Clutter.RequestMode.WIDTH_FOR_HEIGHT });
@@ -701,18 +700,12 @@ var ThumbnailsBox = GObject.registerClass({
         this._syncStackingId = 0;
         this._workareasChangedId = 0;
 
-        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._scrollAdjustment = scrollAdjustment;
 
         this._scrollAdjustment.connect('notify::value', adj => {
+            this._animatingIndicator = (adj.value % 1) != 0;
+            if (!this._animatingIndicator)
+                this._queueUpdateStates();
             this.queue_relayout();
         });
     }
@@ -915,9 +908,6 @@ var ThumbnailsBox = GObject.registerClass({
     _createThumbnails() {
         let workspaceManager = global.workspace_manager;
 
-        this._switchWorkspaceNotifyId =
-            global.window_manager.connect('switch-workspace',
-                                          this._activeWorkspaceChanged.bind(this));
         this._nWorkspacesNotifyId =
             workspaceManager.connect('notify::n-workspaces',
                                      this._workspacesChanged.bind(this));
@@ -950,10 +940,6 @@ var ThumbnailsBox = GObject.registerClass({
         if (this._thumbnails.length == 0)
             return;
 
-        if (this._switchWorkspaceNotifyId > 0) {
-            global.window_manager.disconnect(this._switchWorkspaceNotifyId);
-            this._switchWorkspaceNotifyId = 0;
-        }
         if (this._nWorkspacesNotifyId > 0) {
             let workspaceManager = global.workspace_manager;
             workspaceManager.disconnect(this._nWorkspacesNotifyId);
@@ -982,8 +968,6 @@ var ThumbnailsBox = GObject.registerClass({
         let oldNumWorkspaces = validThumbnails.length;
         let newNumWorkspaces = workspaceManager.n_workspaces;
 
-        this._scrollAdjustment.upper = newNumWorkspaces;
-
         if (newNumWorkspaces > oldNumWorkspaces) {
             this.addThumbnails(oldNumWorkspaces, newNumWorkspaces - oldNumWorkspaces);
         } else {
@@ -1368,17 +1352,4 @@ var ThumbnailsBox = GObject.registerClass({
         childBox.y2 = indicatorY2 + indicatorBottomFullBorder;
         this._indicator.allocate(childBox, flags);
     }
-
-    _activeWorkspaceChanged(_wm, from, to, _direction) {
-        this._scrollAdjustment.value = from;
-        this._animatingIndicator = true;
-        this._scrollAdjustment.ease(to, {
-            progress_mode: Clutter.AnimationMode.EASE_OUT_QUAD,
-            duration: WorkspacesView.WORKSPACE_SWITCH_TIME,
-            onComplete: () => {
-                this._animatingIndicator = false;
-                this._queueUpdateStates();
-            },
-        });
-    }
 });
diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js
index 1d59c1638b..70288772d8 100644
--- a/js/ui/workspacesView.js
+++ b/js/ui/workspacesView.js
@@ -410,24 +410,13 @@ class ExtraWorkspaceView extends WorkspacesViewBase {
 
 var WorkspacesDisplay = GObject.registerClass(
 class WorkspacesDisplay extends St.Widget {
-    _init() {
+    _init(scrollAdjustment) {
         super._init({ clip_to_allocation: true });
         this.connect('notify::allocation', this._updateWorkspacesActualGeometry.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._scrollAdjustment = scrollAdjustment;
 
-        this._updateWorkspaces();
-        workspaceManager.connect('notify::n-workspaces',
-            this._updateWorkspaces.bind(this));
 
         global.window_manager.connect('switch-workspace',
             this._activeWorkspaceChanged.bind(this));
@@ -520,13 +509,6 @@ class WorkspacesDisplay extends St.Widget {
         }
     }
 
-    _updateWorkspaces() {
-        let workspaceManager = global.workspace_manager;
-        let newNumWorkspaces = workspaceManager.n_workspaces;
-
-        this._scrollAdjustment.upper = newNumWorkspaces;
-    }
-
     _workspacesReordered() {
         let workspaceManager = global.workspace_manager;
 


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