.pragma library

    .import "./SpecUtil.js" as Util

function percentToUnit(v) {
    if (v === undefined || v === null) return undefined;
    return v > 1 ? v / 100 : v;
}

var SPEC = {
    currentThemeName: { def: "purple", onChange: "applyStoredTheme" },
    currentThemeCategory: { def: "generic" },
    customThemeFile: { def: "" },
    registryThemeVariants: { def: {} },
    matugenScheme: { def: "scheme-tonal-spot", onChange: "regenSystemThemes" },
    matugenContrast: { def: 0, onChange: "regenSystemThemes" },
    runUserMatugenTemplates: { def: true, onChange: "regenSystemThemes" },
    matugenTargetMonitor: { def: "", onChange: "regenSystemThemes" },

    popupTransparency: { def: 1.0, coerce: percentToUnit },
    dockTransparency: { def: 1.0, coerce: percentToUnit },
    floatingWindowSyncGlobal: { def: true },
    floatingWindowTransparency: { def: 1.0, coerce: percentToUnit },
    floatingWindowForegroundLayers: { def: true },
    floatingWindowForegroundTransparency: { def: 1.0, coerce: percentToUnit },
    dmsWindowsFloating: { def: true },

    widgetBackgroundColor: { def: "sch" },
    widgetBackgroundCustomColor: { def: "#6750A4" },
    widgetBackgroundCustomStrength: { def: 0.50, coerce: percentToUnit },
    widgetColorMode: { def: "default" },
    controlCenterTileColorMode: { def: "primary" },
    buttonColorMode: { def: "primary" },
    cornerRadius: { def: 16, onChange: "updateCompositorLayout" },
    niriLayoutGapsOverride: { def: -1, onChange: "updateCompositorLayout" },
    niriLayoutRadiusOverride: { def: -1, onChange: "updateCompositorLayout" },
    niriLayoutBorderSize: { def: -1, onChange: "updateCompositorLayout" },
    hyprlandLayoutGapsOverride: { def: -1, onChange: "updateCompositorLayout" },
    hyprlandLayoutGapsOutOverride: { def: -1, onChange: "updateCompositorLayout" },
    hyprlandLayoutRadiusOverride: { def: -1, onChange: "updateCompositorLayout" },
    hyprlandLayoutBorderSize: { def: -1, onChange: "updateCompositorLayout" },
    hyprlandResizeOnBorder: { def: false, onChange: "updateCompositorLayout" },
    mangoLayoutGapsOverride: { def: -1, onChange: "updateCompositorLayout" },
    mangoLayoutGapsOutOverride: { def: -1, onChange: "updateCompositorLayout" },
    mangoLayoutRadiusOverride: { def: -1, onChange: "updateCompositorLayout" },
    mangoLayoutBorderSize: { def: -1, onChange: "updateCompositorLayout" },
    mangoTrackpadNaturalScrolling: { def: true, onChange: "updateCompositorCursor" },
    mouseAccelProfile: { def: "default", onChange: "updateCompositorInput" },
    mouseAccelSpeed: { def: 0.0, onChange: "updateCompositorInput" },
    mouseLeftHanded: { def: false, onChange: "updateCompositorInput" },
    mouseMiddleEmulation: { def: false, onChange: "updateCompositorInput" },
    mouseNaturalScroll: { def: false, onChange: "updateCompositorInput" },
    mouseScrollFactor: { def: 1.0, onChange: "updateCompositorInput" },
    mouseScrollMethod: { def: "default", onChange: "updateCompositorInput" },
    touchpadAccelProfile: { def: "default", onChange: "updateCompositorInput" },
    touchpadAccelSpeed: { def: 0.0, onChange: "updateCompositorInput" },
    touchpadDisableOnExternalMouse: { def: false, onChange: "updateCompositorInput" },
    touchpadDisableWhileTyping: { def: true, onChange: "updateCompositorInput" },
    touchpadDragLock: { def: false, onChange: "updateCompositorInput" },
    touchpadMiddleEmulation: { def: false, onChange: "updateCompositorInput" },
    touchpadNaturalScroll: { def: true, onChange: "updateCompositorInput" },
    touchpadScrollFactor: { def: 1.0, onChange: "updateCompositorInput" },
    touchpadScrollMethod: { def: "default", onChange: "updateCompositorInput" },
    touchpadTapAndDrag: { def: true, onChange: "updateCompositorInput" },
    touchpadTapToClick: { def: true, onChange: "updateCompositorInput" },

    keyboardLayouts: { def: "", onChange: "updateCompositorInput" },
    keyboardVariants: { def: "", onChange: "updateCompositorInput" },
    keyboardModel: { def: "", onChange: "updateCompositorInput" },
    keyboardOptions: { def: "", onChange: "updateCompositorInput" },
    keyboardKeymapFile: { def: "", onChange: "updateCompositorInput" },
    keyboardTrackLayout: { def: "", onChange: "updateCompositorInput" },
    keyboardRepeatDelay: { def: 0, onChange: "updateCompositorInput" },
    keyboardRepeatRate: { def: 0, onChange: "updateCompositorInput" },
    keyboardNumlock: { def: false, onChange: "updateCompositorInput" },

    firstDayOfWeek: { def: -1 },
    showWeekNumber: { def: false },
    calendarBackend: { def: "auto" },
    clockFormat: { def: "auto", onChange: "markGreeterSyncPending" },
    showSeconds: { def: false, onChange: "markGreeterSyncPending" },
    padHours12Hour: { def: false, onChange: "markGreeterSyncPending" },
    useFahrenheit: { def: false },
    windSpeedUnit: { def: "kmh" },
    nightModeEnabled: { def: false },
    animationSpeed: { def: 1 },
    customAnimationDuration: { def: 500 },
    syncComponentAnimationSpeeds: { def: true },
    popoutAnimationSpeed: { def: 1 },
    popoutCustomAnimationDuration: { def: 150 },
    modalAnimationSpeed: { def: 1 },
    modalCustomAnimationDuration: { def: 150 },
    enableRippleEffects: { def: true },
    animationVariant: { def: 0 },
    motionEffect: { def: 0 },
    m3ElevationEnabled: { def: true },
    m3ElevationIntensity: { def: 12 },
    m3ElevationOpacity: { def: 30 },
    m3ElevationColorMode: { def: "default" },
    m3ElevationLightDirection: { def: "top" },
    m3ElevationCustomColor: { def: "#000000" },
    modalElevationEnabled: { def: true },
    popoutElevationEnabled: { def: true },
    barElevationEnabled: { def: true },
    blurEnabled: { def: false },
    blurForegroundLayers: { def: true },
    foregroundLayerTransparency: { def: 1.0, coerce: percentToUnit },
    blurLayerOutlineOpacity: { def: 0.12, coerce: percentToUnit },
    blurBorderEnabled: { def: true },
    blurBorderColor: { def: "outline" },
    blurBorderCustomColor: { def: "#ffffff" },
    blurBorderOpacity: { def: 0.35, coerce: percentToUnit },
    wallpaperFillMode: { def: "Fill" },
    blurredWallpaperLayer: { def: false },
    blurWallpaperOnOverview: { def: false },
    wallpaperBackgroundColorMode: { def: "black" },
    wallpaperBackgroundCustomColor: { def: "#000000" },

    showLauncherButton: { def: true },
    showWorkspaceSwitcher: { def: true },
    showFocusedWindow: { def: true },
    showWeather: { def: true },
    showMusic: { def: true },
    showClipboard: { def: true },
    showCpuUsage: { def: true },
    showMemUsage: { def: true },
    showCpuTemp: { def: true },
    showGpuTemp: { def: true },
    selectedGpuIndex: { def: 0 },
    enabledGpuPciIds: { def: [] },
    showSystemTray: { def: true },
    systemTrayIconTintMode: { def: "none" },
    systemTrayIconTintSaturation: { def: 50 },
    systemTrayIconTintStrength: { def: 135 },
    showClock: { def: true },
    showNotificationButton: { def: true },
    showBattery: { def: true },
    showBatteryPercent: { def: true },
    showBatteryPercentOnlyOnBattery: { def: false },
    showBatteryTime: { def: false },
    showBatteryTimeOnlyOnBattery: { def: false },
    batteryPillStyle: { def: false },
    batteryPillPercentSign: { def: false },
    showControlCenterButton: { def: true },
    showCapsLockIndicator: { def: true },

    controlCenterShowNetworkIcon: { def: true },
    controlCenterShowBluetoothIcon: { def: true },
    controlCenterShowAudioIcon: { def: true },
    controlCenterShowAudioPercent: { def: false },
    controlCenterShowVpnIcon: { def: true },
    controlCenterShowBrightnessIcon: { def: false },
    controlCenterShowBrightnessPercent: { def: false },
    controlCenterShowMicIcon: { def: false },
    controlCenterShowMicPercent: { def: false },
    controlCenterShowBatteryIcon: { def: false },
    controlCenterShowPrinterIcon: { def: false },
    controlCenterShowScreenSharingIcon: { def: true },
    controlCenterShowIdleInhibitorIcon: { def: false },
    controlCenterShowDoNotDisturbIcon: { def: false },

    showPrivacyButton: { def: true },
    privacyShowMicIcon: { def: false },
    privacyShowCameraIcon: { def: false },
    privacyShowScreenShareIcon: { def: false },

    controlCenterWidgets: {
        def: [
            { id: "volumeSlider", enabled: true, width: 50 },
            { id: "brightnessSlider", enabled: true, width: 50 },
            { id: "wifi", enabled: true, width: 50 },
            { id: "bluetooth", enabled: true, width: 50 },
            { id: "audioOutput", enabled: true, width: 50 },
            { id: "audioInput", enabled: true, width: 50 },
            { id: "nightMode", enabled: true, width: 50 },
            { id: "darkMode", enabled: true, width: 50 }
        ]
    },

    showWorkspaceIndex: { def: false },
    showWorkspaceName: { def: false },
    showWorkspacePadding: { def: false },
    workspaceScrolling: { def: false },
    showWorkspaceApps: { def: false },
    workspaceDragReorder: { def: true },
    maxWorkspaceIcons: { def: 3 },
    workspaceAppIconSizeOffset: { def: 0 },
    groupWorkspaceApps: { def: true },
    groupActiveWorkspaceApps: { def: false },
    workspaceFollowFocus: { def: false },
    showOccupiedWorkspacesOnly: { def: false },
    reverseScrolling: { def: false },
    dwlShowAllTags: { def: false },
    workspaceActiveAppHighlightEnabled: { def: false },
    workspaceColorMode: { def: "default" },
    workspaceFocusedCustomColor: { def: "#6750A4" },
    workspaceOccupiedColorMode: { def: "none" },
    workspaceOccupiedCustomColor: { def: "#625B71" },
    workspaceUnfocusedColorMode: { def: "default" },
    workspaceUnfocusedCustomColor: { def: "#49454E" },
    workspaceUrgentColorMode: { def: "default" },
    workspaceUrgentCustomColor: { def: "#B3261E" },
    workspaceFocusedBorderEnabled: { def: false },
    workspaceFocusedBorderColor: { def: "primary" },
    workspaceFocusedBorderCustomColor: { def: "#6750A4" },
    workspaceFocusedBorderThickness: { def: 2 },
    workspaceUnfocusedMonitorSeparateAppearance: { def: false },
    workspaceUnfocusedMonitorColorMode: { def: "default" },
    workspaceUnfocusedMonitorFocusedCustomColor: { def: "#6750A4" },
    workspaceUnfocusedMonitorOccupiedColorMode: { def: "none" },
    workspaceUnfocusedMonitorOccupiedCustomColor: { def: "#625B71" },
    workspaceUnfocusedMonitorUnfocusedColorMode: { def: "default" },
    workspaceUnfocusedMonitorUnfocusedCustomColor: { def: "#49454E" },
    workspaceUnfocusedMonitorUrgentColorMode: { def: "default" },
    workspaceUnfocusedMonitorUrgentCustomColor: { def: "#B3261E" },
    workspaceUnfocusedMonitorBorderEnabled: { def: false },
    workspaceUnfocusedMonitorBorderColor: { def: "primary" },
    workspaceUnfocusedMonitorBorderCustomColor: { def: "#6750A4" },
    workspaceUnfocusedMonitorBorderThickness: { def: 2 },
    workspaceNameIcons: { def: {} },
    waveProgressEnabled: { def: true },
    scrollTitleEnabled: { def: true },
    mediaAdaptiveWidthEnabled: { def: true },
    audioVisualizerEnabled: { def: true },
    mediaUseAlbumArtAccent: { def: false },
    appleMusicAnimatedArtEnabled: { def: false },
    audioScrollMode: { def: "volume" },
    audioWheelScrollAmount: { def: 5 },
    audioDeviceScrollVolumeEnabled: { def: false },
    mediaExcludePlayers: { def: [] },
    clockCompactMode: { def: false },
    focusedWindowCompactMode: { def: false },
    focusedWindowSize: { def: 1 },
    focusedWindowShowIcon: { def: true },
    runningAppsCompactMode: { def: true },
    barMaxVisibleApps: { def: 0 },
    barMaxVisibleRunningApps: { def: 0 },
    barShowOverflowBadge: { def: true },
    trayAutoOverflow: { def: true },
    trayPopupSingleLine: { def: true },
    trayMaxVisibleItems: { def: 0 },
    appsDockHideIndicators: { def: false },
    appsDockColorizeActive: { def: false },
    appsDockActiveColorMode: { def: "primary" },
    appsDockEnlargeOnHover: { def: false },
    appsDockEnlargePercentage: { def: 125 },
    appsDockIconSizePercentage: { def: 100 },
    keyboardLayoutNameCompactMode: { def: false },
    keyboardLayoutNameShowIcon: { def: false},
    runningAppsCurrentWorkspace: { def: true },
    runningAppsGroupByApp: { def: false },
    runningAppsCurrentMonitor: { def: false },
    appIdSubstitutions: {
        def: [
            { pattern: "Spotify", replacement: "spotify", type: "exact" },
            { pattern: "beepertexts", replacement: "beeper", type: "exact" },
            { pattern: "home assistant desktop", replacement: "homeassistant-desktop", type: "exact" },
            { pattern: "com.transmissionbt.transmission", replacement: "transmission-gtk", type: "contains" },
            { pattern: "^steam_app_(\\d+)$", replacement: "steam_icon_$1", type: "regex" }
        ]
    },
    centeringMode: { def: "index" },
    clockDateFormat: { def: "" },
    lockDateFormat: { def: "" },
    greeterRememberLastSession: { def: true, onChange: "markGreeterSyncPending" },
    greeterRememberLastUser: { def: true, onChange: "markGreeterSyncPending" },
    greeterAutoLogin: { def: false, onChange: "scheduleGreeterAutoLoginSync" },
    greeterEnableFprint: { def: false, onChange: "markGreeterSyncPending" },
    greeterEnableU2f: { def: false, onChange: "markGreeterSyncPending" },
    greeterWallpaperPath: { def: "", onChange: "markGreeterSyncPending" },
    greeterLockDateFormat: { def: "", onChange: "markGreeterSyncPending" },
    greeterFontFamily: { def: "", onChange: "markGreeterSyncPending" },
    greeterWallpaperFillMode: { def: "", onChange: "markGreeterSyncPending" },
    greeterPamExternallyManaged: { def: false, onChange: "markGreeterSyncPending" },
    mediaSize: { def: 1 },

    appLauncherViewMode: { def: "list" },
    spotlightModalViewMode: { def: "list" },
    browserPickerViewMode: { def: "grid" },
    appPickerViewMode: { def: "grid" },
    sortAppsAlphabetically: { def: false },
    appLauncherGridColumns: { def: 4 },
    spotlightCloseNiriOverview: { def: true },
    rememberLastQuery: { def: false },
    rememberLastMode: { def: true },
    spotlightSectionViewModes: { def: {} },
    appDrawerSectionViewModes: { def: {} },
    niriOverviewOverlayEnabled: { def: true },
    niriOverviewLauncherStyle: { def: "full" },
    dankLauncherV2Size: { def: "compact" },
    dankLauncherV2ShowSourceBadges: { def: true },
    dankLauncherV2BorderEnabled: { def: false },
    dankLauncherV2BorderThickness: { def: 2 },
    dankLauncherV2BorderColor: { def: "primary" },
    dankLauncherV2ShowFooter: { def: true },
    dankLauncherV2UnloadOnClose: { def: false },
    dankLauncherV2IncludeFilesInAll: { def: false },
    dankLauncherV2IncludeFoldersInAll: { def: false },
    launcherUseOverlayLayer: { def: false },
    launcherStyle: { def: "full" },
    spotlightBarShowModeChips: { def: false },
    keybindsFloatingWindow: { def: false },

    useAutoLocation: { def: false },
    weatherEnabled: { def: true },
    dashTabs: { def: [{ id: "overview", enabled: true }, { id: "media", enabled: true }, { id: "wallpaper", enabled: true }, { id: "weather", enabled: true }, { id: "settings", enabled: true }] },

    networkPreference: { def: "auto" },

    iconThemeDark: { def: "System Default", onChange: "applyStoredIconTheme" },
    iconThemeLight: { def: "System Default", onChange: "applyStoredIconTheme" },
    iconThemePerMode: { def: false, onChange: "applyStoredIconTheme" },
    availableIconThemes: { def: ["System Default"], persist: false },
    systemDefaultIconTheme: { def: "", persist: false },

    cursorSettings: { def: { theme: "System Default", size: 24, niri: { hideWhenTyping: false, hideAfterInactiveMs: 0 }, hyprland: { hideOnKeyPress: false, hideOnTouch: false, inactiveTimeout: 0 }, dwl: { cursorHideTimeout: 0 }, mango: { cursorHideTimeout: 0 } }, onChange: "updateCompositorCursor" },
    availableCursorThemes: { def: ["System Default"], persist: false },
    systemDefaultCursorTheme: { def: "", persist: false },

    launcherLogoMode: { def: "apps" },
    launcherLogoCustomPath: { def: "" },
    launcherLogoColorOverride: { def: "" },
    launcherLogoColorInvertOnMode: { def: false },
    launcherLogoBrightness: { def: 0.5 },
    launcherLogoContrast: { def: 1 },
    launcherLogoSizeOffset: { def: 0 },

    fontFamily: { def: "Inter Variable" },
    monoFontFamily: { def: "Fira Code" },
    fontWeight: { def: 400 },
    fontScale: { def: 1.0 },
    textRenderType: { def: 0 },
    textRenderQuality: { def: 0 },

    notepadUseMonospace: { def: true },
    notepadFontFamily: { def: "" },
    notepadFontSize: { def: 14 },
    notificationSummaryFontSize: { def: 0 },
    notificationBodyFontSize: { def: 0 },
    notepadShowLineNumbers: { def: false },
    notepadAutoSave: { def: false },
    notepadSlideoutSide: { def: "right" },
    notepadDefaultMode: { def: "slideout" },
    notepadTransparencyOverride: { def: -1 },
    notepadLastCustomTransparency: { def: 0.7 },
    notepadUseCompositorGap: { def: false },
    notepadEdgeGap: { def: 0 },

    soundsEnabled: { def: true },
    useSystemSoundTheme: { def: false },
    soundLogin: { def: false },
    soundNewNotification: { def: true },
    soundVolumeChanged: { def: true },
    soundPluggedIn: { def: true },
    muteSoundsWhenMediaPlaying: { def: true },

    acMonitorTimeout: { def: 0 },
    acLockTimeout: { def: 0 },
    acSuspendTimeout: { def: 0 },
    acSuspendBehavior: { def: 0 },
    acProfileName: { def: "" },
    acPostLockMonitorTimeout: { def: 0 },
    batteryMonitorTimeout: { def: 0 },
    batteryLockTimeout: { def: 0 },
    batterySuspendTimeout: { def: 0 },
    batterySuspendBehavior: { def: 0 },
    batteryProfileName: { def: "" },
    batteryPostLockMonitorTimeout: { def: 0 },
    batteryChargeLimit: { def: 100 },
    batteryNotifyChargeLimit: { def: false },
    batteryCriticalThreshold: { def: 10 },
    batteryNotifyCritical: { def: true },
    batteryLowThreshold: { def: 20 },
    batteryNotifyLow: { def: false },
    batteryChargeLimitNotificationType: { def: 0 },
    batteryLowNotificationType: { def: 0 },
    batteryCriticalNotificationType: { def: 1 },
    batteryAutoPowerSaver: { def: false },
    lowerDisplayRefreshRateOnBattery: { def: false },
    lockBeforeSuspend: { def: false },
    loginctlLockIntegration: { def: true },
    fadeToLockEnabled: { def: true },
    fadeToLockGracePeriod: { def: 5 },
    fadeToDpmsEnabled: { def: true },
    fadeToDpmsGracePeriod: { def: 5 },
    launchPrefix: { def: "" },

    syncModeWithPortal: { def: true },
    terminalsAlwaysDark: { def: false, onChange: "regenSystemThemes" },

    muxType: { def: "tmux" },
    muxUseCustomCommand: { def: false },
    muxCustomCommand: { def: "" },
    muxSessionFilter: { def: "" },

    runDmsMatugenTemplates: { def: true },
    matugenTemplateGtk: { def: true },
    matugenTemplateNiri: { def: true },
    matugenTemplateHyprland: { def: true },
    matugenTemplateMangowc: { def: true },
    matugenTemplateQt5ct: { def: true },
    matugenTemplateQt6ct: { def: true },
    matugenTemplateFirefox: { def: true },
    matugenTemplatePywalfox: { def: true },
    matugenTemplateZenBrowser: { def: true },
    matugenTemplateVesktop: { def: true },
    matugenTemplateVencord: { def: true },
    matugenTemplateEquibop: { def: true },
    matugenTemplateGhostty: { def: true },
    matugenTemplateKitty: { def: true },
    matugenTemplateFoot: { def: true },
    matugenTemplateAlacritty: { def: true },
    matugenTemplateNeovim: { def: false },
    matugenTemplateWezterm: { def: true },
    matugenTemplateDgop: { def: true },
    matugenTemplateKcolorscheme: { def: true },
    matugenTemplateVscode: { def: true },
    matugenTemplateEmacs: { def: true },
    matugenTemplateZed: { def: true },

    matugenTemplateNeovimSettings: {
        def: {
            dark: { baseTheme: "github_dark", harmony: 0.5 },
            light: { baseTheme: "github_light", harmony: 0.5 }
        }
    },
    matugenTemplateNeovimSetBackground: { def: true },

    showDock: { def: false },
    dockAutoHide: { def: false },
    dockSmartAutoHide: { def: false },
    dockUseOverlayLayer: { def: false },
    dockGroupByApp: { def: false },
    dockRestoreSpecialWorkspaceOnClick: { def: false },
    dockOpenOnOverview: { def: false },
    dockPosition: { def: 1 },
    dockSpacing: { def: 4 },
    dockBottomGap: { def: 0 },
    dockMargin: { def: 0 },
    dockIconSize: { def: 40 },
    dockIndicatorStyle: { def: "circle" },
    dockBorderEnabled: { def: false },
    dockBorderColor: { def: "surfaceText" },
    dockBorderOpacity: { def: 1.0, coerce: percentToUnit },
    dockBorderThickness: { def: 1 },
    dockIsolateDisplays: { def: false },
    dockLauncherEnabled: { def: false },
    dockLauncherLogoMode: { def: "apps" },
    dockLauncherLogoCustomPath: { def: "" },
    dockLauncherLogoColorOverride: { def: "" },
    dockLauncherLogoSizeOffset: { def: 0 },
    dockLauncherLogoBrightness: { def: 0.5, coerce: percentToUnit },
    dockLauncherLogoContrast: { def: 1, coerce: percentToUnit },
    dockMaxVisibleApps: { def: 0 },
    dockMaxVisibleRunningApps: { def: 0 },
    dockShowOverflowBadge: { def: true },
    dockShowTrash: { def: false },
    dockTrashFileManager: { def: "default" },
    dockTrashCustomCommand: { def: "" },

    notificationOverlayEnabled: { def: false },
    notificationPopupShadowEnabled: { def: true },
    notificationPopupPrivacyMode: { def: false },
    notificationForegroundLayers: { def: true },
    overviewRows: { def: 2, persist: false },
    overviewColumns: { def: 5, persist: false },
    overviewScale: { def: 0.16, persist: false },

    modalDarkenBackground: { def: true },

    lockScreenShowPowerActions: { def: true },
    lockScreenShowSystemIcons: { def: true },
    lockScreenShowTime: { def: true },
    lockScreenShowDate: { def: true },
    lockScreenShowProfileImage: { def: true },
    lockScreenShowPasswordField: { def: true },
    lockScreenShowMediaPlayer: { def: true },
    lockScreenPowerOffMonitorsOnLock: { def: false },
    lockAtStartup: { def: false },
    enableFprint: { def: false },
    maxFprintTries: { def: 15 },
    enableU2f: { def: false, onChange: "scheduleAuthApply" },
    u2fMode: { def: "or" },
    lockPamPath: { def: "" },
    lockScreenSecurityKeyShortcut: { def: "Ctrl+Q" },
    lockScreenSecurityKeyShortcutEnabled: { def: false },
    lockPamInlineFprint: { def: false },
    lockPamInlineU2f: { def: false },
    lockPamExternallyManaged: { def: false },
    lockU2fPamPath: { def: "" },
    lockScreenInactiveColor: { def: "#000000" },
    lockScreenNotificationMode: { def: 0 },
    lockScreenVideoEnabled: { def: false },
    lockScreenVideoPath: { def: "" },
    lockScreenVideoCycling: { def: false },
    lockScreenWallpaperPath: { def: "" },
    lockScreenWallpaperFillMode: { def: "" },
    lockScreenFontFamily: { def: "" },
    hideBrightnessSlider: { def: false },

    notificationTimeoutLow: { def: 5000 },
    notificationTimeoutNormal: { def: 5000 },
    notificationTimeoutCritical: { def: 0 },
    notificationIgnoreAppTimeout: { def: false },
    notificationCompactMode: { def: false },
    notificationShowTimeoutBar: { def: false },
    notificationDedupeEnabled: { def: true },
    notificationPopupPosition: { def: 0 },
    notificationAnimationSpeed: { def: 1 },
    notificationCustomAnimationDuration: { def: 400 },
    notificationHistoryEnabled: { def: true },
    notificationHistoryMaxCount: { def: 50 },
    notificationHistoryMaxAgeDays: { def: 7 },
    notificationHistorySaveLow: { def: true },
    notificationHistorySaveNormal: { def: true },
    notificationHistorySaveCritical: { def: true },
    notificationRules: { def: [] },
    notificationFocusedMonitor: { def: false },

    osdAlwaysShowValue: { def: false },
    osdPosition: { def: 5 },
    osdVolumeEnabled: { def: true },
    osdMediaVolumeEnabled: { def: true },
    osdMediaPlaybackEnabled: { def: false },
    osdBrightnessEnabled: { def: true },
    osdIdleInhibitorEnabled: { def: true },
    osdMicMuteEnabled: { def: true },
    osdCapsLockEnabled: { def: true },
    osdPowerProfileEnabled: { def: false },
    osdAudioOutputEnabled: { def: true },

    powerActionConfirm: { def: true },
    powerActionHoldDuration: { def: 0.5 },
    powerMenuActions: { def: ["reboot", "logout", "poweroff", "lock", "suspend", "restart"] },
    powerMenuDefaultAction: { def: "logout" },
    powerMenuGridLayout: { def: false },
    customPowerActionLock: { def: "" },
    customPowerActionLogout: { def: "" },
    customPowerActionSuspend: { def: "" },
    customPowerActionHibernate: { def: "" },
    customPowerActionReboot: { def: "" },
    customPowerActionPowerOff: { def: "" },
    customPowerButtons: { def: [] },

    updaterHideWidget: { def: false },
    updaterCheckOnStart: { def: false },
    updaterUseCustomCommand: { def: false },
    updaterCustomCommand: { def: "" },
    updaterTerminalAdditionalParams: { def: "" },
    updaterIntervalSeconds: { def: 1800 },
    updaterIncludeFlatpak: { def: true },
    updaterAllowAUR: { def: true },
    updaterIgnoredPackages: { def: [] },

    displayNameMode: { def: "system" },
    screenPreferences: { def: {} },
    showOnLastDisplay: { def: {} },
    displayProfiles: { def: {} },
    displayPreviousRefreshModes: { def: {} },
    displayProfileAutoSelect: { def: false },
    displayShowDisconnected: { def: false },
    displaySnapToEdge: { def: true },
    connectedFrameBarStyleBackups: { def: {} },

    barConfigs: {
        def: [{
            id: "default",
            name: "Main Bar",
            enabled: true,
            position: 0,
            screenPreferences: ["all"],
            showOnLastDisplay: true,
            leftWidgets: ["launcherButton", "workspaceSwitcher", "focusedWindow"],
            centerWidgets: ["music", "clock", "weather"],
            rightWidgets: ["systemTray", "clipboard", "cpuUsage", "memUsage", "notificationButton", "battery", "controlCenterButton"],
            spacing: 4,
            innerPadding: 4,
            bottomGap: 0,
            transparency: 1.0,
            widgetTransparency: 1.0,
            squareCorners: false,
            noBackground: false,
            maximizeWidgetIcons: false,
            maximizeWidgetText: false,
            removeWidgetPadding: false,
            widgetPadding: 8,
            gothCornersEnabled: false,
            gothCornerRadiusOverride: false,
            gothCornerRadiusValue: 12,
            borderEnabled: false,
            borderColor: "surfaceText",
            borderOpacity: 1.0,
            borderThickness: 1,
            widgetOutlineEnabled: false,
            widgetOutlineColor: "primary",
            widgetOutlineOpacity: 1.0,
            widgetOutlineThickness: 1,
            fontScale: 1.0,
            iconScale: 1.0,
            autoHide: false,
            autoHideStrict: false,
            autoHideDelay: 250,
            showOnWindowsOpen: false,
            openOnOverview: false,
            visible: true,
            popupGapsAuto: true,
            popupGapsManual: 4,
            maximizeDetection: true,
            useOverlayLayer: false,
            scrollEnabled: true,
            scrollXBehavior: "column",
            scrollYBehavior: "workspace",
            shadowIntensity: 0,
            shadowOpacity: 60,
            shadowColorMode: "default",
            shadowCustomColor: "#000000",
            clickThrough: false,
            hoverPopouts: false,
            hoverPopoutDelay: 150
        }], onChange: "updateBarConfigs"
    },

    desktopClockEnabled: { def: false },
    desktopClockStyle: { def: "analog" },
    desktopClockTransparency: { def: 0.8, coerce: percentToUnit },
    desktopClockColorMode: { def: "primary" },
    desktopClockCustomColor: { def: "#ffffff" },
    desktopClockShowDate: { def: true },
    desktopClockShowAnalogNumbers: { def: false },
    desktopClockShowAnalogSeconds: { def: true },
    desktopClockX: { def: -1 },
    desktopClockY: { def: -1 },
    desktopClockWidth: { def: 280 },
    desktopClockHeight: { def: 180 },
    desktopClockDisplayPreferences: { def: ["all"] },

    systemMonitorEnabled: { def: false },
    systemMonitorShowHeader: { def: true },
    systemMonitorTransparency: { def: 0.8, coerce: percentToUnit },
    systemMonitorColorMode: { def: "primary" },
    systemMonitorCustomColor: { def: "#ffffff" },
    systemMonitorShowCpu: { def: true },
    systemMonitorShowCpuGraph: { def: true },
    systemMonitorShowCpuTemp: { def: true },
    systemMonitorShowGpuTemp: { def: false },
    systemMonitorGpuPciId: { def: "" },
    systemMonitorShowMemory: { def: true },
    systemMonitorShowMemoryGraph: { def: true },
    systemMonitorShowNetwork: { def: true },
    systemMonitorShowNetworkGraph: { def: true },
    systemMonitorShowDisk: { def: true },
    systemMonitorShowTopProcesses: { def: false },
    systemMonitorTopProcessCount: { def: 3 },
    systemMonitorTopProcessSortBy: { def: "cpu" },
    systemMonitorGraphInterval: { def: 60 },
    systemMonitorLayoutMode: { def: "auto" },
    systemMonitorX: { def: -1 },
    systemMonitorY: { def: -1 },
    systemMonitorWidth: { def: 320 },
    systemMonitorHeight: { def: 480 },
    systemMonitorDisplayPreferences: { def: ["all"] },
    systemMonitorVariants: { def: [] },
    desktopWidgetPositions: { def: {} },

    desktopWidgetInstances: { def: [] },

    desktopWidgetGroups: { def: [] },

    builtInPluginSettings: { def: {} },
    clipboardClickToPaste: { def: false },
    clipboardEnterToPaste: { def: false },
    clipboardRememberTypeFilter: { def: false },
    clipboardUseOverlayLayer: { def: false },
    clipboardTypeFilter: { def: "all" },
    clipboardVisibleEntryActions: { def: ["pin", "edit", "delete"] },

    launcherPluginVisibility: { def: {} },
    launcherPluginOrder: { def: [] },

    frameEnabled: { def: false },
    frameThickness: { def: 16 },
    frameRounding: { def: 23 },
    frameColor: { def: "" },
    frameOpacity: { def: 1.0 },
    frameScreenPreferences: { def: ["all"] },
    frameBarSize: { def: 40 },
    frameShowOnOverview: { def: false },
    frameBlurEnabled: { def: true },
    frameCloseGaps: { def: true },
    frameLauncherEmergeSide: { def: "bottom" },
    frameLauncherArcExtender: { def: false },
    frameLauncherEdgeHover: { def: false },
    frameMode: { def: "connected" },
    barInsetPaddingShared: { def: -1 },
    barInsetPaddingSyncAll: { def: false },
    frameBarInsetPadding: { def: -1 }
};

function getValidKeys() {
    return Object.keys(SPEC).filter(function (k) { return SPEC[k].persist !== false; }).concat(["configVersion"]);
}

function set(root, key, value, saveFn, hooks) {
    if (!(key in SPEC)) return;
    if (value === undefined || value === null) value = Util.cloneDef(SPEC[key].def);
    var oldValue = root[key];
    root[key] = value;
    var hookName = SPEC[key].onChange;
    if (hookName && hooks && hooks[hookName]) {
        hooks[hookName](root, key, oldValue);
    }
    saveFn();
}
