summaryrefslogtreecommitdiff
path: root/raveos-hyprland-theme/theme-data/DankMaterialShell/quickshell/Services/BlurService.qml
blob: 40a3aeb83ab7227f293faa0a8d6e5fb928544d6b (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
111
112
113
pragma Singleton
pragma ComponentBehavior: Bound

import QtQuick
import Quickshell
import Quickshell.Io
import Quickshell.Wayland // ! Import is needed despite what qmlls says
import qs.Common

Singleton {
    id: root

    property bool quickshellSupported: false
    property bool compositorSupported: false
    property bool available: quickshellSupported && compositorSupported
    readonly property bool enabled: available && (SettingsData.blurEnabled ?? false)

    readonly property color borderColor: {
        if (!enabled)
            return "transparent";
        const opacity = SettingsData.blurBorderOpacity ?? 0.5;
        switch (SettingsData.blurBorderColor ?? "outline") {
        case "primary":
            return Theme.withAlpha(Theme.primary, opacity);
        case "secondary":
            return Theme.withAlpha(Theme.secondary, opacity);
        case "surfaceText":
            return Theme.withAlpha(Theme.surfaceText, opacity);
        case "custom":
            return Theme.withAlpha(SettingsData.blurBorderCustomColor ?? "#ffffff", opacity);
        default:
            return Theme.withAlpha(Theme.outline, opacity);
        }
    }
    readonly property int borderWidth: enabled ? 1 : 0

    function hoverColor(baseColor, hoverAlpha) {
        if (!enabled)
            return baseColor;
        return Theme.withAlpha(baseColor, hoverAlpha ?? 0.15);
    }

    function createBlurRegion(targetWindow) {
        if (!available)
            return null;

        try {
            const region = Qt.createQmlObject(`
                import Quickshell
                Region {}
            `, targetWindow, "BlurRegion");
            targetWindow.BackgroundEffect.blurRegion = region;
            return region;
        } catch (e) {
            console.warn("BlurService: Failed to create blur region:", e);
            return null;
        }
    }

    function reapplyBlurRegion(targetWindow, region) {
        if (!region || !available)
            return;
        try {
            targetWindow.BackgroundEffect.blurRegion = region;
            region.changed();
        } catch (e) {}
    }

    function destroyBlurRegion(targetWindow, region) {
        if (!region)
            return;
        try {
            targetWindow.BackgroundEffect.blurRegion = null;
        } catch (e) {}
        region.destroy();
    }

    Process {
        id: blurProbe
        running: false
        command: ["dms", "blur", "check"]

        stdout: StdioCollector {
            onStreamFinished: {
                root.compositorSupported = text.trim() === "supported";
                if (root.compositorSupported)
                    console.info("BlurService: Compositor supports ext-background-effect-v1");
                else
                    console.info("BlurService: Compositor does not support ext-background-effect-v1");
            }
        }

        onExited: exitCode => {
            if (exitCode !== 0)
                console.warn("BlurService: blur probe failed with code:", exitCode);
        }
    }

    Component.onCompleted: {
        try {
            const test = Qt.createQmlObject(`
                import Quickshell
                Region { radius: 0 }
            `, root, "BlurAvailabilityTest");
            test.destroy();
            quickshellSupported = true;
            console.info("BlurService: Quickshell blur support available");
            blurProbe.running = true;
        } catch (e) {
            console.info("BlurService: BackgroundEffect not available - blur disabled. Requires a newer version of Quickshell.");
        }
    }
}