[gnome-shell/gbsneto/40-stuff: 60/68] overviewControls: Use specialized class for Overview adjustment




commit 39d2ade3b3ef6607bec0793284769bfce393a721
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.

 js/ui/overviewControls.js | 46 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 40 insertions(+), 6 deletions(-)
---
diff --git a/js/ui/overviewControls.js b/js/ui/overviewControls.js
index 7b70872322..83182049a7 100644
--- a/js/ui/overviewControls.js
+++ b/js/ui/overviewControls.js
@@ -112,6 +112,45 @@ class ControlsManagerLayout extends Clutter.BinLayout {
     }
 });
 
+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,
+        });
+    }
+
+    getState() {
+        const state = this.value;
+
+        const transition = this.get_transition('value');
+        let initialState = transition
+            ? transition.get_interval().peek_initial_value()
+            : state;
+        let finalState = transition
+            ? transition.get_interval().peek_final_value()
+            : state;
+
+        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((state - initialState) / length)
+            : 1;
+
+        return [state, initialState, finalState, progress];
+    }
+});
+
 var ControlsManager = GObject.registerClass(
 class ControlsManager extends St.Widget {
     _init() {
@@ -156,12 +195,7 @@ class ControlsManager extends St.Widget {
             upper: workspaceManager.n_workspaces,
         });
 
-        this._adjustment = new St.Adjustment({
-            actor: this,
-            value: ControlsState.WINDOW_PICKER,
-            lower: ControlsState.HIDDEN,
-            upper: ControlsState.APP_GRID,
-        });
+        this._adjustment = new OverviewAdjustment(this);
 
         this._nWorkspacesNotifyId =
             workspaceManager.connect('notify::n-workspaces',


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