Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions shell/plugins/bar/Bar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import qs.Commons
import qs.Commons as Commons
import qs.Ui
import "BarModel.js" as BarModel
import "FontFamily.js" as FontFamily

Item {
id: root
Expand Down Expand Up @@ -66,10 +67,13 @@ Item {
property bool centerHoverRevealSuppressed: false
property int barConfigSerial: 0
property string position: "top"
// Resolves through fontconfig at paint time (Style.font.family defaults
// to "monospace"), so changing the system font (via `omarchy-font-set`)
// updates the bar without a reload.
property string fontFamily: Style.font.family
// Prefer an installed Propo sibling for UI glyphs. Keep the fontconfig
// alias when no sibling exists, and leave the shared shell font unchanged.
property string fontFamily: {
var selected = Style.font.family === "monospace" ? Style.font.resolvedFamily : Style.font.family
var preferred = FontFamily.preferPropo(selected, Qt.fontFamilies())
return preferred !== selected ? preferred : Style.font.family
}
// Bound to the central Color singleton so the bar tracks shell.toml's
// [bar] section. Property names kept for the rest of this file's bindings.
property color themeForeground: Commons.Color.bar.text
Expand Down
17 changes: 17 additions & 0 deletions shell/plugins/bar/FontFamily.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.pragma library

// Nerd Fonts publishes full family names and, for some fonts, short aliases.
// Only substitute known suffixes; never guess a different underlying typeface.
function preferPropo(family, availableFamilies) {
var candidate = family.replace(/ Nerd Font(?: Mono)?$/i, " Nerd Font Propo");
if (candidate === family)
candidate = family.replace(/ (?:NF|NFM)$/i, " NFP");
if (candidate === family)
return family;

for (var i = 0; i < availableFamilies.length; ++i) {
if (availableFamilies[i].toLowerCase() === candidate.toLowerCase())
return availableFamilies[i];
}
return family;
}
49 changes: 49 additions & 0 deletions test/shell.d/bar-font-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
source "$(dirname "$0")/base-test.sh"

run_node_test <<'JS'
const fs = require('fs')
const vm = require('vm')
const source = fs.readFileSync(path.join(root, 'shell/plugins/bar/FontFamily.js'), 'utf8').replace(/^\.pragma library\n/, '')
const fonts = {}
vm.createContext(fonts)
vm.runInContext(source, fonts)

const cases = [
['normal', 'JetBrainsMono Nerd Font', ['JetBrainsMono Nerd Font Propo'], 'JetBrainsMono Nerd Font Propo'],
['mono', 'JetBrainsMono Nerd Font Mono', ['JetBrainsMono Nerd Font Propo'], 'JetBrainsMono Nerd Font Propo'],
['already Propo', 'JetBrainsMono Nerd Font Propo', [], 'JetBrainsMono Nerd Font Propo'],
['absent sibling', 'JetBrainsMono Nerd Font', ['Other Nerd Font Propo'], 'JetBrainsMono Nerd Font'],
['plain font', 'DejaVu Sans Mono', ['DejaVu Sans Propo'], 'DejaVu Sans Mono'],
['short NF', 'CaskaydiaMono NF', ['CaskaydiaMono NFP'], 'CaskaydiaMono NFP'],
['short NFM', 'CaskaydiaMono NFM', ['CaskaydiaMono NFP'], 'CaskaydiaMono NFP'],
['short NFP', 'CaskaydiaMono NFP', [], 'CaskaydiaMono NFP'],
['case insensitive', 'jetbrainsmono nerd font', ['JetBrainsMono Nerd Font Propo'], 'JetBrainsMono Nerd Font Propo'],
['no substring match', 'Test Nerd Font', ['Test Nerd Font Propo ExtraLight'], 'Test Nerd Font'],
['custom family', 'Ransom Mono NF Propo Unruly', [], 'Ransom Mono NF Propo Unruly'],
['empty family', '', [], '']
]
for (const [description, family, available, expected] of cases)
assertEqual(fonts.preferPropo(family, available), expected, `bar font: ${description}`)

// Exercise the actual binding body with a changing Style source, not a copy
// of the fallback policy. This guards retaining the alias and explicit fonts.
const bar = fs.readFileSync(path.join(root, 'shell/plugins/bar/Bar.qml'), 'utf8')
const binding = bar.match(/property string fontFamily: \{([\s\S]*?)\n \}/)
assert(Boolean(binding), 'bar has a computed font binding')
const context = {
FontFamily: fonts,
Qt: { fontFamilies: () => ['CaskaydiaMono Nerd Font Propo'] },
Style: { font: { family: 'monospace', resolvedFamily: 'CaskaydiaMono Nerd Font Mono' } }
}
vm.createContext(context)
const evaluate = () => vm.runInContext(`(function () {${binding[1]}\n})()`, context)
assertEqual(evaluate(), 'CaskaydiaMono Nerd Font Propo', 'bar uses installed Propo sibling')
context.Style.font.resolvedFamily = 'DejaVu Sans Mono'
assertEqual(evaluate(), 'monospace', 'bar keeps live alias when sibling is absent')
context.Style.font.family = 'Custom UI Font'
assertEqual(evaluate(), 'Custom UI Font', 'bar respects explicit shared family')
context.Style.font.family = 'monospace'
context.Style.font.resolvedFamily = 'CaskaydiaMono Nerd Font'
assertEqual(evaluate(), 'CaskaydiaMono Nerd Font Propo', 'bar follows another resolved family change')
JS
Binary file added test/shell.d/fixtures/bar-font-comparison.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.