More cleanup
This commit is contained in:
+26
-43
@@ -3,25 +3,20 @@ import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
// Single source of truth for shell color surfaces. Top-level tokens
|
||||
// (foreground/background/accent/urgent) come from the theme's colors.toml.
|
||||
// Per-surface roles (Color.bar.*, Color.popups.*, Color.tooltip.*,
|
||||
// Color.notifications.*, Color.menu.*, Color.appLauncher.*,
|
||||
// Color.imagePicker.*, Color.polkit.*, Color.lock.*) come from shell.toml,
|
||||
// which is generated
|
||||
// per theme from default/themed/shell.toml.tpl (or shipped directly by a
|
||||
// theme to override). Surfaces that don't appear in shell.toml fall back to
|
||||
// the foundational palette, so themes can ship partial overrides.
|
||||
// Color surfaces for the shell. Foundational palette (foreground, background,
|
||||
// accent, urgent) comes from theme/colors.toml. Per-surface roles come from
|
||||
// theme/shell.toml — generated per theme from default/themed/shell.toml.tpl,
|
||||
// or shipped directly by a theme to override individual keys. Surfaces that
|
||||
// don't appear in shell.toml fall back to the foundational palette.
|
||||
QtObject {
|
||||
id: root
|
||||
|
||||
// Foundational palette. Live updated from theme/colors.toml.
|
||||
property color foreground: "#cacccc"
|
||||
property color background: "#101315"
|
||||
property color accent: "#cacccc"
|
||||
property color urgent: "#a55555"
|
||||
|
||||
// Flat dictionary of "section.key" -> "#rrggbb" parsed from shell.toml.
|
||||
// Flat dictionary of "section.key" -> raw string from shell.toml.
|
||||
// Reassigning this whole property is what makes surface bindings below
|
||||
// re-evaluate when the theme swaps; mutating it in place would not.
|
||||
property var shellValues: ({})
|
||||
@@ -41,24 +36,15 @@ QtObject {
|
||||
|
||||
function alpha(c, opacity) {
|
||||
if (!c) return Qt.rgba(0, 0, 0, opacity)
|
||||
// pick() returns raw strings from shell.toml; convert to a color object
|
||||
// so .r/.g/.b are defined. Color objects pass through unchanged.
|
||||
if (typeof c === "string") c = Qt.color(c)
|
||||
return Qt.rgba(c.r, c.g, c.b, opacity)
|
||||
}
|
||||
|
||||
// Compose a color from a base-color key and its `-alpha` companion,
|
||||
// applying the alpha to the resolved color. Used by every surface that
|
||||
// exposes an alpha companion so consumers can read a single ready-to-use
|
||||
// value rather than composing themselves.
|
||||
// Compose a color from a base-color key and its `-alpha` companion.
|
||||
function composed(colorKey, alphaKey, colorFallback, alphaFallback) {
|
||||
return alpha(pick(colorKey, colorFallback), pickAlpha(alphaKey, alphaFallback))
|
||||
}
|
||||
|
||||
// Surface roles. Each property reads its shell.toml override if set,
|
||||
// otherwise falls back to a foundational palette token. Color values are
|
||||
// pre-composed with their `-alpha` companion where one exists, so
|
||||
// consumers can drop them straight into a Rectangle.color binding.
|
||||
readonly property QtObject bar: QtObject {
|
||||
property color background: root.composed("bar.background", "bar.background-alpha", root.background, 1.0)
|
||||
property color text: root.pick("bar.text", root.foreground)
|
||||
@@ -67,12 +53,10 @@ QtObject {
|
||||
readonly property QtObject popups: QtObject {
|
||||
property color background: root.composed("popups.background", "popups.background-alpha", root.background, 1.0)
|
||||
property color text: root.pick("popups.text", root.foreground)
|
||||
property color border: root.composed("popups.border", "popups.border-alpha", root.pick("notifications.border", root.accent), 1.0)
|
||||
property color border: root.composed("popups.border", "popups.border-alpha", root.accent, 1.0)
|
||||
}
|
||||
readonly property QtObject tooltip: QtObject {
|
||||
// Default background-alpha 0.97 matches the legacy tooltip opacity so
|
||||
// existing themes look identical until they override it.
|
||||
property color background: root.composed("tooltip.background", "tooltip.background-alpha", root.background, 0.97)
|
||||
property color background: root.composed("tooltip.background", "tooltip.background-alpha", root.background, 1.0)
|
||||
property color text: root.pick("tooltip.text", root.foreground)
|
||||
property color border: root.composed("tooltip.border", "tooltip.border-alpha", root.foreground, 1.0)
|
||||
}
|
||||
@@ -83,7 +67,7 @@ QtObject {
|
||||
property color countdown: root.pick("notifications.countdown", root.accent)
|
||||
}
|
||||
readonly property QtObject appLauncher: QtObject {
|
||||
property color background: root.composed("app-launcher.background", "app-launcher.background-alpha", root.background, 0.95)
|
||||
property color background: root.composed("app-launcher.background", "app-launcher.background-alpha", root.background, 1.0)
|
||||
property color text: root.pick("app-launcher.text", root.foreground)
|
||||
property color border: root.composed("app-launcher.border", "app-launcher.border-alpha", root.foreground, 1.0)
|
||||
property color scrim: root.composed("app-launcher.scrim", "app-launcher.scrim-alpha", root.background, 0.5)
|
||||
@@ -92,17 +76,17 @@ QtObject {
|
||||
property color selectedBorder: root.composed("app-launcher.selected-border", "app-launcher.selected-border-alpha", root.foreground, 0.0)
|
||||
}
|
||||
readonly property QtObject menu: QtObject {
|
||||
// Defaults mirror the panel cursor: a subtle foreground-tint fill,
|
||||
// no visible border, accent text. Themes override any of these
|
||||
// (including the alpha companions) per surface.
|
||||
property color background: root.composed("menu.background", "menu.background-alpha", root.background, 1.0)
|
||||
property color text: root.pick("menu.text", root.foreground)
|
||||
property color border: root.composed("menu.border", "menu.border-alpha", root.foreground, 1.0)
|
||||
property color scrim: root.composed("menu.scrim", "menu.scrim-alpha", root.background, 0.5)
|
||||
property color selectedBackground: root.composed("menu.selected-background", "menu.selected-background-alpha", root.pick("menu.selected", root.foreground), 0.08)
|
||||
property color selectedBackground: root.composed("menu.selected-background", "menu.selected-background-alpha", root.foreground, 0.08)
|
||||
property color selectedText: root.pick("menu.selected-text", root.accent)
|
||||
property color selectedBorder: root.composed("menu.selected-border", "menu.selected-border-alpha", root.foreground, 0.0)
|
||||
}
|
||||
// polkit + lock share a single border-alpha across border / border-active /
|
||||
// border-error: the three states are mutually exclusive in time, so one
|
||||
// companion is enough.
|
||||
readonly property QtObject polkit: QtObject {
|
||||
property color background: root.composed("polkit.background", "polkit.background-alpha", root.background, 1.0)
|
||||
property color text: root.pick("polkit.text", root.foreground)
|
||||
@@ -121,11 +105,10 @@ QtObject {
|
||||
property color borderError: root.composed("lock.border-error", "lock.border-alpha", root.urgent, 1.0)
|
||||
property color selection: root.composed("lock.selection", "lock.selection-alpha", root.accent, 0.45)
|
||||
}
|
||||
// The image picker has no card surface; `scrim` is the full-screen dim
|
||||
// wash, and per-slice dim overlays / text outlines use the foundational
|
||||
// `background` color directly.
|
||||
readonly property QtObject imagePicker: QtObject {
|
||||
// The picker has no separate card; `scrim` is the full-screen dim
|
||||
// wash, `background` is the palette color used for per-slice dim
|
||||
// overlays and text outlines on top of the scrim.
|
||||
property color background: root.composed("image-picker.background", "image-picker.background-alpha", root.background, 1.0)
|
||||
property color scrim: root.composed("image-picker.scrim", "image-picker.scrim-alpha", root.background, 0.5)
|
||||
property color text: root.pick("image-picker.text", root.foreground)
|
||||
property color selectedBorder: root.composed("image-picker.selected-border", "image-picker.selected-border-alpha", root.accent, 1.0)
|
||||
@@ -142,9 +125,8 @@ QtObject {
|
||||
if (match[1] === "foreground") foreground = match[2]
|
||||
else if (match[1] === "background") background = match[2]
|
||||
// Prefer the explicit `accent` key; only fall back to color4 when the
|
||||
// theme doesn't define a separate accent. Aether/oodle/etc define both,
|
||||
// and color4 appears later in the file so the old single-property
|
||||
// approach was clobbering accent with color4 (#8274fd purple).
|
||||
// theme doesn't define a separate accent. color4 appears later in the
|
||||
// file so the old single-property approach clobbered accent with it.
|
||||
else if (match[1] === "accent") { accent = match[2]; foundAccent = true }
|
||||
else if (match[1] === "color4") color4Value = match[2]
|
||||
else if (match[1] === "red" || match[1] === "color1") urgent = match[2]
|
||||
@@ -152,11 +134,10 @@ QtObject {
|
||||
if (!foundAccent && color4Value.length > 0) accent = color4Value
|
||||
}
|
||||
|
||||
// Walk shell.toml line-by-line. The file is small, so no proper TOML
|
||||
// parser. Accepts double- or single-quoted strings for colors and bare
|
||||
// numeric values (e.g. alpha companions like `selected-background-alpha
|
||||
// = 0.08`), and tolerates trailing inline comments. Numbers are kept as
|
||||
// strings here; pickAlpha() coerces and clamps when read.
|
||||
// Single TOML walker for shell.toml. Both Color (surface roles) and Style
|
||||
// (typography, spacing, bar, control states) consume the resulting dict.
|
||||
// Accepts quoted strings and bare numeric values; tolerates inline comments.
|
||||
// Numbers are kept as strings here — readers coerce when they pull a value.
|
||||
function loadShell(raw) {
|
||||
var parsed = {}
|
||||
var text = String(raw || "")
|
||||
@@ -170,12 +151,14 @@ QtObject {
|
||||
if (sectionMatch) { section = sectionMatch[1]; continue }
|
||||
var stringKv = line.match(/^([A-Za-z0-9_-]+)\s*=\s*["']([^"']+)["']\s*(#.*)?$/)
|
||||
var numKv = line.match(/^([A-Za-z0-9_-]+)\s*=\s*(-?\d+(?:\.\d+)?)\s*(#.*)?$/)
|
||||
var kv = stringKv || numKv
|
||||
var bareKv = line.match(/^([A-Za-z0-9_-]+)\s*=\s*([A-Za-z][A-Za-z0-9_-]*)\s*(#.*)?$/)
|
||||
var kv = stringKv || numKv || bareKv
|
||||
if (!kv || !section) continue
|
||||
parsed[section + "." + kv[1]] = kv[2]
|
||||
}
|
||||
}
|
||||
shellValues = parsed
|
||||
Style.applyShellValues(parsed)
|
||||
}
|
||||
|
||||
// Startup load only. Runtime theme switches push the payload explicitly
|
||||
|
||||
Reference in New Issue
Block a user