Quantize GTK text scaling to whole point sizes to stop menu clipping
Raw size/12 ratios hand GTK a fractional point size (11px -> 10.08pt), which clips ascenders in GTK4 menus on scale-1 monitors. Round the scaled interface font to a whole point and derive the factor from that, keeping 12px anchored at exactly 1.0. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
d47b4b0686
commit
fa95901b6f
@@ -7,7 +7,8 @@
|
|||||||
# One knob for apparent text size across the desktop. It drives three settings
|
# One knob for apparent text size across the desktop. It drives three settings
|
||||||
# in lockstep, all anchored to the shell default of 12px:
|
# in lockstep, all anchored to the shell default of 12px:
|
||||||
# • the omarchy shell's font base-size (~/.config/omarchy/shell.toml [font])
|
# • the omarchy shell's font base-size (~/.config/omarchy/shell.toml [font])
|
||||||
# • GNOME/GTK's text-scaling-factor (12px -> 1.0, so 16 -> 1.333)
|
# • 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)
|
# • the terminal font point size (12px -> 9pt, so terminal_pt = px * 9/12)
|
||||||
# The shell override layers on top of the active theme (so the size survives
|
# 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.
|
# theme switches) and the shell watches the file, so shell text re-flows live.
|
||||||
@@ -102,6 +103,20 @@ reset_base_size() {
|
|||||||
|
|
||||||
# ---- GTK text-scaling-factor ----
|
# ---- GTK text-scaling-factor ----
|
||||||
|
|
||||||
|
# Point size of the GTK interface font (font-name), used to quantize the
|
||||||
|
# scaling factor. Falls back to the GNOME default when unreadable.
|
||||||
|
gtk_font_pt() {
|
||||||
|
local name pt
|
||||||
|
name="$(gsettings get "$GKEY_SCHEMA" font-name 2>/dev/null)"
|
||||||
|
pt="${name%\'}"
|
||||||
|
pt="${pt##* }"
|
||||||
|
if [[ $pt =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
|
||||||
|
echo "$pt"
|
||||||
|
else
|
||||||
|
echo 11
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
set_factor() {
|
set_factor() {
|
||||||
gsettings set "$GKEY_SCHEMA" "$GKEY_NAME" "$1" 2>/dev/null || true
|
gsettings set "$GKEY_SCHEMA" "$GKEY_NAME" "$1" 2>/dev/null || true
|
||||||
}
|
}
|
||||||
@@ -200,8 +215,11 @@ fi
|
|||||||
# Shell side: base-size in px (the omarchy shell's rem root).
|
# Shell side: base-size in px (the omarchy shell's rem root).
|
||||||
set_base_size "$size"
|
set_base_size "$size"
|
||||||
|
|
||||||
# GTK side: multiplier anchored so 12px == 1.0.
|
# GTK side: multiplier anchored so 12px == 1.0, quantized so the interface
|
||||||
factor="$(awk -v s="$size" -v b="$SHELL_DEFAULT_PX" 'BEGIN { printf "%.4f", s / b }')"
|
# 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"
|
||||||
|
|
||||||
# Terminal side: point size anchored so 12px == 9pt.
|
# Terminal side: point size anchored so 12px == 9pt.
|
||||||
|
|||||||
Reference in New Issue
Block a user