From debb96a4cb9482a4e55d2437a29396e97821f00c Mon Sep 17 00:00:00 2001 From: sanjyay <102979855+sanjyay@users.noreply.github.com> Date: Sun, 4 Oct 2026 22:36:09 +0530 Subject: [PATCH 1/4] Avoid double scaling Ghostty text --- bin/omarchy-display-text-size | 28 ++++- test/shell.d/ghostty-text-scaling-test.sh | 119 ++++++++++++++++++++++ 2 files changed, 144 insertions(+), 3 deletions(-) create mode 100755 test/shell.d/ghostty-text-scaling-test.sh diff --git a/bin/omarchy-display-text-size b/bin/omarchy-display-text-size index bdf8778695d6..9defa3a78236 100755 --- a/bin/omarchy-display-text-size +++ b/bin/omarchy-display-text-size @@ -121,6 +121,18 @@ set_factor() { gsettings set "$GKEY_SCHEMA" "$GKEY_NAME" "$1" 2>/dev/null || true } +# Ghostty's GTK runtime multiplies font-size by this setting. Read back the +# effective value so a failed set/reset does not cause a second size mismatch. +gtk_factor() { + local factor + factor="$(gsettings get "$GKEY_SCHEMA" "$GKEY_NAME" 2>/dev/null)" + if [[ $factor =~ ^[0-9]+(\.[0-9]+)?$ ]] && awk -v f="$factor" 'BEGIN { exit !(f > 0) }'; then + echo "$factor" + else + echo 1 + fi +} + # ---- terminal font point size ---- # px base-size -> terminal point size, rounded to the nearest integer. @@ -151,7 +163,12 @@ set_terminal_size() { fi if [[ -f ~/.config/ghostty/config ]]; then - sed -i -E "s/^font-size = .*/font-size = $pt/" ~/.config/ghostty/config + # GTK already scales Ghostty's font. Compensate for that multiplier while + # retaining the same apparent point size as the other terminals. + local ghostty_pt + ghostty_pt=$(awk -v p="$pt" -v f="$(gtk_factor)" \ + 'BEGIN { printf "%.4f", p / f }' | sed -E 's/\.?0+$//') + sed -i -E "s/^font-size = .*/font-size = $ghostty_pt/" ~/.config/ghostty/config pkill -SIGUSR2 ghostty 2>/dev/null || true fi @@ -176,10 +193,15 @@ set_terminal_size() { fi } -# Report the current terminal point size from whichever config we find first. +# Report the apparent point size from whichever terminal config we find first. term_current_pt() { if [[ -f ~/.config/ghostty/config ]]; then - grep -oP '^font-size = \K[0-9.]+' ~/.config/ghostty/config | head -1 + local pt + pt=$(grep -oP '^font-size = \K[0-9.]+' ~/.config/ghostty/config | head -1) + if [[ -n $pt ]]; then + awk -v p="$pt" -v f="$(gtk_factor)" \ + 'BEGIN { printf "%.2f", p * f }' | sed -E 's/\.?0+$//' + fi elif [[ -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 diff --git a/test/shell.d/ghostty-text-scaling-test.sh b/test/shell.d/ghostty-text-scaling-test.sh new file mode 100755 index 000000000000..8ac7c271403b --- /dev/null +++ b/test/shell.d/ghostty-text-scaling-test.sh @@ -0,0 +1,119 @@ +#!/bin/bash + +set -euo pipefail +source "$(dirname "${BASH_SOURCE[0]}")/base-test.sh" + +scratch=$(mktemp -d) +trap 'rm -rf "$scratch"' EXIT +export HOME="$scratch/home" OMARCHY_PATH="$ROOT" +export PATH="$scratch/bin:$ROOT/bin:$PATH" +export FACTOR_FILE="$scratch/factor" +mkdir -p "$scratch/bin" "$HOME/.config/"{ghostty,foot,kitty,alacritty,omarchy} +cat >"$scratch/bin/gsettings" <<'STUB' +#!/bin/bash +case "$1:$3" in + get:font-name) echo "'Sans ${GTK_FONT_PT:-11}'" ;; + get:text-scaling-factor) + [[ ${FAIL_READ:-0} == "1" ]] && exit 1 + cat "$FACTOR_FILE" + ;; + set:text-scaling-factor) + [[ ${FAIL_WRITE:-0} == "1" ]] && exit 1 + printf '%s\n' "$4" >"$FACTOR_FILE" + ;; + reset:text-scaling-factor) + [[ ${FAIL_WRITE:-0} == "1" ]] && exit 1 + echo 1.0 >"$FACTOR_FILE" + ;; +esac +STUB +for command in pkill omarchy-notification-send; do + printf '#!/bin/bash\nexit 0\n' >"$scratch/bin/$command" +done +for command in pgrep omarchy-cmd-present; do + printf '#!/bin/bash\nexit 1\n' >"$scratch/bin/$command" +done +chmod +x "$scratch/bin/"* +printf 'font-family = My Font\nfont-size = 9\nbackground = #123456\n' >"$HOME/.config/ghostty/config" +printf '[main]\nfont=My Font:size=9:weight=bold\n' >"$HOME/.config/foot/foot.ini" +printf 'font_size 9.0\n' >"$HOME/.config/kitty/kitty.conf" +printf '[font]\nsize = 9\n' >"$HOME/.config/alacritty/alacritty.toml" +printf '[font]\nfamily = "My Font"\n[bar]\nheight = 24\n' >"$HOME/.config/omarchy/shell.toml" +echo 1.0 >"$FACTOR_FILE" + +run_size() { + "$ROOT/bin/omarchy-display-text-size" "$@" +} + +ghostty_size() { + sed -n 's/^font-size = //p' "$HOME/.config/ghostty/config" +} + +assert_apparent_size() { + local expected=$1 actual factor + actual=$(ghostty_size) + factor=$(cat "$FACTOR_FILE") + awk -v actual="$actual" -v factor="$factor" -v expected="$expected" \ + 'BEGIN { error = actual * factor - expected; exit !(error > -0.001 && error < 0.001) }' || + fail "Ghostty renders the requested $expected pt" "configured=$actual GTK=$factor" + local output + output=$(run_size) + [[ $output == *"terminal font: $expected pt"* ]] || fail "report shows Ghostty apparent size" "$output" +} + +run_size 16 +assert_apparent_size 12 +grep -qx 'font=My Font:size=12:weight=bold' "$HOME/.config/foot/foot.ini" || fail "Foot retains its scaled size and font options" +grep -qx 'font_size 12.0' "$HOME/.config/kitty/kitty.conf" || fail "Kitty retains its scaled size" +grep -qx 'size = 12' "$HOME/.config/alacritty/alacritty.toml" || fail "Alacritty retains its scaled size" +grep -qx 'font-family = My Font' "$HOME/.config/ghostty/config" || fail "Ghostty family is preserved" +grep -qx 'background = #123456' "$HOME/.config/ghostty/config" || fail "Ghostty unrelated config is preserved" +grep -qx 'height = 24' "$HOME/.config/omarchy/shell.toml" || fail "shell unrelated config is preserved" +pass "16px scales Ghostty once and preserves other terminal behavior and customization" + +for font in 9 11 12 10.5; do + export GTK_FONT_PT="$font" + for size in {9..20}; do + run_size "$size" + expected=$(awk -v s="$size" 'BEGIN { printf "%d", int(s * 9 / 12 + 0.5) }') + assert_apparent_size "$expected" + before=$(ghostty_size) + run_size "$size" + [[ $(ghostty_size) == "$before" ]] || fail "repeated size changes are idempotent" + done +done +pass "all accepted sizes compensate for quantized GTK factors and are idempotent" + +run_size reset +assert_apparent_size 9 +[[ $(ghostty_size) == "9" ]] || fail "reset restores Ghostty's default config value" +! grep -q '^base-size' "$HOME/.config/omarchy/shell.toml" || fail "reset removes shell override" +pass "reset restores defaults" + +echo 1.5 >"$FACTOR_FILE" +export FAIL_WRITE=1 +run_size 16 +assert_apparent_size 12 +run_size reset +assert_apparent_size 9 +unset FAIL_WRITE +pass "failed GTK set and reset compensate for the factor actually in use" + +for factor in 0 invalid; do + echo "$factor" >"$FACTOR_FILE" + FAIL_WRITE=1 run_size 16 + [[ $(ghostty_size) == "12" ]] || fail "invalid GTK factor safely falls back to 1" +done +FAIL_READ=1 run_size 16 +[[ $(ghostty_size) == "12" ]] || fail "unavailable GTK factor safely falls back to 1" +pass "invalid or unavailable GTK factors cannot produce invalid font sizes" + +sed -i '/^font-size = /d' "$HOME/.config/ghostty/config" +output=$(run_size) +[[ $output == *"terminal font: n/a pt"* ]] || fail "missing Ghostty size does not become zero" +rm "$HOME/.config/ghostty/config" +run_size 16 +[[ ! -e $HOME/.config/ghostty/config ]] || fail "absent Ghostty config remains absent" +output=$(run_size) +[[ $output == *"terminal font: 12 pt"* ]] || fail "other terminal reporting remains unchanged" +pass "missing Ghostty config and size retain existing behavior" From 9f73f07d0c51308e5c1015326910d6767446b835 Mon Sep 17 00:00:00 2001 From: sanjyay <102979855+sanjyay@users.noreply.github.com> Date: Sun, 4 Oct 2026 22:46:32 +0530 Subject: [PATCH 2/4] Preserve terminal sizes when GTK scaling cannot be read --- bin/omarchy-display-text-size | 32 +++++++++++++-------- test/shell.d/ghostty-text-scaling-test.sh | 34 +++++++++++++++++++---- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/bin/omarchy-display-text-size b/bin/omarchy-display-text-size index 9defa3a78236..5efa40d7fb77 100755 --- a/bin/omarchy-display-text-size +++ b/bin/omarchy-display-text-size @@ -125,11 +125,11 @@ set_factor() { # effective value so a failed set/reset does not cause a second size mismatch. gtk_factor() { local factor - factor="$(gsettings get "$GKEY_SCHEMA" "$GKEY_NAME" 2>/dev/null)" + factor="$(gsettings get "$GKEY_SCHEMA" "$GKEY_NAME" 2>/dev/null)" || return 1 if [[ $factor =~ ^[0-9]+(\.[0-9]+)?$ ]] && awk -v f="$factor" 'BEGIN { exit !(f > 0) }'; then echo "$factor" else - echo 1 + return 1 fi } @@ -146,7 +146,20 @@ term_pt_for() { # 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() { - local pt="$1" + local pt="$1" ghostty_pt + + if [[ -f ~/.config/ghostty/config ]]; then + # GTK already scales Ghostty's font. Compensate for that multiplier while + # retaining the same apparent point size as the other terminals. + local factor + if factor=$(gtk_factor); then + ghostty_pt=$(awk -v p="$pt" -v f="$factor" \ + 'BEGIN { printf "%.4f", p / f }' | sed -E 's/\.?0+$//') + else + echo "Cannot read GTK text scaling; terminal font sizes were left unchanged." >&2 + return 1 + fi + fi if [[ -f ~/.config/alacritty/alacritty.toml ]]; then sed -i -E "s/^size[[:space:]]*=.*/size = $pt/" ~/.config/alacritty/alacritty.toml @@ -163,11 +176,6 @@ set_terminal_size() { fi if [[ -f ~/.config/ghostty/config ]]; then - # GTK already scales Ghostty's font. Compensate for that multiplier while - # retaining the same apparent point size as the other terminals. - local ghostty_pt - ghostty_pt=$(awk -v p="$pt" -v f="$(gtk_factor)" \ - 'BEGIN { printf "%.4f", p / f }' | sed -E 's/\.?0+$//') sed -i -E "s/^font-size = .*/font-size = $ghostty_pt/" ~/.config/ghostty/config pkill -SIGUSR2 ghostty 2>/dev/null || true fi @@ -196,10 +204,10 @@ set_terminal_size() { # Report the apparent point size from whichever terminal config we find first. term_current_pt() { if [[ -f ~/.config/ghostty/config ]]; then - local pt + local pt factor pt=$(grep -oP '^font-size = \K[0-9.]+' ~/.config/ghostty/config | head -1) - if [[ -n $pt ]]; then - awk -v p="$pt" -v f="$(gtk_factor)" \ + if [[ -n $pt ]] && factor=$(gtk_factor); then + awk -v p="$pt" -v f="$factor" \ 'BEGIN { printf "%.2f", p * f }' | sed -E 's/\.?0+$//' fi elif [[ -f ~/.config/alacritty/alacritty.toml ]]; then @@ -233,7 +241,7 @@ case "${1:-}" in reset_base_size gsettings reset "$GKEY_SCHEMA" "$GKEY_NAME" 2>/dev/null || true set_terminal_size "$TERM_DEFAULT_PT" - exit 0 + exit $? ;; esac diff --git a/test/shell.d/ghostty-text-scaling-test.sh b/test/shell.d/ghostty-text-scaling-test.sh index 8ac7c271403b..e306e1476ce0 100755 --- a/test/shell.d/ghostty-text-scaling-test.sh +++ b/test/shell.d/ghostty-text-scaling-test.sh @@ -99,14 +99,38 @@ assert_apparent_size 9 unset FAIL_WRITE pass "failed GTK set and reset compensate for the factor actually in use" +# A failed read must not be mistaken for factor 1 while 1.5 is active. +echo 1.5 >"$FACTOR_FILE" +FAIL_WRITE=1 run_size 16 +for terminal in ghostty foot kitty alacritty; do + cp -r "$HOME/.config/$terminal" "$scratch/$terminal-before" +done +assert_terminal_configs_unchanged() { + local terminal + for terminal in ghostty foot kitty alacritty; do + diff -r "$scratch/$terminal-before" "$HOME/.config/$terminal" >/dev/null || + fail "unreadable GTK factor leaves $terminal config unchanged" + done +} +for action in 18 reset; do + if FAIL_READ=1 run_size "$action" >"$scratch/out" 2>"$scratch/err"; then + fail "unreadable GTK factor returns a failure for $action" + fi + grep -q 'terminal font sizes were left unchanged' "$scratch/err" || fail "failure explains untouched terminal sizes" + assert_terminal_configs_unchanged +done +output=$(FAIL_READ=1 run_size) +[[ $output == *"terminal font: n/a pt"* ]] || fail "failed read does not falsely report an apparent size" +pass "failed GTK reads preserve every terminal config, fail set/reset, and report unknown size" + for factor in 0 invalid; do echo "$factor" >"$FACTOR_FILE" - FAIL_WRITE=1 run_size 16 - [[ $(ghostty_size) == "12" ]] || fail "invalid GTK factor safely falls back to 1" + if FAIL_WRITE=1 run_size 16 >"$scratch/out" 2>"$scratch/err"; then + fail "invalid GTK factor returns a failure" + fi + assert_terminal_configs_unchanged done -FAIL_READ=1 run_size 16 -[[ $(ghostty_size) == "12" ]] || fail "unavailable GTK factor safely falls back to 1" -pass "invalid or unavailable GTK factors cannot produce invalid font sizes" +pass "invalid GTK factors leave terminal config untouched" sed -i '/^font-size = /d' "$HOME/.config/ghostty/config" output=$(run_size) From 493bce1f76f2f3d5d2258b7db4ce660c95c3d584 Mon Sep 17 00:00:00 2001 From: sanjyay <102979855+sanjyay@users.noreply.github.com> Date: Sun, 4 Oct 2026 23:02:15 +0530 Subject: [PATCH 3/4] Roll back GTK scaling when its value cannot be read --- bin/omarchy-display-text-size | 55 ++++++++++++++++------- test/shell.d/ghostty-text-scaling-test.sh | 38 +++++++++++++++- 2 files changed, 74 insertions(+), 19 deletions(-) diff --git a/bin/omarchy-display-text-size b/bin/omarchy-display-text-size index 5efa40d7fb77..806101d45f0c 100755 --- a/bin/omarchy-display-text-size +++ b/bin/omarchy-display-text-size @@ -117,8 +117,35 @@ gtk_font_pt() { fi } +# Update GTK before touching shell/terminal configs. Ghostty needs a readable +# factor both before and after the update so a failed read can be rolled back. set_factor() { - gsettings set "$GKEY_SCHEMA" "$GKEY_NAME" "$1" 2>/dev/null || true + local requested="$1" previous factor + if [[ -f ~/.config/ghostty/config ]]; then + if ! previous=$(gtk_factor); then + echo "Cannot read GTK text scaling; text size was left unchanged." >&2 + return 1 + fi + fi + + if [[ $requested == "reset" ]]; then + gsettings reset "$GKEY_SCHEMA" "$GKEY_NAME" 2>/dev/null || true + else + gsettings set "$GKEY_SCHEMA" "$GKEY_NAME" "$requested" 2>/dev/null || true + fi + + if [[ -f ~/.config/ghostty/config ]]; then + if factor=$(gtk_factor); then + echo "$factor" + else + if gsettings set "$GKEY_SCHEMA" "$GKEY_NAME" "$previous" 2>/dev/null; then + echo "Cannot read GTK text scaling; restored previous scaling. Text size was left unchanged." >&2 + else + echo "Cannot read or restore GTK text scaling; shell and terminal sizes were left unchanged." >&2 + fi + return 1 + fi + fi } # Ghostty's GTK runtime multiplies font-size by this setting. Read back the @@ -146,19 +173,13 @@ term_pt_for() { # 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() { - local pt="$1" ghostty_pt + local pt="$1" factor="$2" ghostty_pt if [[ -f ~/.config/ghostty/config ]]; then # GTK already scales Ghostty's font. Compensate for that multiplier while # retaining the same apparent point size as the other terminals. - local factor - if factor=$(gtk_factor); then - ghostty_pt=$(awk -v p="$pt" -v f="$factor" \ - 'BEGIN { printf "%.4f", p / f }' | sed -E 's/\.?0+$//') - else - echo "Cannot read GTK text scaling; terminal font sizes were left unchanged." >&2 - return 1 - fi + ghostty_pt=$(awk -v p="$pt" -v f="$factor" \ + 'BEGIN { printf "%.4f", p / f }' | sed -E 's/\.?0+$//') fi if [[ -f ~/.config/alacritty/alacritty.toml ]]; then @@ -238,9 +259,9 @@ case "${1:-}" in exit 0 ;; reset | default) + factor=$(set_factor reset) || exit 1 reset_base_size - gsettings reset "$GKEY_SCHEMA" "$GKEY_NAME" 2>/dev/null || true - set_terminal_size "$TERM_DEFAULT_PT" + set_terminal_size "$TERM_DEFAULT_PT" "$factor" exit $? ;; esac @@ -252,15 +273,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" +factor=$(set_factor "$factor") || exit 1 + +# 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")" +set_terminal_size "$(term_pt_for "$size")" "$factor" diff --git a/test/shell.d/ghostty-text-scaling-test.sh b/test/shell.d/ghostty-text-scaling-test.sh index e306e1476ce0..09ee40fac023 100755 --- a/test/shell.d/ghostty-text-scaling-test.sh +++ b/test/shell.d/ghostty-text-scaling-test.sh @@ -7,7 +7,7 @@ scratch=$(mktemp -d) trap 'rm -rf "$scratch"' EXIT export HOME="$scratch/home" OMARCHY_PATH="$ROOT" export PATH="$scratch/bin:$ROOT/bin:$PATH" -export FACTOR_FILE="$scratch/factor" +export FACTOR_FILE="$scratch/factor" READ_COUNT_FILE="$scratch/read-count" mkdir -p "$scratch/bin" "$HOME/.config/"{ghostty,foot,kitty,alacritty,omarchy} cat >"$scratch/bin/gsettings" <<'STUB' #!/bin/bash @@ -15,10 +15,19 @@ case "$1:$3" in get:font-name) echo "'Sans ${GTK_FONT_PT:-11}'" ;; get:text-scaling-factor) [[ ${FAIL_READ:-0} == "1" ]] && exit 1 + if [[ ${FAIL_SECOND_READ:-0} == "1" ]]; then + count=$(cat "$READ_COUNT_FILE") + ((count += 1)) + echo "$count" >"$READ_COUNT_FILE" + ((count == 2)) && exit 1 + fi cat "$FACTOR_FILE" ;; set:text-scaling-factor) [[ ${FAIL_WRITE:-0} == "1" ]] && exit 1 + if [[ ${FAIL_ROLLBACK:-0} == "1" ]] && (( $(cat "$READ_COUNT_FILE") >= 2 )); then + exit 1 + fi printf '%s\n' "$4" >"$FACTOR_FILE" ;; reset:text-scaling-factor) @@ -112,17 +121,42 @@ assert_terminal_configs_unchanged() { fail "unreadable GTK factor leaves $terminal config unchanged" done } +cp "$HOME/.config/omarchy/shell.toml" "$scratch/shell-before" for action in 18 reset; do if FAIL_READ=1 run_size "$action" >"$scratch/out" 2>"$scratch/err"; then fail "unreadable GTK factor returns a failure for $action" fi - grep -q 'terminal font sizes were left unchanged' "$scratch/err" || fail "failure explains untouched terminal sizes" + grep -q 'text size was left unchanged' "$scratch/err" || fail "failure explains untouched terminal sizes" assert_terminal_configs_unchanged + cmp -s "$scratch/shell-before" "$HOME/.config/omarchy/shell.toml" || fail "unreadable GTK factor preserves shell config" + [[ $(cat "$FACTOR_FILE") == "1.5" ]] || fail "unreadable GTK factor preserves GTK setting" done output=$(FAIL_READ=1 run_size) [[ $output == *"terminal font: n/a pt"* ]] || fail "failed read does not falsely report an apparent size" pass "failed GTK reads preserve every terminal config, fail set/reset, and report unknown size" +for action in 18 reset; do + echo 0 >"$READ_COUNT_FILE" + if FAIL_SECOND_READ=1 run_size "$action" >"$scratch/out" 2>"$scratch/err"; then + fail "failed GTK readback returns a failure for $action" + fi + grep -q 'restored previous scaling' "$scratch/err" || fail "readback failure reports GTK rollback" + [[ $(cat "$FACTOR_FILE") == "1.5" ]] || fail "failed readback restores previous GTK factor" + cmp -s "$scratch/shell-before" "$HOME/.config/omarchy/shell.toml" || fail "failed readback preserves shell config" + assert_terminal_configs_unchanged +done +pass "failed GTK readback rolls back scaling before shell or terminal config updates" + +echo 0 >"$READ_COUNT_FILE" +if FAIL_SECOND_READ=1 FAIL_ROLLBACK=1 run_size 18 >"$scratch/out" 2>"$scratch/err"; then + fail "failed GTK rollback returns a failure" +fi +grep -q 'Cannot read or restore GTK text scaling' "$scratch/err" || fail "failed rollback reports unrestored GTK scaling" +assert_terminal_configs_unchanged +cmp -s "$scratch/shell-before" "$HOME/.config/omarchy/shell.toml" || fail "failed rollback still preserves shell config" +echo 1.5 >"$FACTOR_FILE" +pass "a failed rollback is diagnosed and still leaves shell and terminal configs untouched" + for factor in 0 invalid; do echo "$factor" >"$FACTOR_FILE" if FAIL_WRITE=1 run_size 16 >"$scratch/out" 2>"$scratch/err"; then From a16098966a39a67b9c5461937a40ad6a40c34271 Mon Sep 17 00:00:00 2001 From: sanjyay <102979855+sanjyay@users.noreply.github.com> Date: Mon, 30 Nov 2026 22:55:52 +0530 Subject: [PATCH 4/4] Keep Ghostty scaling checks in desktop helper tests --- test/shell.d/desktop-helpers-test.sh | 181 +++++++++++++++++++++ test/shell.d/ghostty-text-scaling-test.sh | 184 ---------------------- 2 files changed, 181 insertions(+), 184 deletions(-) delete mode 100755 test/shell.d/ghostty-text-scaling-test.sh diff --git a/test/shell.d/desktop-helpers-test.sh b/test/shell.d/desktop-helpers-test.sh index d37bc001dd7a..ee71c961e5ef 100755 --- a/test/shell.d/desktop-helpers-test.sh +++ b/test/shell.d/desktop-helpers-test.sh @@ -196,3 +196,184 @@ fi (( $(wc -l <"$tmp/hyprctl-pop-calls") == 1 )) || fail "omarchy-hyprland-window-pop does not replay toggles after a partial batch failure" "$(<"$tmp/hyprctl-pop-calls")" pass "omarchy-hyprland-window-pop batches dispatches and handles fallback safely" + +# Ghostty applies GTK text scaling to its configured font size. +scratch=$(mktemp -d) +trap 'rm -rf "$tmp" "$scratch"' EXIT +export HOME="$scratch/home" OMARCHY_PATH="$ROOT" +export PATH="$scratch/bin:$ROOT/bin:$PATH" +export FACTOR_FILE="$scratch/factor" READ_COUNT_FILE="$scratch/read-count" +mkdir -p "$scratch/bin" "$HOME/.config/"{ghostty,foot,kitty,alacritty,omarchy} +cat >"$scratch/bin/gsettings" <<'STUB' +#!/bin/bash +case "$1:$3" in + get:font-name) echo "'Sans ${GTK_FONT_PT:-11}'" ;; + get:text-scaling-factor) + [[ ${FAIL_READ:-0} == "1" ]] && exit 1 + if [[ ${FAIL_SECOND_READ:-0} == "1" ]]; then + count=$(cat "$READ_COUNT_FILE") + ((count += 1)) + echo "$count" >"$READ_COUNT_FILE" + ((count == 2)) && exit 1 + fi + cat "$FACTOR_FILE" + ;; + set:text-scaling-factor) + [[ ${FAIL_WRITE:-0} == "1" ]] && exit 1 + if [[ ${FAIL_ROLLBACK:-0} == "1" ]] && (( $(cat "$READ_COUNT_FILE") >= 2 )); then + exit 1 + fi + printf '%s\n' "$4" >"$FACTOR_FILE" + ;; + reset:text-scaling-factor) + [[ ${FAIL_WRITE:-0} == "1" ]] && exit 1 + echo 1.0 >"$FACTOR_FILE" + ;; +esac +STUB +for command in pkill omarchy-notification-send; do + printf '#!/bin/bash\nexit 0\n' >"$scratch/bin/$command" +done +for command in pgrep omarchy-cmd-present; do + printf '#!/bin/bash\nexit 1\n' >"$scratch/bin/$command" +done +chmod +x "$scratch/bin/"* +printf 'font-family = My Font\nfont-size = 9\nbackground = #123456\n' >"$HOME/.config/ghostty/config" +printf '[main]\nfont=My Font:size=9:weight=bold\n' >"$HOME/.config/foot/foot.ini" +printf 'font_size 9.0\n' >"$HOME/.config/kitty/kitty.conf" +printf '[font]\nsize = 9\n' >"$HOME/.config/alacritty/alacritty.toml" +printf '[font]\nfamily = "My Font"\n[bar]\nheight = 24\n' >"$HOME/.config/omarchy/shell.toml" +echo 1.0 >"$FACTOR_FILE" + +run_size() { + "$ROOT/bin/omarchy-display-text-size" "$@" +} + +ghostty_size() { + sed -n 's/^font-size = //p' "$HOME/.config/ghostty/config" +} + +assert_apparent_size() { + local expected=$1 actual factor + actual=$(ghostty_size) + factor=$(cat "$FACTOR_FILE") + awk -v actual="$actual" -v factor="$factor" -v expected="$expected" \ + 'BEGIN { error = actual * factor - expected; exit !(error > -0.001 && error < 0.001) }' || + fail "Ghostty renders the requested $expected pt" "configured=$actual GTK=$factor" + local output + output=$(run_size) + [[ $output == *"terminal font: $expected pt"* ]] || fail "report shows Ghostty apparent size" "$output" +} + +run_size 16 +assert_apparent_size 12 +grep -qx 'font=My Font:size=12:weight=bold' "$HOME/.config/foot/foot.ini" || fail "Foot retains its scaled size and font options" +grep -qx 'font_size 12.0' "$HOME/.config/kitty/kitty.conf" || fail "Kitty retains its scaled size" +grep -qx 'size = 12' "$HOME/.config/alacritty/alacritty.toml" || fail "Alacritty retains its scaled size" +grep -qx 'font-family = My Font' "$HOME/.config/ghostty/config" || fail "Ghostty family is preserved" +grep -qx 'background = #123456' "$HOME/.config/ghostty/config" || fail "Ghostty unrelated config is preserved" +grep -qx 'height = 24' "$HOME/.config/omarchy/shell.toml" || fail "shell unrelated config is preserved" +pass "16px scales Ghostty once and preserves other terminal behavior and customization" + +for font in 9 11 12 10.5; do + export GTK_FONT_PT="$font" + for size in {9..20}; do + run_size "$size" + expected=$(awk -v s="$size" 'BEGIN { printf "%d", int(s * 9 / 12 + 0.5) }') + assert_apparent_size "$expected" + before=$(ghostty_size) + run_size "$size" + [[ $(ghostty_size) == "$before" ]] || fail "repeated size changes are idempotent" + done +done +pass "all accepted sizes compensate for quantized GTK factors and are idempotent" + +run_size reset +assert_apparent_size 9 +[[ $(ghostty_size) == "9" ]] || fail "reset restores Ghostty's default config value" +! grep -q '^base-size' "$HOME/.config/omarchy/shell.toml" || fail "reset removes shell override" +pass "reset restores defaults" + +echo 1.5 >"$FACTOR_FILE" +export FAIL_WRITE=1 +run_size 16 +assert_apparent_size 12 +run_size reset +assert_apparent_size 9 +unset FAIL_WRITE +pass "failed GTK set and reset compensate for the factor actually in use" + +# A failed read must not be mistaken for factor 1 while 1.5 is active. +echo 1.5 >"$FACTOR_FILE" +FAIL_WRITE=1 run_size 16 +for terminal in ghostty foot kitty alacritty; do + cp -r "$HOME/.config/$terminal" "$scratch/$terminal-before" +done +assert_terminal_configs_unchanged() { + local terminal + for terminal in ghostty foot kitty alacritty; do + diff -r "$scratch/$terminal-before" "$HOME/.config/$terminal" >/dev/null || + fail "unreadable GTK factor leaves $terminal config unchanged" + done +} +cp "$HOME/.config/omarchy/shell.toml" "$scratch/shell-before" +for action in 18 reset; do + if FAIL_READ=1 run_size "$action" >"$scratch/out" 2>"$scratch/err"; then + fail "unreadable GTK factor returns a failure for $action" + fi + grep -q 'text size was left unchanged' "$scratch/err" || fail "failure explains untouched terminal sizes" + assert_terminal_configs_unchanged + cmp -s "$scratch/shell-before" "$HOME/.config/omarchy/shell.toml" || fail "unreadable GTK factor preserves shell config" + [[ $(cat "$FACTOR_FILE") == "1.5" ]] || fail "unreadable GTK factor preserves GTK setting" +done +output=$(FAIL_READ=1 run_size) +[[ $output == *"terminal font: n/a pt"* ]] || fail "failed read does not falsely report an apparent size" +pass "failed GTK reads preserve every terminal config, fail set/reset, and report unknown size" + +for action in 18 reset; do + echo 0 >"$READ_COUNT_FILE" + if FAIL_SECOND_READ=1 run_size "$action" >"$scratch/out" 2>"$scratch/err"; then + fail "failed GTK readback returns a failure for $action" + fi + grep -q 'restored previous scaling' "$scratch/err" || fail "readback failure reports GTK rollback" + [[ $(cat "$FACTOR_FILE") == "1.5" ]] || fail "failed readback restores previous GTK factor" + cmp -s "$scratch/shell-before" "$HOME/.config/omarchy/shell.toml" || fail "failed readback preserves shell config" + assert_terminal_configs_unchanged +done +pass "failed GTK readback rolls back scaling before shell or terminal config updates" + +echo 0 >"$READ_COUNT_FILE" +if FAIL_SECOND_READ=1 FAIL_ROLLBACK=1 run_size 18 >"$scratch/out" 2>"$scratch/err"; then + fail "failed GTK rollback returns a failure" +fi +grep -q 'Cannot read or restore GTK text scaling' "$scratch/err" || fail "failed rollback reports unrestored GTK scaling" +assert_terminal_configs_unchanged +cmp -s "$scratch/shell-before" "$HOME/.config/omarchy/shell.toml" || fail "failed rollback still preserves shell config" +echo 1.5 >"$FACTOR_FILE" +pass "a failed rollback is diagnosed and still leaves shell and terminal configs untouched" + +for factor in 0 invalid; do + echo "$factor" >"$FACTOR_FILE" + if FAIL_WRITE=1 run_size 16 >"$scratch/out" 2>"$scratch/err"; then + fail "invalid GTK factor returns a failure" + fi + assert_terminal_configs_unchanged +done +pass "invalid GTK factors leave terminal config untouched" + +sed -i '/^font-size = /d' "$HOME/.config/ghostty/config" +output=$(run_size) +[[ $output == *"terminal font: n/a pt"* ]] || fail "missing Ghostty size does not become zero" +rm "$HOME/.config/ghostty/config" +run_size 16 +[[ ! -e $HOME/.config/ghostty/config ]] || fail "absent Ghostty config remains absent" +output=$(run_size) +[[ $output == *"terminal font: 12 pt"* ]] || fail "other terminal reporting remains unchanged" +pass "missing Ghostty config and size retain existing behavior" + +printf 'font-size = 9\n' >"$scratch/ghostty-shared" +ln -s "$scratch/ghostty-shared" "$HOME/.config/ghostty/config" +run_size 16 +[[ -L $HOME/.config/ghostty/config ]] || fail "Ghostty config remains a symlink" +assert_apparent_size 12 +pass "Ghostty scales the font in the symlink target" diff --git a/test/shell.d/ghostty-text-scaling-test.sh b/test/shell.d/ghostty-text-scaling-test.sh deleted file mode 100755 index e7608e7a89ab..000000000000 --- a/test/shell.d/ghostty-text-scaling-test.sh +++ /dev/null @@ -1,184 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(dirname "${BASH_SOURCE[0]}")/base-test.sh" - -scratch=$(mktemp -d) -trap 'rm -rf "$scratch"' EXIT -export HOME="$scratch/home" OMARCHY_PATH="$ROOT" -export PATH="$scratch/bin:$ROOT/bin:$PATH" -export FACTOR_FILE="$scratch/factor" READ_COUNT_FILE="$scratch/read-count" -mkdir -p "$scratch/bin" "$HOME/.config/"{ghostty,foot,kitty,alacritty,omarchy} -cat >"$scratch/bin/gsettings" <<'STUB' -#!/bin/bash -case "$1:$3" in - get:font-name) echo "'Sans ${GTK_FONT_PT:-11}'" ;; - get:text-scaling-factor) - [[ ${FAIL_READ:-0} == "1" ]] && exit 1 - if [[ ${FAIL_SECOND_READ:-0} == "1" ]]; then - count=$(cat "$READ_COUNT_FILE") - ((count += 1)) - echo "$count" >"$READ_COUNT_FILE" - ((count == 2)) && exit 1 - fi - cat "$FACTOR_FILE" - ;; - set:text-scaling-factor) - [[ ${FAIL_WRITE:-0} == "1" ]] && exit 1 - if [[ ${FAIL_ROLLBACK:-0} == "1" ]] && (( $(cat "$READ_COUNT_FILE") >= 2 )); then - exit 1 - fi - printf '%s\n' "$4" >"$FACTOR_FILE" - ;; - reset:text-scaling-factor) - [[ ${FAIL_WRITE:-0} == "1" ]] && exit 1 - echo 1.0 >"$FACTOR_FILE" - ;; -esac -STUB -for command in pkill omarchy-notification-send; do - printf '#!/bin/bash\nexit 0\n' >"$scratch/bin/$command" -done -for command in pgrep omarchy-cmd-present; do - printf '#!/bin/bash\nexit 1\n' >"$scratch/bin/$command" -done -chmod +x "$scratch/bin/"* -printf 'font-family = My Font\nfont-size = 9\nbackground = #123456\n' >"$HOME/.config/ghostty/config" -printf '[main]\nfont=My Font:size=9:weight=bold\n' >"$HOME/.config/foot/foot.ini" -printf 'font_size 9.0\n' >"$HOME/.config/kitty/kitty.conf" -printf '[font]\nsize = 9\n' >"$HOME/.config/alacritty/alacritty.toml" -printf '[font]\nfamily = "My Font"\n[bar]\nheight = 24\n' >"$HOME/.config/omarchy/shell.toml" -echo 1.0 >"$FACTOR_FILE" - -run_size() { - "$ROOT/bin/omarchy-display-text-size" "$@" -} - -ghostty_size() { - sed -n 's/^font-size = //p' "$HOME/.config/ghostty/config" -} - -assert_apparent_size() { - local expected=$1 actual factor - actual=$(ghostty_size) - factor=$(cat "$FACTOR_FILE") - awk -v actual="$actual" -v factor="$factor" -v expected="$expected" \ - 'BEGIN { error = actual * factor - expected; exit !(error > -0.001 && error < 0.001) }' || - fail "Ghostty renders the requested $expected pt" "configured=$actual GTK=$factor" - local output - output=$(run_size) - [[ $output == *"terminal font: $expected pt"* ]] || fail "report shows Ghostty apparent size" "$output" -} - -run_size 16 -assert_apparent_size 12 -grep -qx 'font=My Font:size=12:weight=bold' "$HOME/.config/foot/foot.ini" || fail "Foot retains its scaled size and font options" -grep -qx 'font_size 12.0' "$HOME/.config/kitty/kitty.conf" || fail "Kitty retains its scaled size" -grep -qx 'size = 12' "$HOME/.config/alacritty/alacritty.toml" || fail "Alacritty retains its scaled size" -grep -qx 'font-family = My Font' "$HOME/.config/ghostty/config" || fail "Ghostty family is preserved" -grep -qx 'background = #123456' "$HOME/.config/ghostty/config" || fail "Ghostty unrelated config is preserved" -grep -qx 'height = 24' "$HOME/.config/omarchy/shell.toml" || fail "shell unrelated config is preserved" -pass "16px scales Ghostty once and preserves other terminal behavior and customization" - -for font in 9 11 12 10.5; do - export GTK_FONT_PT="$font" - for size in {9..20}; do - run_size "$size" - expected=$(awk -v s="$size" 'BEGIN { printf "%d", int(s * 9 / 12 + 0.5) }') - assert_apparent_size "$expected" - before=$(ghostty_size) - run_size "$size" - [[ $(ghostty_size) == "$before" ]] || fail "repeated size changes are idempotent" - done -done -pass "all accepted sizes compensate for quantized GTK factors and are idempotent" - -run_size reset -assert_apparent_size 9 -[[ $(ghostty_size) == "9" ]] || fail "reset restores Ghostty's default config value" -! grep -q '^base-size' "$HOME/.config/omarchy/shell.toml" || fail "reset removes shell override" -pass "reset restores defaults" - -echo 1.5 >"$FACTOR_FILE" -export FAIL_WRITE=1 -run_size 16 -assert_apparent_size 12 -run_size reset -assert_apparent_size 9 -unset FAIL_WRITE -pass "failed GTK set and reset compensate for the factor actually in use" - -# A failed read must not be mistaken for factor 1 while 1.5 is active. -echo 1.5 >"$FACTOR_FILE" -FAIL_WRITE=1 run_size 16 -for terminal in ghostty foot kitty alacritty; do - cp -r "$HOME/.config/$terminal" "$scratch/$terminal-before" -done -assert_terminal_configs_unchanged() { - local terminal - for terminal in ghostty foot kitty alacritty; do - diff -r "$scratch/$terminal-before" "$HOME/.config/$terminal" >/dev/null || - fail "unreadable GTK factor leaves $terminal config unchanged" - done -} -cp "$HOME/.config/omarchy/shell.toml" "$scratch/shell-before" -for action in 18 reset; do - if FAIL_READ=1 run_size "$action" >"$scratch/out" 2>"$scratch/err"; then - fail "unreadable GTK factor returns a failure for $action" - fi - grep -q 'text size was left unchanged' "$scratch/err" || fail "failure explains untouched terminal sizes" - assert_terminal_configs_unchanged - cmp -s "$scratch/shell-before" "$HOME/.config/omarchy/shell.toml" || fail "unreadable GTK factor preserves shell config" - [[ $(cat "$FACTOR_FILE") == "1.5" ]] || fail "unreadable GTK factor preserves GTK setting" -done -output=$(FAIL_READ=1 run_size) -[[ $output == *"terminal font: n/a pt"* ]] || fail "failed read does not falsely report an apparent size" -pass "failed GTK reads preserve every terminal config, fail set/reset, and report unknown size" - -for action in 18 reset; do - echo 0 >"$READ_COUNT_FILE" - if FAIL_SECOND_READ=1 run_size "$action" >"$scratch/out" 2>"$scratch/err"; then - fail "failed GTK readback returns a failure for $action" - fi - grep -q 'restored previous scaling' "$scratch/err" || fail "readback failure reports GTK rollback" - [[ $(cat "$FACTOR_FILE") == "1.5" ]] || fail "failed readback restores previous GTK factor" - cmp -s "$scratch/shell-before" "$HOME/.config/omarchy/shell.toml" || fail "failed readback preserves shell config" - assert_terminal_configs_unchanged -done -pass "failed GTK readback rolls back scaling before shell or terminal config updates" - -echo 0 >"$READ_COUNT_FILE" -if FAIL_SECOND_READ=1 FAIL_ROLLBACK=1 run_size 18 >"$scratch/out" 2>"$scratch/err"; then - fail "failed GTK rollback returns a failure" -fi -grep -q 'Cannot read or restore GTK text scaling' "$scratch/err" || fail "failed rollback reports unrestored GTK scaling" -assert_terminal_configs_unchanged -cmp -s "$scratch/shell-before" "$HOME/.config/omarchy/shell.toml" || fail "failed rollback still preserves shell config" -echo 1.5 >"$FACTOR_FILE" -pass "a failed rollback is diagnosed and still leaves shell and terminal configs untouched" - -for factor in 0 invalid; do - echo "$factor" >"$FACTOR_FILE" - if FAIL_WRITE=1 run_size 16 >"$scratch/out" 2>"$scratch/err"; then - fail "invalid GTK factor returns a failure" - fi - assert_terminal_configs_unchanged -done -pass "invalid GTK factors leave terminal config untouched" - -sed -i '/^font-size = /d' "$HOME/.config/ghostty/config" -output=$(run_size) -[[ $output == *"terminal font: n/a pt"* ]] || fail "missing Ghostty size does not become zero" -rm "$HOME/.config/ghostty/config" -run_size 16 -[[ ! -e $HOME/.config/ghostty/config ]] || fail "absent Ghostty config remains absent" -output=$(run_size) -[[ $output == *"terminal font: 12 pt"* ]] || fail "other terminal reporting remains unchanged" -pass "missing Ghostty config and size retain existing behavior" - -printf 'font-size = 9\n' >"$scratch/ghostty-shared" -ln -s "$scratch/ghostty-shared" "$HOME/.config/ghostty/config" -run_size 16 -[[ -L $HOME/.config/ghostty/config ]] || fail "Ghostty config remains a symlink" -assert_apparent_size 12 -pass "Ghostty scales the font in the symlink target"