[gnome-shell/wip/exalm/gestures2: 2/7] workspaceAnimation: Stop depending on shellwm



commit ed0ce5734bff74f313028e5781bdb186e6290fb1
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Tue Jan 21 18:09:56 2020 +0500

    workspaceAnimation: Stop depending on shellwm
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1326

 js/ui/windowManager.js      | 13 +++++++++++--
 js/ui/workspaceAnimation.js | 44 ++++++++++++++++++++++----------------------
 2 files changed, 33 insertions(+), 24 deletions(-)
---
diff --git a/js/ui/windowManager.js b/js/ui/windowManager.js
index 99eefcd364..6815615dc4 100644
--- a/js/ui/windowManager.js
+++ b/js/ui/windowManager.js
@@ -984,6 +984,14 @@ var WindowManager = class {
 
         this._workspaceAnimation =
             new WorkspaceAnimation.WorkspaceAnimationController();
+
+        this._shellwm.connect('kill-switch-workspace', () => {
+            if (!this._workspaceAnimation.isAnimating() || this._workspaceAnimation.canCancelGesture())
+                return;
+
+            this._workspaceAnimation.cancelSwitchAnimation();
+            this._shellwm.completed_switch_workspace();
+        });
     }
 
     _showPadOsd(display, device, settings, imagePath, editionMode, monitorIndex) {
@@ -1608,8 +1616,9 @@ var WindowManager = class {
             return;
         }
 
-        this._workspaceAnimation.animateSwitchWorkspace(shellwm, from, to,
-            direction);
+        this._workspaceAnimation.animateSwitchWorkspace(from, to, direction, () => {
+            this._shellwm.completed_switch_workspace();
+        });
     }
 
     _showTilePreview(shellwm, window, tileRect, monitorIndex) {
diff --git a/js/ui/workspaceAnimation.js b/js/ui/workspaceAnimation.js
index 4a40631c5d..bf93fe04bc 100644
--- a/js/ui/workspaceAnimation.js
+++ b/js/ui/workspaceAnimation.js
@@ -10,18 +10,8 @@ const WINDOW_ANIMATION_TIME = 250;
 
 var WorkspaceAnimationController = class {
     constructor() {
-        this._shellwm = global.window_manager;
         this._movingWindow = null;
-
         this._switchData = null;
-        this._shellwm.connect('kill-switch-workspace', shellwm => {
-            if (this._switchData) {
-                if (this._switchData.inProgress)
-                    this._switchWorkspaceDone(shellwm);
-                else if (!this._switchData.gestureActivated)
-                    this._finishWorkspaceSwitch(this._switchData);
-            }
-        });
 
         global.display.connect('restacked', this._syncStacking.bind(this));
 
@@ -130,7 +120,7 @@ var WorkspaceAnimationController = class {
         const workspaceManager = global.workspace_manager;
         const curWs = workspaceManager.get_workspace_by_index(from);
 
-        for (let dir of Object.values(Meta.MotionDirection)) {
+        for (const dir of Object.values(Meta.MotionDirection)) {
             let ws = null;
 
             if (to < 0)
@@ -184,8 +174,8 @@ var WorkspaceAnimationController = class {
                 switchData.curGroup.add_child(windowActor);
             } else {
                 let visible = false;
-                for (let dir of Object.values(Meta.MotionDirection)) {
-                    let info = switchData.surroundings[dir];
+                for (const dir of Object.values(Meta.MotionDirection)) {
+                    const info = switchData.surroundings[dir];
 
                     if (!info || info.index !== window.get_workspace().index())
                         continue;
@@ -225,7 +215,7 @@ var WorkspaceAnimationController = class {
         this.movingWindow = null;
     }
 
-    animateSwitchWorkspace(shellwm, from, to, direction) {
+    animateSwitchWorkspace(from, to, direction, onComplete) {
         this._prepareWorkspaceSwitch(from, to, direction);
         this._switchData.inProgress = true;
 
@@ -247,15 +237,13 @@ var WorkspaceAnimationController = class {
             y: yDest,
             duration: WINDOW_ANIMATION_TIME,
             mode: Clutter.AnimationMode.EASE_OUT_CUBIC,
-            onComplete: () => this._switchWorkspaceDone(shellwm),
+            onComplete: () => {
+                this._finishWorkspaceSwitch(this._switchData);
+                onComplete();
+            },
         });
     }
 
-    _switchWorkspaceDone(shellwm) {
-        this._finishWorkspaceSwitch(this._switchData);
-        shellwm.completed_switch_workspace();
-    }
-
     _directionForProgress(progress) {
         if (global.workspace_manager.layout_rows === -1) {
             return progress > 0
@@ -289,14 +277,14 @@ var WorkspaceAnimationController = class {
         let direction = this._directionForProgress(-1);
         let info = this._switchData.surroundings[direction];
         if (info !== null) {
-            let distance = horiz ? info.xDest : info.yDest;
+            const distance = horiz ? info.xDest : info.yDest;
             lower = -Math.abs(distance) / baseDistance;
         }
 
         direction = this._directionForProgress(1);
         info = this._switchData.surroundings[direction];
         if (info !== null) {
-            let distance = horiz ? info.xDest : info.yDest;
+            const distance = horiz ? info.xDest : info.yDest;
             upper = Math.abs(distance) / baseDistance;
         }
 
@@ -412,6 +400,18 @@ var WorkspaceAnimationController = class {
         return this._switchData !== null;
     }
 
+    canCancelGesture() {
+        return this.isAnimating() && this._switchData.gestureActivated;
+    }
+
+    cancelSwitchAnimation() {
+        if (!this._switchData)
+            return;
+
+        if (this._switchData.inProgress || !this._switchData.gestureActivated)
+            this._finishWorkspaceSwitch(this._switchData);
+    }
+
     set movingWindow(movingWindow) {
         this._movingWindow = movingWindow;
     }


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