Predefined ColorSchemes

- added support for predefined color schemes
- moved all the code regarding colors generation from wallpaper to the
ColorSchemes service
This commit is contained in:
quadbyte 2025-08-15 15:37:00 -04:00
parent a8e7f6e01d
commit f5b4cb452b
9 changed files with 126 additions and 94 deletions

View file

@ -15,6 +15,8 @@ Singleton {
property var schemes: []
property bool scanning: false
property string schemesDirectory: Quickshell.shellDir + "/Assets/ColorSchemes"
property string colorsJsonFilePath: Settings.configDir + "colors.json"
function loadColorSchemes() {
console.log("[ColorSchemes] Load ColorSchemes")
@ -22,7 +24,20 @@ Singleton {
schemes = []
// Unsetting, then setting the folder will re-trigger the parsing!
folderModel.folder = ""
folderModel.folder = "file://" + Quickshell.shellDir + "/Assets/ColorSchemes"
folderModel.folder = "file://" + schemesDirectory
}
function applyScheme(filePath) {
Quickshell.execDetached(["cp", filePath, colorsJsonFilePath])
}
function changedWallpaper() {
if (Settings.data.colorSchemes.useWallpaperColors) {
console.log("[ColorSchemes] Starting color generation process")
generateColorsProcess.running = true
// Invalidate potential predefined scheme
Settings.data.colorSchemes.predefinedScheme = ""
}
}
FolderListModel {
@ -34,12 +49,30 @@ Singleton {
if (status === FolderListModel.Ready) {
var files = []
for (var i = 0; i < count; i++) {
var filepath = folderModel.folder + "/" + get(i, "fileName")
var filepath = schemesDirectory + "/" + get(i, "fileName")
files.push(filepath)
}
schemes = files
scanning = false
console.log(schemes)
}
}
}
Process {
id: generateColorsProcess
command: ["matugen", "image", Wallpapers.currentWallpaper, "--config", Quickshell.shellDir + "/Assets/Matugen/matugen.toml"]
workingDirectory: Quickshell.shellDir
running: false
stdout: StdioCollector {
onStreamFinished: {
console.log("[ColorSchemes] Generated colors from wallpaper")
}
}
stderr: StdioCollector {
onStreamFinished: {
if (this.text !== "") {
console.error(this.text)
}
}
}
}

View file

@ -13,29 +13,25 @@ Singleton {
id: root
// --- Key Colors: These are the main accent colors that define your app's style
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
property color mPrimary: customColors.mPrimary
property color mOnPrimary: customColors.mOnPrimary
property color mSecondary: customColors.mSecondary
property color mOnSecondary: customColors.mOnSecondary
property color mTertiary: customColors.mTertiary
property color mOnTertiary: customColors.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
property color mError: customColors.mError
property color mOnError: customColors.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)
property color mSurface: customColors.mSurface
property color mOnSurface: customColors.mOnSurface
property color mSurfaceVariant: customColors.mSurfaceVariant
property color mOnSurfaceVariant: customColors.mOnSurfaceVariant
property color mOutline: customColors.mOutline
property color mOutlineVariant: customColors.mOutlineVariant
property color mShadow: customColors.mShadow
// -----------
function applyOpacity(color, opacity) {
@ -98,11 +94,11 @@ Singleton {
path: Settings.configDir + "colors.json"
watchChanges: true
onFileChanged: {
console.log("[Colors] reloading colors file from disk")
console.log("[Colors] Reloading colors from disk")
reload()
}
onAdapterUpdated: {
console.log("[Colors] writing colors to disk, primary color:", mPrimary)
console.log("[Colors] Writing colors to disk")
writeAdapter()
}
onLoadFailed: function (error) {

View file

@ -119,7 +119,6 @@ Singleton {
property string current: ""
property bool isRandom: false
property int randomInterval: 300
property bool generateColors: false
property JsonObject swww
onDirectoryChanged: Wallpapers.loadWallpapers()
@ -190,6 +189,13 @@ Singleton {
property list<var> monitorBrightness: []
property int brightnessStep: 5
}
property JsonObject colorSchemes
colorSchemes: JsonObject {
property bool useWallpaperColors: false
property string predefinedScheme: ""
}
}
}
}

View file

@ -39,7 +39,7 @@ Singleton {
}
function setCurrentWallpaper(path, isInitial) {
// Only generate colors if the wallpaper actually changed
// Only regenerate colors if the wallpaper actually changed
var wallpaperChanged = currentWallpaper !== path
currentWallpaper = path
@ -64,9 +64,9 @@ Singleton {
randomWallpaperTimer.restart()
}
// Only generate colors if the wallpaper actually changed
// Only notify ColorSchemes service if the wallpaper actually changed
if (wallpaperChanged) {
generateColors()
ColorSchemes.changedWallpaper()
}
}
@ -95,14 +95,6 @@ Singleton {
}
}
function generateColors() {
console.log("[Wallpapers] generateColors() called, generateColors setting:", Settings.data.wallpaper.generateColors)
if (Settings.data.wallpaper.generateColors) {
console.log("[Wallpapers] Starting color generation process")
generateThemeProcess.running = true
}
}
function startSWWWDaemon() {
if (Settings.data.wallpaper.swww.enabled) {
console.log("[SWWW] Requesting swww-daemon")
@ -160,25 +152,6 @@ Singleton {
}
}
Process {
id: generateThemeProcess
command: ["matugen", "image", currentWallpaper, "--config", Quickshell.shellDir + "/Assets/Matugen/matugen.toml"]
workingDirectory: Quickshell.shellDir
running: false
stdout: StdioCollector {
onStreamFinished: {
console.log("[Wallpapers] generated colors from image")
}
}
stderr: StdioCollector {
onStreamFinished: {
if (this.text !== "") {
console.error(this.text)
}
}
}
}
Process {
id: startDaemonProcess
command: ["swww-daemon", "--format", "xrgb"]