[gnome-shell/gbsneto/40-stuff: 20/68] workspacesView: Center active workspace in allocation




commit 45fab8ac6bed85365a8ad91a6afdf82b1cf11ef5
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Dec 30 12:44:00 2020 -0300

    workspacesView: Center active workspace in allocation
    
    When vertically snapping, WorkspacesView currently allocates workspaces
    side-by-side, then applies an extra step of translation to center to
    the active workspace. This extra step is done in an idle timeout, to
    avoid a nasty pick-while-picking case. However, it also means that the
    translation can be out of sync with the current allocation state of
    workspaces, producing some bad visuals when running transitions.
    
    Move the translation of workspaces to the allocation code itself, and
    remove the extra translation step.

 js/ui/workspacesView.js | 51 ++++++++-----------------------------------------
 1 file changed, 8 insertions(+), 43 deletions(-)
---
diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js
index 47a32c636e..2a15ff7e2c 100644
--- a/js/ui/workspacesView.js
+++ b/js/ui/workspacesView.js
@@ -153,15 +153,22 @@ class WorkspacesView extends WorkspacesViewBase {
         const [width, height] = box.get_size();
         const [workspace] = this._workspaces;
 
+        const rtl = this.text_direction === Clutter.TextDirection.RTL;
+        const adj = this._scrollAdjustment;
+        const currentWorkspace = vertical || !rtl
+            ? adj.value : adj.upper - adj.value;
+
         // Snapped in the vertical axis also means horizontally centered
         let x1 = box.x1;
         let y1 = box.y1;
         if (vertical) {
             const [, workspaceHeight] = workspace.get_preferred_height(width);
             y1 += (height - workspaceHeight) / 2;
+            y1 -= currentWorkspace * (workspaceHeight + spacing);
         } else {
             const [, workspaceWidth] = workspace.get_preferred_width(height);
             x1 += (width - workspaceWidth) / 2;
+            x1 -= currentWorkspace * (workspaceWidth + spacing);
         }
 
         const verticalBox = new Clutter.ActorBox({ x1, y1 });
@@ -248,8 +255,6 @@ class WorkspacesView extends WorkspacesViewBase {
                     horizontalBox.y1);
             }
         });
-
-        this._updateScrollPosition();
     }
 
     getActiveWorkspace() {
@@ -261,7 +266,6 @@ class WorkspacesView extends WorkspacesViewBase {
     animateToOverview() {
         for (let w = 0; w < this._workspaces.length; w++)
             this._workspaces[w].zoomToOverview();
-        this._updateScrollPosition();
     }
 
     animateFromOverview() {
@@ -314,8 +318,6 @@ class WorkspacesView extends WorkspacesViewBase {
             this._workspaces[j].destroy();
             this._workspaces.splice(j, 1);
         }
-
-        this._updateScrollPosition();
     }
 
     _activeWorkspaceChanged(_wm, _from, _to, _direction) {
@@ -374,44 +376,7 @@ class WorkspacesView extends WorkspacesViewBase {
             metaWorkspace.activate(global.get_current_time());
         }
 
-        this._updateScrollPosition();
-    }
-
-    _updateScrollPosition() {
-        if (!this.has_allocation())
-            return;
-
-        const adj = this._scrollAdjustment;
-
-        if (adj.upper == 1)
-            return;
-
-        const workspaceManager = global.workspace_manager;
-        const vertical = workspaceManager.layout_rows === -1;
-        const rtl = this.text_direction === Clutter.TextDirection.RTL;
-        const snapProgress = this._snapAdjustment.value;
-        let progress = vertical || !rtl
-            ? adj.value : adj.upper - adj.value;
-        progress = progress / (adj.upper - 1) * snapProgress;
-
-        // Use workspaces geometry to determine the size to offset
-        const firstWorkspaceBox = rtl
-            ? this._workspaces[this._workspaces.length - 1].allocation
-            : this._workspaces[0].allocation;
-        const lastWorkspaceBox = rtl
-            ? this._workspaces[0].allocation
-            : this._workspaces[this._workspaces.length - 1].allocation;
-        const [workspaceWidth, workspaceHeight] = firstWorkspaceBox.get_size();
-        const size = vertical
-            ? lastWorkspaceBox.y2 - firstWorkspaceBox.y1 - workspaceHeight
-            : lastWorkspaceBox.x2 - firstWorkspaceBox.x1 - workspaceWidth;
-
-        for (const ws of this._workspaces) {
-            if (vertical)
-                ws.translation_y = -progress * size;
-            else
-                ws.translation_x = -progress * size;
-        }
+        this.queue_relayout();
     }
 });
 


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