summaryrefslogtreecommitdiff
path: root/raveos-gnome-theme/theme-data/extensions/installed/blur-my-shell@aunetx/components/screenshot.js
blob: dcf05ebaa4058975fdb350a9daea8e8ac23d9880 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import * as Main from 'resource:///org/gnome/shell/ui/main.js';

import { Pipeline } from '../conveniences/pipeline.js';

export const ScreenshotBlur = class ScreenshotBlur {
    constructor(connections, settings, effects_manager) {
        this.connections = connections;
        this.settings = settings;
        this.screenshot_background_managers = [];
        this.effects_manager = effects_manager;
    }

    enable() {
        this._log("blurring screenshot's window selector");

        // connect to monitors change
        this.connections.connect(Main.layoutManager, 'monitors-changed',
            _ => this.update_backgrounds()
        );

        // update backgrounds when the component is enabled
        this.update_backgrounds();
    }

    update_backgrounds() {
        // remove every old background
        this.remove_background_actors();
        // create new backgrounds for the screenshot window selector
        for (let i = 0; i < Main.screenshotUI._windowSelectors.length; i++) {
            const window_selector = Main.screenshotUI._windowSelectors[i];
            const pipeline = new Pipeline(
                this.effects_manager,
                global.blur_my_shell._pipelines_manager,
                this.settings.screenshot.PIPELINE
            );
            pipeline.create_background_with_effects(
                window_selector._monitorIndex, this.screenshot_background_managers,
                window_selector, 'bms-screenshot-blurred-widget', false
            );

            // prevent old `BackgroundActor` from being accessed, which creates a whole bug of logs
            this.connections.connect(window_selector.get_parent(), 'destroy', _ => {
                this.screenshot_background_managers.forEach(background_manager => {
                    if (background_manager.backgroundActor) {
                        let widget = background_manager.backgroundActor.get_parent();
                        let parent = widget?.get_parent();

                        if (parent == window_selector) {
                            background_manager._bms_pipeline.destroy();
                            parent.remove_child(widget);
                        }
                    }
                    background_manager.destroy();
                });

                window_selector.get_children().forEach(child => {
                    if (child.get_name() == 'bms-screenshot-blurred-widget')
                        window_selector.remove_child(child);
                });

                let index = this.screenshot_background_managers.indexOf(window_selector);
                this.screenshot_background_managers.splice(index, 1);
            });
        }
    }

    update_pipeline() {
        this.screenshot_background_managers.forEach(background_manager =>
            background_manager._bms_pipeline.change_pipeline_to(
                this.settings.screenshot.PIPELINE
            )
        );
    }

    remove_background_actors() {
        this.screenshot_background_managers.forEach(background_manager => {
            background_manager._bms_pipeline.destroy();
            if (background_manager.backgroundActor) {
                let widget = background_manager.backgroundActor.get_parent();
                widget?.get_parent()?.remove_child(widget);
            }
            background_manager.destroy();
        });

        Main.screenshotUI._windowSelectors.forEach(window_selector =>
            window_selector.get_children().forEach(child => {
                if (child.get_name() == 'bms-screenshot-blurred-widget')
                    window_selector.remove_child(child);
            })
        );

        this.screenshot_background_managers = [];
    }

    disable() {
        this._log("removing blur from screenshot's window selector");

        this.remove_background_actors();
        this.connections.disconnect_all();
    }

    _log(str) {
        if (this.settings.DEBUG)
            console.log(`[Blur my Shell > screenshot]   ${str}`);
    }

    _warn(str) {
        console.warn(`[Blur my Shell > screenshot]   ${str}`);
    }
};