[gnome-shell] overviewControls: Use specialized class for Overview adjustment



commit 83127bf805cd56da09fb4b944881913afbb7567a
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Jan 15 15:28:23 2021 -0300

    overviewControls: Use specialized class for Overview adjustment
    
    It'll be useful for the next commits to have a handy 'getState' method
    that calculates the progress of any particular transition.
    
    Move the St.Adjustment to a specialized subclass.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1624>

 js/ui/overviewControls.js | 52 +++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 46 insertions(+), 6 deletions(-)
---
diff --git a/js/ui/overviewControls.js b/js/ui/overviewControls.js
index c0998983b1..64edcd7631 100644
--- a/js/ui/overviewControls.js
+++ b/js/ui/overviewControls.js
@@ -75,6 +75,51 @@ class ControlsManagerLayout extends Clutter.BoxLayout {
     }
 });
 
+var OverviewAdjustment = GObject.registerClass(
+class OverviewAdjustment extends St.Adjustment {
+    _init(actor) {
+        super._init({
+            actor,
+            value: ControlsState.WINDOW_PICKER,
+            lower: ControlsState.HIDDEN,
+            upper: ControlsState.APP_GRID,
+        });
+    }
+
+    getStateTransitionParams() {
+        const currentState = this.value;
+
+        const transition = this.get_transition('value');
+        let initialState = transition
+            ? transition.get_interval().peek_initial_value()
+            : currentState;
+        let finalState = transition
+            ? transition.get_interval().peek_final_value()
+            : currentState;
+
+        if (initialState > finalState) {
+            initialState = Math.ceil(initialState);
+            finalState = Math.floor(finalState);
+        } else {
+            initialState = Math.floor(initialState);
+            finalState = Math.ceil(finalState);
+        }
+
+        const length = Math.abs(finalState - initialState);
+        const progress = length > 0
+            ? Math.abs((currentState - initialState) / length)
+            : 1;
+
+        return {
+            transitioning: transition !== null,
+            currentState,
+            initialState,
+            finalState,
+            progress,
+        };
+    }
+});
+
 var ControlsManager = GObject.registerClass(
 class ControlsManager extends St.Widget {
     _init() {
@@ -118,12 +163,7 @@ class ControlsManager extends St.Widget {
             upper: workspaceManager.n_workspaces,
         });
 
-        this._stateAdjustment = new St.Adjustment({
-            actor: this,
-            value: ControlsState.WINDOW_PICKER,
-            lower: ControlsState.HIDDEN,
-            upper: ControlsState.APP_GRID,
-        });
+        this._stateAdjustment = new OverviewAdjustment(this);
 
         this._nWorkspacesNotifyId =
             workspaceManager.connect('notify::n-workspaces',


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