noctalia-shell/Services/Colors.qml
2025-08-14 19:52:03 -04:00

131 lines
5.4 KiB
QML

pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
import qs.Services
// --------------------------------
// Noctalia Colors - Material Design 3
// We only use a very small subset of all available m3 colors to avoid complexity
Singleton {
id: root
// --- Key Colors: These are the main accent colors that define your app's theme
property color mPrimary: useCustom ? customColors.mPrimary : defaultColors.mPrimary
property color mOnPrimary: useCustom ? customColors.mOnPrimary : defaultColors.mOnPrimary
property color mSecondary: useCustom ? customColors.mSecondary : defaultColors.mSecondary
property color mOnSecondary: useCustom ? customColors.mOnSecondary : defaultColors.mOnSecondary
property color mTertiary: useCustom ? customColors.mTertiary : defaultColors.mTertiary
property color mOnTertiary: useCustom ? customColors.mOnTertiary : defaultColors.mOnTertiary
// --- Utility Colors: These colors serve specific, universal purposes like indicating errors
property color mError: useCustom ? customColors.mError : defaultColors.mError
property color mOnError: useCustom ? customColors.mOnError : defaultColors.mOnError
// --- Surface and Variant Colors: These provide additional options for surfaces and their contents, creating visual hierarchy
property color mSurface: useCustom ? customColors.mSurface : defaultColors.mSurface
property color mOnSurface: useCustom ? customColors.mOnSurface : defaultColors.mOnSurface
property color mSurfaceVariant: useCustom ? customColors.mSurfaceVariant : defaultColors.mSurfaceVariant
property color mOnSurfaceVariant: useCustom ? customColors.mOnSurfaceVariant : defaultColors.mOnSurfaceVariant
property color mOutline: useCustom ? customColors.mOutline : defaultColors.mOutline
property color mOutlineVariant: useCustom ? customColors.mOutlineVariant : defaultColors.mOutlineVariant
property color mShadow: useCustom ? customColors.mShadow : defaultColors.mShadow
// -----------
// Check if we should use custom colors
property bool useCustom: (Settings.data.wallpaper.generateColors && customColorsFile.loaded)
// -----------
function applyOpacity(color, opacity) {
// Convert color to string and apply opacity
return color.toString().replace("#", "#" + opacity)
}
// --------------------------------
// Default colors: RosePine
QtObject {
id: defaultColors
property color mPrimary: "#ebbcba"
property color mOnPrimary: "#191724"
property color mSecondary: "#31748f"
property color mOnSecondary: "#e0def4"
property color mTertiary: "#9ccfd8"
property color mOnTertiary: "#191724"
property color mError: "#eb6f92"
property color mOnError: "#191724"
property color mSurface: "#191724"
property color mOnSurface: "#e0def4"
property color mSurfaceVariant: "#26233a"
property color mOnSurfaceVariant: "#908caa"
property color mOutline: "#44415a"
property color mOutlineVariant: "#514e6c"
property color mShadow: "#191724"
}
// ----------------------------------------------------------------
// Custom colors loaded from colors.json
// These can be generated by matugen or simply come from a well know color scheme (Dracula, Gruvbox, Nord, ...)
QtObject {
id: customColors
property color mPrimary: customColorsData.mPrimary
property color mOnPrimary: customColorsData.mOnPrimary
property color mSecondary: customColorsData.mSecondary
property color mOnSecondary: customColorsData.mOnSecondary
property color mTertiary: customColorsData.mTertiary
property color mOnTertiary: customColorsData.mOnTertiary
property color mError: customColorsData.mError
property color mOnError: customColorsData.mOnError
property color mSurface: customColorsData.mSurface
property color mOnSurface: customColorsData.mOnSurface
property color mSurfaceVariant: customColorsData.mSurfaceVariant
property color mOnSurfaceVariant: customColorsData.mOnSurfaceVariant
property color mOutline: customColorsData.mOutline
property color mOutlineVariant: customColorsData.mOutlineVariant
property color mShadow: customColorsData.mShadow
}
// FileView to load custom colors data from colors.json
FileView {
id: customColorsFile
path: Settings.configDir + "colors.json"
watchChanges: true
onFileChanged: reload()
onAdapterUpdated: writeAdapter()
onLoadFailed: function (error) {
if (error.toString().includes("No such file") || error === 2) {
// File doesn't exist, create it with default values
writeAdapter()
}
}
JsonAdapter {
id: customColorsData
property color mPrimary: defaultColors.mPrimary
property color mOnPrimary: defaultColors.mOnPrimary
property color mSecondary: defaultColors.mSecondary
property color mOnSecondary: defaultColors.mOnSecondary
property color mTertiary: defaultColors.mTertiary
property color mOnTertiary: defaultColors.mOnTertiary
property color mError: defaultColors.mError
property color mOnError: defaultColors.mOnError
property color mSurface: defaultColors.mSurface
property color mOnSurface: defaultColors.mOnSurface
property color mSurfaceVariant: defaultColors.mSurfaceVariant
property color mOnSurfaceVariant: defaultColors.mOnSurfaceVariant
property color mOutline: defaultColors.mOutline
property color mOutlineVariant: defaultColors.mOutlineVariant
property color mShadow: defaultColors.mShadow
}
}
}