[gnome-shell/wip/exalm/gestures2: 3/7] workspaceAnimation: Extract WorkspaceGroup



commit b6fd112ccfacfb6b0dbecfd9acb9d0944cb7b56f
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Thu Jul 4 22:44:15 2019 +0500

    workspaceAnimation: Extract WorkspaceGroup
    
    Simplify the code a bit. The workspace group is relatively self-contained,
    so split it from the general animation. Reimplement _syncStacking().
    
    This will help a lot later, with workspace strip and multi-monitor support.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1326

 js/ui/workspaceAnimation.js | 176 +++++++++++++++++++++++---------------------
 1 file changed, 94 insertions(+), 82 deletions(-)
---
diff --git a/js/ui/workspaceAnimation.js b/js/ui/workspaceAnimation.js
index bf93fe04bc..0c1f40597f 100644
--- a/js/ui/workspaceAnimation.js
+++ b/js/ui/workspaceAnimation.js
@@ -1,20 +1,94 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 /* exported WorkspaceAnimationController */
 
-const { Clutter, Meta, Shell } = imports.gi;
+const { Clutter, GObject, Meta, Shell } = imports.gi;
 
 const Main = imports.ui.main;
 const SwipeTracker = imports.ui.swipeTracker;
 
 const WINDOW_ANIMATION_TIME = 250;
 
+const WorkspaceGroup = GObject.registerClass(
+class WorkspaceGroup extends Clutter.Actor {
+    _init(workspace, movingWindow) {
+        super._init();
+
+        this._workspace = workspace;
+        this._movingWindow = movingWindow;
+        this._windows = [];
+
+        this._refreshWindows();
+
+        this.connect('destroy', this._onDestroy.bind(this));
+        this._restackedId = global.display.connect('restacked',
+            this._refreshWindows.bind(this));
+    }
+
+    _shouldShowWindow(window) {
+        if (window.get_workspace() !== this._workspace)
+            return false;
+
+        if (!window.showing_on_its_workspace())
+            return false;
+
+        if (window.is_on_all_workspaces())
+            return false;
+
+        if (this._movingWindow && window === this._movingWindow)
+            return false;
+
+        return true;
+    }
+
+    _refreshWindows() {
+        if (this._windows.length > 0)
+            this._removeWindows();
+
+        const windows = global.get_window_actors().filter(w =>
+            this._shouldShowWindow(w.meta_window));
+
+        for (const windowActor of windows) {
+            const record = {
+                windowActor,
+                parent: windowActor.get_parent(),
+            };
+
+            record.parent.remove_child(windowActor);
+            this.add_child(windowActor);
+            windowActor.show();
+
+            record.windowDestroyId = windowActor.connect('destroy', () => {
+                this._windows.splice(this._windows.indexOf(record), 1);
+            });
+
+            this._windows.push(record);
+        }
+    }
+
+    _removeWindows() {
+        for (const record of this._windows) {
+            record.windowActor.disconnect(record.windowDestroyId);
+            this.remove_child(record.windowActor);
+            record.parent.add_child(record.windowActor);
+
+            if (!record.windowActor.get_meta_window().get_workspace().active)
+                record.windowActor.hide();
+        }
+
+        this._windows = [];
+    }
+
+    _onDestroy() {
+        global.display.disconnect(this._restackedId);
+        this._removeWindows();
+    }
+});
+
 var WorkspaceAnimationController = class {
     constructor() {
         this._movingWindow = null;
         this._switchData = null;
 
-        global.display.connect('restacked', this._syncStacking.bind(this));
-
         Main.overview.connect('showing', () => {
             if (this._switchData) {
                 if (this._switchData.gestureActivated)
@@ -34,35 +108,6 @@ var WorkspaceAnimationController = class {
         this._swipeTracker = swipeTracker;
     }
 
-    _syncStacking() {
-        if (this._switchData === null)
-            return;
-
-        const windows = global.get_window_actors();
-        let lastCurSibling = null;
-        const lastDirSibling = [];
-        for (const i = 0; i < windows.length; i++) {
-            if (windows[i].get_parent() === this._switchData.curGroup) {
-                this._switchData.curGroup.set_child_above_sibling(windows[i], lastCurSibling);
-                lastCurSibling = windows[i];
-            } else {
-                for (const dir of Object.values(Meta.MotionDirection)) {
-                    const info = this._switchData.surroundings[dir];
-                    if (!info || windows[i].get_parent() !== info.actor)
-                        continue;
-
-                    let sibling = lastDirSibling[dir];
-                    if (sibling === undefined)
-                        sibling = null;
-
-                    info.actor.set_child_above_sibling(windows[i], sibling);
-                    lastDirSibling[dir] = windows[i];
-                    break;
-                }
-            }
-        }
-    }
-
     _getPositionForDirection(direction, fromWs, toWs) {
         let xDest = 0, yDest = 0;
 
@@ -100,13 +145,15 @@ var WorkspaceAnimationController = class {
             return;
 
         const wgroup = global.window_group;
-        const windows = global.get_window_actors();
+        const workspaceManager = global.workspace_manager;
+        const curWs = workspaceManager.get_workspace_by_index(from);
+
         const switchData = {};
 
         this._switchData = switchData;
-        switchData.curGroup = new Clutter.Actor();
+        switchData.curGroup = new WorkspaceGroup(curWs, this.movingWindow);
         switchData.movingWindowBin = new Clutter.Actor();
-        switchData.windows = [];
+        switchData.movingWindow = null;
         switchData.surroundings = {};
         switchData.gestureActivated = false;
         switchData.inProgress = false;
@@ -117,9 +164,6 @@ var WorkspaceAnimationController = class {
         wgroup.add_child(switchData.movingWindowBin);
         wgroup.add_child(switchData.container);
 
-        const workspaceManager = global.workspace_manager;
-        const curWs = workspaceManager.get_workspace_by_index(from);
-
         for (const dir of Object.values(Meta.MotionDirection)) {
             let ws = null;
 
@@ -136,7 +180,7 @@ var WorkspaceAnimationController = class {
             const [x, y] = this._getPositionForDirection(dir, curWs, ws);
             const info = {
                 index: ws.index(),
-                actor: new Clutter.Actor(),
+                actor: new WorkspaceGroup(ws, this.movingWindow),
                 xDest: x,
                 yDest: y,
             };
@@ -149,51 +193,18 @@ var WorkspaceAnimationController = class {
 
         wgroup.set_child_above_sibling(switchData.movingWindowBin, null);
 
-        for (const windowActor of windows) {
-            const window = windowActor.get_meta_window();
-
-            if (!window.showing_on_its_workspace())
-                continue;
-
-            if (window.is_on_all_workspaces())
-                continue;
+        if (this.movingWindow) {
+            const windowActor = this.movingWindow.get_compositor_private();
 
-            const record = {
+            switchData.movingWindow = {
                 windowActor,
                 parent: windowActor.get_parent(),
             };
 
-            if (this.movingWindow && window === this.movingWindow) {
-                record.parent.remove_child(windowActor);
-                switchData.movingWindow = record;
-                switchData.windows.push(switchData.movingWindow);
-                switchData.movingWindowBin.add_child(windowActor);
-            } else if (window.get_workspace().index() === from) {
-                record.parent.remove_child(windowActor);
-                switchData.windows.push(record);
-                switchData.curGroup.add_child(windowActor);
-            } else {
-                let visible = false;
-                for (const dir of Object.values(Meta.MotionDirection)) {
-                    const info = switchData.surroundings[dir];
-
-                    if (!info || info.index !== window.get_workspace().index())
-                        continue;
-
-                    record.parent.remove_child(windowActor);
-                    switchData.windows.push(record);
-                    info.actor.add_child(windowActor);
-                    visible = true;
-                    break;
-                }
-
-                windowActor.visible = visible;
-            }
-        }
-
-        for (const record of switchData.windows) {
-            record.windowDestroyId = record.windowActor.connect('destroy', () => {
-                switchData.windows.splice(switchData.windows.indexOf(record), 1);
+            switchData.movingWindow.parent.remove_child(windowActor);
+            switchData.movingWindowBin.add_child(windowActor);
+            switchData.movingWindow.windowDestroyId = windowActor.connect('destroy', () => {
+                switchData.movingWindow = null;
             });
         }
     }
@@ -201,14 +212,15 @@ var WorkspaceAnimationController = class {
     _finishWorkspaceSwitch(switchData) {
         this._switchData = null;
 
-        for (const record of switchData.windows) {
+        if (switchData.movingWindow) {
+            const record = switchData.movingWindow;
             record.windowActor.disconnect(record.windowDestroyId);
             switchData.movingWindowBin.remove_child(record.windowActor);
             record.parent.add_child(record.windowActor);
 
-            if (!record.windowActor.get_meta_window().get_workspace().active)
-                record.windowActor.hide();
+            switchData.movingWindow = null;
         }
+
         switchData.container.destroy();
         switchData.movingWindowBin.destroy();
 


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