Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

quickshell/nuguland/AuroraBackdrop.qml

Raw
pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import Quickshell.Io
import Quickshell.Wayland

PanelWindow {
    id: root

    required property Resources resourceService
    property real targetX: 0.5
    property real targetY: 0.5
    property real smoothX: 0.5
    property real smoothY: 0.5
    property int activeTicks: 0
    property bool auroraAvailable: false
    property bool lowPowerMode: false
    property real firestormMix: 0
    property real auroraTime: 0

    function targetFirestormMix() {
        return root.resourceService ? Number(root.resourceService.firestormTarget || 0) : 0;
    }

    visible: true
    color: "#101010"
    exclusionMode: ExclusionMode.Ignore
    implicitWidth: 1
    implicitHeight: 1
    WlrLayershell.layer: WlrLayer.Background
    WlrLayershell.namespace: "nuguland-backdrop"
    WlrLayershell.keyboardFocus: WlrKeyboardFocus.None

    anchors {
        top: true
        bottom: true
        left: true
        right: true
    }

    FileView {
        id: auroraBlob

        path: Qt.resolvedUrl("shaders/aurora.frag.qsb").toString().replace(/^file:\/\//, "")
        preload: true
        blockLoading: true
        printErrors: false
        onLoaded: root.auroraAvailable = true
        onLoadFailed: root.auroraAvailable = false
    }

    Loader {
        id: auroraLoader

        anchors.fill: parent
        active: root.auroraAvailable && !root.lowPowerMode

        sourceComponent: ShaderEffect {
            property real iTime: root.auroraTime
            property vector2d iResolution: Qt.vector2d(width, height)
            property vector2d iMouse: Qt.vector2d(root.smoothX, root.smoothY)
            property real iFirestormMix: root.firestormMix

            blending: true
            fragmentShader: Qt.resolvedUrl("shaders/aurora.frag.qsb")
        }
    }

    MouseArea {
        anchors.fill: parent
        hoverEnabled: true
        acceptedButtons: Qt.NoButton
        onPositionChanged: mouse => {
            root.targetX = mouse.x / Math.max(1, width);
            root.targetY = mouse.y / Math.max(1, height);
            root.activeTicks = root.lowPowerMode ? 0 : 45;
        }
    }

    Timer {
        interval: 67
        running: (root.activeTicks > 0 || Math.abs(root.firestormMix - root.targetFirestormMix()) > 0.001) && !root.lowPowerMode
        repeat: true
        onTriggered: {
            root.activeTicks = Math.max(0, root.activeTicks - 1);
            if (auroraLoader.item)
                root.auroraTime += 0.04;

            root.smoothX += (root.targetX - root.smoothX) * 0.035;
            root.smoothY += (root.targetY - root.smoothY) * 0.035;
            root.firestormMix += (root.targetFirestormMix() - root.firestormMix) * 0.0035;
        }
    }
}