From fff49e747c91f7d9387af4808e409f8a450091a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Mon, 24 Aug 2026 19:46:26 -0400 Subject: [PATCH] Add display scale presets with revert confirmation Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01QKxGW1raAWaqeU8WdHsMsp --- bin/omarchy-cn-display-scale | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 bin/omarchy-cn-display-scale diff --git a/bin/omarchy-cn-display-scale b/bin/omarchy-cn-display-scale new file mode 100755 index 00000000..35d13f40 --- /dev/null +++ b/bin/omarchy-cn-display-scale @@ -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