Audit monitor scaling changes
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
# omarchy:examples=omarchy hyprland monitor scaling | omarchy hyprland monitor scaling 1.6 | omarchy hyprland monitor scaling up | omarchy hyprland monitor scaling down
|
||||
|
||||
SCALES=(1 1.25 1.6 2 3 4)
|
||||
STATE_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/omarchy"
|
||||
SCALE_LOG="$STATE_DIR/monitor-scaling.log"
|
||||
|
||||
usage() {
|
||||
echo "Usage: omarchy-hyprland-monitor-scaling [up|down|1|1.25|1.6|2|3|4]"
|
||||
@@ -14,16 +16,55 @@ focused_monitor_scale() {
|
||||
hyprctl monitors -j | jq -er '.[] | select(.focused == true) | .scale'
|
||||
}
|
||||
|
||||
cmdline_for_pid() {
|
||||
local pid="$1"
|
||||
|
||||
[[ -r /proc/$pid/cmdline ]] || return 0
|
||||
tr '\0\t\n' ' ' <"/proc/$pid/cmdline" | sed -E 's/[[:space:]]+/ /g; s/[[:space:]]+$//'
|
||||
}
|
||||
|
||||
audit_scale_change() {
|
||||
local requested="$1"
|
||||
local active_monitor="$2"
|
||||
local current_scale="$3"
|
||||
local new_scale="$4"
|
||||
local parent_pid="$PPID"
|
||||
local grandparent_pid
|
||||
local parent_cmd
|
||||
local grandparent_cmd
|
||||
|
||||
mkdir -p "$STATE_DIR" || return 0
|
||||
|
||||
grandparent_pid=$(ps -o ppid= -p "$parent_pid" 2>/dev/null | tr -d ' ')
|
||||
parent_cmd=$(cmdline_for_pid "$parent_pid")
|
||||
grandparent_cmd=$(cmdline_for_pid "$grandparent_pid")
|
||||
|
||||
printf 'at=%s\trequested=%s\tcurrent=%s\tnew=%s\tmonitor=%s\tpid=%s\tppid=%s\tparent=%s\tgppid=%s\tgrandparent=%s\n' \
|
||||
"$(date --iso-8601=seconds)" \
|
||||
"$requested" \
|
||||
"$current_scale" \
|
||||
"$new_scale" \
|
||||
"$active_monitor" \
|
||||
"$$" \
|
||||
"$parent_pid" \
|
||||
"$parent_cmd" \
|
||||
"$grandparent_pid" \
|
||||
"$grandparent_cmd" >>"$SCALE_LOG"
|
||||
}
|
||||
|
||||
set_scale() {
|
||||
local new_scale="$1"
|
||||
local requested="${2:-$new_scale}"
|
||||
local monitor_info="$(hyprctl monitors -j | jq -e -c '.[] | select(.focused == true)')"
|
||||
local active_monitor="$(echo "$monitor_info" | jq -r '.name')"
|
||||
local current_scale="$(echo "$monitor_info" | jq -r '.scale')"
|
||||
local width="$(echo "$monitor_info" | jq -r '.width')"
|
||||
local height="$(echo "$monitor_info" | jq -r '.height')"
|
||||
local refresh_rate="$(echo "$monitor_info" | jq -r '.refreshRate')"
|
||||
local monitor_lua="$HOME/.config/hypr/monitors.lua"
|
||||
|
||||
hyprctl eval "hl.monitor({ output = \"$active_monitor\", mode = \"${width}x${height}@${refresh_rate}\", position = \"auto\", scale = $new_scale })" >/dev/null
|
||||
audit_scale_change "$requested" "$active_monitor" "$current_scale" "$new_scale"
|
||||
|
||||
# Persist to monitors.lua if the user still has Omarchy's generic catch-all
|
||||
# defaults, so the scale survives reboots.
|
||||
@@ -84,13 +125,13 @@ case "${1:-}" in
|
||||
usage
|
||||
;;
|
||||
up)
|
||||
set_scale "$(focused_monitor_scale | scale_from_current next)"
|
||||
set_scale "$(focused_monitor_scale | scale_from_current next)" "up"
|
||||
;;
|
||||
down)
|
||||
set_scale "$(focused_monitor_scale | scale_from_current previous)"
|
||||
set_scale "$(focused_monitor_scale | scale_from_current previous)" "down"
|
||||
;;
|
||||
1 | 1.25 | 1.6 | 2 | 3 | 4)
|
||||
set_scale "$1"
|
||||
set_scale "$1" "$1"
|
||||
;;
|
||||
*)
|
||||
usage >&2
|
||||
|
||||
@@ -11,6 +11,7 @@ stub_bin="$test_tmp/bin"
|
||||
eval_out="$test_tmp/hyprctl-eval"
|
||||
home_dir="$test_tmp/home"
|
||||
monitor_lua="$home_dir/.config/hypr/monitors.lua"
|
||||
scale_log="$home_dir/.local/state/omarchy/monitor-scaling.log"
|
||||
|
||||
mkdir -p "$stub_bin" "$home_dir/.config/hypr"
|
||||
|
||||
@@ -36,6 +37,7 @@ LUA
|
||||
|
||||
run_scaling() {
|
||||
HOME="$home_dir" \
|
||||
XDG_STATE_HOME="$home_dir/.local/state" \
|
||||
PATH="$stub_bin:$PATH" \
|
||||
OMARCHY_TEST_HYPRCTL_EVAL_OUT="$eval_out" \
|
||||
OMARCHY_TEST_MONITOR_SCALE="${OMARCHY_TEST_MONITOR_SCALE:-2}" \
|
||||
@@ -46,6 +48,7 @@ write_monitor_config
|
||||
OMARCHY_TEST_MONITOR_SCALE=2 run_scaling up
|
||||
grep -F 'scale = 3' "$eval_out" >/dev/null || fail "monitor scaling up reaches 3x"
|
||||
grep -Fx 'local omarchy_monitor_scale = 3' "$monitor_lua" >/dev/null || fail "monitor scaling up persists 3x"
|
||||
grep -F $'requested=up\tcurrent=2\tnew=3\tmonitor=eDP-1' "$scale_log" >/dev/null || fail "monitor scaling up writes audit log"
|
||||
pass "monitor scaling up reaches 3x"
|
||||
|
||||
write_monitor_config
|
||||
|
||||
Reference in New Issue
Block a user