Compare commits

...

6 Commits

Author SHA1 Message Date
Simon Schneegans 62c57a5163 Merge branch 'main' into feature/magic-lamp
Checks / Check Clang-Format (push) Has been cancelled
Checks / Check Compliance with REUSE Specification (push) Has been cancelled
Checks / Check Comment Percentage (push) Has been cancelled
Checks / Run ShellCheck (push) Has been cancelled
Checks / Generate References (push) Has been cancelled
Checks / Run Tests (gnome-wayland-nested, 32) (push) Has been cancelled
Checks / Run Tests (gnome-wayland-nested, 33) (push) Has been cancelled
Checks / Run Tests (gnome-wayland-nested, 34) (push) Has been cancelled
Checks / Run Tests (gnome-wayland-nested, 35) (push) Has been cancelled
Checks / Run Tests (gnome-wayland-nested, 36) (push) Has been cancelled
Checks / Run Tests (gnome-wayland-nested, 37) (push) Has been cancelled
Checks / Run Tests (gnome-wayland-nested, 38) (push) Has been cancelled
Checks / Run Tests (gnome-wayland-nested, rawhide) (push) Has been cancelled
Checks / Run Tests (gnome-xsession, 32) (push) Has been cancelled
Checks / Run Tests (gnome-xsession, 33) (push) Has been cancelled
Checks / Run Tests (gnome-xsession, 34) (push) Has been cancelled
Checks / Run Tests (gnome-xsession, 35) (push) Has been cancelled
Checks / Run Tests (gnome-xsession, 36) (push) Has been cancelled
Checks / Run Tests (gnome-xsession, 37) (push) Has been cancelled
Checks / Run Tests (gnome-xsession, 38) (push) Has been cancelled
Checks / Run Tests (gnome-xsession, rawhide) (push) Has been cancelled
2023-08-13 12:43:40 +02:00
Simon Schneegans b9901bad86 🔧 Work on lamp warping 2023-08-05 12:15:55 +02:00
Simon Schneegans 21dc4eac3d 🔧 Pass initial pointer position to magic lamp shader 2023-08-02 19:25:31 +02:00
Simon Schneegans b53b856c3e 🔧 Add some warping 2023-08-02 14:02:38 +02:00
Simon Schneegans 7625c98ad8 Merge branch 'main' into feature/magic-lamp 2023-08-02 13:49:00 +02:00
Simon Schneegans 6eebcc6b8c 🎉 Add initial magic lamp code 2023-03-29 20:00:11 +02:00
6 changed files with 318 additions and 0 deletions
+1
View File
@@ -64,6 +64,7 @@ class Extension {
new Me.imports.src.effects.Glitch.Glitch(), new Me.imports.src.effects.Glitch.Glitch(),
new Me.imports.src.effects.Hexagon.Hexagon(), new Me.imports.src.effects.Hexagon.Hexagon(),
new Me.imports.src.effects.Incinerate.Incinerate(), new Me.imports.src.effects.Incinerate.Incinerate(),
new Me.imports.src.effects.MagicLamp.MagicLamp(),
new Me.imports.src.effects.Matrix.Matrix(), new Me.imports.src.effects.Matrix.Matrix(),
new Me.imports.src.effects.PaintBrush.PaintBrush(), new Me.imports.src.effects.PaintBrush.PaintBrush(),
new Me.imports.src.effects.Pixelate.Pixelate(), new Me.imports.src.effects.Pixelate.Pixelate(),
+1
View File
@@ -55,6 +55,7 @@ var PreferencesDialog = class PreferencesDialog {
new Me.imports.src.effects.Glitch.Glitch(), new Me.imports.src.effects.Glitch.Glitch(),
new Me.imports.src.effects.Hexagon.Hexagon(), new Me.imports.src.effects.Hexagon.Hexagon(),
new Me.imports.src.effects.Incinerate.Incinerate(), new Me.imports.src.effects.Incinerate.Incinerate(),
new Me.imports.src.effects.MagicLamp.MagicLamp(),
new Me.imports.src.effects.Matrix.Matrix(), new Me.imports.src.effects.Matrix.Matrix(),
new Me.imports.src.effects.PaintBrush.PaintBrush(), new Me.imports.src.effects.PaintBrush.PaintBrush(),
new Me.imports.src.effects.Pixelate.Pixelate(), new Me.imports.src.effects.Pixelate.Pixelate(),
+69
View File
@@ -0,0 +1,69 @@
//////////////////////////////////////////////////////////////////////////////////////////
// ) ( //
// ( /( ( ( ) ( ( ( ( )\ ) ( ( //
// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< //
// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ //
// |__/ //
//////////////////////////////////////////////////////////////////////////////////////////
// SPDX-FileCopyrightText: Simon Schneegans <code@simonschneegans.de>
// SPDX-License-Identifier: GPL-3.0-or-later
// The content from common.glsl is automatically prepended to each shader effect.
uniform vec2 uActorScale;
uniform vec2 uInitialPointerPos;
uniform vec2 uCurrentPointerPos;
uniform vec2 uControlPointA;
uniform vec2 uControlPointB;
vec2 threeWayMix(float fac, vec2 a, vec2 b, vec2 c) {
if (fac < 0.5) {
return mix(a, b, smoothstep(0.0, 1.0, fac * 2.0));
}
return mix(b, c, smoothstep(0.0, 1.0, fac * 2.0 - 1.0));
}
void main() {
vec2 texcoord = iTexCoord.st;
texcoord = texcoord * uActorScale + 0.5 - uActorScale * 0.5;
float circle = length((texcoord - uCurrentPointerPos) / uActorScale * 2.0);
float progress = uForOpening ? 1.0 - uProgress : uProgress;
progress = clamp(mix(max(0.0, uProgress*2.0 - circle), 2.0 * uProgress, uProgress), 0.0, 1.0);
// progress = smoothstep(0.0, 1.0, pow(2.0 * progress - circle, 0.5));
vec2 warpA = (texcoord - uControlPointA) * uProgress * progress / (1.0 - uProgress);
vec2 warpB = (texcoord - uControlPointB) * uProgress * progress / (1.0 - uProgress);
vec2 warpC = (texcoord - uCurrentPointerPos) * uProgress * progress / (1.0 - uProgress);
vec2 warp = threeWayMix(progress, warpA, warpB, warpC);
// vec2 warp = (warpA + warpB + warpC) / (progressA + progressB + progressC);
vec4 oColor = getInputColor(texcoord + warp);
// oColor = vec4(tritone(progress, vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 1.0)), 1.0);
// if (length(texcoord - uInitialPointerPos) < 0.02) {
// oColor = vec4(1.0);
// }
// if (length(texcoord - uCurrentPointerPos) < 0.02) {
// oColor = vec4(1.0, 0.0, 0.0, 1.0);
// }
// if (length(texcoord - uControlPointA) < 0.02) {
// oColor = vec4(0.0, 1.0, 0.0, 1.0);
// }
// if (length(texcoord - uControlPointB) < 0.02) {
// oColor = vec4(0.0, 0.0, 1.0, 1.0);
// }
setOutputColor(oColor);
}
+47
View File
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
SPDX-FileCopyrightText: Simon Schneegans <code@simonschneegans.de>
SPDX-License-Identifier: GPL-3.0-or-later
-->
<interface domain="burn-my-windows">
<object class="AdwExpanderRow" id="magic-lamp-prefs">
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Animation Time [ms]</property>
<child>
<object class="GtkScale">
<property name="valign">center</property>
<property name="draw-value">1</property>
<property name="digits">0</property>
<property name="value-pos">left</property>
<property name="width-request">300</property>
<property name="adjustment">
<object class="GtkAdjustment" id="magic-lamp-animation-time">
<property name="upper">10000</property>
<property name="lower">100</property>
<property name="step-increment">1</property>
<property name="page-increment">100</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkButton" id="reset-magic-lamp-animation-time">
<property name="icon-name">edit-clear-symbolic</property>
<property name="valign">center</property>
<property name="tooltip-text" translatable="yes">Reset to Default Value</property>
<style>
<class name="flat" />
</style>
</object>
</child>
</object>
</child>
</object>
</interface>
@@ -318,6 +318,22 @@ SPDX-License-Identifier: CC0-1.0
<description>The amount of shifting.</description> <description>The amount of shifting.</description>
</key> </key>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Magic Lamp Options -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<key name="magic-lamp-enable-effect" type="b">
<default>false</default>
<summary>Magic Lamp Enable Effect</summary>
<description>Use the magic lamp effect.</description>
</key>
<key name="magic-lamp-animation-time" type="i">
<default>1500</default>
<summary>Magic Lamp Animation Time</summary>
<description>The time the magic lamp effect takes.</description>
</key>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Matrix Options --> <!-- Matrix Options -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+184
View File
@@ -0,0 +1,184 @@
//////////////////////////////////////////////////////////////////////////////////////////
// ) ( //
// ( /( ( ( ) ( ( ( ( )\ ) ( ( //
// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< //
// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ //
// |__/ //
//////////////////////////////////////////////////////////////////////////////////////////
// SPDX-FileCopyrightText: Simon Schneegans <code@simonschneegans.de>
// SPDX-License-Identifier: GPL-3.0-or-later
'use strict';
const {GObject, Graphene} = imports.gi;
const _ = imports.gettext.domain('burn-my-windows').gettext;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const utils = Me.imports.src.utils;
const ShaderFactory = Me.imports.src.ShaderFactory.ShaderFactory;
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
// The effect class can be used to get some metadata (like the effect's name or supported
// GNOME Shell versions), to initialize the respective page of the settings dialog, as
// well as to create the actual shader for the effect.
var MagicLamp = class {
// The constructor creates a ShaderFactory which will be used by extension.js to create
// shader instances for this effect. The shaders will be automagically created using the
// GLSL file in resources/shaders/<nick>.glsl. The callback will be called for each
// newly created shader instance.
constructor() {
this.shaderFactory = new ShaderFactory(this.getNick(), (shader) => {
// Store uniform locations of newly created shaders.
shader._uActorScale = shader.get_uniform_location('uActorScale');
shader._uInitialPointerPos = shader.get_uniform_location('uInitialPointerPos');
shader._uCurrentPointerPos = shader.get_uniform_location('uCurrentPointerPos');
shader._uControlPointA = shader.get_uniform_location('uControlPointA');
shader._uControlPointB = shader.get_uniform_location('uControlPointB');
// Write all uniform values at the start of each animation.
shader.connect('begin-animation',
(shader, settings, forOpening, testMode, actor) => {
this._initialPointerPos = null;
this._controlPointA = null;
this._controlPointB = null;
shader.set_uniform_float(shader._uActorScale, 2, [
2.0 * Math.max(1.0, global.stage.width / actor.width),
2.0 * Math.max(1.0, global.stage.height / actor.height)
]);
this._actor = actor;
});
shader.connect('update-animation', (shader) => {
const convertCoords = coords => {
const [ok, localX, localY] =
this._actor.transform_stage_point(coords[0], coords[1]);
const scale = [
2.0 * Math.max(1.0, global.stage.width / this._actor.width),
2.0 * Math.max(1.0, global.stage.height / this._actor.height)
];
return [
ok,
localX / this._actor.width * scale[0] + 0.5 - scale[0] * 0.5,
localY / this._actor.height * scale[1] + 0.5 - scale[1] * 0.5,
];
};
const pointer = global.get_pointer();
{
const [ok, x, y] = convertCoords(pointer);
if (ok) {
if (!this._initialPointerPos) {
this._initialPointerPos = [x, y];
shader.set_uniform_float(shader._uInitialPointerPos, 2, [x, y]);
}
shader.set_uniform_float(shader._uCurrentPointerPos, 2, [x, y]);
}
}
{
const center = this._actor.apply_transform_to_point(new Graphene.Point3D(
{x: this._actor.width / 2, y: this._actor.height / 2, z: 0}));
const controlPointA =
[pointer[0] * 0.33 + 0.66 * center.x, pointer[1] * 0.33 + 0.66 * center.y];
if (!this._controlPointA) {
this._controlPointA = controlPointA;
} else {
this._controlPointA = [
this._controlPointA[0] * 0.99 + controlPointA[0] * 0.01,
this._controlPointA[1] * 0.99 + controlPointA[1] * 0.01
];
}
const [ok, x, y] = convertCoords(this._controlPointA);
shader.set_uniform_float(shader._uControlPointA, 2, [x, y]);
}
{
const center = this._actor.apply_transform_to_point(new Graphene.Point3D(
{x: this._actor.width / 2, y: this._actor.height / 2, z: 0}));
const controlPointB =
[pointer[0] * 0.66 + 0.33 * center.x, pointer[1] * 0.66 + 0.33 * center.y];
if (!this._controlPointB) {
this._controlPointB = controlPointB;
} else {
this._controlPointB = [
this._controlPointB[0] * 0.95 + controlPointB[0] * 0.05,
this._controlPointB[1] * 0.95 + controlPointB[1] * 0.05
];
}
const [ok, x, y] = convertCoords(this._controlPointB);
shader.set_uniform_float(shader._uControlPointB, 2, [x, y]);
}
});
});
}
// ---------------------------------------------------------------------------- metadata
// The effect is not available on GNOME Shell 3.36 as it requires scaling of the window
// actor.
getMinShellVersion() {
return [3, 38];
}
// This will be called in various places where a unique identifier for this effect is
// required. It should match the prefix of the settings keys which store whether the
// effect is enabled currently (e.g. '*-enable-effect'), and its animation time
// (e.g. '*-animation-time').
getNick() {
return 'magic-lamp';
}
// This will be shown in the sidebar of the preferences dialog as well as in the
// drop-down menus where the user can choose the effect.
getLabel() {
return _('Magic Lamp');
}
// -------------------------------------------------------------------- API for prefs.js
// This is called by the preferences dialog whenever a new effect profile is loaded. It
// binds all user interface elements to the respective settings keys of the profile.
bindPreferences(dialog) {
dialog.bindAdjustment('magic-lamp-animation-time');
// dialog.bindAdjustment('doom-horizontal-scale');
// dialog.bindAdjustment('doom-vertical-scale');
// dialog.bindAdjustment('doom-pixel-size');
}
// ---------------------------------------------------------------- API for extension.js
// The getActorScale() is called from extension.js to adjust the actor's size during the
// animation. This is useful if the effect requires drawing something beyond the usual
// bounds of the actor. This only works for GNOME 3.38+.
// For this effect, we scale the actor vertically so that it covers the entire screen.
// This ensures that the melted window will not be cut off.
getActorScale(settings, forOpening, actor) {
// return {x: 1.0, y: 1.0};
return {
x: 2.0 * Math.max(1.0, global.stage.width / actor.width),
y: 2.0 * Math.max(1.0, global.stage.height / actor.height)
};
}
}