From e9b82d0b78dfe0ab187b57c47b9e0b072667a4d6 Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Sat, 7 May 2022 20:45:20 +0200 Subject: [PATCH] :wrench: Prevent non-fatal error message --- extension.js | 36 +++++++++++++++++++++++++++--------- src/Fire.js | 12 ++++++------ src/Hexagon.js | 12 ++++++------ 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/extension.js b/extension.js index 3e66690..6577ccf 100644 --- a/extension.js +++ b/extension.js @@ -78,6 +78,7 @@ class Extension { this._origDoRemoveWindow = Workspace.prototype._doRemoveWindow; this._origShouldAnimateActor = WindowManager.prototype._shouldAnimateActor; this._origWaitForOverviewToHide = WindowManager.prototype._waitForOverviewToHide; + this._origDestroyWindowDone = WindowManager.prototype._destroyWindowDone; // We will also override these animation times. this._origWindowTime = imports.ui.windowManager.DESTROY_WINDOW_ANIMATION_TIME; @@ -199,9 +200,9 @@ class Extension { // ----------------------------------------------- patching the window-close animation - // The signal handler below is all which is required outside of the overview. All - // other hacks further below are just required to defer the window-hiding in the - // overview until the effect is finished. + // The signal handler below and the following patch are all which is required outside + // of the overview. All other hacks further below are just required to defer the + // window-hiding in the overview until the effect is finished. // The close animation is set up in WindowManager's _destroyWindow: // https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/windowManager.js#L1541 @@ -211,6 +212,23 @@ class Extension { this._setupEffect(actor, false); }); + // Once the window-close animation is is finished, the window manager's + // _destroyWindowDone is called. We use this to free the effect so that it can be + // re-used in future. + // https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/windowManager.js#L1541 + WindowManager.prototype._destroyWindowDone = function(shellwm, actor) { + if (this._destroying.has(actor)) { + const shader = actor.get_effect('burn-my-windows-effect'); + if (shader) { + actor.remove_effect(shader); + shader.free(); + } + } + + // Call the original method. + extensionThis._origDestroyWindowDone.apply(this, [shellwm, actor]); + }; + // These three method overrides are mega-hacky! Usually, windows are not faded when // closed from the overview (why?). With these overrides we make sure that they are // actually faded out. To do this, _windowRemoved and _doRemoveWindow now check @@ -301,6 +319,7 @@ class Extension { Workspace.prototype._doRemoveWindow = this._origDoRemoveWindow; WindowManager.prototype._shouldAnimateActor = this._origShouldAnimateActor; WindowManager.prototype._waitForOverviewToHide = this._origWaitForOverviewToHide; + WindowManager.prototype._destroyWindowDone = this._origDestroyWindowDone; imports.ui.windowManager.DESTROY_WINDOW_ANIMATION_TIME = this._origWindowTime; imports.ui.windowManager.DIALOG_DESTROY_WINDOW_ANIMATION_TIME = this._origDialogTime; @@ -469,13 +488,12 @@ class Extension { }); // Remove the effect if the animation finished or was interrupted. - transition.connect('stopped', () => { - if (forOpening) { + if (forOpening) { + transition.connect('stopped', () => { actor.remove_effect_by_name('burn-my-windows-effect'); - } - - effect.returnShader(shader); - }); + shader.free(); + }); + } } // Finally, ensure that all animation times are set properly so that other extensions diff --git a/src/Fire.js b/src/Fire.js index bc356ec..4f06d40 100644 --- a/src/Fire.js +++ b/src/Fire.js @@ -119,12 +119,6 @@ var Fire = class Fire { return shader; } - // This will be called from extension.js once a shader which was previously acquired via - // getShader() is not used anymore. - static returnShader(shader) { - availableShaders.push(shader); - } - // The tweakTransition() is called from extension.js to tweak a window's open / close // transitions - usually windows are faded in / out and scaled up / down by GNOME Shell. // The parameter 'forOpening' is set to true if this is called for a window-open @@ -289,6 +283,12 @@ if (utils.isInShellProcess()) { [settings.get_double('flame-movement-speed')]); } + // This is called by extension.js when the shader is not used anymore. We will store + // this instance of the shader so that it can be re-used in th future. + free() { + availableShaders.push(this); + } + // This is called by the constructor. This is means it's only called when the effect // is used for the first time. vfunc_build_pipeline() { diff --git a/src/Hexagon.js b/src/Hexagon.js index e9be7cd..4642b78 100644 --- a/src/Hexagon.js +++ b/src/Hexagon.js @@ -101,12 +101,6 @@ var Hexagon = class Hexagon { return shader; } - // This will be called from extension.js once a shader which was previously acquired via - // getShader() is not used anymore. - static returnShader(shader) { - availableShaders.push(shader); - } - // The tweakTransition() is called from extension.js to tweak a window's open / close // transitions - usually windows are faded in / out and scaled up / down by GNOME Shell. // The parameter 'forOpening' is set to true if this is called for a window-open @@ -189,6 +183,12 @@ if (utils.isInShellProcess()) { [line.red / 255, line.green / 255, line.blue / 255, line.alpha / 255]); } + // This is called by extension.js when the shader is not used anymore. We will store + // this instance of the shader so that it can be re-used in th future. + free() { + availableShaders.push(this); + } + // This is called by the constructor. This is means it's only called when the effect // is used for the first time. vfunc_build_pipeline() {