@@ -4,9 +4,9 @@ import Quickshell
44import Quickshell.Io
55
66// Shared structural style tokens for the shell. Color is the palette
7- // singleton; Style holds the *shape* and *focus-affordance* tokens that
8- // every panel surface and qs.Ui component should bind to so they stay
9- // in sync as the user toggles round/sharp corners or as themes change .
7+ // singleton; Style holds everything else themes can influence — corner
8+ // rounding, focus affordances, typography scale, and bar dimensions —
9+ // so panels and qs.Ui components have a single source of truth .
1010//
1111// `cornerRadius` mirrors Hyprland's `decoration:rounding`. Themes ship
1212// their own rounding via theme/hyprland.lua; the user toggle via
@@ -15,9 +15,11 @@ import Quickshell.Io
1515// up the change here by re-running `hyprctl getoption` whenever either
1616// of those input files changes.
1717//
18- // Single source of truth lives in Hyprland; the shell follows. That
19- // means a theme that ships `rounding = 10` gives us 10px panels by
20- // default, and the round/sharp user toggle still works on top of it.
18+ // Typography and bar size come from `theme/shell.toml`. `[font] base-size`
19+ // is the rem root; every `Style.font.<token>` derives from it via the
20+ // scale multipliers below unless the theme pins that specific token.
21+ // `[bar] size-horizontal` / `size-vertical` set the cross-axis dimension
22+ // for top/bottom and left/right bars respectively.
2123QtObject {
2224 id: root
2325
@@ -36,6 +38,69 @@ QtObject {
3638 readonly property color hotFill: Qt .rgba (Color .foreground .r , Color .foreground .g , Color .foreground .b , 0.08 )
3739 readonly property color selectedFill: Qt .rgba (Color .foreground .r , Color .foreground .g , Color .foreground .b , 0.18 )
3840
41+ // ---------------------------------------------------------- typography
42+ //
43+ // `fontFamily` defaults to "monospace" so the bar and every qs.Ui
44+ // component follows the fontconfig alias `omarchy-font-set` writes.
45+ // Themes can override per-token via [font] in shell.toml, but the
46+ // family stays system-wide.
47+ property string fontFamily: " monospace"
48+
49+ // The concrete family `monospace` resolves to right now, e.g.
50+ // "JetBrainsMono Nerd Font". Bind `font.family` to `fontFamily` (so the
51+ // alias path keeps working when the user runs `omarchy font set`), but
52+ // read `resolvedFontFamily` when you want to *display* what's drawing.
53+ property string resolvedFontFamily: " monospace"
54+
55+ // Clamped 11..13 by loadShell — bar height and row heights are fixed
56+ // until we ship matching spacing tokens, so unbounded growth clips.
57+ property int fontBaseSize: 12
58+
59+ // Parsed maps populated by loadShell. Keep them as plain dicts so
60+ // reassigning the whole property fires reactive bindings.
61+ property var fontOverrides: ({})
62+ property var barOverrides: ({})
63+
64+ function fontPx (mult ) {
65+ return Math .max (1 , Math .round (fontBaseSize * mult))
66+ }
67+
68+ function fontToken (key , fallback ) {
69+ var v = fontOverrides[key]
70+ var n = Number (v)
71+ return (isFinite (n) && n > 0 ) ? Math .round (n) : fallback
72+ }
73+
74+ function barToken (key , fallback ) {
75+ var v = barOverrides[key]
76+ var n = Number (v)
77+ return (isFinite (n) && n > 0 ) ? Math .round (n) : fallback
78+ }
79+
80+ readonly property QtObject font: QtObject {
81+ readonly property string family: root .fontFamily
82+ readonly property string resolvedFamily: root .resolvedFontFamily
83+ readonly property int baseSize: root .fontBaseSize
84+
85+ readonly property int caption: root .fontToken (" caption" , root .fontPx (0.833 )) // 10
86+ readonly property int bodySmall: root .fontToken (" body-small" , root .fontPx (0.917 )) // 11
87+ readonly property int body: root .fontToken (" body" , root .fontPx (1.0 )) // 12
88+ readonly property int subtitle: root .fontToken (" subtitle" , root .fontPx (1.083 )) // 13
89+ readonly property int title: root .fontToken (" title" , root .fontPx (1.167 )) // 14
90+ readonly property int heading: root .fontToken (" heading" , root .fontPx (1.333 )) // 16
91+ readonly property int display: root .fontToken (" display" , root .fontPx (2.0 )) // 24
92+ readonly property int displayLarge: root .fontToken (" display-large" , root .fontPx (2.333 )) // 28
93+
94+ readonly property int iconSmall: root .fontToken (" icon-small" , bodySmall)
95+ readonly property int icon: root .fontToken (" icon" , title)
96+ readonly property int iconLarge: root .fontToken (" icon-large" , root .fontPx (1.5 )) // 18
97+ }
98+
99+ readonly property QtObject bar: QtObject {
100+ readonly property int sizeHorizontal: root .barToken (" size-horizontal" , 26 )
101+ readonly property int sizeVertical: root .barToken (" size-vertical" , 28 )
102+ }
103+
39104 function refresh () {
40105 hyprctlProc .running = true
41106 }
@@ -50,6 +115,43 @@ QtObject {
50115 }
51116 }
52117
118+ // Parse [font] base-size + per-token overrides and [bar] size-* keys
119+ // out of shell.toml. Color.qml owns the quoted-string side of the same
120+ // file; we only care about the unquoted integer values here.
121+ function loadShell (raw ) {
122+ var fontOut = {}
123+ var barOut = {}
124+ var nextBase = 12
125+ var text = String (raw || " " )
126+ if (text) {
127+ var lines = text .split (" \n " )
128+ var section = " "
129+ for (var i = 0 ; i < lines .length ; i++ ) {
130+ var line = lines[i].replace (/ ^ \s + | \s + $ / g , " " )
131+ if (! line || line .charAt (0 ) === " #" ) continue
132+ var sectionMatch = line .match (/ ^ \[ ([A-Za-z0-9 _-] + )\] \s * (#. * )? $ / )
133+ if (sectionMatch) { section = sectionMatch[1 ]; continue }
134+ var kv = line .match (/ ^ ([A-Za-z0-9 _-] + )\s * =\s * (-? \d + )\s * (#. * )? $ / )
135+ if (! kv) continue
136+ var key = kv[1 ]
137+ var val = parseInt (kv[2 ], 10 )
138+ if (section === " font" ) {
139+ if (key === " base-size" ) nextBase = val
140+ else fontOut[key] = val
141+ } else if (section === " bar" && (key === " size-horizontal" || key === " size-vertical" )) {
142+ barOut[key] = val
143+ }
144+ }
145+ }
146+ // Clamp the rem root. Per-token overrides aren't clamped — a theme
147+ // that wants display-large = 64 should be allowed to ship it.
148+ if (nextBase < 11 ) nextBase = 11
149+ if (nextBase > 13 ) nextBase = 13
150+ fontBaseSize = nextBase
151+ fontOverrides = fontOut
152+ barOverrides = barOut
153+ }
154+
53155 property Process hyprctlProc: Process {
54156 id: hyprctlProc
55157 command: [" hyprctl" , " -j" , " getoption" , " decoration:rounding" ]
@@ -59,6 +161,34 @@ QtObject {
59161 }
60162 }
61163
164+ // Resolve the fontconfig alias to a concrete family name. `omarchy font
165+ // set <name>` rewrites ~/.config/fontconfig/fonts.conf and restarts the
166+ // shell, but rerun on file change anyway so manual edits propagate too.
167+ function resolveFontFamily () {
168+ fcMatchProc .running = true
169+ }
170+
171+ property Process fcMatchProc: Process {
172+ id: fcMatchProc
173+ command: [" fc-match" , " -f" , " %{family[0]}" , " monospace" ]
174+ stdout: StdioCollector {
175+ waitForEnd: true
176+ onStreamFinished: {
177+ var name = String (text || " " ).trim ()
178+ if (name .length > 0 ) root .resolvedFontFamily = name
179+ }
180+ }
181+ }
182+
183+ property FileView fontconfigFile: FileView {
184+ path: Quickshell .env (" HOME" ) + " /.config/fontconfig/fonts.conf"
185+ watchChanges: true
186+ printErrors: false
187+ onFileChanged: root .resolveFontFamily ()
188+ onLoaded: root .resolveFontFamily ()
189+ onLoadFailed: root .resolveFontFamily ()
190+ }
191+
62192 // Re-poll Hyprland a beat after either input file changes. Hyprland's
63193 // auto-reload runs asynchronously when its sourced .lua files change,
64194 // so racing it with an immediate hyprctl gives the old value. 200ms is
@@ -71,12 +201,18 @@ QtObject {
71201 }
72202
73203 // The theme name flips whenever `omarchy-theme-set` swaps the theme/
74- // symlink; that's when theme/hyprland.lua's `rounding` value changes.
204+ // symlink; that's when theme/hyprland.lua's `rounding` value changes
205+ // and the new theme/shell.toml drops into place. Force a reload of
206+ // shell.toml here so we don't wait on the inotify watch — Color.qml
207+ // uses the same tripwire for the same reason.
75208 property FileView themeNameFile: FileView {
76209 path: Quickshell .env (" HOME" ) + " /.config/omarchy/current/theme.name"
77210 watchChanges: true
78211 printErrors: false
79- onFileChanged: refreshTimer .restart ()
212+ onFileChanged: {
213+ refreshTimer .restart ()
214+ shellTomlFile .reload ()
215+ }
80216 }
81217
82218 // `omarchy style corners <round|sharp>` creates or removes this flag file.
@@ -91,5 +227,18 @@ QtObject {
91227 onLoadFailed: refreshTimer .restart ()
92228 }
93229
94- Component .onCompleted : refresh ()
230+ property FileView shellTomlFile: FileView {
231+ id: shellTomlFile
232+ path: Quickshell .env (" HOME" ) + " /.config/omarchy/current/theme/shell.toml"
233+ watchChanges: true
234+ printErrors: false
235+ onLoaded: root .loadShell (text ())
236+ onLoadFailed: root .loadShell (" " )
237+ onFileChanged: reload ()
238+ }
239+
240+ Component .onCompleted : {
241+ refresh ()
242+ resolveFontFamily ()
243+ }
95244}
0 commit comments