🔧 Use an array of effect instances
This commit is contained in:
+16
-21
@@ -69,10 +69,6 @@ class Extension {
|
|||||||
// Store a reference to the settings object.
|
// Store a reference to the settings object.
|
||||||
this._settings = ExtensionUtils.getSettings();
|
this._settings = ExtensionUtils.getSettings();
|
||||||
|
|
||||||
// This will store an item of ALL_EFFECTS array which was used the last time a window
|
|
||||||
// was opened / closed.
|
|
||||||
this._currentEffect = 0;
|
|
||||||
|
|
||||||
// We will use extensionThis to refer to the extension inside the patched methods.
|
// We will use extensionThis to refer to the extension inside the patched methods.
|
||||||
const extensionThis = this;
|
const extensionThis = this;
|
||||||
|
|
||||||
@@ -352,11 +348,11 @@ class Extension {
|
|||||||
// ------------------------------------------------------------------ choose an effect
|
// ------------------------------------------------------------------ choose an effect
|
||||||
|
|
||||||
// Now we chose a random effect from all enabled effects.
|
// Now we chose a random effect from all enabled effects.
|
||||||
this._currentEffect = null;
|
let effect = null;
|
||||||
|
|
||||||
// First we check if an effect is to be previewed.
|
// First we check if an effect is to be previewed.
|
||||||
if (previewNick != '') {
|
if (previewNick != '') {
|
||||||
this._currentEffect = ALL_EFFECTS.find(Effect => {
|
effect = ALL_EFFECTS.find(Effect => {
|
||||||
return Effect.getNick() == previewNick;
|
return Effect.getNick() == previewNick;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -374,12 +370,12 @@ class Extension {
|
|||||||
|
|
||||||
// And then choose a random effect.
|
// And then choose a random effect.
|
||||||
if (enabled.length > 0) {
|
if (enabled.length > 0) {
|
||||||
this._currentEffect = enabled[Math.floor(Math.random() * enabled.length)];
|
effect = enabled[Math.floor(Math.random() * enabled.length)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If nothing was enabled, we have to do nothing :)
|
// If nothing was enabled, we have to do nothing :)
|
||||||
if (this._currentEffect == null) {
|
if (effect == null) {
|
||||||
this._fixAnimationTimes(isDialogWindow, forOpening, null);
|
this._fixAnimationTimes(isDialogWindow, forOpening, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -393,10 +389,9 @@ class Extension {
|
|||||||
// The following is used to tweak the ongoing transitions of a window actor. Usually
|
// The following is used to tweak the ongoing transitions of a window actor. Usually
|
||||||
// windows are faded in / out scaled up / down slightly by GNOME Shell. Here, we allow
|
// windows are faded in / out scaled up / down slightly by GNOME Shell. Here, we allow
|
||||||
// modifications to this behavior by the effects.
|
// modifications to this behavior by the effects.
|
||||||
const config = this._currentEffect.tweakTransition(actor, this._settings, forOpening);
|
const config = effect.tweakTransition(actor, this._settings, forOpening);
|
||||||
const duration = testMode ?
|
const duration =
|
||||||
5000 :
|
testMode ? 5000 : this._settings.get_int(effect.getNick() + '-animation-time');
|
||||||
this._settings.get_int(this._currentEffect.getNick() + '-animation-time');
|
|
||||||
|
|
||||||
// All animations are relative to the window's center.
|
// All animations are relative to the window's center.
|
||||||
actor.set_pivot_point(0.5, 0.5);
|
actor.set_pivot_point(0.5, 0.5);
|
||||||
@@ -447,7 +442,7 @@ class Extension {
|
|||||||
// -------------------------------------------------------------------- add the shader
|
// -------------------------------------------------------------------- add the shader
|
||||||
|
|
||||||
// Now add a cool shader to our window actor!
|
// Now add a cool shader to our window actor!
|
||||||
const shader = this._currentEffect.getShader(actor, this._settings, forOpening);
|
const shader = effect.getShader(actor, this._settings, forOpening);
|
||||||
|
|
||||||
if (shader) {
|
if (shader) {
|
||||||
// There should always be an opacity transition going on...
|
// There should always be an opacity transition going on...
|
||||||
@@ -459,9 +454,7 @@ class Extension {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First remove any old effect.
|
actor.add_effect_with_name('burn-my-windows-effect', shader);
|
||||||
actor.remove_effect_by_name(`burn-my-windows-effect`);
|
|
||||||
actor.add_effect_with_name(`burn-my-windows-effect`, shader);
|
|
||||||
|
|
||||||
// Update uniforms at each frame.
|
// Update uniforms at each frame.
|
||||||
transition.connect('new-frame', (t) => {
|
transition.connect('new-frame', (t) => {
|
||||||
@@ -476,11 +469,13 @@ class Extension {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Remove the effect if the animation finished or was interrupted.
|
// Remove the effect if the animation finished or was interrupted.
|
||||||
if (forOpening) {
|
transition.connect('stopped', () => {
|
||||||
transition.connect('stopped', () => {
|
if (forOpening) {
|
||||||
actor.remove_effect_by_name(`burn-my-windows-effect`);
|
actor.remove_effect_by_name('burn-my-windows-effect');
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
effect.returnShader(shader);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, ensure that all animation times are set properly so that other extensions
|
// Finally, ensure that all animation times are set properly so that other extensions
|
||||||
|
|||||||
+23
-10
@@ -30,10 +30,12 @@ const utils = Me.imports.src.utils;
|
|||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// The shader class for this effect is registered further down in this file. When this
|
// The shader class for this effect is registered further down in this file. When this
|
||||||
// effect is used for the first time, shaderInstance will store one instance of
|
// effect is used for the first time, an instance of this shader class is created. Once
|
||||||
// ShaderClass which will be used whenever this effect is used.
|
// the effect is finished, the shader will be stored in the shaderInstances array and will
|
||||||
let ShaderClass = null;
|
// then be reused if a new shader is requested. ShaderClass which will be used whenever
|
||||||
let shaderInstance = null;
|
// this effect is used.
|
||||||
|
let ShaderClass = null;
|
||||||
|
let availableShaders = [];
|
||||||
|
|
||||||
// The effect class is completely static. It can be used to get some metadata (like the
|
// The effect class is completely static. It can be used to get some metadata (like the
|
||||||
// effect's name or supported GNOME Shell versions), to initialize the respective page of
|
// effect's name or supported GNOME Shell versions), to initialize the respective page of
|
||||||
@@ -101,15 +103,26 @@ var Fire = class Fire {
|
|||||||
// ---------------------------------------------------------------- API for extension.js
|
// ---------------------------------------------------------------- API for extension.js
|
||||||
|
|
||||||
// This is called from extension.js whenever a window is opened or closed with this
|
// This is called from extension.js whenever a window is opened or closed with this
|
||||||
// effect.
|
// effect. It returns an instance of the shader class, trying to reuse previously
|
||||||
|
// created shaders.
|
||||||
static getShader(actor, settings, forOpening) {
|
static getShader(actor, settings, forOpening) {
|
||||||
if (shaderInstance == null) {
|
let shader;
|
||||||
shaderInstance = new ShaderClass();
|
|
||||||
|
if (availableShaders.length == 0) {
|
||||||
|
shader = new ShaderClass();
|
||||||
|
} else {
|
||||||
|
shader = availableShaders.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
shaderInstance.setUniforms(settings, forOpening);
|
shader.setUniforms(settings, forOpening);
|
||||||
|
|
||||||
return shaderInstance;
|
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
|
// The tweakTransition() is called from extension.js to tweak a window's open / close
|
||||||
@@ -133,7 +146,7 @@ var Fire = class Fire {
|
|||||||
// This is called from extension.js if the extension is disabled. This should free all
|
// This is called from extension.js if the extension is disabled. This should free all
|
||||||
// static resources.
|
// static resources.
|
||||||
static cleanUp() {
|
static cleanUp() {
|
||||||
shaderInstance = null;
|
availableShaders = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- private stuff
|
// ----------------------------------------------------------------------- private stuff
|
||||||
|
|||||||
+22
-9
@@ -27,10 +27,12 @@ const utils = Me.imports.src.utils;
|
|||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// The shader class for this effect is registered further down in this file. When this
|
// The shader class for this effect is registered further down in this file. When this
|
||||||
// effect is used for the first time, shaderInstance will store one instance of
|
// effect is used for the first time, an instance of this shader class is created. Once
|
||||||
// ShaderClass which will be used whenever this effect is used.
|
// the effect is finished, the shader will be stored in the shaderInstances array and will
|
||||||
let ShaderClass = null;
|
// then be reused if a new shader is requested. ShaderClass which will be used whenever
|
||||||
let shaderInstance = null;
|
// this effect is used.
|
||||||
|
let ShaderClass = null;
|
||||||
|
let availableShaders = [];
|
||||||
|
|
||||||
// The effect class is completely static. It can be used to get some metadata (like the
|
// The effect class is completely static. It can be used to get some metadata (like the
|
||||||
// effect's name or supported GNOME Shell versions), to initialize the respective page of
|
// effect's name or supported GNOME Shell versions), to initialize the respective page of
|
||||||
@@ -83,15 +85,26 @@ var Hexagon = class Hexagon {
|
|||||||
// ---------------------------------------------------------------- API for extension.js
|
// ---------------------------------------------------------------- API for extension.js
|
||||||
|
|
||||||
// This is called from extension.js whenever a window is opened or closed with this
|
// This is called from extension.js whenever a window is opened or closed with this
|
||||||
// effect.
|
// effect. It returns an instance of the shader class, trying to reuse previously
|
||||||
|
// created shaders.
|
||||||
static getShader(actor, settings, forOpening) {
|
static getShader(actor, settings, forOpening) {
|
||||||
if (shaderInstance == null) {
|
let shader;
|
||||||
shaderInstance = new ShaderClass();
|
|
||||||
|
if (availableShaders.length == 0) {
|
||||||
|
shader = new ShaderClass();
|
||||||
|
} else {
|
||||||
|
shader = availableShaders.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
shaderInstance.setUniforms(settings, forOpening);
|
shader.setUniforms(settings, forOpening);
|
||||||
|
|
||||||
return shaderInstance;
|
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
|
// The tweakTransition() is called from extension.js to tweak a window's open / close
|
||||||
|
|||||||
Reference in New Issue
Block a user