summaryrefslogtreecommitdiff
path: root/raveos-gnome-theme/theme-data/extensions/installed/blur-my-shell@aunetx/components/popup/static_corner.js
blob: e575e091af35cc09e832f9befd3f35b0aaa65d17 (plain)
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
export const PopupBlurStaticCorner = class PopupBlurStaticCorner {
    constructor(effects_manager, get_radius) {
        this.effects_manager = effects_manager;
        this.get_radius = get_radius;
        this.pipeline = null;
        this.actor = null;
        this.effect = null;
    }

    bind(pipeline, actor) {
        this.pipeline = pipeline;
        this.actor = actor;
        this.update();
    }

    update() {
        if (!this.pipeline || !this.actor)
            return;

        this.pipeline.apply_effect_overrides('corner');

        if (this.pipeline_has_corner_effect()) {
            this.destroy_external_effect();
            return;
        }

        if (!this.effect) {
            this.effect = this.effects_manager.new_corner_effect({
                radius: this.get_radius(),
            });
            this.attach_external_effect_as_outermost();
            return;
        }

        this.effect.radius = this.get_radius();
    }

    attach_external_effect_as_outermost() {
        const existing_effects = this.pipeline?.effects ?? [];

        existing_effects.forEach(effect => {
            this.actor.remove_effect(effect);
        });

        this.actor.add_effect(this.effect);

        existing_effects.forEach(effect => {
            this.actor.add_effect(effect);
        });
    }

    pipeline_has_corner_effect() {
        const corner_class = this.effects_manager.SUPPORTED_EFFECTS.corner.class;
        return this.pipeline.effects.some(effect => effect instanceof corner_class);
    }

    destroy_external_effect() {
        if (!this.effect)
            return;

        this.effects_manager.remove(this.effect);
        this.effect = null;
    }

    destroy() {
        this.destroy_external_effect();
        this.pipeline = null;
        this.actor = null;
    }
};