aboutsummaryrefslogtreecommitdiffstats
path: root/appearance/Theme.qml
blob: 423dd49cb53b5e3fd1202d2a7f5cd1ab27bbdd2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

pragma Singleton

import Quickshell
import Quickshell.Io
import QtQuick

// The palette comes from unified-desktop-theme: udt-accent writes
// ~/.cache/wal/udt-palette.qml on every wallpaper change, holding the
// Macchiato colours from its palette.rasi plus the accent snapped from the
// wallpaper. Watching that file is what makes a theme edit show up here.
//
// The defaults below are only what renders before the file is read, or on a
// machine where unified-desktop-theme is not installed.
Singleton {
    id: root

    property color base: "#24273a"
    property color surface: "#363a4f"
    property color text: "#cad3f5"
    property color subtext: "#a5adcb"
    property color red: "#ed8796"
    property color green: "#a6da95"
    property color yellow: "#eed49f"
    property color surfaceAlt: "#494d64"
    property color overlay: "#6e738d"
    property color accent: "#b7bdf8"

    readonly property string fontFamily: "Noto Sans"
    readonly property int fontSize: 16

    // Parsed rather than imported: a generated file cannot be a QML import
    // without a qmldir next to it, and the cache directory has no reason to
    // carry one. The format is fixed and machine-written, so a regex is enough.
    FileView {
        path: `${Quickshell.env("HOME")}/.cache/wal/udt-palette.qml`
        watchChanges: true
        onFileChanged: reload()
        onLoaded: {
            const pick = key => {
                const m = text().match(new RegExp(`property color ${key}: "(#[0-9a-fA-F]{6})"`));
                return m ? m[1] : null;
            };
            root.base    = pick("base")     ?? root.base;
            root.surface = pick("surface0") ?? root.surface;
            root.text    = pick("text")     ?? root.text;
            root.subtext = pick("subtext0") ?? root.subtext;
            root.red     = pick("red")      ?? root.red;
            root.green = pick("green") ?? root.green;
            root.yellow = pick("yellow") ?? root.yellow;
            root.surfaceAlt = pick("surface1") ?? root.surfaceAlt;
            root.overlay = pick("overlay0") ?? root.overlay;
            root.accent  = pick("accent")   ?? root.accent;
        }
    }
}