🎉 Add initial magic lamp code

This commit is contained in:
Simon Schneegans
2023-03-29 20:00:11 +02:00
parent e051551747
commit 6eebcc6b8c
6 changed files with 282 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.Pixelate.Pixelate(), new Me.imports.src.effects.Pixelate.Pixelate(),
new Me.imports.src.effects.PixelWheel.PixelWheel(), new Me.imports.src.effects.PixelWheel.PixelWheel(),
+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.Pixelate.Pixelate(), new Me.imports.src.effects.Pixelate.Pixelate(),
new Me.imports.src.effects.PixelWheel.PixelWheel(), new Me.imports.src.effects.PixelWheel.PixelWheel(),
+44
View File
@@ -0,0 +1,44 @@
//////////////////////////////////////////////////////////////////////////////////////////
// ) ( //
// ( /( ( ( ) ( ( ( ( )\ ) ( ( //
// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
// | '_ \ || | '_| ' \)) | ' \()| || | \ 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 uPointerPos;
uniform vec2 uControlPointA;
uniform vec2 uControlPointB;
void main() {
float progress = uForOpening ? 1.0 - uProgress : uProgress;
vec2 texcoord = iTexCoord.st;
texcoord = texcoord * uActorScale + 0.5 - uActorScale * 0.5;
vec4 oColor = getInputColor(texcoord);
oColor.rgb *= vec3(1.0, 0.5, 0.5);
if (length(texcoord - uPointerPos) < 0.02) {
oColor = vec4(1.0);
}
if (length(texcoord - uControlPointA) < 0.02) {
oColor = vec4(1.0, 0.0, 0.0, 1.0);
}
if (length(texcoord - uControlPointB) < 0.02) {
oColor = vec4(0.0, 1.0, 0.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 -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+173
View File
@@ -0,0 +1,173 @@
//////////////////////////////////////////////////////////////////////////////////////////
// ) ( //
// ( /( ( ( ) ( ( ( ( )\ ) ( ( //
// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
// | '_ \ || | '_| ' \)) | ' \()| || | \ 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._uPointerPos = shader.get_uniform_location('uPointerPos');
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) => {
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) {
shader.set_uniform_float(shader._uPointerPos, 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._uControlPointA) {
this._uControlPointA = controlPointA;
} else {
this._uControlPointA = [
this._uControlPointA[0] * 0.95 + controlPointA[0] * 0.05,
this._uControlPointA[1] * 0.95 + controlPointA[1] * 0.05
];
}
const [ok, x, y] = convertCoords(this._uControlPointA);
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._uControlPointB) {
this._uControlPointB = controlPointB;
} else {
this._uControlPointB = [
this._uControlPointB[0] * 0.9 + controlPointB[0] * 0.1,
this._uControlPointB[1] * 0.9 + controlPointB[1] * 0.1
];
}
const [ok, x, y] = convertCoords(this._uControlPointB);
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)
};
}
}