diff --git a/options.ts b/options.ts index 13b163b..426f293 100644 --- a/options.ts +++ b/options.ts @@ -796,6 +796,7 @@ const options = mkOptions(OPTIONS, { terminal: opt("kitty"), wallpaper: { + enable: opt(true), image: opt("") }, diff --git a/scss/options_trackers.ts b/scss/options_trackers.ts index d77f3aa..b83545c 100644 --- a/scss/options_trackers.ts +++ b/scss/options_trackers.ts @@ -37,10 +37,19 @@ export const initializeTrackers = (resetCssFunc: Function) => { }) Wallpaper.connect("changed", () => { + console.info("Wallpaper changed, regenerating Matugen colors...") if (options.theme.matugen.value) { options.resetTheme(); resetCssFunc(); } }) + options.wallpaper.image.connect("changed", () => { + if ((!Wallpaper.isRunning() && options.theme.matugen.value) || !options.wallpaper.enable.value) { + console.info("Wallpaper path changed, regenerating Matugen colors...") + options.resetTheme(); + resetCssFunc(); + } + }) + } diff --git a/scss/style.ts b/scss/style.ts index 31a6037..46885e0 100644 --- a/scss/style.ts +++ b/scss/style.ts @@ -2,7 +2,7 @@ import options from "options"; import { bash, dependencies } from "lib/utils"; import { MatugenColors } from "lib/types/options"; import { initializeTrackers } from "./options_trackers"; -import { generateMatugenColors, replaceHexValues } from "./matugen/index"; +import { generateMatugenColors, replaceHexValues } from "../services/matugen/index"; const deps = [ "font", diff --git a/services/Wallpaper.ts b/services/Wallpaper.ts index 9b35c9d..be87f8a 100644 --- a/services/Wallpaper.ts +++ b/services/Wallpaper.ts @@ -1,4 +1,5 @@ import { dependencies, sh } from "lib/utils" +import options from "options"; const hyprland = await Service.import("hyprland"); const WP = `${Utils.HOME}/.config/background` @@ -11,6 +12,7 @@ class Wallpaper extends Service { } #blockMonitor = false + #isRunning = false #wallpaper() { if (!dependencies("swww")) @@ -42,21 +44,42 @@ class Wallpaper extends Service { } readonly set = (path: string) => { this.#setWallpaper(path) } + readonly isRunning = () => { return this.#isRunning } + get wallpaper() { return WP } constructor() { super() - if (!dependencies("swww")) + options.wallpaper.enable.connect("changed", () => { + if (options.wallpaper.enable.value) { + this.#isRunning = true + Utils.execAsync("swww-daemon") + .then(() => { + this.#wallpaper + }) + .catch(() => null) + } else { + this.#isRunning = false + Utils.execAsync("pkill swww-daemon") + .catch(() => null) + } + + }) + + if (!dependencies("swww") || !options.wallpaper.enable.value) return this + this.#isRunning = true Utils.monitorFile(WP, () => { if (!this.#blockMonitor) this.#wallpaper() }) Utils.execAsync("swww-daemon") - .then(this.#wallpaper) + .then(() => { + this.#wallpaper + }) .catch(() => null) } } diff --git a/scss/matugen/index.ts b/services/matugen/index.ts similarity index 100% rename from scss/matugen/index.ts rename to services/matugen/index.ts diff --git a/scss/matugen/variations.ts b/services/matugen/variations.ts similarity index 100% rename from scss/matugen/variations.ts rename to services/matugen/variations.ts diff --git a/widget/settings/pages/theme/menus/index.ts b/widget/settings/pages/theme/menus/index.ts index da78b3e..cdebc5f 100644 --- a/widget/settings/pages/theme/menus/index.ts +++ b/widget/settings/pages/theme/menus/index.ts @@ -14,6 +14,7 @@ export const MenuTheme = () => { children: [ Header('General'), Option({ opt: options.theme.bar.menus.monochrome, title: 'Use Global Colors', type: 'boolean', disabledBinding: options.theme.matugen }), + Option({ opt: options.wallpaper.enable, title: 'Apply Wallpapers', subtitle: 'Whether to apply the wallpaper or to only use it for Matugen color generation.', type: 'boolean' }), Option({ opt: options.wallpaper.image, title: 'Wallpaper', subtitle: options.wallpaper.image.bind("value"), type: 'wallpaper' }), Option({ opt: options.theme.bar.menus.background, title: 'Background Color', type: 'color' }), Option({ opt: options.theme.bar.menus.cards, title: 'Cards', type: 'color' }), diff --git a/widget/settings/shared/Inputter.ts b/widget/settings/shared/Inputter.ts index d9e9376..8ae340d 100644 --- a/widget/settings/shared/Inputter.ts +++ b/widget/settings/shared/Inputter.ts @@ -5,6 +5,7 @@ import { RowProps } from "lib/types/options" import { Variable } from "types/variable"; import Wallpaper from "services/Wallpaper"; import { dependencies as checkDependencies } from "lib/utils"; +import options from "options"; const EnumSetter = (opt: Opt, values: string[]) => { const lbl = Widget.Label({ label: opt.bind().as(v => `${v}`) }) @@ -159,7 +160,9 @@ export const Inputter = ({ case "wallpaper": return self.child = Widget.FileChooserButton({ on_file_set: ({ uri }) => { opt.value = uri!.replace("file://", "") as T; - Wallpaper.set(uri!.replace("file://", "")); + if (options.wallpaper.enable.value) { + Wallpaper.set(uri!.replace("file://", "")); + } }, })