From 84cf7840805c5bcbd36e9817432abb72e00185ca Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Sat, 8 Mar 2025 13:30:50 +0100 Subject: [PATCH 1/3] :beetle: Fix some effects on GNOME 48 --- src/effects/BrokenGlass.js | 8 +------- src/effects/Matrix.js | 10 +--------- src/effects/PaintBrush.js | 8 +------- src/effects/SnapOfDisintegration.js | 7 +------ src/effects/TRexAttack.js | 7 +------ src/utils.js | 26 ++++++++++++++++++++++++++ 6 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/effects/BrokenGlass.js b/src/effects/BrokenGlass.js index 955fd6d..7791745 100644 --- a/src/effects/BrokenGlass.js +++ b/src/effects/BrokenGlass.js @@ -20,8 +20,6 @@ import * as utils from '../utils.js'; // preferences process. They are used only in the creator function of the ShaderFactory // which is only called within GNOME Shell's process. const ShaderFactory = await utils.importInShellOnly('./ShaderFactory.js'); -const St = await utils.importInShellOnly('gi://St'); -const GdkPixbuf = await utils.importInShellOnly('gi://GdkPixbuf'); const Cogl = await utils.importInShellOnly('gi://Cogl'); const _ = await utils.importGettext(); @@ -55,11 +53,7 @@ export default class Effect { this.shaderFactory = new ShaderFactory(Effect.getNick(), (shader) => { // Create the texture in the first call. if (!this._shardTexture) { - const shardData = GdkPixbuf.Pixbuf.new_from_resource('/img/shards.png'); - this._shardTexture = new St.ImageContent(); - this._shardTexture.set_data(shardData.get_pixels(), Cogl.PixelFormat.RGB_888, - shardData.width, shardData.height, - shardData.rowstride); + this._shardTexture = utils.getImageResource('/img/shards.png'); } // Store all uniform locations. diff --git a/src/effects/Matrix.js b/src/effects/Matrix.js index ca800f8..45065ec 100644 --- a/src/effects/Matrix.js +++ b/src/effects/Matrix.js @@ -20,9 +20,6 @@ import * as utils from '../utils.js'; // preferences process. They are used only in the creator function of the ShaderFactory // which is only called within GNOME Shell's process. const ShaderFactory = await utils.importInShellOnly('./ShaderFactory.js'); -const St = await utils.importInShellOnly('gi://St'); -const GdkPixbuf = await utils.importInShellOnly('gi://GdkPixbuf'); -const Cogl = await utils.importInShellOnly('gi://Cogl'); const _ = await utils.importGettext(); @@ -47,12 +44,7 @@ export default class Effect { this.shaderFactory = new ShaderFactory(Effect.getNick(), (shader) => { // Create the texture in the first call. if (!this._fontTexture) { - const fontData = GdkPixbuf.Pixbuf.new_from_resource('/img/matrixFont.png'); - this._fontTexture = new St.ImageContent(); - this._fontTexture.set_data( - fontData.get_pixels(), - fontData.has_alpha ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888, - fontData.width, fontData.height, fontData.rowstride); + this._fontTexture = utils.getImageResource('/img/matrixFont.png'); } // Store uniform locations of newly created shaders. diff --git a/src/effects/PaintBrush.js b/src/effects/PaintBrush.js index 94d7e2d..da9b7b1 100644 --- a/src/effects/PaintBrush.js +++ b/src/effects/PaintBrush.js @@ -20,8 +20,6 @@ import * as utils from '../utils.js'; // preferences process. They are used only in the creator function of the ShaderFactory // which is only called within GNOME Shell's process. const ShaderFactory = await utils.importInShellOnly('./ShaderFactory.js'); -const St = await utils.importInShellOnly('gi://St'); -const GdkPixbuf = await utils.importInShellOnly('gi://GdkPixbuf'); const Cogl = await utils.importInShellOnly('gi://Cogl'); const _ = await utils.importGettext(); @@ -45,11 +43,7 @@ export default class Effect { this.shaderFactory = new ShaderFactory(Effect.getNick(), (shader) => { // Create the texture in the first call. if (!this._brushTexture) { - const brushData = GdkPixbuf.Pixbuf.new_from_resource('/img/brush.png'); - this._brushTexture = new St.ImageContent(); - this._brushTexture.set_data(brushData.get_pixels(), - Cogl.PixelFormat.RGBA_8888_PRE, brushData.width, - brushData.height, brushData.rowstride); + this._brushTexture = utils.getImageResource('/img/brush.png', true); } // Store uniform locations of newly created shaders. diff --git a/src/effects/SnapOfDisintegration.js b/src/effects/SnapOfDisintegration.js index 86126a9..78fcd5e 100644 --- a/src/effects/SnapOfDisintegration.js +++ b/src/effects/SnapOfDisintegration.js @@ -20,8 +20,6 @@ import * as utils from '../utils.js'; // preferences process. They are used only in the creator function of the ShaderFactory // which is only called within GNOME Shell's process. const ShaderFactory = await utils.importInShellOnly('./ShaderFactory.js'); -const St = await utils.importInShellOnly('gi://St'); -const GdkPixbuf = await utils.importInShellOnly('gi://GdkPixbuf'); const Cogl = await utils.importInShellOnly('gi://Cogl'); const _ = await utils.importGettext(); @@ -49,10 +47,7 @@ export default class Effect { this.shaderFactory = new ShaderFactory(Effect.getNick(), (shader) => { // Create the texture in the first call. if (!this._dustTexture) { - const dustData = GdkPixbuf.Pixbuf.new_from_resource('/img/dust.png'); - this._dustTexture = new St.ImageContent(); - this._dustTexture.set_data(dustData.get_pixels(), Cogl.PixelFormat.RGB_888, - dustData.width, dustData.height, dustData.rowstride); + this._dustTexture = utils.getImageResource('/img/dust.png'); } // Store uniform locations of newly created shaders. diff --git a/src/effects/TRexAttack.js b/src/effects/TRexAttack.js index 111335c..04c68f9 100644 --- a/src/effects/TRexAttack.js +++ b/src/effects/TRexAttack.js @@ -20,8 +20,6 @@ import * as utils from '../utils.js'; // preferences process. They are used only in the creator function of the ShaderFactory // which is only called within GNOME Shell's process. const ShaderFactory = await utils.importInShellOnly('./ShaderFactory.js'); -const St = await utils.importInShellOnly('gi://St'); -const GdkPixbuf = await utils.importInShellOnly('gi://GdkPixbuf'); const Cogl = await utils.importInShellOnly('gi://Cogl'); const _ = await utils.importGettext(); @@ -45,10 +43,7 @@ export default class Effect { this.shaderFactory = new ShaderFactory(Effect.getNick(), (shader) => { // Create the texture in the first call. if (!this._clawTexture) { - const clawData = GdkPixbuf.Pixbuf.new_from_resource('/img/claws.png'); - this._clawTexture = new St.ImageContent(); - this._clawTexture.set_data(clawData.get_pixels(), Cogl.PixelFormat.RGB_888, - clawData.width, clawData.height, clawData.rowstride); + this._clawTexture = utils.getImageResource('/img/claws.png'); } // Store uniform locations of newly created shaders. diff --git a/src/utils.js b/src/utils.js index 73ad404..72b1de2 100644 --- a/src/utils.js +++ b/src/utils.js @@ -20,8 +20,10 @@ import GLib from 'gi://GLib'; // We import some modules optionally. This file is used in the preferences process as well // as in the GNOME Shell process. Some modules are only available or required in one of // these processes. +const GdkPixbuf = await importInShellOnly('gi://GdkPixbuf'); const Clutter = await importInShellOnly('gi://Clutter'); const Cogl = await importInShellOnly('gi://Cogl'); +const St = await importInShellOnly('gi://St'); // We import the Config module. This is done differently in the GNOME Shell process and in // the preferences process. @@ -117,6 +119,30 @@ export function getStringResource(path) { return new TextDecoder().decode(data.get_data()); } +// Reads the contents of an image file contained in the global resources archive. The data +// is returned as a St.ImageContent. +export function getImageResource(path, premultiplied=false) { + const data = GdkPixbuf.Pixbuf.new_from_resource(path); + const texture = St.ImageContent.new_with_preferred_size(data.width, data.height); + const format = data.has_alpha ? (premultiplied ? Cogl.PixelFormat.RGBA_8888_PRE : Cogl.PixelFormat.RGBA_8888) : Cogl.PixelFormat.RGB_888; + + // https://gitlab.gnome.org/GNOME/gnome-shell/-/commit/44b84e458a22046fedb85701ea25ad08ecc0d43f + if (shellVersionIsAtLeast(48, 'beta')) { + texture.set_data( + global.stage.context.get_backend().get_cogl_context(), + data.get_pixels(), + format, + data.width, data.height, data.rowstride); + } else { + texture.set_data( + data.get_pixels(), + format, + data.width, data.height, data.rowstride); + } + + return texture; +} + // Executes a command asynchronously and returns the output from 'stdout' on success or // throw an error with output from 'stderr' on failure. If given, input will be passed to // 'stdin' and cancellable can be used to stop the process before it finishes. From 72475d8f6fafeeb23ba5bd51c28df0a3ac49185c Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Sat, 8 Mar 2025 13:35:26 +0100 Subject: [PATCH 2/3] :sparkles: Apply clang-format --- src/effects/BrokenGlass.js | 2 +- src/effects/PaintBrush.js | 2 +- src/effects/SnapOfDisintegration.js | 2 +- src/effects/TRexAttack.js | 2 +- src/utils.js | 24 ++++++++++-------------- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/effects/BrokenGlass.js b/src/effects/BrokenGlass.js index 7791745..94f7bc3 100644 --- a/src/effects/BrokenGlass.js +++ b/src/effects/BrokenGlass.js @@ -53,7 +53,7 @@ export default class Effect { this.shaderFactory = new ShaderFactory(Effect.getNick(), (shader) => { // Create the texture in the first call. if (!this._shardTexture) { - this._shardTexture = utils.getImageResource('/img/shards.png'); + this._shardTexture = utils.getImageResource('/img/shards.png'); } // Store all uniform locations. diff --git a/src/effects/PaintBrush.js b/src/effects/PaintBrush.js index da9b7b1..d352833 100644 --- a/src/effects/PaintBrush.js +++ b/src/effects/PaintBrush.js @@ -43,7 +43,7 @@ export default class Effect { this.shaderFactory = new ShaderFactory(Effect.getNick(), (shader) => { // Create the texture in the first call. if (!this._brushTexture) { - this._brushTexture = utils.getImageResource('/img/brush.png', true); + this._brushTexture = utils.getImageResource('/img/brush.png', true); } // Store uniform locations of newly created shaders. diff --git a/src/effects/SnapOfDisintegration.js b/src/effects/SnapOfDisintegration.js index 78fcd5e..3bb4417 100644 --- a/src/effects/SnapOfDisintegration.js +++ b/src/effects/SnapOfDisintegration.js @@ -47,7 +47,7 @@ export default class Effect { this.shaderFactory = new ShaderFactory(Effect.getNick(), (shader) => { // Create the texture in the first call. if (!this._dustTexture) { - this._dustTexture = utils.getImageResource('/img/dust.png'); + this._dustTexture = utils.getImageResource('/img/dust.png'); } // Store uniform locations of newly created shaders. diff --git a/src/effects/TRexAttack.js b/src/effects/TRexAttack.js index 04c68f9..3c7f278 100644 --- a/src/effects/TRexAttack.js +++ b/src/effects/TRexAttack.js @@ -43,7 +43,7 @@ export default class Effect { this.shaderFactory = new ShaderFactory(Effect.getNick(), (shader) => { // Create the texture in the first call. if (!this._clawTexture) { - this._clawTexture = utils.getImageResource('/img/claws.png'); + this._clawTexture = utils.getImageResource('/img/claws.png'); } // Store uniform locations of newly created shaders. diff --git a/src/utils.js b/src/utils.js index 72b1de2..c136cf5 100644 --- a/src/utils.js +++ b/src/utils.js @@ -21,9 +21,9 @@ import GLib from 'gi://GLib'; // as in the GNOME Shell process. Some modules are only available or required in one of // these processes. const GdkPixbuf = await importInShellOnly('gi://GdkPixbuf'); -const Clutter = await importInShellOnly('gi://Clutter'); -const Cogl = await importInShellOnly('gi://Cogl'); -const St = await importInShellOnly('gi://St'); +const Clutter = await importInShellOnly('gi://Clutter'); +const Cogl = await importInShellOnly('gi://Cogl'); +const St = await importInShellOnly('gi://St'); // We import the Config module. This is done differently in the GNOME Shell process and in // the preferences process. @@ -121,23 +121,19 @@ export function getStringResource(path) { // Reads the contents of an image file contained in the global resources archive. The data // is returned as a St.ImageContent. -export function getImageResource(path, premultiplied=false) { +export function getImageResource(path, premultiplied = false) { const data = GdkPixbuf.Pixbuf.new_from_resource(path); const texture = St.ImageContent.new_with_preferred_size(data.width, data.height); - const format = data.has_alpha ? (premultiplied ? Cogl.PixelFormat.RGBA_8888_PRE : Cogl.PixelFormat.RGBA_8888) : Cogl.PixelFormat.RGB_888; + const format = data.has_alpha ? + (premultiplied ? Cogl.PixelFormat.RGBA_8888_PRE : Cogl.PixelFormat.RGBA_8888) : + Cogl.PixelFormat.RGB_888; // https://gitlab.gnome.org/GNOME/gnome-shell/-/commit/44b84e458a22046fedb85701ea25ad08ecc0d43f if (shellVersionIsAtLeast(48, 'beta')) { - texture.set_data( - global.stage.context.get_backend().get_cogl_context(), - data.get_pixels(), - format, - data.width, data.height, data.rowstride); + texture.set_data(global.stage.context.get_backend().get_cogl_context(), + data.get_pixels(), format, data.width, data.height, data.rowstride); } else { - texture.set_data( - data.get_pixels(), - format, - data.width, data.height, data.rowstride); + texture.set_data(data.get_pixels(), format, data.width, data.height, data.rowstride); } return texture; From ceb32a3da3670d3800a26d0d80858167a49d5596 Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Sat, 8 Mar 2025 13:57:26 +0100 Subject: [PATCH 3/3] :memo: Add changelog entry --- docs/changelog.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 6ac7160..d3538d4 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -5,6 +5,14 @@ SPDX-License-Identifier: CC-BY-4.0 # Changelog of the Burn-My-Windows Extension +## [unreleased] + +**Release Date:** TBD + +#### 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). + ## [Burn My Windows 45](https://github.com/schneegans/Burn-My-Windows/releases/tag/v45) **Release Date:** 2025-02-21