[gnome-shell/wip/exalm/gestures: 79/82] workspaceAnimation: Extract WorkspaceGroup



commit 1b8ff7a49494ee30f9cfa11a1ef8c22532bab5f4
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Thu Jul 4 22:44:15 2019 +0500

    workspaceAnimation: Extract WorkspaceGroup
    
    Reimplement _syncStacking().
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/605

 js/ui/workspaceAnimation.js | 178 +++++++++++++++++++++++---------------------
 1 file changed, 92 insertions(+), 86 deletions(-)
---
diff --git a/js/ui/workspaceAnimation.js b/js/ui/workspaceAnimation.js
index 24a34221e8..6dddf3c73f 100644
--- a/js/ui/workspaceAnimation.js
+++ b/js/ui/workspaceAnimation.js
@@ -8,6 +8,79 @@ const SwipeTracker = imports.ui.swipeTracker;
 
 var WINDOW_ANIMATION_TIME = 250;
 
+var 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: window,
+                           parent: window.get_parent() };
+
+            window.reparent(this);
+
+            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);
+            w.window.reparent(w.parent);
+
+            if (w.window.get_meta_window().get_workspace() !=
+                global.workspace_manager.get_active_workspace())
+                w.window.hide();
+        }
+
+        this._windows = [];
+    }
+
+    _onDestroy() {
+        global.display.disconnect(this._restackedId);
+        this.removeWindows();
+    }
+});
+
 var WorkspaceAnimation = GObject.registerClass({
     Properties: {
         'progress': GObject.ParamSpec.double(
@@ -22,25 +95,23 @@ var WorkspaceAnimation = GObject.registerClass({
         this.connect('destroy', this._onDestroy.bind(this));
 
         this._controller = controller;
-        this._curGroup = new Clutter.Actor();
         this._movingWindowBin = new Clutter.Actor();
-        this._windows = [];
+        this._movingWindow = null;
         this._surroundings = {};
         this._progress = 0;
 
-        let wgroup = global.window_group;
-        let windows = global.get_window_actors();
-
         this._container = new Clutter.Actor();
-        this._container.add_actor(this._curGroup);
 
         this.add_actor(this._container);
-        wgroup.add_actor(this);
-        wgroup.add_actor(this._movingWindowBin);
+        global.window_group.add_actor(this);
+        global.window_group.add_actor(this._movingWindowBin);
 
         let workspaceManager = global.workspace_manager;
         let curWs = workspaceManager.get_workspace_by_index(from);
 
+        this._curGroup = new WorkspaceGroup(controller, curWs);
+        this._container.add_actor(this._curGroup);
+
         for (let dir of Object.values(Meta.MotionDirection)) {
             let ws = null;
 
@@ -56,7 +127,7 @@ var WorkspaceAnimation = GObject.registerClass({
 
             let [x, y] = this._getPositionForDirection(dir, curWs, ws);
             let info = { index: ws.index(),
-                         actor: new Clutter.Actor(),
+                         actor: new WorkspaceGroup(controller, ws),
                          xDest: x,
                          yDest: y };
             this._surroundings[dir] = info;
@@ -68,67 +139,28 @@ var WorkspaceAnimation = GObject.registerClass({
 
         this._movingWindowBin.raise_top();
 
-        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;
-
-            let record = { window: actor,
-                           parent: actor.get_parent() };
-
-            if (this._controller.movingWindow && window == this._controller.movingWindow) {
-                this._movingWindow = record;
-                this._windows.push(this._movingWindow);
-                actor.reparent(this._movingWindowBin);
-            } else if (window.get_workspace().index() == from) {
-                this._windows.push(record);
-                actor.reparent(this._curGroup);
-            } else {
-                let visible = false;
-                for (let dir of Object.values(Meta.MotionDirection)) {
-                    let info = this._surroundings[dir];
-
-                    if (!info || info.index != window.get_workspace().index())
-                        continue;
-
-                    this._windows.push(record);
-                    actor.reparent(info.actor);
-                    visible = true;
-                    break;
-                }
-
-                actor.visible = visible;
-            }
-        }
+        if (this._controller.movingWindow) {
+            let actor = this._controller.movingWindow.get_compositor_private();
 
-        for (let i = 0; i < this._windows.length; i++) {
-            let w = this._windows[i];
+            this._movingWindow = { window: actor,
+                                   parent: actor.get_parent() };
 
-            w.windowDestroyId = w.window.connect('destroy', () => {
-                this._windows.splice(this._windows.indexOf(w), 1);
+            actor.reparent(this._movingWindowBin);
+            this._movingWindow.windowDestroyId = actor.connect('destroy', () => {
+                this._movingWindow = null;
             });
         }
-
-        global.display.connect('restacked', this._syncStacking.bind(this));
     }
 
     _onDestroy() {
         this.remove_all_transitions();
 
-        for (let i = 0; i < this._windows.length; i++) {
-            let w = this._windows[i];
-
-            w.window.disconnect(w.windowDestroyId);
-            w.window.reparent(w.parent);
+        if (this._movingWindow) {
+            let record = this._movingWindow;
+            record.window.disconnect(record.windowDestroyId);
+            record.window.reparent(record.parent);
 
-            if (w.window.get_meta_window().get_workspace() !=
-                global.workspace_manager.get_active_workspace())
-                w.window.hide();
+            this._movingWindow = null;
         }
 
         this._container.destroy();
@@ -167,32 +199,6 @@ var WorkspaceAnimation = GObject.registerClass({
         return [xDest, yDest];
     }
 
-    _syncStacking() {
-        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._curGroup) {
-                this._curGroup.set_child_above_sibling(windows[i], lastCurSibling);
-                lastCurSibling = windows[i];
-            } else {
-                for (let dir of Object.values(Meta.MotionDirection)) {
-                    let info = this._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;
-                }
-            }
-        }
-    }
-
     directionForProgress(progress) {
         if (global.workspace_manager.layout_rows == -1)
             return (progress > 0) ? Meta.MotionDirection.DOWN : Meta.MotionDirection.UP;


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