Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

quickshell/nuguland/shell.qml

Raw
//@ pragma IconTheme Papirus
pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import Quickshell.Io
import Quickshell.Wayland
import Quickshell.Services.UPower
import "features/notifications" as NotificationsFeature

ShellRoot {
    id: shell

    // Connector name of the monitor that hosts the interactive nuguland
    // surfaces (bar, OSD, toasts). Set e.g. "DP-1" to pin them; left empty it
    // falls back to the first connected screen. The wallpaper stays on every
    // screen; interactive security prompts stay on the primary screen.
    property string primaryOutput: ""
    readonly property var primaryScreens: {
        const screens = Quickshell.screens;
        const want = String(shell.primaryOutput || "");
        for (let i = 0; i < screens.length; i++)
            if (want.length === 0 || String(screens[i].name) === want)
                return [screens[i]];

        return [];
    }
    readonly property string primaryScreenName: primaryScreens.length > 0 ? String(primaryScreens[0].name) : ""

    // Bar orientation: "horizontal" (top edge, default) or "vertical" (left
    // edge). Injected into the Bar and the SurfaceManager so layout and popup
    // geometry share one source of truth.
    readonly property string orientation: featureRegistry.config.orientation
    onOrientationChanged: Qt.callLater(shell.remapBar)
    function remapBar(): void {
        shell.barRemap = false;
        barRemapTimer.restart();
    }

    // Layer-shell surfaces size from anchors/implicitWidth only at map time, so
    // flipping orientation at runtime needs a remap: drop the bar then re-show
    // it a frame later to pick up the new thickness and anchored edges.
    property bool barRemap: true

    Timer {
        id: barRemapTimer

        interval: 60
        onTriggered: shell.barRemap = true
    }

    Theme {
        id: nuguTheme

        lowPowerMode: featureRegistry.power.lowPowerMode
    }

    Niri {
        id: niri
    }

    Connections {
        target: lock

        function onLogicalLockedChanged() {
            if (lock.logicalLocked)
                featureRegistry.vault.lock();
        }
    }

    Registry {
        id: featureRegistry

        theme: nuguTheme
        lockService: lock
        niriService: niri
        privilegeService: privilege
        surfaces: surfaceManager
        // Singletons reach the system service as injected inputs, never imports.
        upower: UPower
        powerProfiles: PowerProfiles
    }

    Privilege {
        id: privilege
    }

    Lock {
        id: lock

        theme: nuguTheme
    }

    SurfaceManager {
        id: surfaceManager

        niriService: niri
        registry: featureRegistry
    }

    Usage {
        id: usage

        widgets: featureRegistry.chips
    }

    Diagnostics {
        id: diagnosticsService

        surfaces: surfaceManager
        screens: Quickshell.screens
        niriService: niri
        audioService: featureRegistry.audio
        networkService: featureRegistry.connectivity
        vaultService: featureRegistry.vault
        nokoService: featureRegistry.noko
    }

    // Registry overlays and focus overlays, e.g. the OSD and noko's capture tab.
    OverlayHost {
        registry: featureRegistry
        primaryScreenName: shell.primaryScreenName
        niriService: niri
        surfaces: surfaceManager
    }

    NotificationsFeature.NotificationToasts {
        theme: nuguTheme
        notificationService: featureRegistry.notifications
        primaryScreenName: shell.primaryScreenName
    }
    Variants {
        model: shell.primaryScreens

        delegate: Component {
            PanelWindow {
                required property var modelData

                objectName: "privilegeSecuritySurface"
                screen: modelData
                visible: privilege.active || privilege.error.length > 0 || privilege.confirming
                color: "transparent"
                exclusionMode: ExclusionMode.Ignore
                WlrLayershell.layer: WlrLayer.Overlay
                WlrLayershell.namespace: "nuguland-privilege"
                WlrLayershell.keyboardFocus: WlrKeyboardFocus.Exclusive

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

                onVisibleChanged: if (visible)
                    Qt.callLater(privilegeSurface.focusSecret)

                PrivilegeSurface {
                    id: privilegeSurface

                    anchors.fill: parent
                    theme: nuguTheme
                    privilegeService: privilege
                }
            }
        }
    }

    Variants {
        model: Quickshell.screens

        delegate: Component {
            AuroraBackdrop {
                required property var modelData

                screen: modelData
                resourceService: featureRegistry.system
                theme: nuguTheme
                lowPowerMode: nuguTheme.lowPowerMode
            }
        }
    }

    Variants {
        model: shell.barRemap ? shell.primaryScreens : []

        delegate: Component {
            Bar {
                required property var modelData

                // primary monitor only; the bar consolidates every output's
                // workspaces into per-output trays (see Bar.qml workspaceStrip).
                screen: modelData
                theme: nuguTheme
                niriService: niri
                registry: featureRegistry
                privilegeService: privilege
                surfaces: surfaceManager
                usageService: usage
                orientation: shell.orientation
            }
        }
    }

    IpcHandler {
        target: "noko"

        function trigger(): string {
            return featureRegistry.noko.trigger();
        }
    }

    IpcHandler {
        function increase() {
            return featureRegistry.audio.increase();
        }

        function decrease() {
            return featureRegistry.audio.decrease();
        }

        function muteOutput() {
            return featureRegistry.audio.muteOutput();
        }

        function muteInput() {
            return featureRegistry.audio.muteInput();
        }

        target: "volume"
    }

    IpcHandler {
        function next() {
            return featureRegistry.media.action("next");
        }

        function previous() {
            return featureRegistry.media.action("previous");
        }

        function playPause() {
            return featureRegistry.media.action("playPause");
        }

        target: "media"
    }

    IpcHandler {
        function increase(): string {
            return featureRegistry.brightness.increase();
        }

        function decrease(): string {
            return featureRegistry.brightness.decrease();
        }

        target: "brightness"
    }

    IpcHandler {
        target: "vault"

        function open(): string {
            return surfaceManager.openRegisteredPopup("vault", niri.focusedOutputName);
        }
    }

    IpcHandler {
        function diagnostics(): string {
            return diagnosticsService.snapshot();
        }

        function setOrientation(mode: string): string {
            return featureRegistry.config.setOrientation(mode);
        }

        function notificationsState(): string {
            return featureRegistry.notifications.stateJson();
        }

        function notificationsDismissToasts(): string {
            return featureRegistry.notifications.dismissToasts();
        }

        function openLauncher(): string {
            return surfaceManager.openRegisteredPopup("launcher", niri.focusedOutputName);
        }

        function osdTrigger(event: string, value: string): string {
            return JSON.stringify(featureRegistry.osd.trigger(event, value));
        }

        function osdState(): string {
            return featureRegistry.osd.stateJson();
        }

        function lockRequest(): string {
            return lock.request();
        }

        function openRegisteredPopup(name: string): string {
            return surfaceManager.openRegisteredPopup(name);
        }

        function closePopup(): string {
            return surfaceManager.closePopup("");
        }

        target: "nuguland"
    }
}