From 845c765843bc9780d0f3c1be37c93953286530fd Mon Sep 17 00:00:00 2001 From: Justin Garza Date: Sat, 8 Mar 2025 11:45:31 -0500 Subject: [PATCH 1/7] resync and updated --- resources/shaders/fire.frag | 59 ++++++++++++++++++- resources/ui/adw/fire.ui | 24 +++++++- ...nsions.burn-my-windows-profile.gschema.xml | 8 ++- src/Shader.js | 2 +- src/ShaderFactory.js | 2 +- src/effects/Fire.js | 35 +++++++++++ 6 files changed, 124 insertions(+), 6 deletions(-) diff --git a/resources/shaders/fire.frag b/resources/shaders/fire.frag index 06a6957..218334b 100644 --- a/resources/shaders/fire.frag +++ b/resources/shaders/fire.frag @@ -23,6 +23,10 @@ uniform vec4 uGradient3; uniform vec4 uGradient4; uniform vec4 uGradient5; +//new +uniform bool uRandomColor; +uniform float uSeed; + // These may be configurable in the future. const float EDGE_FADE = 70.0; const float FADE_WIDTH = 0.1; @@ -58,6 +62,36 @@ vec4 getFireColor(float v) { return colors[4]; } +vec4 getFireColorV2(float v, vec4 c0, vec4 c1, vec4 c2, vec4 c3, vec4 c4) +{ + float steps[5]; + steps[0] = 0.0; + steps[1] = 0.2; + steps[2] = 0.35; + steps[3] = 0.5; + steps[4] = 0.8; + + vec4 colors[5]; + colors[0] = c0; + colors[1] = c1; + colors[2] = c2; + colors[3] = c3; + colors[4] = c4; + + if (v < steps[0]) { + return colors[0]; + } + + for (int i = 0; i < 4; ++i) { + if (v <= steps[i + 1]) { + return mix(colors[i], colors[i + 1], + vec4(v - steps[i]) / (steps[i + 1] - steps[i])); + } + } + + return colors[4]; +} + // This method requires the uniforms from standardUniforms() to be available. // It returns two values: The first is an alpha value which can be used for the window // texture. This gradually dissolves the window from top to bottom. The second can be used @@ -114,7 +148,28 @@ void main() { noise *= effectMask.y; // Map noise value to color. - vec4 fire = getFireColor(noise); + vec4 fire = vec4(0.0); + + if (uRandomColor) + { + vec3 baseColor0 = offsetHue(vec3(1.0,0.0,0.0), hash11(uSeed)); + vec3 baseColor1 = offsetHue(baseColor0, 0.1); + vec3 baseColor2 = offsetHue(baseColor1, 0.1); + + //hardcoding alpha values + vec4 c0 = vec4(baseColor0,0.0); + vec4 c1 = vec4(baseColor0,0.3); + vec4 c2 = vec4(baseColor1,0.6); + vec4 c3 = vec4(baseColor1,0.9); + vec4 c4 = vec4(baseColor2,1.0); + + + fire = getFireColorV2(noise,c0,c1,c2,c3,c4); + } + else + { + fire = getFireColor(noise); + } // Get the window texture. vec4 oColor = getInputColor(iTexCoord.st); @@ -131,4 +186,4 @@ void main() { // oColor = vec4(vec3(effectMask.y), 1); setOutputColor(oColor); -} \ No newline at end of file +} diff --git a/resources/ui/adw/fire.ui b/resources/ui/adw/fire.ui index 08d7e81..038f585 100644 --- a/resources/ui/adw/fire.ui +++ b/resources/ui/adw/fire.ui @@ -147,6 +147,28 @@ SPDX-License-Identifier: GPL-3.0-or-later + + + Use Random Color + fire-random-color + + + center + + + + + edit-clear-symbolic + center + Reset to Default Value + + + + + + Gradient @@ -206,4 +228,4 @@ SPDX-License-Identifier: GPL-3.0-or-later - \ No newline at end of file + diff --git a/schemas/org.gnome.shell.extensions.burn-my-windows-profile.gschema.xml b/schemas/org.gnome.shell.extensions.burn-my-windows-profile.gschema.xml index 47cebb9..e6b87a4 100644 --- a/schemas/org.gnome.shell.extensions.burn-my-windows-profile.gschema.xml +++ b/schemas/org.gnome.shell.extensions.burn-my-windows-profile.gschema.xml @@ -242,6 +242,12 @@ SPDX-License-Identifier: CC0-1.0 The size of the fire. + + false + use a random color for the fire + use a random color of the fire + + false Fire 3D Noise @@ -1110,4 +1116,4 @@ SPDX-License-Identifier: CC0-1.0 - \ No newline at end of file + diff --git a/src/Shader.js b/src/Shader.js index fa5ba48..9719884 100644 --- a/src/Shader.js +++ b/src/Shader.js @@ -61,7 +61,7 @@ export var Shader = GObject.registerClass({ } }, - class Shader extends Shell.GLSLEffect { + class Shader extends Shell.GLSLEffect{ // -------------------------------------------- // The constructor automagically loads the shader's source code (in // vfunc_build_pipeline()) from the resource file resources/shaders/.glsl diff --git a/src/ShaderFactory.js b/src/ShaderFactory.js index 6056262..06fbea7 100644 --- a/src/ShaderFactory.js +++ b/src/ShaderFactory.js @@ -61,7 +61,7 @@ export default class ShaderFactory { // Only try to register the new type once. if (GObject.type_from_name(typeName) == null) { const outerThis = this; - GObject.registerClass({GTypeName: typeName}, class ShaderImp extends Shader { + GObject.registerClass({GTypeName: typeName}, class ShaderImp extends Shader{ // This will actually load the GLSL source code from the resources. _init() { super._init(outerThis._nick); diff --git a/src/effects/Fire.js b/src/effects/Fire.js index f10e765..d763621 100644 --- a/src/effects/Fire.js +++ b/src/effects/Fire.js @@ -12,6 +12,8 @@ // SPDX-FileCopyrightText: Simon Schneegans // SPDX-License-Identifier: GPL-3.0-or-later +// modified by Justin Garza + 'use strict'; import Gio from 'gi://Gio'; @@ -58,6 +60,9 @@ export default class Effect { shader._uScale = shader.get_uniform_location('uScale'); shader._uMovementSpeed = shader.get_uniform_location('uMovementSpeed'); + shader._uRandomColor = shader.get_uniform_location('uRandomColor'); + shader._uSeed = shader.get_uniform_location('uSeed'); + // And update all uniforms at the start of each animation. shader.connect('begin-animation', (shader, settings) => { for (let i = 1; i <= 5; i++) { @@ -68,6 +73,8 @@ export default class Effect { // clang-format off shader.set_uniform_float(shader._u3DNoise, 1, [settings.get_boolean('fire-3d-noise')]); + shader.set_uniform_float(shader._uRandomColor, 1, [settings.get_boolean('fire-random-color')]); + shader.set_uniform_float(shader._uSeed, 1, [Math.random()]); shader.set_uniform_float(shader._uScale, 1, [settings.get_double('fire-scale')]); shader.set_uniform_float(shader._uMovementSpeed, 1, [settings.get_double('fire-movement-speed')]); // clang-format on @@ -107,6 +114,7 @@ export default class Effect { dialog.bindAdjustment('fire-movement-speed'); dialog.bindAdjustment('fire-scale'); dialog.bindSwitch('fire-3d-noise'); + dialog.bindSwitch('fire-random-color'); dialog.bindColorButton('fire-color-1'); dialog.bindColorButton('fire-color-2'); dialog.bindColorButton('fire-color-3'); @@ -129,6 +137,33 @@ export default class Effect { // Initialize the fire-preset dropdown. Effect._createFirePresets(dialog); } + + // enables and disables the color buttons + function EnableDisableColorButtons(dialog, state) { + + for (let i = 1; i <= 5; i++) { + dialog.getBuilder().get_object('fire-color-' + i).set_sensitive(!state); + } + } + + const switchWidget = dialog.getBuilder().get_object('fire-random-color'); + if (switchWidget) { + // Connect to the "state-set" signal to update preferences dynamically based on + // the switch state. + switchWidget.connect('state-set', (widget, state) => { + EnableDisableColorButtons(dialog, + state); // Update sensitivity when the state changes. + }); + + // Manually call the update function on startup, using the initial state of the + // switch. + const initialState = + switchWidget.get_active(); // Get the current state of the switch. + EnableDisableColorButtons(dialog, initialState); + } else { + // Log an error if the switch widget is not found in the UI. + log('Error: \'fire-random-color\' switch widget not found.'); + } } // ---------------------------------------------------------------- API for extension.js From 18d1e3f6f6fa24de771d48da666f0b15cdf67263 Mon Sep 17 00:00:00 2001 From: Justin Garza Date: Sat, 8 Mar 2025 11:53:38 -0500 Subject: [PATCH 2/7] Update Fire.js --- src/effects/Fire.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/effects/Fire.js b/src/effects/Fire.js index d763621..07f2c2d 100644 --- a/src/effects/Fire.js +++ b/src/effects/Fire.js @@ -139,7 +139,7 @@ export default class Effect { } // enables and disables the color buttons - function EnableDisableColorButtons(dialog, state) { + function enableDisableColorButtons(dialog, state) { for (let i = 1; i <= 5; i++) { dialog.getBuilder().get_object('fire-color-' + i).set_sensitive(!state); @@ -151,7 +151,7 @@ export default class Effect { // Connect to the "state-set" signal to update preferences dynamically based on // the switch state. switchWidget.connect('state-set', (widget, state) => { - EnableDisableColorButtons(dialog, + enableDisableColorButtons(dialog, state); // Update sensitivity when the state changes. }); @@ -159,7 +159,7 @@ export default class Effect { // switch. const initialState = switchWidget.get_active(); // Get the current state of the switch. - EnableDisableColorButtons(dialog, initialState); + enableDisableColorButtons(dialog, initialState); } else { // Log an error if the switch widget is not found in the UI. log('Error: \'fire-random-color\' switch widget not found.'); From 87ac8b401a7aedf5f36eba0033dacd6409b1c206 Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Sun, 9 Mar 2025 11:01:21 +0100 Subject: [PATCH 3/7] :recycle: Remove duplicated code --- resources/shaders/fire.frag | 63 +++++++++---------------------------- 1 file changed, 14 insertions(+), 49 deletions(-) diff --git a/resources/shaders/fire.frag b/resources/shaders/fire.frag index 218334b..d399bae 100644 --- a/resources/shaders/fire.frag +++ b/resources/shaders/fire.frag @@ -22,8 +22,6 @@ uniform vec4 uGradient2; uniform vec4 uGradient3; uniform vec4 uGradient4; uniform vec4 uGradient5; - -//new uniform bool uRandomColor; uniform float uSeed; @@ -33,37 +31,7 @@ const float FADE_WIDTH = 0.1; const float HIDE_TIME = 0.4; // This maps the input value from [0..1] to a color from the gradient. -vec4 getFireColor(float v) { - float steps[5]; - steps[0] = 0.0; - steps[1] = 0.2; - steps[2] = 0.35; - steps[3] = 0.5; - steps[4] = 0.8; - - vec4 colors[5]; - colors[0] = uGradient1; - colors[1] = uGradient2; - colors[2] = uGradient3; - colors[3] = uGradient4; - colors[4] = uGradient5; - - if (v < steps[0]) { - return colors[0]; - } - - for (int i = 0; i < 4; ++i) { - if (v <= steps[i + 1]) { - return mix(colors[i], colors[i + 1], - vec4(v - steps[i]) / (steps[i + 1] - steps[i])); - } - } - - return colors[4]; -} - -vec4 getFireColorV2(float v, vec4 c0, vec4 c1, vec4 c2, vec4 c3, vec4 c4) -{ +vec4 getFireColor(float v, vec4 c0, vec4 c1, vec4 c2, vec4 c3, vec4 c4) { float steps[5]; steps[0] = 0.0; steps[1] = 0.2; @@ -149,26 +117,23 @@ void main() { // Map noise value to color. vec4 fire = vec4(0.0); - - if (uRandomColor) - { - vec3 baseColor0 = offsetHue(vec3(1.0,0.0,0.0), hash11(uSeed)); + + if (uRandomColor) { + vec3 baseColor0 = offsetHue(vec3(1.0, 0.0, 0.0), hash11(uSeed)); vec3 baseColor1 = offsetHue(baseColor0, 0.1); vec3 baseColor2 = offsetHue(baseColor1, 0.1); - //hardcoding alpha values - vec4 c0 = vec4(baseColor0,0.0); - vec4 c1 = vec4(baseColor0,0.3); - vec4 c2 = vec4(baseColor1,0.6); - vec4 c3 = vec4(baseColor1,0.9); - vec4 c4 = vec4(baseColor2,1.0); + // Hardcoding some alpha values. + vec4 c0 = vec4(baseColor0, 0.0); + vec4 c1 = vec4(baseColor0, 0.3); + vec4 c2 = vec4(baseColor1, 0.6); + vec4 c3 = vec4(baseColor1, 0.9); + vec4 c4 = vec4(baseColor2, 1.0); - - fire = getFireColorV2(noise,c0,c1,c2,c3,c4); - } - else - { - fire = getFireColor(noise); + fire = getFireColor(noise, c0, c1, c2, c3, c4); + } else { + fire = + getFireColor(noise, uGradient1, uGradient2, uGradient3, uGradient4, uGradient5); } // Get the window texture. From b5ad70a2a4bdedc6ddb35c22c215cd0c36ca53d0 Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Sun, 9 Mar 2025 11:01:32 +0100 Subject: [PATCH 4/7] :sparkles: Apply clang-format --- src/Shader.js | 2 +- src/ShaderFactory.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Shader.js b/src/Shader.js index 9719884..fa5ba48 100644 --- a/src/Shader.js +++ b/src/Shader.js @@ -61,7 +61,7 @@ export var Shader = GObject.registerClass({ } }, - class Shader extends Shell.GLSLEffect{ + class Shader extends Shell.GLSLEffect { // -------------------------------------------- // The constructor automagically loads the shader's source code (in // vfunc_build_pipeline()) from the resource file resources/shaders/.glsl diff --git a/src/ShaderFactory.js b/src/ShaderFactory.js index 06fbea7..6056262 100644 --- a/src/ShaderFactory.js +++ b/src/ShaderFactory.js @@ -61,7 +61,7 @@ export default class ShaderFactory { // Only try to register the new type once. if (GObject.type_from_name(typeName) == null) { const outerThis = this; - GObject.registerClass({GTypeName: typeName}, class ShaderImp extends Shader{ + GObject.registerClass({GTypeName: typeName}, class ShaderImp extends Shader { // This will actually load the GLSL source code from the resources. _init() { super._init(outerThis._nick); From cb2db00d59d5ee10e8d24865e806f05a7ae16a22 Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Sun, 9 Mar 2025 11:02:37 +0100 Subject: [PATCH 5/7] :memo: Add changelog entry --- docs/changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index d3538d4..e7b781e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -9,6 +9,10 @@ SPDX-License-Identifier: CC-BY-4.0 **Release Date:** TBD +#### New Features + +- Added an option to choose a random color for the Fire effect each time a window is closed or opened. Thanks to [@jgarza9788](https://github.com/jgarza9788) for this contribution! + #### Bug Fixes - Fixed an issue introduced by the GNOME 48 Beta release which caused some effects to break (Broken Glass, Matrix, Paint Brush, Snap of Disintegration, T-Rex Attack). From ee1b49269a9943b6c339f88b63a0ea3c08adf7a1 Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Sun, 9 Mar 2025 11:07:35 +0100 Subject: [PATCH 6/7] :wrench: Use more opaque alpha values for the random fire colors --- resources/shaders/fire.frag | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/shaders/fire.frag b/resources/shaders/fire.frag index d399bae..4ed281d 100644 --- a/resources/shaders/fire.frag +++ b/resources/shaders/fire.frag @@ -125,8 +125,8 @@ void main() { // Hardcoding some alpha values. vec4 c0 = vec4(baseColor0, 0.0); - vec4 c1 = vec4(baseColor0, 0.3); - vec4 c2 = vec4(baseColor1, 0.6); + vec4 c1 = vec4(baseColor0, 0.5); + vec4 c2 = vec4(baseColor1, 0.8); vec4 c3 = vec4(baseColor1, 0.9); vec4 c4 = vec4(baseColor2, 1.0); From 60c96c03d7a079960cdf481b27a9a716e813a6d6 Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Sun, 9 Mar 2025 11:18:31 +0100 Subject: [PATCH 7/7] :wrench: Port random fire option to KWin --- kwin/fire/config.ui | 287 +++++++++++++++++---------------- kwin/fire/main.xml | 3 + kwin/fire/onAnimationBegin.js | 8 + kwin/fire/onSettingsChanged.js | 2 + 4 files changed, 160 insertions(+), 140 deletions(-) create mode 100644 kwin/fire/onAnimationBegin.js diff --git a/kwin/fire/config.ui b/kwin/fire/config.ui index 509b83c..0999985 100755 --- a/kwin/fire/config.ui +++ b/kwin/fire/config.ui @@ -6,145 +6,152 @@ SPDX-License-Identifier: GPL-3.0-or-later --> - BMWConfigForm - - - - 0 - 0 - 562 - 365 - - - - - - - Gradient - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 100 - - - 9999 - - - 100 - - - - - - - 0.100000000000000 - - - 10.000000000000000 - - - - - - - Speed - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - -5.000000000000000 - - - 5.000000000000000 - - - - - - - Scale - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - true - - - - - - - true - - - - - - - true - - - - - - - true - - - - - - - true - - - - - - - - - 3D Noise - - - - - - - Animation Time [ms] - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - + BMWConfigForm + + + + 0 + 0 + 562 + 365 + + + + + + + Animation Time [ms] + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + - - - KColorButton - QPushButton -
kcolorbutton.h
-
-
- - +
+ + + + 100 + + + 9999 + + + 100 + + + + + + + Scale + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + 0.100000000000000 + + + 10.000000000000000 + + + + + + + Speed + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + -5.000000000000000 + + + 5.000000000000000 + + + + + + + Gradient + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + + + true + + + + + + + true + + + + + + + true + + + + + + + true + + + + + + + true + + + + + + + + + 3D Noise + + + + + + + Use Random Color + + + +
+
+ + + KColorButton + QPushButton +
kcolorbutton.h
+
+
+ +
diff --git a/kwin/fire/main.xml b/kwin/fire/main.xml index 0ca4dc0..da48b7d 100755 --- a/kwin/fire/main.xml +++ b/kwin/fire/main.xml @@ -36,5 +36,8 @@ SPDX-License-Identifier: GPL-3.0-or-later false + + false + \ No newline at end of file diff --git a/kwin/fire/onAnimationBegin.js b/kwin/fire/onAnimationBegin.js new file mode 100644 index 0000000..fcc14a2 --- /dev/null +++ b/kwin/fire/onAnimationBegin.js @@ -0,0 +1,8 @@ +// SPDX-FileCopyrightText: Simon Schneegans +// SPDX-License-Identifier: GPL-3.0-or-later + +// This part is automatically included in the effect's source during the build process. +// The code below is called whenever a window is closed or opened. + +let seed = Math.random(); +effect.setUniform(this.shader, 'uSeed', seed); diff --git a/kwin/fire/onSettingsChanged.js b/kwin/fire/onSettingsChanged.js index 5490f4b..2e4ade8 100644 --- a/kwin/fire/onSettingsChanged.js +++ b/kwin/fire/onSettingsChanged.js @@ -8,6 +8,8 @@ effect.setUniform(this.shader, 'uDuration', this.duration * 0.001); effect.setUniform(this.shader, 'u3DNoise', effect.readConfig('3DNoise', true) ? 1.0 : 0.0); +effect.setUniform(this.shader, 'uRandomColor', + effect.readConfig('RandomColor', true) ? 1.0 : 0.0); effect.setUniform(this.shader, 'uScale', effect.readConfig('Scale', 1.0)); effect.setUniform(this.shader, 'uMovementSpeed', effect.readConfig('MovementSpeed', 1.0)); effect.setUniform(this.shader, 'uGradient1', this.readRGBAConfig('Gradient1'));