Files
Panama/config/dot/quickshell/services/Fonts.qml
Gabriel Brown d1b2cd2083 Make typography choosable instead of hardcoded
Theme.qml was the largest remaining thing in this desktop that could
only be changed by editing a file, and typeface is the first thing
someone changes when they want a desktop to feel like theirs. Interface
font, icon font, and the base text size are settings now.

The two font choices are deliberately separate lists. Theme.fontMono is
used only to draw glyphs -- workspace pills, the status cluster, search
icons -- so a plain monospace family there replaces every icon in the
shell with tofu. The picker offers only Nerd Fonts for that slot and
says why.

Candidates are rendered in the family they name. A list of font names
set in the current font tells you nothing about what you are choosing.

The four type sizes derive from the base rather than being stored
separately, so the relationship between body, caption, heading and title
survives a change instead of four numbers drifting apart.

hypr/looks.lua reads the same key. Following the preference only on the
QML side would leave the compositor and the shell disagreeing about the
interface font, which nobody notices until a tooltip renders in a
different typeface.

Only a family this machine reports is accepted: the value reaches
hl.config as a string, and a settings file moved between machines will
name fonts that are not installed. A missing family is reported rather
than silently substituted by fontconfig.

Also collapses the wallpaper grid to two rows. Sixty tiles is two
screens of pictures on a page that also holds typography, window
geometry and effects -- everything below it was unreachable without
scrolling past all of them.

Claude-Session: https://claude.ai/code/session_01BRvzt4H8XXLPVH5MyYdk9L
2026-08-18 07:06:53 -04:00

103 lines
3.5 KiB
QML

pragma Singleton
// Installed fonts, split by what they can actually be used for.
//
// Two different questions with different answers: which families are readable
// as interface text, and which carry the Nerd Font glyphs the shell draws its
// icons with. Offering one list for both is how you end up with a desktop full
// of tofu, so they stay separate.
//
// Enumerated once on demand. Fonts do not appear while you are looking at a
// settings page, and fc-list over a few hundred families is not free.
import Quickshell
import Quickshell.Io
import QtQuick
import qs.config
Singleton {
id: root
readonly property string helperPath: Quickshell.shellDir + "/scripts/panama-fonts"
property var interfaceFonts: []
property var monospaceFonts: []
property var iconFonts: []
property bool scanning: false
property string lastError: ""
readonly property string interfaceFont: DesktopPreferences.get("interfaceFont")
readonly property string iconFont: DesktopPreferences.get("iconFont")
readonly property bool loaded: root.interfaceFonts.length > 0
// True when the stored family is not installed. fontconfig silently
// substitutes something else, so the shell keeps working and quietly stops
// looking the way it was configured to -- worth saying out loud.
readonly property bool interfaceMissing: root.loaded
&& root.interfaceFonts.indexOf(root.interfaceFont) < 0
readonly property bool iconMissing: root.iconFonts.length > 0
&& root.iconFonts.indexOf(root.iconFont) < 0
Process {
id: scan
command: [root.helperPath]
stdout: StdioCollector {
onStreamFinished: {
try {
const parsed = JSON.parse(this.text);
root.interfaceFonts = parsed.interface ?? [];
root.monospaceFonts = parsed.monospace ?? [];
root.iconFonts = parsed.icons ?? [];
root.lastError = "";
} catch (error) {
root.lastError = "The installed fonts could not be read.";
}
root.scanning = false;
}
}
onExited: (exitCode, exitStatus) => {
root.scanning = false;
if (exitCode !== 0)
root.lastError = "The installed fonts could not be read.";
}
}
Component.onCompleted: root.refresh()
function refresh(): void {
if (scan.running)
return;
root.scanning = true;
scan.running = true;
}
// Only a family this machine reported is accepted, so a hand-edited
// settings file cannot put arbitrary text where a font name belongs -- it
// reaches hl.config as a string on the compositor side.
function setInterface(family: string): bool {
if (root.interfaceFonts.indexOf(family) < 0) {
root.lastError = "That font is not installed.";
return false;
}
return root.store("interfaceFont", family);
}
function setIcon(family: string): bool {
if (root.iconFonts.indexOf(family) < 0) {
root.lastError = "That font does not carry icon glyphs.";
return false;
}
return root.store("iconFont", family);
}
function store(key: string, family: string): bool {
if (!DesktopPreferences.set(key, family)) {
root.lastError = "That font name could not be saved.";
return false;
}
root.lastError = "";
return true;
}
}