Adapted script to correctly detect the size of the monitor

This commit is contained in:
2026-02-28 18:11:46 +01:00
parent 7f9e5d9df0
commit 4eaa05f158
@@ -55,22 +55,20 @@ columnwidth_for_resolution() {
# Output format should be WIDTHxHEIGHT (e.g. 3840x1080).
get_monitor_resolution() {
local mon="$1"
# hyprctl monitors prints lines like:
# Monitor DP-1 (ID 0): 3840x1080@119.88 at 0x0 ...
# We'll extract the first WIDTHxHEIGHT after the colon.
local line
if ! line="$(hyprctl monitors 2>/dev/null | grep -F "Monitor ${mon} " -m1 || true)"; then
if ! line="$(hyprctl monitors 2>/dev/null | grep -A1 -E "^Monitor ${mon} " -m1 | tail -n1 || true)"; then
echo ""
return 0
fi
# Extract token like 3840x1080@... then strip @...
# Extract the resolution (e.g., 3840x1080) from the line
local token
token="$(awk -F': ' '{print $2}' <<<"$line" | awk '{print $1}' | cut -d'@' -f1 || true)"
token="$(echo "$line" | awk '{print $1}' | cut -d'@' -f1 || true)"
echo "$token"
}
resolution="$(get_monitor_resolution "$MONITOR")"
if [[ -z "$resolution" ]]; then
echo "Could not determine resolution for monitor '$MONITOR'."