Promote shell to its own top-level directory
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
pragma Singleton
|
||||
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.notifications.*,
|
||||
// Color.menu.*, Color.imagePicker.*) 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.
|
||||
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.
|
||||
// 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: ({})
|
||||
|
||||
function pick(key, fallback) {
|
||||
var v = shellValues[key]
|
||||
return (typeof v === "string" && v.length > 0) ? v : fallback
|
||||
}
|
||||
|
||||
// Surface roles. Each property reads its shell.toml override if set,
|
||||
// otherwise falls back to a foundational palette token.
|
||||
readonly property QtObject bar: QtObject {
|
||||
property color background: root.pick("bar.background", root.background)
|
||||
property color text: root.pick("bar.text", root.foreground)
|
||||
property color active: root.pick("bar.active", root.urgent)
|
||||
}
|
||||
readonly property QtObject popups: QtObject {
|
||||
property color background: root.pick("popups.background", root.background)
|
||||
property color border: root.pick("popups.border", root.foreground)
|
||||
}
|
||||
readonly property QtObject notifications: QtObject {
|
||||
property color background: root.pick("notifications.background", root.background)
|
||||
property color text: root.pick("notifications.text", root.foreground)
|
||||
property color border: root.pick("notifications.border", root.accent)
|
||||
property color countdown: root.pick("notifications.countdown", root.accent)
|
||||
}
|
||||
readonly property QtObject menu: QtObject {
|
||||
property color background: root.pick("menu.background", root.background)
|
||||
property color text: root.pick("menu.text", root.foreground)
|
||||
property color selected: root.pick("menu.selected", root.accent)
|
||||
}
|
||||
readonly property QtObject imagePicker: QtObject {
|
||||
property color background: root.pick("image-picker.background", root.background)
|
||||
property color text: root.pick("image-picker.text", root.foreground)
|
||||
property color selectedBorder: root.pick("image-picker.selected-border", root.accent)
|
||||
property color unselectedBorder: root.pick("image-picker.unselected-border", root.foreground)
|
||||
}
|
||||
|
||||
function alpha(c, opacity) {
|
||||
if (!c) return Qt.rgba(0, 0, 0, opacity)
|
||||
return Qt.rgba(c.r, c.g, c.b, opacity)
|
||||
}
|
||||
|
||||
function loadColors(raw) {
|
||||
var lines = String(raw || "").split("\n")
|
||||
var foundAccent = false
|
||||
var color4Value = ""
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var match = lines[i].match(/^\s*([A-Za-z0-9_-]+)\s*=\s*["']?(#[0-9A-Fa-f]{6})/)
|
||||
if (!match) continue
|
||||
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).
|
||||
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]
|
||||
}
|
||||
if (!foundAccent && color4Value.length > 0) accent = color4Value
|
||||
}
|
||||
|
||||
// Walk shell.toml line-by-line. We only need string values for color keys,
|
||||
// and the file is small, so no proper TOML parser. Accepts double- or
|
||||
// single-quoted values and tolerates trailing inline comments.
|
||||
function loadShell(raw) {
|
||||
var parsed = {}
|
||||
var text = String(raw || "")
|
||||
if (text) {
|
||||
var lines = text.split("\n")
|
||||
var section = ""
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var line = lines[i].replace(/^\s+|\s+$/g, "")
|
||||
if (!line || line.charAt(0) === "#") continue
|
||||
var sectionMatch = line.match(/^\[([A-Za-z0-9_-]+)\]\s*(#.*)?$/)
|
||||
if (sectionMatch) { section = sectionMatch[1]; continue }
|
||||
var kv = line.match(/^([A-Za-z0-9_-]+)\s*=\s*["']([^"']+)["']\s*(#.*)?$/)
|
||||
if (!kv || !section) continue
|
||||
parsed[section + "." + kv[1]] = kv[2]
|
||||
}
|
||||
}
|
||||
shellValues = parsed
|
||||
}
|
||||
|
||||
property bool themeReloadSuspended: false
|
||||
|
||||
function suspendThemeReloads() {
|
||||
themeReloadSuspended = true
|
||||
}
|
||||
|
||||
function resumeThemeReloads() {
|
||||
themeReloadSuspended = false
|
||||
}
|
||||
|
||||
function reloadTheme() {
|
||||
if (themeReloadSuspended) return
|
||||
colorsFile.reload()
|
||||
shellFile.reload()
|
||||
}
|
||||
|
||||
// `omarchy-theme-set` recreates the theme/ directory via rm+mv, which kills
|
||||
// the inotify watch on colors.toml. Use theme.name (overwritten in place) as
|
||||
// a tripwire that forces a fresh reload after each swap.
|
||||
property FileView colorsFile: FileView {
|
||||
id: colorsFile
|
||||
path: Quickshell.env("HOME") + "/.config/omarchy/current/theme/colors.toml"
|
||||
watchChanges: true
|
||||
printErrors: false
|
||||
onLoaded: root.loadColors(text())
|
||||
onFileChanged: root.reloadTheme()
|
||||
}
|
||||
property FileView shellFile: FileView {
|
||||
id: shellFile
|
||||
path: Quickshell.env("HOME") + "/.config/omarchy/current/theme/shell.toml"
|
||||
watchChanges: true
|
||||
printErrors: false
|
||||
onLoaded: root.loadShell(text())
|
||||
onLoadFailed: root.loadShell("")
|
||||
onFileChanged: root.reloadTheme()
|
||||
}
|
||||
property FileView themeNameFile: FileView {
|
||||
path: Quickshell.env("HOME") + "/.config/omarchy/current/theme.name"
|
||||
watchChanges: true
|
||||
printErrors: false
|
||||
onFileChanged: root.reloadTheme()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
pragma Singleton
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
// Shared structural style tokens for the shell. Color is the palette
|
||||
// singleton; Style holds the *shape* and *focus-affordance* tokens that
|
||||
// every panel surface and qs.Ui component should bind to so they stay
|
||||
// in sync as the user toggles round/sharp corners or as themes change.
|
||||
//
|
||||
// `cornerRadius` mirrors Hyprland's `decoration:rounding`. Themes ship
|
||||
// their own rounding via theme/hyprland.lua; the user toggle via
|
||||
// `omarchy style corners <round|sharp>` flips Hyprland's flag file
|
||||
// and Hyprland's auto-reload pushes the new value out. The shell picks
|
||||
// up the change here by re-running `hyprctl getoption` whenever either
|
||||
// of those input files changes.
|
||||
//
|
||||
// Single source of truth lives in Hyprland; the shell follows. That
|
||||
// means a theme that ships `rounding = 10` gives us 10px panels by
|
||||
// default, and the round/sharp user toggle still works on top of it.
|
||||
QtObject {
|
||||
id: root
|
||||
|
||||
property int cornerRadius: 0
|
||||
|
||||
// Focus affordances. Deliberately distinct from "selected" (which uses an
|
||||
// accent fill) so the keyboard cursor never reads as the chosen value.
|
||||
// The settings panel originated these tokens; promoting them here means
|
||||
// every Ui component picks them up uniformly.
|
||||
readonly property color focusBorderColor: Color.accent
|
||||
readonly property color focusFillColor: Qt.rgba(Color.accent.r, Color.accent.g, Color.accent.b, 0.22)
|
||||
readonly property int focusBorderWidth: 3
|
||||
|
||||
// Convenience: the standard "hot" (hover or keyboard cursor) tint used by
|
||||
// PillButton, PanelActionButton, etc. Foreground at 0.12 alpha matches the
|
||||
// value PillButton was already painting before promotion.
|
||||
readonly property color hotFill: Qt.rgba(Color.foreground.r, Color.foreground.g, Color.foreground.b, 0.12)
|
||||
|
||||
function refresh() {
|
||||
hyprctlProc.running = true
|
||||
}
|
||||
|
||||
function applyRoundingJson(raw) {
|
||||
try {
|
||||
var json = JSON.parse(raw || "{}")
|
||||
var n = Number(json.int)
|
||||
if (isFinite(n) && n >= 0) cornerRadius = n
|
||||
} catch (e) {
|
||||
// hyprctl missing / Hyprland not running — leave the previous value.
|
||||
}
|
||||
}
|
||||
|
||||
property Process hyprctlProc: Process {
|
||||
id: hyprctlProc
|
||||
command: ["hyprctl", "-j", "getoption", "decoration:rounding"]
|
||||
stdout: StdioCollector {
|
||||
waitForEnd: true
|
||||
onStreamFinished: root.applyRoundingJson(text)
|
||||
}
|
||||
}
|
||||
|
||||
// Re-poll Hyprland a beat after either input file changes. Hyprland's
|
||||
// auto-reload runs asynchronously when its sourced .lua files change,
|
||||
// so racing it with an immediate hyprctl gives the old value. 200ms is
|
||||
// generous enough for Hyprland to settle without being user-visible.
|
||||
property Timer refreshTimer: Timer {
|
||||
id: refreshTimer
|
||||
interval: 200
|
||||
repeat: false
|
||||
onTriggered: root.refresh()
|
||||
}
|
||||
|
||||
// The theme name flips whenever `omarchy-theme-set` swaps the theme/
|
||||
// symlink; that's when theme/hyprland.lua's `rounding` value changes.
|
||||
property FileView themeNameFile: FileView {
|
||||
path: Quickshell.env("HOME") + "/.config/omarchy/current/theme.name"
|
||||
watchChanges: true
|
||||
printErrors: false
|
||||
onFileChanged: refreshTimer.restart()
|
||||
}
|
||||
|
||||
// `omarchy style corners <round|sharp>` creates or removes this flag file.
|
||||
// Hyprland reloads its config when sourced files change, then hyprctl
|
||||
// reflects the new effective rounding value.
|
||||
property FileView roundedCornersToggle: FileView {
|
||||
path: Quickshell.env("HOME") + "/.local/state/omarchy/toggles/hypr/rounded-corners.lua"
|
||||
watchChanges: true
|
||||
printErrors: false
|
||||
onFileChanged: refreshTimer.restart()
|
||||
onLoaded: refreshTimer.restart()
|
||||
onLoadFailed: refreshTimer.restart()
|
||||
}
|
||||
|
||||
Component.onCompleted: refresh()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module qs.Commons
|
||||
singleton Color 1.0 Color.qml
|
||||
singleton Style 1.0 Style.qml
|
||||
Reference in New Issue
Block a user