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 set resolutions
|
|
|
|
set_resolutions() {
|
|
|
|
monitor_list=$(detect_connected_monitors)
|
2024-09-12 21:14:50 +01:00
|
|
|
monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
|
|
|
|
|
2024-08-05 20:24:05 +01:00
|
|
|
while true; do
|
|
|
|
clear
|
2024-09-12 21:14:50 +01:00
|
|
|
printf "%b\n" "${YELLOW}=========================================${RC}"
|
|
|
|
printf "%b\n" "${YELLOW} Monitor Configuration${RC}"
|
|
|
|
printf "%b\n" "${YELLOW}=========================================${RC}"
|
|
|
|
|
|
|
|
printf "%b\n" "${YELLOW}Choose a monitor to configure:${RC}"
|
|
|
|
i=1
|
|
|
|
for monitor in $monitor_array; do
|
|
|
|
printf "%b\n" "$i. ${YELLOW}$monitor${RC}"
|
|
|
|
i=$((i + 1))
|
2024-08-05 20:24:05 +01:00
|
|
|
done
|
|
|
|
|
2024-09-19 01:01:56 +01:00
|
|
|
printf "%b\n" "Enter the choice (or 'q' to quit): "
|
|
|
|
read -r monitor_choice
|
2024-08-05 20:24:05 +01:00
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
if [ "$monitor_choice" = "q" ]; then
|
|
|
|
printf "%b\n" "${RED}Exiting...${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
|
|
|
|
printf "%b\n" "${RED}Invalid selection. Please try again.${RC}"
|
2024-09-19 01:01:56 +01:00
|
|
|
printf "%b\n" "Press [Enter] to continue..."
|
|
|
|
read -r dummy
|
2024-08-05 20:24:05 +01:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
monitor_name=$(echo "$monitor_array" | cut -d' ' -f"$monitor_choice")
|
2024-08-29 22:04:21 +01:00
|
|
|
resolutions=$(get_unique_resolutions "$monitor_name" | sort -rn -t'x' -k1,1 -k2,2)
|
2024-08-05 20:24:05 +01:00
|
|
|
|
|
|
|
temp_res_file=$(mktemp)
|
2024-08-29 21:59:23 +01:00
|
|
|
echo "$resolutions" | awk '{print NR " " $0}' > "$temp_res_file"
|
2024-08-05 20:24:05 +01:00
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
i=1
|
|
|
|
while read -r resolution; do
|
2024-09-19 01:01:56 +01:00
|
|
|
echo "$resolution" >> "$temp_res_file"
|
2024-09-12 21:14:50 +01:00
|
|
|
i=$((i + 1))
|
2024-08-05 20:24:05 +01:00
|
|
|
done < "$temp_res_file"
|
|
|
|
|
|
|
|
clear
|
2024-09-12 21:14:50 +01:00
|
|
|
printf "%b\n" "${YELLOW}=========================================${RC}"
|
|
|
|
printf "%b\n" "${YELLOW} Resolution Configuration for ${YELLOW}$monitor_name${RC}"
|
|
|
|
printf "%b\n" "${YELLOW}=========================================${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
awk '{print $1 ". " $2}' "$temp_res_file"
|
|
|
|
|
|
|
|
while true; do
|
2024-09-19 01:01:56 +01:00
|
|
|
printf "%b\n" "Enter the choice (or 'q' to quit): "
|
|
|
|
read -r resolution_choice
|
2024-08-05 20:24:05 +01:00
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
if [ "$resolution_choice" = "q" ]; then
|
|
|
|
printf "%b\n" "${RED}Exiting...${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
rm "$temp_res_file"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
if ! echo "$resolution_choice" | grep -qE '^[0-9]+$' || [ "$resolution_choice" -lt 1 ] || [ "$resolution_choice" -gt "$((i - 1))" ]; then
|
|
|
|
printf "%b\n" "${RED}Invalid selection. Please try again.${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2024-09-19 01:01:56 +01:00
|
|
|
selected_resolution=$(awk "NR==$resolution_choice" "$temp_res_file")
|
2024-08-05 20:24:05 +01:00
|
|
|
|
2024-09-19 01:01:56 +01:00
|
|
|
printf "%b\n" "Set resolution for $monitor_name to $selected_resolution? (y/n): "
|
|
|
|
read -r confirm
|
2024-09-12 21:14:50 +01:00
|
|
|
if echo "$confirm" | grep -qE '^[Yy]$'; then
|
|
|
|
printf "%b\n" "${GREEN}Setting resolution for $monitor_name to $selected_resolution${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
execute_command "xrandr --output $monitor_name --mode $selected_resolution"
|
|
|
|
break
|
|
|
|
else
|
2024-09-12 21:14:50 +01:00
|
|
|
printf "%b\n" "${RED}Action canceled. Please choose a different resolution.${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
rm "$temp_res_file"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
set_resolutions
|