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

148 lines
7 KiB
QML

pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
import qs.Services
// --------------------------------
// Material3 Colors
// We only use a subset of all materials colors to avoid complexity
Singleton {
id: root
// -----------
// Check if we should use custom colors
property bool useCustom: Settings.data.wallpaper.generateColors && customColorsFile.loaded
// --- Key Colors
property color colorPrimary: useCustom ? customColors.colorPrimary : defaultTheme.colorPrimary
property color colorOnPrimary: useCustom ? customColors.colorOnPrimary : defaultTheme.colorOnPrimary
property color colorSecondary: useCustom ? customColors.colorSecondary : defaultTheme.colorSecondary
property color colorOnSecondary: useCustom ? customColors.colorOnSecondary : defaultTheme.colorOnSecondary
property color colorTertiary: useCustom ? customColors.colorTertiary : defaultTheme.colorTertiary
property color colorOnTertiary: useCustom ? customColors.colorOnTertiary : defaultTheme.colorOnTertiary
// --- Utility Colors
property color colorError: useCustom ? customColors.colorError : defaultTheme.colorError
property color colorOnError: useCustom ? customColors.colorOnError : defaultTheme.colorOnError
// --- Surface and Variant Colors
property color colorSurface: useCustom ? customColors.colorSurface : defaultTheme.colorSurface
property color colorOnSurface: useCustom ? customColors.colorOnSurface : defaultTheme.colorOnSurface
property color colorSurfaceVariant: useCustom ? customColors.colorSurfaceVariant : defaultTheme.colorSurfaceVariant
property color colorOnSurfaceVariant: useCustom ? customColors.colorOnSurfaceVariant : defaultTheme.colorOnSurfaceVariant
property color colorOutline: useCustom ? customColors.colorOutline : defaultTheme.colorOutline
property color colorOutlineVariant: useCustom ? customColors.colorOutlineVariant : defaultTheme.colorOutlineVariant
property color colorShadow: useCustom ? customColors.colorShadow : defaultTheme.colorShadow
// -----------
function applyOpacity(color, opacity) {
// Convert color to string and apply opacity
return color.toString().replace("#", "#" + opacity)
}
// --------------------------------
// Default theme colors - RosePine
QtObject {
id: defaultTheme
// // --- Key Colors: These are the main accent colors that define your app's theme.
property color colorPrimary: "#ebbcba" // The main brand color, used most frequently.
property color colorOnPrimary: "#191724" // Color for text/icons on a Primary background.
property color colorSecondary: "#31748f" // An accent color for less prominent components.
property color colorOnSecondary: "#e0def4" // Color for text/icons on a Secondary background.
property color colorTertiary: "#9ccfd8" // A contrasting accent color used for things like highlights or special actions.
property color colorOnTertiary: "#191724" // Color for text/icons on a Tertiary background.
// --- Utility colorColors: These colors serve specific, universal purposes like indicating errors or providing neutral backgrounds.
property color colorError: "#eb6f92" // Indicates an error state.
property color colorOnError: "#191724" // Color for text/icons on an Error background.
// --- Surface colorand Variant Colors: These provide additional options for surfaces and their contents, creating visual hierarchy.
property color colorSurface: "#191724" // The color for component surfaces like cards, sheets, and menus.
property color colorOnSurface: "#e0def4" // The primary color for text/icons on a Surface background.
property color colorSurfaceVariant: "#26233a" // A surface color with a slightly different tint for differentiation.
property color colorOnSurfaceVariant: "#908caa" // The color for less prominent text/icons on a Surface.
property color colorOutline: "#44415a" // The color for component outlines, like text fields or buttons.
property color colorOutlineVariant: "#514e6c" // A subtler outline color for decorative elements or dividers.
property color colorShadow: "#191724" // The color used for shadows to create elevation.
}
// ----------------------------------------------------------------
// 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
// --- Key Colors
property color colorPrimary: customColorsData.colorPrimary
property color colorOnPrimary: customColorsData.colorOnPrimary
property color colorSecondary: customColorsData.colorSecondary
property color colorOnSecondary: customColorsData.colorOnSecondary
property color colorTertiary: customColorsData.colorTertiary
property color colorOnTertiary: customColorsData.colorOnTertiary
// --- Utility Colors
property color colorError: customColorsData.colorError
property color colorOnError: customColorsData.colorOnError
// --- Surface and Variant Colors
property color colorSurface: customColorsData.colorSurface
property color colorOnSurface: customColorsData.colorOnSurface
property color colorSurfaceVariant: customColorsData.colorSurfaceVariant
property color colorOnSurfaceVariant: customColorsData.colorOnSurfaceVariant
property color colorOutline: customColorsData.colorOutline
property color colorOutlineVariant: customColorsData.colorOutlineVariant
property color colorShadow: customColorsData.colorShadow
}
// 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
// --- Key Colors
property color colorPrimary: defaultTheme.colorPrimary
property color colorOnPrimary: defaultTheme.colorOnPrimary
property color colorSecondary: defaultTheme.colorSecondary
property color colorOnSecondary: defaultTheme.colorOnSecondary
property color colorTertiary: defaultTheme.colorTertiary
property color colorOnTertiary: defaultTheme.colorOnTertiary
// --- Utility Colors
property color colorError: defaultTheme.colorError
property color colorOnError: defaultTheme.colorOnError
// --- Surface and Variant Colors
property color colorSurface: defaultTheme.colorSurface
property color colorOnSurface: defaultTheme.colorOnSurface
property color colorSurfaceVariant: defaultTheme.colorSurfaceVariant
property color colorOnSurfaceVariant: defaultTheme.colorOnSurfaceVariant
property color colorOutline: defaultTheme.colorOutline
property color colorOutlineVariant: defaultTheme.colorOutlineVariant
property color colorShadow: defaultTheme.colorShadow
}
}
}