Add display scale presets with revert confirmation

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QKxGW1raAWaqeU8WdHsMsp
This commit is contained in:
2026-08-24 19:46:26 -04:00
co-authored by Claude Fable 5
parent 4a762052ca
commit fff49e747c
+58
View File
@@ -0,0 +1,58 @@
#!/bin/bash
# omarchy:summary=Apply a display scale preset with 15s revert confirmation
# omarchy:args=<1.0|1.25|1.5|1.6|1.75|2.0>
# omarchy:examples=omarchycn display scale 1.6
set -euo pipefail
preset="${1:?usage: omarchycn display scale <1.0|1.25|1.5|1.6|1.75|2.0>}"
case "$preset" in
1.0 | 1.25 | 1.5 | 1.6 | 1.75 | 2.0) ;;
*)
echo "Unknown preset: $preset (supported: 1.0 1.25 1.5 1.6 1.75 2.0)" >&2
exit 1
;;
esac
monitors="$HOME/.config/hypr/monitors.lua"
if [[ ! -f $monitors ]]; then
omarchy-refresh-config hypr/monitors.lua
fi
gdk=$(printf '%.0f' "$preset")
backup="$monitors.omarchycn-prev"
cp "$monitors" "$backup"
sed -i -E \
-e "s|^local omarchy_monitor_scale = .*|local omarchy_monitor_scale = $preset|" \
-e "s|^local omarchy_gdk_scale = .*|local omarchy_gdk_scale = $gdk|" \
"$monitors"
if ! grep -q "omarchy_monitor_scale = $preset" "$monitors"; then
mv "$backup" "$monitors"
echo "monitors.lua has no omarchy_monitor_scale line; reverted, edit it manually" >&2
exit 1
fi
echo "Monitor scale: $preset, GDK scale: $gdk"
if command -v hyprctl > /dev/null 2>&1 && hyprctl reload > /dev/null 2>&1; then
if [[ -t 0 ]]; then
echo "15 秒内按 y 保留新缩放,超时或按其他键自动恢复"
if read -r -t 15 -n 1 answer && [[ $answer == "y" ]]; then
rm -f "$backup"
echo "已保留"
else
mv "$backup" "$monitors"
hyprctl reload > /dev/null 2>&1
echo "已恢复原缩放"
exit 0
fi
else
rm -f "$backup"
fi
else
rm -f "$backup"
echo "Hyprland 未运行,重登录后生效"
fi