[gnome-shell/wip/exalm/gestures2: 35/39] workspaceAnimation: Extract WorkspaceGroup



commit 379ef71ef8499d8f946dbe091a8100d68b5a9d5b
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 | 190 +++++++++++++++++++++++---------------------
 1 file changed, 100 insertions(+), 90 deletions(-)
---
diff --git a/js/ui/workspaceAnimation.js b/js/ui/workspaceAnimation.js
index 42794c3254..dde1d50629 100644
--- a/js/ui/workspaceAnimation.js
+++ b/js/ui/workspaceAnimation.js
@@ -1,20 +1,97 @@
 // -*- 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(controller, workspace) {
+        super._init();
+
+        this._controller = controller;
+        this._workspace = workspace;
+        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._controller.movingWindow &&
+            window === this._controller.movingWindow)
+            return false;
+
+        return true;
+    }
+
+    _refreshWindows() {
+        if (this._windows.length > 0)
+            this._removeWindows();
+
+        let windows = global.get_window_actors();
+        windows = windows.filter(w => this._shouldShowWindow(w.meta_window));
+
+        for (let window of windows) {
+            let record = {
+                window,
+                parent: window.get_parent(),
+            };
+
+            record.parent.remove_child(window);
+            this.add_child(window);
+            window.show();
+
+            record.windowDestroyId = window.connect('destroy', () => {
+                this._windows.splice(this._windows.indexOf(record), 1);
+            });
+
+            this._windows.push(record);
+        }
+    }
+
+    _removeWindows() {
+        for (let i = 0; i < this._windows.length; i++) {
+            let w = this._windows[i];
+
+            w.window.disconnect(w.windowDestroyId);
+            this.remove_child(w.window);
+            w.parent.add_child(w.window);
+
+            if (!w.window.get_meta_window().get_workspace().active)
+                w.window.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 +111,6 @@ var WorkspaceAnimationController = class {
         this._swipeTracker = swipeTracker;
     }
 
-    _syncStacking() {
-        if (this._switchData === null)
-            return;
-
-        let windows = global.get_window_actors();
-        let lastCurSibling = null;
-        let lastDirSibling = [];
-        for (let 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 (let dir of Object.values(Meta.MotionDirection)) {
-                    let 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 +148,15 @@ var WorkspaceAnimationController = class {
             return;
 
         let wgroup = global.window_group;
-        let windows = global.get_window_actors();
+        let workspaceManager = global.workspace_manager;
+        let curWs = workspaceManager.get_workspace_by_index(from);
+
         let switchData = {};
 
         this._switchData = switchData;
-        switchData.curGroup = new Clutter.Actor();
+        switchData.curGroup = new WorkspaceGroup(this, curWs);
         switchData.movingWindowBin = new Clutter.Actor();
-        switchData.windows = [];
+        switchData.movingWindow = null;
         switchData.surroundings = {};
         switchData.gestureActivated = false;
         switchData.inProgress = false;
@@ -117,9 +167,6 @@ var WorkspaceAnimationController = class {
         wgroup.add_actor(switchData.movingWindowBin);
         wgroup.add_actor(switchData.container);
 
-        let workspaceManager = global.workspace_manager;
-        let curWs = workspaceManager.get_workspace_by_index(from);
-
         for (let dir of Object.values(Meta.MotionDirection)) {
             let ws = null;
 
@@ -136,7 +183,7 @@ var WorkspaceAnimationController = class {
             let [x, y] = this._getPositionForDirection(dir, curWs, ws);
             let info = {
                 index: ws.index(),
-                actor: new Clutter.Actor(),
+                actor: new WorkspaceGroup(this, ws),
                 xDest: x,
                 yDest: y,
             };
@@ -149,54 +196,18 @@ var WorkspaceAnimationController = class {
 
         wgroup.set_child_above_sibling(switchData.movingWindowBin, null);
 
-        for (let i = 0; i < windows.length; i++) {
-            let actor = windows[i];
-            let window = actor.get_meta_window();
-
-            if (!window.showing_on_its_workspace())
-                continue;
-
-            if (window.is_on_all_workspaces())
-                continue;
+        if (this.movingWindow) {
+            let actor = this.movingWindow.get_compositor_private();
 
-            let record = {
+            switchData.movingWindow = {
                 window: actor,
                 parent: actor.get_parent(),
             };
 
-            if (this.movingWindow && window === this.movingWindow) {
-                record.parent.remove_child(actor);
-                switchData.movingWindow = record;
-                switchData.windows.push(switchData.movingWindow);
-                switchData.movingWindowBin.add_child(actor);
-            } else if (window.get_workspace().index() === from) {
-                record.parent.remove_child(actor);
-                switchData.windows.push(record);
-                switchData.curGroup.add_child(actor);
-            } else {
-                let visible = false;
-                for (let dir of Object.values(Meta.MotionDirection)) {
-                    let info = switchData.surroundings[dir];
-
-                    if (!info || info.index !== window.get_workspace().index())
-                        continue;
-
-                    record.parent.remove_child(actor);
-                    switchData.windows.push(record);
-                    info.actor.add_child(actor);
-                    visible = true;
-                    break;
-                }
-
-                actor.visible = visible;
-            }
-        }
-
-        for (let i = 0; i < switchData.windows.length; i++) {
-            let w = switchData.windows[i];
-
-            w.windowDestroyId = w.window.connect('destroy', () => {
-                switchData.windows.splice(switchData.windows.indexOf(w), 1);
+            switchData.movingWindow.parent.remove_child(actor);
+            switchData.movingWindowBin.add_child(actor);
+            switchData.movingWindow.windowDestroyId = actor.connect('destroy', () => {
+                switchData.movingWindow = null;
             });
         }
     }
@@ -204,16 +215,15 @@ var WorkspaceAnimationController = class {
     _finishWorkspaceSwitch(switchData) {
         this._switchData = null;
 
-        for (let i = 0; i < switchData.windows.length; i++) {
-            let w = switchData.windows[i];
-
-            w.window.disconnect(w.windowDestroyId);
-            w.window.get_parent().remove_child(w.window);
-            w.parent.add_child(w.window);
+        if (switchData.movingWindow) {
+            let record = switchData.movingWindow;
+            record.window.disconnect(record.windowDestroyId);
+            record.window.get_parent().remove_child(record.window);
+            record.parent.add_child(record.window);
 
-            if (!w.window.get_meta_window().get_workspace().active)
-                w.window.hide();
+            switchData.movingWindow = null;
         }
+
         switchData.container.destroy();
         switchData.movingWindowBin.destroy();
 


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