-
-
Notifications
You must be signed in to change notification settings - Fork 79
/
extension.js
629 lines (522 loc) · 27.8 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
//////////////////////////////////////////////////////////////////////////////////////////
// ) ( //
// ( /( ( ( ) ( ( ( ( )\ ) ( ( //
// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< //
// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ //
// |__/ //
//////////////////////////////////////////////////////////////////////////////////////////
// SPDX-FileCopyrightText: Simon Schneegans <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
'use strict';
import Gio from 'gi://Gio';
import Meta from 'gi://Meta';
import {fromVersion26} from './src/migrate.js';
import {ProfileManager} from './src/ProfileManager.js';
import {WindowPicker} from './src/WindowPicker.js';
import * as utils from './src/utils.js';
import Apparition from './src/effects/Apparition.js';
import BrokenGlass from './src/effects/BrokenGlass.js';
import Doom from './src/effects/Doom.js';
import EnergizeA from './src/effects/EnergizeA.js';
import EnergizeB from './src/effects/EnergizeB.js';
import Fire from './src/effects/Fire.js';
import Focus from './src/effects/Focus.js';
import Glide from './src/effects/Glide.js';
import Glitch from './src/effects/Glitch.js';
import Hexagon from './src/effects/Hexagon.js';
import Incinerate from './src/effects/Incinerate.js';
import Matrix from './src/effects/Matrix.js';
import PaintBrush from './src/effects/PaintBrush.js';
import Pixelate from './src/effects/Pixelate.js';
import PixelWheel from './src/effects/PixelWheel.js';
import PixelWipe from './src/effects/PixelWipe.js';
import Portal from './src/effects/Portal.js';
import SnapOfDisintegration from './src/effects/SnapOfDisintegration.js';
import TRexAttack from './src/effects/TRexAttack.js';
import TVEffect from './src/effects/TVEffect.js';
import TVGlitch from './src/effects/TVGlitch.js';
import Wisps from './src/effects/Wisps.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import {Workspace} from 'resource:///org/gnome/shell/ui/workspace.js';
import {WindowPreview} from 'resource:///org/gnome/shell/ui/windowPreview.js';
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
//////////////////////////////////////////////////////////////////////////////////////////
// This extensions modifies the window-close and window-open animations with all kinds //
// of effects. The effects are implemented using GLSL shaders which are applied to the //
// window's Clutter.Actor. The extension is actually very simple, much of the //
// complexity comes from the fact that GNOME Shell usually does not show an animation //
// when a window is closed in the overview. Several methods need to be monkey-patched //
// to get this working. For more details, read the other comments in this file... //
//////////////////////////////////////////////////////////////////////////////////////////
export default class BurnMyWindows extends Extension {
// ------------------------------------------------------------------------ public stuff
// This function could be called after the extension is enabled, which could be done
// from GNOME Tweaks, when you log in or when the screen is unlocked.
enable() {
// New effects must be registered here and in prefs.js.
this._ALL_EFFECTS = [
new Apparition(), new BrokenGlass(), new Doom(),
new EnergizeA(), new EnergizeB(), new Fire(),
new Focus(), new Glide(), new Glitch(),
new Hexagon(), new Incinerate(), new Matrix(),
new PaintBrush(), new Pixelate(), new PixelWheel(),
new PixelWipe(), new Portal(), new SnapOfDisintegration(),
new TRexAttack(), new TVEffect(), new TVGlitch(),
new Wisps(),
];
// Load all of our resources.
this._resources =
Gio.Resource.load(this.path + '/resources/burn-my-windows.gresource');
Gio.resources_register(this._resources);
// Store a reference to the settings object.
this._settings = this.getSettings();
// Now we check whether the extension settings need to be migrated from a previous
// version. If this is the case, we defer the profile loading until this is finished.
const lastVersion = this._settings.get_int('last-extension-version');
if (lastVersion < this.metadata.version) {
if (lastVersion <= 26) {
// If the profile migration fails for some reason, the callback will create a
// default profile instead.
fromVersion26().finally(() => {
this._loadProfiles();
this._settings.set_int('last-extension-version', this.metadata.version);
});
} else {
this._loadProfiles();
}
} else {
this._loadProfiles();
}
// We reload all effect profiles whenever the currently edited profile in the
// preferences dialog changes. This is most likely a bit too often, but it will also
// happen whenever a new profile is created and whenever an old profile is deleted.
this._settings.connect('changed::active-profile', () => {
this._loadProfiles();
});
// This is used to get the desktop's color scheme.
this._shellSettings = new Gio.Settings({schema: 'org.gnome.desktop.interface'});
// Enable the window-picking D-Bus API for the preferences dialog.
this._windowPicker = new WindowPicker();
this._windowPicker.export();
// We will use extensionThis to refer to the extension inside the patched methods.
const extensionThis = this;
// This is used to get the battery state.
const UPowerProxy = Gio.DBusProxy.makeProxyWrapper(
utils.getStringResource('/interfaces/org.freedesktop.UPower.xml'));
this._upowerProxy = new UPowerProxy(Gio.DBus.system, 'org.freedesktop.UPower',
'/org/freedesktop/UPower');
// This is used to get the current power profile.
try {
const PowerProfilesProxy = Gio.DBusProxy.makeProxyWrapper(
utils.getStringResource('/interfaces/net.hadess.PowerProfiles.xml'));
this._powerProfilesProxy = new PowerProfilesProxy(
Gio.DBus.system, 'net.hadess.PowerProfiles', '/net/hadess/PowerProfiles');
} catch (e) {
// Maybe the service is masked...
}
// We will monkey-patch these methods. Let's store the original ones.
this._origShouldAnimateActor = Main.wm._shouldAnimateActor;
this._origWaitForOverviewToHide = Main.wm._waitForOverviewToHide;
this._origAddWindowClone = Workspace.prototype._addWindowClone;
this._origWindowRemoved = Workspace.prototype._windowRemoved;
this._origDoRemoveWindow = Workspace.prototype._doRemoveWindow;
// ------------------------------- patching the window animations outside the overview
// If a window is created, the transitions are set up in the async _mapWindow() of the
// WindowManager:
// https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/windowManager.js#L1436
// AFAIK, overriding this method is not possible as it's called by a signal to which
// it is bound via the bind() method. To tweak the async transition anyways, we
// override the actors ease() method once. We do this in _shouldAnimateActor() which
// is called right before the ease() in _mapWindow:
// https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/windowManager.js#L1465
// The same trick is done for the window-close animation. This is set up in a similar
// fashion in the WindowManager's _destroyWindow():
// https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/windowManager.js#L1525
// Here is _shouldAnimateActor() also called right before. So we use it again to
// monkey-patch the window actor's ease() once.
// We override WindowManager._shouldAnimateActor() also for another purpose: Usually,
// it returns false when we are in the overview. This prevents the window animations
// there. To enable animations in the overview, we check inside the method whether it
// was called by either _mapWindow or _destroyWindow. If so, we return true. Let's see
// if this breaks stuff left and right...
Main.wm._shouldAnimateActor = function(actor, types) {
const stack = (new Error()).stack;
const forClosing = stack.includes('_destroyWindow@');
const forOpening = stack.includes('_mapWindow@');
// This is also called in other cases, for instance when minimizing windows. We are
// only interested in window opening and window closing for now.
if (forClosing || forOpening) {
// If there is an applicable effect profile, we intercept the ease() method to
// setup our own effect.
const chosenEffect = extensionThis._chooseEffect(actor, forOpening);
if (chosenEffect) {
// Store the original ease() method of the actor.
const orig = actor.ease;
// Now intercept the next call to actor.ease().
actor.ease = function(...params) {
// There is a really weird issue in GNOME Shell 44: A few non-GTK windows are
// resized directly after they are mapped on X11. This happens for instance
// for keepassxc after it was closed in the maximized state. As the
// _mapWindow() method is called asynchronously, the window is not yet visible
// when the resize happens. Hence, our ease-override is called for the resize
// animation instead of the window-open or window-close animation. This is not
// what we want. So we check again whether the ease() call is for the
// window-open or window-close animation. If not, we just call the original
// ease() method. See also:
// https://github.com/Schneegans/Burn-My-Windows/issues/335
const stack = (new Error()).stack;
const forClosing = stack.includes('_destroyWindow@');
const forOpening = stack.includes('_mapWindow@');
if (forClosing || forOpening) {
// Quickly restore the original behavior. Nobody noticed, I guess :D
actor.ease = orig;
// And then create the effect!
extensionThis._setupEffect(actor, forOpening, chosenEffect.effect,
chosenEffect.profile);
} else {
orig.apply(this, params);
}
};
return true;
}
}
return extensionThis._origShouldAnimateActor.apply(this, [actor, types]);
};
// Make sure to remove any effects if requested by the window manager.
this._killEffectsSignal =
global.window_manager.connect('kill-window-effects', (wm, actor) => {
const shader = actor.get_effect('burn-my-windows-effect');
if (shader) {
shader.endAnimation();
}
});
// --------------------------------------------- fix window animations in the overview
// Some of the effects require that the window's actor is enlarged to provide a bigger
// canvas to draw the effects. Outside the overview we can simply increase the scale
// of the actor. However, if we are in the overview, we have to enlarge the clone of
// the window as well.
Workspace.prototype._addWindowClone = function(...params) {
const clone = extensionThis._origAddWindowClone.apply(this, params);
const container = clone.window_container;
const realWindow = params[0].get_compositor_private();
// Store the overview clone as temporary members of the real window actor. When we
// set up the effect, we will check for the existence of these and enlarge the clone
// as needed.
realWindow._bmwOverviewClone = clone;
realWindow._bmwOverviewCloneContainer = container;
// Remove the temporary members again once the clone is deleted.
container.connect('destroy', () => {
delete realWindow._bmwOverviewClone;
delete realWindow._bmwOverviewCloneContainer;
});
return clone;
};
// Usually, windows are faded in after the overview is completely hidden. We enable
// window-open animations by not waiting for this.
Main.wm._waitForOverviewToHide = async function() {
return Promise.resolve();
};
// These three method overrides are mega-hacky! Usually, windows are not faded when
// closed from the overview (why?). With these overrides we make sure that they are
// actually faded out. To do this, _windowRemoved and _doRemoveWindow now check
// whether there is a transition ongoing (via extensionThis._shouldDestroy). If that's
// the case, these methods do nothing.
// https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/workspace.js#L1258
Workspace.prototype._windowRemoved = function(ws, metaWin) {
if (extensionThis._shouldDestroy(this, metaWin)) {
extensionThis._origWindowRemoved.apply(this, [ws, metaWin]);
}
};
// https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/workspace.js#L1137
Workspace.prototype._doRemoveWindow = function(metaWin) {
if (extensionThis._shouldDestroy(this, metaWin)) {
extensionThis._origDoRemoveWindow.apply(this, [metaWin]);
}
};
// With the code below, we hide the window-overlay (icon, label, close button) in the
// overview once the close-animation is running.
// We will monkey-patch these methods.
this._origDeleteAll = WindowPreview.prototype._deleteAll;
this._origRestack = WindowPreview.prototype._restack;
this._origInit = WindowPreview.prototype._init;
// Whenever a WindowPreview is created, we connect to the referenced Meta.Window's
// 'unmanaged' signal to hide the overlay.
WindowPreview.prototype._init = function(...params) {
extensionThis._origInit.apply(this, params);
// Hide the window's icon, name, and close button.
const connectionID = this.metaWindow.connect('unmanaged', () => {
if (this.window_container) {
this.overlayEnabled = false;
this._icon.visible = false;
}
});
// Make sure to not call the callback above if the Meta.Window was not unmanaged
// before leaving the overview.
this.connect('destroy', () => {
this.metaWindow.disconnect(connectionID);
});
};
// The _deleteAll is called when the user clicks the X in the overview. We should
// not attempt to close windows twice. Due to the animation in the overview, the
// close button can be clicked twice which normally would lead to a crash.
WindowPreview.prototype._deleteAll = function() {
if (!this._closeRequested) {
extensionThis._origDeleteAll.apply(this);
}
};
// This is required, else WindowPreview's _restack() which is called by the
// "this.overlayEnabled = false", sometimes tries to access an already delete
// WindowPreview.
WindowPreview.prototype._restack = function() {
if (!this._closeRequested) {
extensionThis._origRestack.apply(this);
}
};
}
// This function could be called after the extension is uninstalled, disabled in GNOME
// Tweaks, when you log out or when the screen locks.
disable() {
// Free all effect resources.
this._ALL_EFFECTS = [];
// Unregister our resources.
Gio.resources_unregister(this._resources);
// Disable the window-picking D-Bus API.
this._windowPicker.unexport();
global.window_manager.disconnect(this._killEffectsSignal);
// Restore the original window-open and window-close animations.
Workspace.prototype._addWindowClone = this._origAddWindowClone;
Workspace.prototype._windowRemoved = this._origWindowRemoved;
Workspace.prototype._doRemoveWindow = this._origDoRemoveWindow;
Main.wm._shouldAnimateActor = this._origShouldAnimateActor;
Main.wm._waitForOverviewToHide = this._origWaitForOverviewToHide;
WindowPreview.prototype._deleteAll = this._origDeleteAll;
WindowPreview.prototype._restack = this._origRestack;
WindowPreview.prototype._init = this._origInit;
this._settings = null;
}
// ----------------------------------------------------------------------- private stuff
// This loads all effect profiles and assigns a priority to each profile. Whenever a
// window is opened or closed, the matching effect profile with the highest priority
// will be chosen.
// This method is called whenever the currently edited profile in the/ preferences
// dialog changes. This is most likely a bit too often, but it will also happen whenever
// a new profile is created and whenever an old profile is deleted.
_loadProfiles() {
// Get all currently available profiles.
const profileManager = new ProfileManager(this.metadata);
this._profiles = profileManager.getProfiles();
// Whenever the properties of a profile is changed in the settings, we may have to
// resort all profiles according to their priority.
const updatePriority = (p) => {
p.priority = profileManager.getProfilePriority(p.settings);
this._profiles.sort((a, b) => b.priority - a.priority);
};
// For each profile, assign an initial priority and update the priority whenever a
// related setting changes.
this._profiles.forEach(p => {
p.priority = profileManager.getProfilePriority(p.settings);
p.settings.connect('changed::profile-app', () => updatePriority(p));
p.settings.connect('changed::profile-animation-type', () => updatePriority(p));
p.settings.connect('changed::profile-window-type', () => updatePriority(p));
p.settings.connect('changed::profile-color-scheme', () => updatePriority(p));
p.settings.connect('changed::profile-power-mode', () => updatePriority(p));
p.settings.connect('changed::profile-power-profile', () => updatePriority(p));
p.settings.connect('changed::profile-high-priority', () => updatePriority(p));
});
// Sort all profiles initially according to their initial priority.
this._profiles.sort((a, b) => b.priority - a.priority);
}
// This method selects an effect profile matching the current circumstances. Then a
// random effect from its enabled effects will be selected. It returns null if no
// profile is currently applicable.
_chooseEffect(actor, forOpening) {
// For now, we only add effects to normal windows and dialog windows.
const isNormalWindow = actor.meta_window.window_type == Meta.WindowType.NORMAL;
const isDialogWindow =
actor.meta_window.window_type == Meta.WindowType.MODAL_DIALOG ||
actor.meta_window.window_type == Meta.WindowType.DIALOG;
if (!isNormalWindow && !isDialogWindow) {
return null;
}
// ----------------------------------------------- choose a profile and then an effect
// Usually, we use the effect profile with the highest priority which matches the
// current circumstances. From this profile, we choose a random effect. However, if an
// effect is to be previewed, we choose the currently edited profile regardless of the
// circumstances.
let profile = null;
let effect = null;
// Hence, we first check if an effect is to be previewed.
const previewNick = this._settings.get_string('preview-effect');
if (previewNick != '') {
const activeProfile = this._settings.get_string('active-profile');
effect =
this._ALL_EFFECTS.find(effect => effect.constructor.getNick() == previewNick);
profile = this._profiles.find(p => p.path == activeProfile);
// Only preview the effect until the preview window is closed.
if (!profile || !forOpening) {
this._settings.set_string('preview-effect', '');
}
}
// If no effect is previewed, we use the effect profile with the highest priority
// which matches the current circumstances. From this profile, we choose a random
// effect.
else {
// These numbers match the indices in the Gtk.StringLists defined in the UI files
// (e.g. resources/ui/adw/prefs.ui).
const animationType = forOpening ? 1 : 2;
const windowType = isNormalWindow ? 1 : 2;
const powerMode = this._upowerProxy.OnBattery ? 1 : 2;
// Get the first profile whose constraints match the circumstances. The list is
// sorted by priority, so we are good to take the first match.
profile = this._profiles.find(p => {
const profileApp = p.settings.get_string('profile-app');
const profileAnimationType = p.settings.get_int('profile-animation-type');
const profileWindowType = p.settings.get_int('profile-window-type');
const profilePowerMode = p.settings.get_int('profile-power-mode');
const profileColorScheme = p.settings.get_int('profile-color-scheme');
const profilePowerProfile = p.settings.get_int('profile-power-profile');
// First we check whether the animation type, window type, and power mode are
// matching.
let matches =
(profileAnimationType == 0 || profileAnimationType == animationType) &&
(profileWindowType == 0 || profileWindowType == windowType) &&
(profilePowerMode == 0 || profilePowerMode == powerMode);
// If that was the case, we also check the application name.
if (matches && profileApp != '') {
const wmClass = actor.meta_window.get_wm_class();
if (wmClass) {
const app = wmClass.toLowerCase();
// Split app names at |, remove any whitespace, and transform to lower case.
const profileApps =
profileApp.split('|').map(item => item.trim().toLowerCase());
matches = profileApps.includes(app);
} else {
matches = false;
}
}
// If the profile is still matching, we also check the color scheme.
if (matches && profileColorScheme != 0) {
const colorScheme = this._shellSettings.get_string('color-scheme');
matches &= (profileColorScheme == 1 && colorScheme == 'default') ||
(profileColorScheme == 2 && colorScheme == 'prefer-dark');
}
// Finally, we may also have to check the power profile.
if (matches && profilePowerProfile != 0 && this._powerProfilesProxy) {
const powerProfile = this._powerProfilesProxy.ActiveProfile;
// To understand the numbers, please refer to the indices in the Gtk.StringList
// of the profile-power-profile Adw.ComboRow in resources/ui/adw/prefs.ui.
if (powerProfile == 'power-saver') {
matches &= profilePowerProfile == 1 || profilePowerProfile == 4;
} else if (powerProfile == 'balanced') {
matches &= profilePowerProfile == 2 || profilePowerProfile == 4 ||
profilePowerProfile == 5;
} else {
matches &= profilePowerProfile == 3 || profilePowerProfile == 5;
}
}
return matches;
});
// If we found a matching profile, choose a random effect from it.
if (profile) {
// Create a list of all enabled effects of this profile.
const enabled = this._ALL_EFFECTS.filter(effect => {
return profile.settings.get_boolean(
`${effect.constructor.getNick()}-enable-effect`);
});
// And then choose a random effect.
if (enabled.length > 0) {
effect = enabled[Math.floor(Math.random() * enabled.length)];
}
}
}
// If nothing was enabled, we have to do nothing :)
if (!effect || !profile) {
return null;
}
return {effect: effect, profile: profile};
}
// This method adds the given effect using the settings from the given profile to the
// given actor.
_setupEffect(actor, forOpening, effect, profile) {
// There is the weird case where an animation is already ongoing. This happens when a
// window is closed which has been created before the session was started (e.g. when
// GNOME Shell has been restarted in the meantime).
const oldShader = actor.get_effect('burn-my-windows-effect');
if (oldShader) {
oldShader.endAnimation();
}
// If we are currently performing integration test, all animations are set to a fixed
// duration and show a fixed frame from the middle of the animation.
const testMode = this._settings.get_boolean('test-mode');
// The following is used to tweak the ongoing transitions of a window actor. Usually
// windows are faded in / out scaled up / down slightly by GNOME Shell. Here, we tweak
// the transitions so that nothing changes. The window stays opaque and is scaled to
// actorScale.
const actorScale =
effect.constructor.getActorScale(profile.settings, forOpening, actor);
// All scaling is relative to the window's center.
actor.set_pivot_point(0.5, 0.5);
actor.opacity = 255;
actor.scale_x = actorScale.x;
actor.scale_y = actorScale.y;
// If we are in the overview, we have to enlarge the window's clone as well. We also
// disable the clone's overlay (e.g. its icon, name, and close button) during the
// animation.
if (actor._bmwOverviewClone) {
actor._bmwOverviewClone.overlayEnabled = false;
actor._bmwOverviewCloneContainer.set_pivot_point(0.5, 0.5);
actor._bmwOverviewCloneContainer.scale_x = actorScale.x;
actor._bmwOverviewCloneContainer.scale_y = actorScale.y;
}
// Now add a cool shader to our window actor!
const shader = effect.shaderFactory.getShader();
actor.add_effect_with_name('burn-my-windows-effect', shader);
// At the end of the animation, we restore the scale of the overview clone (if any)
// and call the methods which would have been called by the original ease() calls at
// the end of the standard fade-in animation.
const endID = shader.connect('end-animation', () => {
shader.disconnect(endID);
if (actor._bmwOverviewClone) {
actor._bmwOverviewClone.overlayEnabled = true;
actor._bmwOverviewCloneContainer.scale_x = 1.0;
actor._bmwOverviewCloneContainer.scale_y = 1.0;
}
// Restore the original scale of the window actor.
actor.scale_x = 1.0;
actor.scale_y = 1.0;
// Remove the shader and mark it being re-usable for future animations.
actor.remove_effect(shader);
shader.returnToFactory();
// Finally, once the animation is done or interrupted, we call the methods which
// should have been called by the original ease() methods.
// https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/windowManager.js#L1487
// https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/windowManager.js#L1558.
if (forOpening) {
Main.wm._mapWindowDone(global.window_manager, actor);
} else {
Main.wm._destroyWindowDone(global.window_manager, actor);
}
});
// To make things deterministic during testing, we set the effect duration to 8
// seconds.
const duration = testMode ?
8000 :
profile.settings.get_int(effect.constructor.getNick() + '-animation-time');
// Finally start the animation!
shader.beginAnimation(profile.settings, forOpening, testMode, duration, actor);
}
// This is required to enable window-close animations in the overview. See the comment
// for Workspace.prototype._windowRemoved above for an explanation.
_shouldDestroy(workspace, metaWindow) {
const index = workspace._lookupIndex(metaWindow);
if (index == -1) {
return true;
}
const actor = workspace._windows[index]._windowActor;
const shader = actor.get_effect('burn-my-windows-effect');
return shader == null;
}
}