summaryrefslogtreecommitdiff
path: root/raveos-gnome-theme/theme-data/extensions/installed/blur-my-shell@aunetx/conveniences/paint_signals.js
blob: 5fbfee47fbf4d18c428372ef090043cd41388cc0 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import GObject from 'gi://GObject';
import Clutter from 'gi://Clutter';


export const PaintSignals = class PaintSignals {
    constructor(connections) {
        this.buffer = [];
        this.connections = connections;
    }

    connect(actor, blur_effect) {
        let paint_effect = new EmitPaintSignal();
        let infos = {
            actor: actor,
            paint_effect: paint_effect
        };
        let counter = 0;

        actor.add_effect(paint_effect);
        this.connections.connect(paint_effect, 'update-blur', () => {
            try {
                // checking if blur_effect.queue_repaint() has been recently called
                if (counter === 0) {
                    counter = 2;
                    blur_effect.queue_repaint();
                }
                else counter--;
            } catch (e) { }
        });

        // remove the actor from buffer when it is destroyed
        if (
            actor.connect &&
            (
                !(actor instanceof GObject.Object) ||
                GObject.signal_lookup('destroy', actor)
            )
        )
            this.connections.connect(actor, 'destroy', () => {
                const immutable_buffer = [...this.buffer];
                immutable_buffer.forEach(infos => {
                    if (infos.actor === actor) {
                        // remove from buffer
                        let index = this.buffer.indexOf(infos);
                        this.buffer.splice(index, 1);
                    }
                });
            });

        this.buffer.push(infos);
    }

    disconnect_all_for_actor(actor) {
        const immutable_buffer = [...this.buffer];
        immutable_buffer.forEach(infos => {
            if (infos.actor === actor) {
                this.connections.disconnect_all_for(infos.paint_effect);
                infos.actor.remove_effect(infos.paint_effect);

                // remove from buffer
                let index = this.buffer.indexOf(infos);
                this.buffer.splice(index, 1);
            }
        });
    }

    disconnect_all() {
        this.buffer.forEach(infos => {
            this.connections.disconnect_all_for(infos.paint_effect);
            infos.actor.remove_effect(infos.paint_effect);
        });

        this.buffer = [];
    }
};

export const EmitPaintSignal = GObject.registerClass({
    GTypeName: 'EmitPaintSignal',
    Signals: {
        'update-blur': {
            param_types: []
        },
    }
},
    class EmitPaintSignal extends Clutter.Effect {
        vfunc_paint(node, paint_context, paint_flags) {
            this.emit("update-blur");
            super.vfunc_paint(node, paint_context, paint_flags);
        }
    }
);