#!/bin/bash # Get primary display name display=$(xrandr --query | awk '/ connected primary/{print $1}') # If no primary, use first connected if [ -z "$display" ]; then display=$(xrandr --query | awk '/ connected/{print $1; exit}') fi if [ -z "$display" ]; then echo "No connected display found." exit 1 fi # Get physical dimensions line for that display dim_line=$(xrandr --query | grep "^$display connected") # Extract width and height in mm width_mm=$(echo "$dim_line" | sed -n 's/.* \([0-9]\+\)mm x \([0-9]\+\)mm.*/\1/p') height_mm=$(echo "$dim_line" | sed -n 's/.* \([0-9]\+\)mm x \([0-9]\+\)mm.*/\2/p') if [ -z "$width_mm" ] || [ -z "$height_mm" ]; then echo "Could not determine physical screen size." exit 1 fi # Calculate diagonal in mm diagonal_mm=$(echo "scale=4; sqrt($width_mm^2 + $height_mm^2)" | bc -l) # Convert to inches diagonal_in=$(echo "scale=2; $diagonal_mm / 25.4" | bc -l) return ${diagonal_in%.*}