summaryrefslogtreecommitdiff
path: root/raveos-gnome-theme/theme-data/extensions/installed/blur-my-shell@aunetx/effects/native_dynamic_gaussian_blur.js
blob: fc24e078dae579eef1cbc9f12dd9f750ff6eb6ca (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
import GObject from 'gi://GObject';

import * as utils from '../conveniences/utils.js';
const St = await utils.import_in_shell_only('gi://St');

const BlurModule = await utils.import_in_shell_only('gi://Blur');
const Shell = await utils.import_in_shell_only('gi://Shell');
const BlurOrShell = utils.is_usable_blur_module(BlurModule) ? BlurModule : Shell;
const SUPPORTS_CORNER_RADIUS = Boolean(
    BlurOrShell?.BlurEffect?.list_properties()
        .some(property => property.name === 'corner-radius')
);


const DEFAULT_PARAMS = {
    unscaled_radius: 30,
    brightness: 0.6,
    unscaled_corner_radius: 0,
};


export const NativeDynamicBlurEffect = utils.IS_IN_PREFERENCES ?
    { default_params: DEFAULT_PARAMS, supports_corner_radius: false } :
    new GObject.registerClass({
        GTypeName: "NativeDynamicBlurEffect"
    }, class NativeDynamicBlurEffect extends BlurOrShell.BlurEffect {
        constructor(params) {
            const normalized_params = { ...params };
            if (!('unscaled_radius' in normalized_params) && 'radius' in normalized_params)
                normalized_params.unscaled_radius = normalized_params.radius;
            delete normalized_params.radius;

            if (!('unscaled_corner_radius' in normalized_params) && 'corner_radius' in normalized_params)
                normalized_params.unscaled_corner_radius = normalized_params.corner_radius;
            delete normalized_params.corner_radius;

            const parent_params = { ...normalized_params };
            delete parent_params.unscaled_radius;
            delete parent_params.brightness;
            delete parent_params.unscaled_corner_radius;
            super({ ...parent_params, mode: BlurOrShell.BlurMode.BACKGROUND });

            this._theme_context = St.ThemeContext.get_for_stage(global.stage);
            this._theme_context.connectObject(
                'notify::scale-factor',
                _ => {
                    this.radius = Math.max(0, this.unscaled_radius * this._theme_context.scale_factor);
                    if (SUPPORTS_CORNER_RADIUS)
                        this.corner_radius = this.unscaled_corner_radius * this._theme_context.scale_factor;
                },
                this
            );

            utils.setup_params(this, normalized_params);
        }

        static get default_params() {
            return DEFAULT_PARAMS;
        }

        static get supports_corner_radius() {
            return SUPPORTS_CORNER_RADIUS;
        }

        get unscaled_radius() {
            return this._unscaled_radius;
        }

        set unscaled_radius(value) {
            this._unscaled_radius = value;
            this.radius = Math.max(0, value * this._theme_context.scale_factor);
        }

        get unscaled_corner_radius() {
            return this._unscaled_corner_radius;
        }

        set unscaled_corner_radius(value) {
            this._unscaled_corner_radius = value;
            if (SUPPORTS_CORNER_RADIUS)
                this.corner_radius = value * this._theme_context.scale_factor;
        }
    });