From d08c318b7da04ac3893df7c0d4a0e62a228e2d2e Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Fri, 10 Jun 2022 13:57:21 +0200 Subject: [PATCH] :wrench: Tweak kwin build process --- kwin/build.sh | 38 ++++++++++++++---- kwin/kwin4_effect_energize_a/loadConfig.js | 5 --- .../onSettingsChanged.js | 6 +++ kwin/kwin4_effect_energize_b/loadConfig.js | 5 --- .../onSettingsChanged.js | 6 +++ kwin/kwin4_effect_tv/loadConfig.js | 4 -- kwin/kwin4_effect_tv/onSettingsChanged.js | 5 +++ kwin/main.js.in | 39 ++++++++++--------- resources/shaders/common.glsl | 29 +++++--------- 9 files changed, 77 insertions(+), 60 deletions(-) delete mode 100644 kwin/kwin4_effect_energize_a/loadConfig.js create mode 100644 kwin/kwin4_effect_energize_a/onSettingsChanged.js delete mode 100644 kwin/kwin4_effect_energize_b/loadConfig.js create mode 100644 kwin/kwin4_effect_energize_b/onSettingsChanged.js delete mode 100644 kwin/kwin4_effect_tv/loadConfig.js create mode 100644 kwin/kwin4_effect_tv/onSettingsChanged.js diff --git a/kwin/build.sh b/kwin/build.sh index dfe2268..2811fed 100755 --- a/kwin/build.sh +++ b/kwin/build.sh @@ -41,15 +41,34 @@ generate() { mkdir -p "$BUILD_DIR/$DIR_NAME/contents/config" mkdir -p "$BUILD_DIR/$DIR_NAME/contents/ui" - # Copy the config and ui files. - cp "$DIR_NAME/main.xml" "$BUILD_DIR/$DIR_NAME/contents/config" - cp "$DIR_NAME/config.ui" "$BUILD_DIR/$DIR_NAME/contents/ui" + # Copy the config file if it exists. + if [ -f "$DIR_NAME/main.xml" ]; then + cp "$DIR_NAME/main.xml" "$BUILD_DIR/$DIR_NAME/contents/config" + fi - perl -pe "s/%LOAD_CONFIG%/$(tr '/' '\f' < "$DIR_NAME/loadConfig.js")/g;" \ - main.js.in | tr '\f' '/' > "$BUILD_DIR/$DIR_NAME/contents/code/main.js" + # Copy the ui file if it exists. + if [ -f "$DIR_NAME/config.ui" ]; then + cp "$DIR_NAME/config.ui" "$BUILD_DIR/$DIR_NAME/contents/ui" + fi - perl -pi -e "s/%EFFECT_CLASS%/$EFFECT_CLASS/g;" "$BUILD_DIR/$DIR_NAME/contents/code/main.js" - perl -pi -e "s/%SHADER_NAME%/$1/g;" "$BUILD_DIR/$DIR_NAME/contents/code/main.js" + + ON_SETTINGS_CHANGE="" + ON_ANIMATION_BEGIN="" + + if [ -f "$DIR_NAME/onSettingsChanged.js" ]; then + ON_SETTINGS_CHANGE=$(tr '/' '\f' < "$DIR_NAME/onSettingsChanged.js") + fi + + if [ -f "$DIR_NAME/onAnimationBegin.js" ]; then + ON_ANIMATION_BEGIN=$(tr '/' '\f' < "$DIR_NAME/onAnimationBegin.js") + fi + + cp main.js.in "$BUILD_DIR/$DIR_NAME/contents/code/main.js" + perl -pi -e "s/%ON_SETTINGS_CHANGE%/$ON_SETTINGS_CHANGE/g;" "$BUILD_DIR/$DIR_NAME/contents/code/main.js" + perl -pi -e "s/%ON_ANIMATION_BEGIN%/$ON_ANIMATION_BEGIN/g;" "$BUILD_DIR/$DIR_NAME/contents/code/main.js" + perl -pi -e "s/%EFFECT_CLASS%/$EFFECT_CLASS/g;" "$BUILD_DIR/$DIR_NAME/contents/code/main.js" + perl -pi -e "s/%SHADER_NAME%/$1/g;" "$BUILD_DIR/$DIR_NAME/contents/code/main.js" + perl -pi -e "s/\f/\//g;" "$BUILD_DIR/$DIR_NAME/contents/code/main.js" cp metadata.desktop.in "$BUILD_DIR/$DIR_NAME/metadata.desktop" perl -pi -e "s/%ICON%/$1/g;" "$BUILD_DIR/$DIR_NAME/metadata.desktop" @@ -75,9 +94,12 @@ generate() { cat "../resources/shaders/common.glsl" cat "../resources/shaders/$1.frag" } > "$BUILD_DIR/$DIR_NAME/contents/shaders/$1.frag" + + # If clang-format is installed, try to beauty the code a bit. } -generate "tv" "TV Effect" "Make windows close like turning off a TV" generate "energize-a" "Energize A" "Beam your windows away" generate "energize-b" "Energize B" "Using different transporter technology results in an alternative visual effect" +generate "hexagon" "Hexagon" "With glowing lines and hexagon-shaped tiles, this effect looks very sci-fi" +generate "tv" "TV Effect" "Make windows close like turning off a TV" # generate "fire" "Fire" "Make windows burn" \ No newline at end of file diff --git a/kwin/kwin4_effect_energize_a/loadConfig.js b/kwin/kwin4_effect_energize_a/loadConfig.js deleted file mode 100644 index bda8a0b..0000000 --- a/kwin/kwin4_effect_energize_a/loadConfig.js +++ /dev/null @@ -1,5 +0,0 @@ -loadConfig() { - this.duration = animationTime(effect.readConfig('Duration', 1000)); - effect.setUniform(this.shader, 'uColor', effect.readConfig('Color', 'white')); - effect.setUniform(this.shader, 'uScale', effect.readConfig('Scale', 1.0)); -} \ No newline at end of file diff --git a/kwin/kwin4_effect_energize_a/onSettingsChanged.js b/kwin/kwin4_effect_energize_a/onSettingsChanged.js new file mode 100644 index 0000000..5becc52 --- /dev/null +++ b/kwin/kwin4_effect_energize_a/onSettingsChanged.js @@ -0,0 +1,6 @@ +// This part is automatically included in the effect's source during the build process. +// The code below is called whenever the user changes something in the configuration of +// the effect. + +effect.setUniform(this.shader, 'uColor', effect.readConfig('Color', 'white')); +effect.setUniform(this.shader, 'uScale', effect.readConfig('Scale', 1.0)); \ No newline at end of file diff --git a/kwin/kwin4_effect_energize_b/loadConfig.js b/kwin/kwin4_effect_energize_b/loadConfig.js deleted file mode 100644 index bda8a0b..0000000 --- a/kwin/kwin4_effect_energize_b/loadConfig.js +++ /dev/null @@ -1,5 +0,0 @@ -loadConfig() { - this.duration = animationTime(effect.readConfig('Duration', 1000)); - effect.setUniform(this.shader, 'uColor', effect.readConfig('Color', 'white')); - effect.setUniform(this.shader, 'uScale', effect.readConfig('Scale', 1.0)); -} \ No newline at end of file diff --git a/kwin/kwin4_effect_energize_b/onSettingsChanged.js b/kwin/kwin4_effect_energize_b/onSettingsChanged.js new file mode 100644 index 0000000..5a5dce5 --- /dev/null +++ b/kwin/kwin4_effect_energize_b/onSettingsChanged.js @@ -0,0 +1,6 @@ +// This part is automatically included in the effect's source during the build process. +// The code below is called whenever the user changes something in the configuration of +// the effect. + +effect.setUniform(this.shader, 'uColor', effect.readConfig('Color', 'white')); +effect.setUniform(this.shader, 'uScale', effect.readConfig('Scale', 1.0)); diff --git a/kwin/kwin4_effect_tv/loadConfig.js b/kwin/kwin4_effect_tv/loadConfig.js deleted file mode 100644 index 9330cf9..0000000 --- a/kwin/kwin4_effect_tv/loadConfig.js +++ /dev/null @@ -1,4 +0,0 @@ -loadConfig() { - this.duration = animationTime(effect.readConfig('Duration', 1000)); - effect.setUniform(this.shader, 'uColor', effect.readConfig('Color', 'white')); -} \ No newline at end of file diff --git a/kwin/kwin4_effect_tv/onSettingsChanged.js b/kwin/kwin4_effect_tv/onSettingsChanged.js new file mode 100644 index 0000000..e656b03 --- /dev/null +++ b/kwin/kwin4_effect_tv/onSettingsChanged.js @@ -0,0 +1,5 @@ +// This part is automatically included in the effect's source during the build process. +// The code below is called whenever the user changes something in the configuration of +// the effect. + +effect.setUniform(this.shader, 'uColor', effect.readConfig('Color', 'white')); \ No newline at end of file diff --git a/kwin/main.js.in b/kwin/main.js.in index 13452bc..89a82a3 100755 --- a/kwin/main.js.in +++ b/kwin/main.js.in @@ -30,7 +30,12 @@ class %EFFECT_CLASS% { this.loadConfig(); } - %LOAD_CONFIG% + loadConfig() { + this.duration = animationTime(effect.readConfig('Duration', 1000)); + effect.setUniform(this.shader, 'uDuration', this.duration * 0.001); + + %ON_SETTINGS_CHANGE% + } static isScaleWindow(window) { // We don't want to animate most of plasmashell's windows, yet, some @@ -95,6 +100,11 @@ class %EFFECT_CLASS% { return; } this.setupForcedRoles(window); + + effect.setUniform(this.shader, 'uForOpening', 1.0); + + %ON_ANIMATION_BEGIN% + window.scaleInAnimation = animate({ window: window, curve: QEasingCurve.Linear, @@ -103,16 +113,9 @@ class %EFFECT_CLASS% { { type: Effect.ShaderUniform, fragmentShader: this.shader, - uniform: "forOpening", - from: 1.0, + uniform: "uProgress", + from: 0.0, to: 1.0 - }, - { - type: Effect.ShaderUniform, - fragmentShader: this.shader, - uniform: "uDuration", - from: this.duration * 0.001, - to: this.duration * 0.001 } ] }); @@ -136,6 +139,11 @@ class %EFFECT_CLASS% { delete window.scaleInAnimation; } this.setupForcedRoles(window); + + effect.setUniform(this.shader, 'uForOpening', 0.0); + + %ON_ANIMATION_BEGIN% + window.scaleOutAnimation = animate({ window: window, curve: QEasingCurve.Linear, @@ -144,16 +152,9 @@ class %EFFECT_CLASS% { { type: Effect.ShaderUniform, fragmentShader: this.shader, - uniform: "forOpening", + uniform: "uProgress", from: 0.0, - to: 0.0 - }, - { - type: Effect.ShaderUniform, - fragmentShader: this.shader, - uniform: "uDuration", - from: this.duration * 0.001, - to: this.duration * 0.001 + to: 1.0 } ] }); diff --git a/resources/shaders/common.glsl b/resources/shaders/common.glsl index fbced17..80894b7 100644 --- a/resources/shaders/common.glsl +++ b/resources/shaders/common.glsl @@ -33,23 +33,22 @@ // vec4 getInputColor(vec2 coords) // void setOutputColor(vec4 outColor) +uniform bool uForOpening; +uniform float uProgress; +uniform float uDuration; + #if defined(KWIN) // -------------------------------------------------------------------- -uniform float forOpening; uniform sampler2D sampler; -uniform float uDuration; uniform int textureWidth; uniform int textureHeight; -uniform float animationProgress; in vec2 texcoord0; out vec4 fragColor; -vec2 uSize = vec2(textureWidth, textureHeight); -bool uForOpening = forOpening == 1.0; -vec2 iTexCoord = vec2(texcoord0.x, 1.0 - texcoord0.y); -float uProgress = animationProgress; -float uPadding = 0.0; +vec2 uSize = vec2(textureWidth, textureHeight); +vec2 iTexCoord = vec2(texcoord0.x, 1.0 - texcoord0.y); +float uPadding = 0.0; vec4 getInputColor(vec2 coords) { vec4 color = texture2D(sampler, vec2(coords.x, 1.0 - coords.y)); @@ -67,20 +66,15 @@ void setOutputColor(vec4 outColor) { #elif defined(KWIN_LEGACY) // ----------------------------------------------------------- -uniform float forOpening; uniform sampler2D sampler; -uniform float uDuration; uniform int textureWidth; uniform int textureHeight; -uniform float animationProgress; varying vec2 texcoord0; -vec2 uSize = vec2(textureWidth, textureHeight); -bool uForOpening = forOpening == 1.0; -vec2 iTexCoord = vec2(texcoord0.x, 1.0 - texcoord0.y); -float uProgress = animationProgress; -float uPadding = 0.0; +vec2 uSize = vec2(textureWidth, textureHeight); +vec2 iTexCoord = vec2(texcoord0.x, 1.0 - texcoord0.y); +float uPadding = 0.0; vec4 getInputColor(vec2 coords) { vec4 color = texture2D(sampler, vec2(coords.x, 1.0 - coords.y)); @@ -99,10 +93,7 @@ void setOutputColor(vec4 outColor) { #else // GNOME -------------------------------------------------------------------------- // On GNOME, the uniforms are just normal uniforms. -uniform bool uForOpening; uniform sampler2D uTexture; -uniform float uProgress; -uniform float uDuration; uniform vec2 uSize; uniform float uPadding;