Verify display position restoration
This commit is contained in:
@@ -170,6 +170,8 @@ original_transform=""
|
||||
original_width=""
|
||||
original_height=""
|
||||
original_refresh=""
|
||||
original_x=""
|
||||
original_y=""
|
||||
monitor_name=""
|
||||
|
||||
monitor_state() {
|
||||
@@ -186,15 +188,18 @@ display_is_restored() {
|
||||
--argjson refresh "$original_refresh" \
|
||||
--argjson scale "$original_scale" \
|
||||
--argjson transform "$original_transform" \
|
||||
--argjson x "$original_x" \
|
||||
--argjson y "$original_y" \
|
||||
'.width == $width and .height == $height
|
||||
and ((.refreshRate - $refresh) | fabs) < 0.01
|
||||
and ((.scale - $scale) | fabs) < 0.001
|
||||
and .transform == $transform' <<<"$current" >/dev/null
|
||||
and .transform == $transform
|
||||
and .x == $x and .y == $y' <<<"$current" >/dev/null
|
||||
}
|
||||
|
||||
restore_display() {
|
||||
[[ -n "$original_mode" ]] || return 0
|
||||
hyprctl eval "hl.monitor({ output = \"$monitor_name\", mode = \"$original_mode\", scale = $original_scale, transform = $original_transform })" >/dev/null \
|
||||
hyprctl eval "hl.monitor({ output = \"$monitor_name\", mode = \"$original_mode\", position = \"${original_x}x${original_y}\", scale = $original_scale, transform = $original_transform })" >/dev/null \
|
||||
|| return 1
|
||||
for _ in $(seq 1 50); do
|
||||
display_is_restored && return 0
|
||||
@@ -215,8 +220,9 @@ cleanup() {
|
||||
local status=$?
|
||||
trap - EXIT
|
||||
if ! restore_display; then
|
||||
printf 'displays contract: FAILED to restore %s to %s scale %s transform %s\n' \
|
||||
"$monitor_name" "$original_mode" "$original_scale" "$original_transform" >&2
|
||||
printf 'displays contract: FAILED to restore %s to %s at %sx%s scale %s transform %s\n' \
|
||||
"$monitor_name" "$original_mode" "$original_x" "$original_y" \
|
||||
"$original_scale" "$original_transform" >&2
|
||||
status=1
|
||||
fi
|
||||
stop_harness
|
||||
@@ -262,6 +268,8 @@ original_height="$(jq -r .height <<<"$state")"
|
||||
original_refresh="$(jq -r .refresh <<<"$state")"
|
||||
original_scale="$(jq -r .scale <<<"$state")"
|
||||
original_transform="$(jq -r .transform <<<"$state")"
|
||||
original_x="$(jq -r .x <<<"$state")"
|
||||
original_y="$(jq -r .y <<<"$state")"
|
||||
|
||||
[[ "$(jq -r .modes <<<"$state")" -gt 0 ]] || fail 'the display reported no usable modes'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user