summaryrefslogtreecommitdiff
path: root/raveos-gnome-theme/theme-data/extensions/installed/blur-my-shell@aunetx/components/popup/surface_style.js
blob: 1dfb9475ef0e752e71041ed38162fa5218a8e01a (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
export const PopupBlurSurfaceStyle = class PopupBlurSurfaceStyle {
    constructor(surface) {
        this.surface = surface;
        this.original_target_style = null;
        this.target_style_set = false;
    }

    capture_target_style() {
        this.original_target_style = this.surface.target ? this.surface.target.get_style() : null;
    }

    update_target_style() {
        if (
            !this.surface.target.set_style
            || !this.surface.settings.popup.OVERRIDE_BACKGROUND
        ) {
            this.restore_target_style();
            return;
        }

        if (
            this.has_style_class(this.surface.target, 'bms-keyboard-surface')
        )
            return;

        const base_style = this.original_target_style ?? '';
        const separator = base_style.trim() && !base_style.trim().endsWith(';') ? '; ' : '';

        this.surface.target.set_style(
            `${base_style}${separator}border-radius: ${this.surface.get_corner_radius()}px;`
        );
        this.target_style_set = true;
    }

    restore_target_style() {
        if (!this.target_style_set || !this.surface.target.set_style)
            return;

        this.surface.target.set_style(this.original_target_style);
        this.target_style_set = false;
    }

    has_any_style_class(actor, style_classes) {
        return style_classes.some(style_class => this.has_style_class(actor, style_class));
    }

    has_style_class(actor, style_class) {
        if (!actor)
            return false;

        if (actor.has_style_class_name)
            return actor.has_style_class_name(style_class);

        if (actor.get_style_class_name)
            return (actor.get_style_class_name() ?? '').split(/\s+/).includes(style_class);

        return false;
    }
};