2024-08-15 03:41:41 +01:00
|
|
|
#!/bin/sh -e
|
|
|
|
|
2024-08-21 08:18:34 +01:00
|
|
|
. ./utility_functions.sh
|
2024-08-05 20:24:05 +01:00
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
. ../../common-script.sh
|
|
|
|
|
2024-08-05 20:24:05 +01:00
|
|
|
# Function to auto-detect displays and set common resolution
|
|
|
|
auto_detect_displays() {
|
|
|
|
if confirm_action "Auto-detect displays and set common resolution?"; then
|
|
|
|
execute_command "xrandr --auto"
|
|
|
|
|
|
|
|
monitors=$(detect_connected_monitors)
|
|
|
|
first_monitor=$(echo "$monitors" | head -n 1)
|
|
|
|
common_resolutions=$(get_unique_resolutions "$first_monitor")
|
|
|
|
|
|
|
|
for monitor in $monitors; do
|
|
|
|
resolutions=$(get_unique_resolutions "$monitor")
|
2024-09-12 21:14:50 +01:00
|
|
|
temp_common_resolutions=$(mktemp)
|
|
|
|
temp_resolutions=$(mktemp)
|
|
|
|
|
2024-09-19 01:37:59 +01:00
|
|
|
printf "%s" "$common_resolutions" > "$temp_common_resolutions"
|
|
|
|
printf "%s" "$resolutions" > "$temp_resolutions"
|
2024-09-12 21:14:50 +01:00
|
|
|
|
|
|
|
common_resolutions=$(comm -12 "$temp_common_resolutions" "$temp_resolutions")
|
|
|
|
|
|
|
|
rm -f "$temp_common_resolutions" "$temp_resolutions"
|
2024-08-05 20:24:05 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "$common_resolutions" ]; then
|
2024-09-19 01:37:59 +01:00
|
|
|
printf "%b\n" "${RED}No common resolution found among connected monitors.${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
highest_resolution=$(echo "$common_resolutions" | sort -n -t'x' -k1,1 -k2,2 | tail -n 1)
|
|
|
|
|
|
|
|
for monitor in $monitors; do
|
2024-09-19 01:37:59 +01:00
|
|
|
printf "%b\n" "${YELLOW}Setting resolution for $monitor to $highest_resolution...${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
execute_command "xrandr --output $monitor --mode $highest_resolution"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
auto_detect_displays
|