repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

quickshell/nugu/shell.qml

Raw
import QtQuick
import Quickshell
import Quickshell.Io
import "."

Scope {
    id: root

    // New surfaces start hidden so this config can run beside Ironbar/Mako until
    // the parity checklist says it is safe to retire the old companions.
    property bool diagnosticsVisible: false
    property bool barVisible: false
    property bool nativeNotificationsEnabled: false

    // One theme object is shared across all panels so dark/light changes are
    // instant and every widget uses the same Nugu semantic palette.
    Theme { id: nuguTheme }

    // One command boundary keeps process launching out of widgets and makes later
    // Hypr config simplification a search-and-replace instead of archaeology.
    Commands { id: commandBus }

    IpcHandler {
        target: "nugu"

        // Diagnostics IPC gives us a safe visual probe before replacing any live service.
        function showDiagnostics(): void { root.diagnosticsVisible = true }
        function hideDiagnostics(): void { root.diagnosticsVisible = false }
        function toggleDiagnostics(): void { root.diagnosticsVisible = !root.diagnosticsVisible }

        // Bar IPC lets Hypr binds and verification scripts exercise the Quickshell
        // bar while Ironbar remains the user's real production bar.
        function showBar(): void { root.barVisible = true }
        function hideBar(): void { root.barVisible = false }
        function toggleBar(): void { root.barVisible = !root.barVisible }

        function reloadTheme(): void { nuguTheme.reload() }
        function setThemeMode(mode: string): string {
            nuguTheme.setMode(mode)
            return nuguTheme.mode
        }
        function themeMode(): string { return nuguTheme.mode }
        function themeSource(): string { return nuguTheme.modeSource }
        function themeState(): string {
            // Smoke tests assert actual token values, not only mode names. Keep
            // this flat so shell tests can parse it without depending on jq.
            return JSON.stringify({
                "mode": nuguTheme.mode,
                "source": nuguTheme.modeSource,
                "error": nuguTheme.error,
                "warning": nuguTheme.warning,
                "info": nuguTheme.info,
                "debug": nuguTheme.debug,
                "contentNormal": nuguTheme.content.normal,
                "contentBackdrop": nuguTheme.content.backdrop,
                "contentAccent": nuguTheme.content.accent,
                "uiNormal": nuguTheme.ui.normal,
                "uiBackdrop": nuguTheme.ui.backdrop,
                "uiAccent": nuguTheme.ui.accent,
                "uiFocus": nuguTheme.ui.focus
            })
        }

        // Scaffold smoke needs one cheap truth source and one cleanup button. This
        // keeps test scripts brutal: show surfaces, assert state, hide everything.
        function scaffoldState(): string {
            return JSON.stringify({
                "theme": nuguTheme.mode,
                "themeSource": nuguTheme.modeSource,
                "diagnostics": root.diagnosticsVisible,
                "bar": root.barVisible,
                "nativeNotifications": root.nativeNotificationsEnabled,
                "launcher": launcher.open,
                "clipboardPicker": clipboardPicker.open,
                "powerMenu": powerMenu.open,
                "pendingPower": powerMenu.pendingAction,
                "lastOsd": commandBus.lastOsdAction,
                "lastPower": commandBus.lastPowerAction
            })
        }
        function hideAll(): void {
            root.diagnosticsVisible = false
            root.barVisible = false
            root.nativeNotificationsEnabled = false
            osd.hide()
            launcher.close()
            clipboardPicker.close()
            powerMenu.close()
        }

        // Native notifications are opt-in while Mako is still live. Tests must stop
        // Mako first, enable this daemon, then rollback by disabling and restarting Mako.
        function enableNativeNotifications(): string {
            root.nativeNotificationsEnabled = true
            return "enabled"
        }
        function disableNativeNotifications(): string {
            root.nativeNotificationsEnabled = false
            return "disabled"
        }
        function nativeNotificationCount(): int {
            return notificationLoader.item ? notificationLoader.item.count : 0
        }
        function dismissNativeNotifications(): void {
            if (notificationLoader.item) notificationLoader.item.dismissAll()
        }
        function restoreNativeNotification(): void {
            if (notificationLoader.item) notificationLoader.item.restoreLast()
        }

        // OSD IPC gives Hypr binds a stable replacement target for current
        // `hyprctl notify` helpers before those binds are migrated.
        function showOsd(message: string, tone: string): string { return osd.showText(message, tone) }
        function hideOsd(): void { osd.hide() }
        function showVolumeOsd(level: string): string { return osd.showText(`Volume ${level}`, "info") }
        function showBrightnessOsd(level: string): string { return osd.showText(`Brightness ${level}`, "warning") }

        // These IPC methods mirror the current `hyprctl notify` wrapper actions.
        // Hypr binds remain unchanged until each replacement is proven live.
        function osdVolumeUp(): string { return commandBus.volumeUp() }
        function osdVolumeDown(): string { return commandBus.volumeDown() }
        function osdMuteAudio(): string { return commandBus.muteAudio() }
        function osdMuteMic(): string { return commandBus.muteMic() }
        function osdBrightnessUp(): string { return commandBus.brightnessUp() }
        function osdBrightnessDown(): string { return commandBus.brightnessDown() }
        function osdMediaNext(): string { return commandBus.mediaNext() }
        function osdMediaToggle(): string { return commandBus.mediaToggle() }
        function osdMediaPrev(): string { return commandBus.mediaPrev() }
        function osdReloadHypr(): string { return commandBus.reloadHypr() }
        function osdSessionLock(): string { return commandBus.sessionLockOsd() }
        function osdSessionSuspendDryRun(): string { return commandBus.sessionSuspendDryRun() }
        function osdCaptureRegion(): string { return commandBus.captureRegion() }
        function osdCaptureWindow(): string { return commandBus.captureWindow() }
        function osdCaptureOutput(): string { return commandBus.captureOutput() }
        function osdCaptureAnnotate(): string { return commandBus.captureAnnotate() }
        function osdPickColor(): string { return commandBus.pickColor() }
        function lastOsdAction(): string { return commandBus.lastOsdAction }

        // Launcher IPC is the future `SUPER+Space` target. It stays opt-in until
        // desktop-entry filtering, keyboard navigation, and app launch are proven.
        function openLauncher(query: string): string { return launcher.show(query) }
        function closeLauncher(): void { launcher.close() }
        function launcherVisible(): bool { return launcher.open }
        function launcherMatchCount(): int { return launcher.matchCount() }
        function launcherFirstMatchName(): string { return launcher.firstMatchName() }

        // Full clipboard picker IPC replaces `hyprlauncher --dmenu` later while
        // keeping `cliphist` as the storage backend for safety and parity.
        function openClipboardPicker(query: string): string { return clipboardPicker.show(query) }
        function closeClipboardPicker(): void { clipboardPicker.close() }
        function clipboardPickerVisible(): bool { return clipboardPicker.open }
        function clipboardPickerMatchCount(): int { return clipboardPicker.matchCount() }
        function clipboardPickerFirstPreview(): string { return clipboardPicker.firstMatchPreview() }
        function chooseClipboardIndex(index: int): string { return clipboardPicker.chooseIndex(index) }

        // Power IPC is the future CTRL+ALT+Delete target. Non-lock actions keep
        // dry-run semantics after confirmation until explicit parity approval.
        function openPowerMenu(): string { return powerMenu.show() }
        function closePowerMenu(): void { powerMenu.close() }
        function powerMenuVisible(): bool { return powerMenu.open }
        function requestPowerAction(action: string): string { return powerMenu.request(action) }
        function pendingPowerAction(): string { return powerMenu.pendingAction }
        function confirmPowerAction(): string { return powerMenu.confirm() }
        function lastPowerAction(): string { return commandBus.lastPowerAction }
    }

    Connections {
        target: commandBus
        function onOsdRequested(message: string, tone: string): void {
            osd.showText(message, tone)
        }
    }

    Loader {
        id: notificationLoader
        active: root.nativeNotificationsEnabled
        sourceComponent: Component {
            NotificationDaemon { theme: nuguTheme }
        }
    }

    Osd {
        id: osd
        theme: nuguTheme
    }

    Launcher {
        id: launcher
        theme: nuguTheme
    }

    ClipboardPicker {
        id: clipboardPicker
        theme: nuguTheme
        commands: commandBus
    }

    PowerMenu {
        id: powerMenu
        theme: nuguTheme
        commands: commandBus
    }

    // Create one bar per monitor, matching Ironbar's multi-output behavior.
    Variants {
        model: Quickshell.screens
        delegate: Component {
            Bar {
                required property var modelData

                screen: modelData
                theme: nuguTheme
                commands: commandBus
                shown: root.barVisible
            }
        }
    }

    Diagnostics {
        visible: root.diagnosticsVisible
        theme: nuguTheme
    }
}