[gnome-shell/wip/exalm/gestures: 19/30] workspaceThumbnail: Sync indicator with WorkspacesDisplay



commit 9b3de7f5e3ef6bc59c7e7fed4f890ef9ef0e0b87
Author: Alexander Mikhaylenko <exalm7659 gmail com>
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/605

 js/ui/overviewControls.js   | 24 ++++++++++++++++++++++--
 js/ui/viewSelector.js       |  4 ++--
 js/ui/workspaceThumbnail.js | 37 +++++--------------------------------
 js/ui/workspacesView.js     | 19 ++-----------------
 4 files changed, 31 insertions(+), 53 deletions(-)
---
diff --git a/js/ui/overviewControls.js b/js/ui/overviewControls.js
index cf6fcf3a7..dd56d10e1 100644
--- a/js/ui/overviewControls.js
+++ b/js/ui/overviewControls.js
@@ -398,10 +398,23 @@ var ControlsManager = class {
         this._dashSpacer = new DashSpacer();
         this._dashSpacer.setDashActor(this._dashSlider.actor);
 
-        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.viewSelector = new ViewSelector.ViewSelector(searchEntry, this._workspaceAdjustment,
                                                           this.dash.showAppsButton);
         this.viewSelector.connect('page-changed', this._setVisibility.bind(this));
         this.viewSelector.connect('page-empty', this._onPageEmpty.bind(this));
@@ -437,6 +450,13 @@ var ControlsManager = class {
         });
     }
 
+    _updateWorkspaces() {
+        let workspaceManager = global.workspace_manager;
+        let newNumWorkspaces = workspaceManager.n_workspaces;
+
+        this._workspaceAdjustment.upper = newNumWorkspaces;
+    }
+
     _updateWorkspacesGeometry() {
         let [x, y] = this.actor.get_transformed_position();
         let [width, height] = this.actor.get_transformed_size();
diff --git a/js/ui/viewSelector.js b/js/ui/viewSelector.js
index 9567c6675..338fa9e9d 100644
--- a/js/ui/viewSelector.js
+++ b/js/ui/viewSelector.js
@@ -121,7 +121,7 @@ var ShowOverviewAction = GObject.registerClass({
 });
 
 var ViewSelector = class {
-    constructor(searchEntry, showAppsButton) {
+    constructor(searchEntry, workspaceAdjustment, showAppsButton) {
         this.actor = new Shell.Stack({ name: 'viewSelector' });
 
         this._showAppsButton = showAppsButton;
@@ -161,7 +161,7 @@ var ViewSelector = class {
         this._iconClickedId = 0;
         this._capturedEventId = 0;
 
-        this._workspacesDisplay = new WorkspacesView.WorkspacesDisplay();
+        this._workspacesDisplay = new WorkspacesView.WorkspacesDisplay(workspaceAdjustment);
         this._workspacesPage = this._addPage(this._workspacesDisplay.actor,
                                              _("Windows"), 'focus-windows-symbolic');
 
diff --git a/js/ui/workspaceThumbnail.js b/js/ui/workspaceThumbnail.js
index fac2281d6..9992b9bf4 100644
--- a/js/ui/workspaceThumbnail.js
+++ b/js/ui/workspaceThumbnail.js
@@ -596,7 +596,7 @@ Signals.addSignalMethods(WorkspaceThumbnail.prototype);
 
 var ThumbnailsBox = GObject.registerClass(
 class ThumbnailsBox extends St.Widget {
-    _init() {
+    _init(adjustment) {
         super._init({ reactive: true,
                       style_class: 'workspace-thumbnails',
                       request_mode: Clutter.RequestMode.WIDTH_FOR_HEIGHT });
@@ -673,16 +673,12 @@ class ThumbnailsBox extends St.Widget {
         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 = adjustment;
 
         this._scrollAdjustment.connect('notify::value', adj => {
+            this._animatingIndicator = (adj.value % 1) != 0;
+            if (!this._animatingIndicator)
+                this._queueUpdateStates();
             this.queue_relayout();
         });
     }
@@ -872,9 +868,6 @@ class ThumbnailsBox extends St.Widget {
     _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));
@@ -907,10 +900,6 @@ class ThumbnailsBox extends St.Widget {
         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);
@@ -939,8 +928,6 @@ class ThumbnailsBox extends St.Widget {
         let oldNumWorkspaces = validThumbnails.length;
         let newNumWorkspaces = workspaceManager.n_workspaces;
 
-        this._scrollAdjustment.upper = newNumWorkspaces;
-
         if (newNumWorkspaces > oldNumWorkspaces) {
             this.addThumbnails(oldNumWorkspaces, newNumWorkspaces - oldNumWorkspaces);
         } else {
@@ -1326,18 +1313,4 @@ class ThumbnailsBox extends St.Widget {
         childBox.y2 = indicatorY2 + indicatorBottomFullBorder;
         this._indicator.allocate(childBox, flags);
     }
-
-    _activeWorkspaceChanged(_wm, from, to, _direction) {
-        this._scrollAdjustment.value = from;
-        this._animatingIndicator = true;
-        Tweener.addTween(this._scrollAdjustment,
-                         { value: to,
-                           time: WorkspacesView.WORKSPACE_SWITCH_TIME / 1000,
-                           transition: 'easeOutQuad',
-                           onComplete: () => {
-                               this._animatingIndicator = false;
-                               this._queueUpdateStates();
-                           }
-                         });
-    }
 });
diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js
index 565f4f955..a327e686d 100644
--- a/js/ui/workspacesView.js
+++ b/js/ui/workspacesView.js
@@ -412,7 +412,7 @@ class DelegateFocusNavigator extends St.Widget {
 });
 
 var WorkspacesDisplay = class {
-    constructor() {
+    constructor(adjustment) {
         this.actor = new DelegateFocusNavigator({ clip_to_allocation: true });
         this.actor._delegate = this;
         this.actor.connect('notify::allocation', this._updateWorkspacesActualGeometry.bind(this));
@@ -420,16 +420,8 @@ var WorkspacesDisplay = class {
 
         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 = adjustment;
 
-        this._updateWorkspaces();
-        workspaceManager.connect('notify::n-workspaces',
-                                 this._updateWorkspaces.bind(this));
         this._scrollAdjustment.connect('notify::value',
                                        this._scrollValueChanged.bind(this));
 
@@ -511,13 +503,6 @@ var WorkspacesDisplay = class {
         this._animatingScroll = false; // programmatically updating the adjustment
     }
 
-    _updateWorkspaces() {
-        let workspaceManager = global.workspace_manager;
-        let newNumWorkspaces = workspaceManager.n_workspaces;
-
-        this._scrollAdjustment.upper = newNumWorkspaces;
-    }
-
     _activeWorkspaceChanged(_wm, _from, _to, _direction) {
         if (this._scrolling)
             return;


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