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
32 changes: 14 additions & 18 deletions bin/omarchy-display-text-size
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
# • the omarchy shell's font base-size (~/.config/omarchy/shell.toml [font])
# • GNOME/GTK's text-scaling-factor (12px -> 1.0, quantized so the GTK
# interface font lands on a whole point size, so 16 -> 15pt/11pt = 1.3636)
# • the terminal font point size (12px -> 9pt, so terminal_pt = px * 9/12)
# • terminal font point sizes except Ghostty, which already follows GTK's
# text-scaling-factor (12px -> 9pt for the other terminals)
# The shell override layers on top of the active theme (so the size survives
# theme switches) and the shell watches the file, so shell text re-flows live.
# Accepts an integer from 9 to 20 (px).
Expand All @@ -29,7 +30,7 @@ usage() {
echo "Usage: omarchy-display-text-size [size|reset]"
echo " (no args) print the current text size, GTK factor, and terminal size"
echo " <size> set text size in px ($MIN–$MAX); shell + GTK + terminals together"
echo " reset return all three to their defaults (12px / 1.0 / 9pt)"
echo " reset return shell, GTK, and other terminals to defaults; keep Ghostty's base font"
}

# ---- shell base-size: the rem root every shell type size derives from ----
Expand Down Expand Up @@ -122,7 +123,7 @@ gtk_font_pt() {
}

set_factor() {
gsettings set "$GKEY_SCHEMA" "$GKEY_NAME" "$1" 2>/dev/null || true
gsettings set "$GKEY_SCHEMA" "$GKEY_NAME" "$1"
}

# ---- terminal font point size ----
Expand All @@ -133,8 +134,9 @@ term_pt_for() {
'BEGIN { printf "%d", int(s * p / b + 0.5) }'
}

# Set the font point size in terminal configs, creating Kitty overrides when
# it inherits its size from the system config. Family is left
# Set the font point size in terminal configs other than Ghostty, which applies
# GTK's text-scaling-factor to its existing base font size. Create Kitty
# overrides when it inherits its size from the system config. Family is left
# untouched — that is omarchy-font-set's job. Live-reload signals mirror
# omarchy-font-set; foot has no reload signal, so running instances are nudged.
set_terminal_size() {
Expand All @@ -154,11 +156,6 @@ set_terminal_size() {
pkill -USR1 kitty 2>/dev/null || true
fi

if [[ -f ~/.config/ghostty/config ]]; then
sed --follow-symlinks -i -E "s/^font-size = .*/font-size = $pt/" ~/.config/ghostty/config
pkill -SIGUSR2 ghostty 2>/dev/null || true
fi

if [[ -f ~/.config/foot/foot.ini ]]; then
sed --follow-symlinks -i -E "s/(:size=)[0-9.]+/\1$pt/" ~/.config/foot/foot.ini
# Foot has no config-reload signal, so a running instance keeps its startup
Expand All @@ -181,10 +178,9 @@ set_terminal_size() {
}

# Report the current terminal point size from whichever config we find first.
# Ghostty is skipped: its font-size is a base the GTK factor scales, not the size set here.
term_current_pt() {
if [[ -f ~/.config/ghostty/config ]]; then
grep -oP '^font-size = \K[0-9.]+' ~/.config/ghostty/config | head -1
elif [[ -f ~/.config/alacritty/alacritty.toml ]]; then
if [[ -f ~/.config/alacritty/alacritty.toml ]]; then
grep -oP '^size[[:space:]]*=[[:space:]]*\K[0-9.]+' ~/.config/alacritty/alacritty.toml | head -1
elif [[ -f ~/.config/kitty/kitty.conf ]]; then
local pt
Expand Down Expand Up @@ -212,8 +208,8 @@ case "${1:-}" in
exit 0
;;
reset | default)
gsettings reset "$GKEY_SCHEMA" "$GKEY_NAME" || exit 1
reset_base_size
gsettings reset "$GKEY_SCHEMA" "$GKEY_NAME" 2>/dev/null || true
set_terminal_size "$TERM_DEFAULT_PT"
exit 0
;;
Expand All @@ -226,15 +222,15 @@ if [[ ! $size =~ ^[0-9]+$ ]] || ((size < MIN || size > MAX)); then
exit 1
fi

# Shell side: base-size in px (the omarchy shell's rem root).
set_base_size "$size"

# GTK side: multiplier anchored so 12px == 1.0, quantized so the interface
# font renders at a whole point size. Raw ratios yield fractional point sizes,
# which GTK4 menus clip at the ascenders on scale-1 monitors.
factor="$(awk -v s="$size" -v b="$SHELL_DEFAULT_PX" -v f="$(gtk_font_pt)" \
'BEGIN { printf "%.4f", int(f * s / b + 0.5) / f }')"
set_factor "$factor"
set_factor "$factor" || exit 1
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved

# Shell side: base-size in px (the omarchy shell's rem root).
set_base_size "$size"

# Terminal side: point size anchored so 12px == 9pt.
set_terminal_size "$(term_pt_for "$size")"
133 changes: 131 additions & 2 deletions test/shell.d/desktop-helpers-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ grep -Fxq 'base-size = 16' "$tmp/dots/shell.toml" ||
fail "omarchy-display-text-size writes through symlinked shell.toml" "$(<"$tmp/dots/shell.toml")"
grep -Fxq 'size = 12' "$tmp/dots/alacritty.toml" ||
fail "omarchy-display-text-size writes through symlinked alacritty.toml" "$(<"$tmp/dots/alacritty.toml")"
grep -Fxq 'font-size = 12' "$tmp/dots/ghostty.conf" ||
fail "omarchy-display-text-size writes through symlinked ghostty config" "$(<"$tmp/dots/ghostty.conf")"
grep -Fxq 'font-size = 9' "$tmp/dots/ghostty.conf" ||
fail "omarchy-display-text-size preserves the base size in a symlinked Ghostty config" "$(<"$tmp/dots/ghostty.conf")"
grep -Fxq 'font=B&H <Mono> "Pro" / 1'\''s:size=12' "$tmp/dots/foot.ini" ||
fail "omarchy-display-text-size writes through symlinked foot.ini" "$(<"$tmp/dots/foot.ini")"
HOME="$tmp/home" XDG_RUNTIME_DIR="$tmp" PATH="$tmp/bin:$ROOT/bin:$PATH" "$ROOT/bin/omarchy-display-text-size" reset >/dev/null
Expand All @@ -68,6 +68,135 @@ HOME="$tmp/home" XDG_RUNTIME_DIR="$tmp" PATH="$tmp/bin:$ROOT/bin:$PATH" "$ROOT/b
fail "omarchy-display-text-size reset clears base-size in symlinked shell.toml" "$(<"$tmp/dots/shell.toml")"
pass "omarchy-display-text-size preserves symlinked shell and terminal configs"

# Isolate the Ghostty fixtures from the other desktop helper checks.
(
test_dir=$(mktemp -d)
trap 'rm -rf "$test_dir"' EXIT
test_home="$test_dir/home"
ghostty_config="$test_home/.config/ghostty/config"
alacritty_config="$test_home/.config/alacritty/alacritty.toml"
shell_config="$test_home/.config/omarchy/shell.toml"
mkdir -p "$test_dir/bin"

# Ghostty applies GTK's text-scaling-factor to its own font-size, so the command
# must change the factor and leave Ghostty's config alone.
cat >"$test_dir/bin/gsettings" <<'SH'
#!/bin/bash
if [[ $1 == "get" && $3 == "font-name" ]]; then
echo "'Cantarell 11'"
elif [[ $1 == "get" ]]; then
cat "$FACTOR_FILE" 2>/dev/null || echo 1.0
elif [[ ${FAIL_GSETTINGS:-} == "1" ]]; then
exit 55
elif [[ $1 == "set" ]]; then
printf '%s\n' "$4" >"$FACTOR_FILE"
else
rm -f "$FACTOR_FILE"
fi
SH
printf '#!/bin/bash\nprintf "%%s\\n" "$*" >>"$SIGNAL_LOG"\n' >"$test_dir/bin/pkill"
printf '#!/bin/bash\nexit 1\n' >"$test_dir/bin/omarchy-cmd-present"
cat >"$test_dir/bin/pgrep" <<'SH'
#!/bin/bash
[[ ${FOOT_RUNNING:-0} == "1" && $1 == "-x" && $2 == "foot" ]]
SH
cat >"$test_dir/bin/omarchy-i18n" <<'SH'
#!/bin/bash
[[ $1 == "display.restartFootForFontSize" ]] || exit 64
printf '%s\n' "$1" >>"$I18N_LOG"
printf '%s\n' "Localized Foot restart notice"
SH
cat >"$test_dir/bin/omarchy-notification-send" <<'SH'
#!/bin/bash
{
printf '%s\n' "call"
printf 'arg=%s\n' "$@"
} >>"$NOTIFICATION_LOG"
printf '%s\n' 417
SH
chmod +x "$test_dir/bin/"*

run_command() {
env HOME="$test_home" OMARCHY_PATH="$ROOT" PATH="$test_dir/bin:$ROOT/bin:$PATH" \
FACTOR_FILE="$test_dir/factor" SIGNAL_LOG="$test_dir/signals" \
I18N_LOG="$test_dir/i18n" NOTIFICATION_LOG="$test_dir/notifications" \
XDG_RUNTIME_DIR="$test_dir/runtime" FOOT_RUNNING="${FOOT_RUNNING:-0}" \
"$ROOT/bin/omarchy-display-text-size" "$@"
}

reset_fixture() {
rm -rf "$test_home" "$test_dir/factor" "$test_dir/signals" "$test_dir/dotfiles-ghostty" \
"$test_dir/runtime" "$test_dir/i18n" "$test_dir/notifications"
mkdir -p "$test_dir/runtime" "$(dirname "$ghostty_config")" "$(dirname "$alacritty_config")"
printf 'size = 9\n' >"$alacritty_config"
}

for base in 9 13 15; do
reset_fixture
printf 'font-family = "JetBrainsMono Nerd Font"\nfont-size = %s\n' "$base" >"$ghostty_config"
cp "$ghostty_config" "$test_dir/ghostty-before"

run_command 20 || fail "size 20 succeeds with Ghostty at ${base}pt"
[[ $(<"$test_dir/factor") == "1.6364" ]] || fail "size 20 sets the GTK factor"
grep -qx 'size = 15' "$alacritty_config" || fail "size 20 sizes the other terminals"
grep -qx 'base-size = 20' "$shell_config" || fail "size 20 sets the shell base size"
cmp -s "$test_dir/ghostty-before" "$ghostty_config" || fail "size 20 leaves Ghostty's ${base}pt base font alone"
[[ $(run_command) == *"terminal font: 15 pt"* ]] || fail "size report names the size the command set"

run_command reset || fail "reset succeeds with Ghostty at ${base}pt"
[[ ! -e $test_dir/factor ]] || fail "reset restores the GTK factor"
grep -qx 'size = 9' "$alacritty_config" || fail "reset restores the other terminals"
! grep -q 'base-size' "$shell_config" || fail "reset restores the shell base size"
cmp -s "$test_dir/ghostty-before" "$ghostty_config" || fail "reset leaves Ghostty's ${base}pt base font alone"
! grep -q ghostty "$test_dir/signals" 2>/dev/null || fail "Ghostty is never signalled to reload"
done
pass "size and reset scale Ghostty through GTK and leave its base font alone"

reset_fixture
printf 'font-size = 12\n' >"$test_dir/dotfiles-ghostty"
ln -s "$test_dir/dotfiles-ghostty" "$ghostty_config"
run_command 20
run_command reset
[[ -L $ghostty_config ]] || fail "a dotfile symlink survives"
grep -qx 'font-size = 12' "$test_dir/dotfiles-ghostty" || fail "the symlink target is untouched"
pass "a symlinked Ghostty config is left alone"

reset_fixture
run_command 20 || fail "size succeeds without a Ghostty config"
run_command reset || fail "reset succeeds without a Ghostty config"
[[ ! -e $ghostty_config ]] || fail "an absent Ghostty config stays absent"
pass "an absent Ghostty config is not created"

reset_fixture
printf 'font-size = 13\n' >"$ghostty_config"
for args in 20 reset; do
if FAIL_GSETTINGS=1 run_command "$args" 2>/dev/null; then
fail "$args fails when GSettings refuses the write"
fi
grep -qx 'size = 9' "$alacritty_config" || fail "$args changes no terminal when GSettings fails"
[[ ! -e $shell_config ]] || fail "$args changes no shell size when GSettings fails"
grep -qx 'font-size = 13' "$ghostty_config" || fail "$args leaves Ghostty alone when GSettings fails"
done
pass "a refused GSettings write changes nothing else"

reset_fixture
mkdir -p "$test_home/.config/foot"
printf 'font=monospace:size=9\n' >"$test_home/.config/foot/foot.ini"
FOOT_RUNNING=1 run_command 20 || fail "size succeeds with Foot running"
grep -qx 'font=monospace:size=15' "$test_home/.config/foot/foot.ini" || fail "size updates Foot's config"
grep -qx 'display.restartFootForFontSize' "$test_dir/i18n" || fail "the Foot notice uses its localization key"
grep -qx 'arg=Localized Foot restart notice' "$test_dir/notifications" || fail "the translated Foot notice is sent"
[[ $(<"$test_dir/runtime/omarchy-display-text-size.foot-notif-id") == "417" ]] || fail "the Foot notification id is retained"

FOOT_RUNNING=1 run_command reset || fail "reset succeeds with Foot running"
grep -qx 'font=monospace:size=9' "$test_home/.config/foot/foot.ini" || fail "reset restores Foot's config"
[[ $(grep -c '^call$' "$test_dir/notifications") == "2" ]] || fail "size and reset each notify running Foot"
[[ $(grep -c '^display.restartFootForFontSize$' "$test_dir/i18n") == "2" ]] || fail "both Foot notices use localization"
grep -qx 'arg=-r' "$test_dir/notifications" || fail "the Foot notice replaces the previous notification"
grep -qx 'arg=417' "$test_dir/notifications" || fail "the previous Foot notification id is reused"
pass "Foot sizing and reset retain localized replacement notices"
)

# Clipboard helpers fail cleanly on missing --history-index value instead of looping.
for helper in omarchy-clipboard-open omarchy-clipboard-paste-text; do
if timeout 2s "$ROOT/bin/$helper" --history-index >/dev/null 2>&1; then
Expand Down