[gnome-shell/wip/exalm/gestures-part-3: 23/31] workspaceThumbnail: Use scroll adjustment



commit cf39b600cbf0b582df75187c03ad68a3d0a363ef
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Jun 28 01:51:10 2019 +0500

    workspaceThumbnail: Use scroll adjustment
    
    This will allow it to share adjustment with WorkspacesDisplay in the next
    commit.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/821

 js/ui/workspaceThumbnail.js | 77 ++++++++++++++++++++++++---------------------
 1 file changed, 42 insertions(+), 35 deletions(-)
---
diff --git a/js/ui/workspaceThumbnail.js b/js/ui/workspaceThumbnail.js
index d9c7723dd9..53cd513c9e 100644
--- a/js/ui/workspaceThumbnail.js
+++ b/js/ui/workspaceThumbnail.js
@@ -658,7 +658,6 @@ var ThumbnailsBox = GObject.registerClass({
         this._pendingScaleUpdate = false;
         this._stateUpdateQueued = false;
         this._animatingIndicator = false;
-        this._indicatorY = 0; // only used when _animatingIndicator is true
 
         this._stateCounts = {};
         for (let key in ThumbnailState)
@@ -701,6 +700,21 @@ var ThumbnailsBox = GObject.registerClass({
         this._nWorkspacesNotifyId = 0;
         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.connect('notify::value', adj => {
+            this.queue_relayout();
+        });
     }
 
     _updateSwitcherVisibility() {
@@ -968,6 +982,8 @@ 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 {
@@ -1056,21 +1072,6 @@ var ThumbnailsBox = GObject.registerClass({
         return this._scale;
     }
 
-    // eslint-disable-next-line camelcase
-    set indicator_y(indicatorY) {
-        if (this._indicatorY == indicatorY)
-            return;
-
-        this._indicatorY = indicatorY;
-        this.notify('indicator-y');
-        this.queue_relayout();
-    }
-
-    // eslint-disable-next-line camelcase
-    get indicator_y() {
-        return this._indicatorY;
-    }
-
     _setThumbnailState(thumbnail, state) {
         this._stateCounts[thumbnail.state]--;
         thumbnail.state = state;
@@ -1263,13 +1264,16 @@ var ThumbnailsBox = GObject.registerClass({
         else
             slideOffset = thumbnailWidth + themeNode.get_padding(St.Side.RIGHT);
 
-        let indicatorY1 = this._indicatorY;
-        let indicatorY2;
-        // when not animating, the workspace position overrides this._indicatorY
-        let activeWorkspace = workspaceManager.get_active_workspace();
-        let indicatorWorkspace = !this._animatingIndicator ? activeWorkspace : null;
-        let indicatorThemeNode = this._indicator.get_theme_node();
+        let indicatorValue = this._scrollAdjustment.value;
+        let indicatorUpperWs = Math.ceil(indicatorValue);
+        let indicatorLowerWs = Math.floor(indicatorValue);
 
+        let indicatorLowerY1 = 0;
+        let indicatorLowerY2 = 0;
+        let indicatorUpperY1 = 0;
+        let indicatorUpperY2 = 0;
+
+        let indicatorThemeNode = this._indicator.get_theme_node();
         let indicatorTopFullBorder = indicatorThemeNode.get_padding(St.Side.TOP) + 
indicatorThemeNode.get_border_width(St.Side.TOP);
         let indicatorBottomFullBorder = indicatorThemeNode.get_padding(St.Side.BOTTOM) + 
indicatorThemeNode.get_border_width(St.Side.BOTTOM);
         let indicatorLeftFullBorder = indicatorThemeNode.get_padding(St.Side.LEFT) + 
indicatorThemeNode.get_border_width(St.Side.LEFT);
@@ -1321,9 +1325,13 @@ var ThumbnailsBox = GObject.registerClass({
             let y2 = Math.round(y + thumbnailHeight);
             let roundedVScale = (y2 - y1) / portholeHeight;
 
-            if (thumbnail.metaWorkspace == indicatorWorkspace) {
-                indicatorY1 = y1;
-                indicatorY2 = y2;
+            if (i == indicatorUpperWs) {
+                indicatorUpperY1 = y1;
+                indicatorUpperY2 = y2;
+            }
+            if (i == indicatorLowerWs) {
+                indicatorLowerY1 = y1;
+                indicatorLowerY2 = y2;
             }
 
             // Allocating a scaled actor is funny - x1/y1 correspond to the origin
@@ -1349,23 +1357,22 @@ var ThumbnailsBox = GObject.registerClass({
             childBox.x1 = box.x2 - thumbnailWidth;
             childBox.x2 = box.x2;
         }
+        let indicatorY1 = indicatorLowerY1 +
+            (indicatorUpperY1 - indicatorLowerY1) * (indicatorValue % 1);
+        let indicatorY2 = indicatorLowerY2 +
+            (indicatorUpperY2 - indicatorLowerY2) * (indicatorValue % 1);
+
         childBox.x1 -= indicatorLeftFullBorder;
         childBox.x2 += indicatorRightFullBorder;
         childBox.y1 = indicatorY1 - indicatorTopFullBorder;
-        childBox.y2 = (indicatorY2 ? indicatorY2 : indicatorY1 + thumbnailHeight) + 
indicatorBottomFullBorder;
+        childBox.y2 = indicatorY2 + indicatorBottomFullBorder;
         this._indicator.allocate(childBox, flags);
     }
 
-    _activeWorkspaceChanged(_wm, _from, _to, _direction) {
-        let workspaceManager = global.workspace_manager;
-        let activeWorkspace = workspaceManager.get_active_workspace();
-        let thumbnail = this._thumbnails.find(t => t.metaWorkspace == activeWorkspace);
-
+    _activeWorkspaceChanged(_wm, from, to, _direction) {
+        this._scrollAdjustment.value = from;
         this._animatingIndicator = true;
-        let indicatorThemeNode = this._indicator.get_theme_node();
-        let indicatorTopFullBorder = indicatorThemeNode.get_padding(St.Side.TOP) + 
indicatorThemeNode.get_border_width(St.Side.TOP);
-        this.indicator_y = this._indicator.allocation.y1 + indicatorTopFullBorder;
-        this.ease_property('indicator-y', thumbnail.allocation.y1, {
+        this._scrollAdjustment.ease(to, {
             progress_mode: Clutter.AnimationMode.EASE_OUT_QUAD,
             duration: WorkspacesView.WORKSPACE_SWITCH_TIME,
             onComplete: () => {


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