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 manage monitor arrangement
|
|
|
|
manage_arrangement() {
|
|
|
|
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
|
|
|
|
|
|
|
clear
|
2024-09-12 21:14:50 +01:00
|
|
|
printf "%b\n" "${YELLOW}=========================================${RC}"
|
|
|
|
printf "%b\n" "${YELLOW} Manage Monitor Arrangement${RC}"
|
|
|
|
printf "%b\n" "${YELLOW}=========================================${RC}"
|
|
|
|
printf "%b\n" "${YELLOW}Choose the monitor to arrange:${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-18 19:30:49 +01:00
|
|
|
printf "Enter the number of the monitor to arrange: "
|
|
|
|
read -r monitor_choice
|
2024-08-05 20:24:05 +01:00
|
|
|
|
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.${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
monitor_name=$(echo "$monitor_array" | cut -d' ' -f"$monitor_choice")
|
2024-08-05 20:24:05 +01:00
|
|
|
|
|
|
|
clear
|
2024-09-12 21:14:50 +01:00
|
|
|
printf "%b\n" "${YELLOW}Choose position relative to other monitors:${RC}"
|
|
|
|
printf "%b\n" "1. ${YELLOW}Left of${RC}"
|
|
|
|
printf "%b\n" "2. ${YELLOW}Right of${RC}"
|
|
|
|
printf "%b\n" "3. ${YELLOW}Above${RC}"
|
|
|
|
printf "%b\n" "4. ${YELLOW}Below${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
|
2024-09-18 19:30:49 +01:00
|
|
|
printf "Enter the number of the position: "
|
|
|
|
read -r position_choice
|
2024-08-05 20:24:05 +01:00
|
|
|
|
|
|
|
case $position_choice in
|
|
|
|
1) position="--left-of" ;;
|
|
|
|
2) position="--right-of" ;;
|
|
|
|
3) position="--above" ;;
|
|
|
|
4) position="--below" ;;
|
2024-09-12 21:14:50 +01:00
|
|
|
*) printf "%b\n" "${RED}Invalid selection.${RC}"; return ;;
|
2024-08-05 20:24:05 +01:00
|
|
|
esac
|
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
printf "%b\n" "${YELLOW}Choose the reference monitor:${RC}"
|
|
|
|
for i in $monitor_array; do
|
|
|
|
if [ "$i" != "$monitor_name" ]; then
|
|
|
|
printf "%b\n" "$((i + 1)). ${YELLOW}$i${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2024-09-18 19:30:49 +01:00
|
|
|
printf "Enter the number of the reference monitor: "
|
|
|
|
read -r ref_choice
|
2024-08-05 20:24:05 +01:00
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
if ! echo "$ref_choice" | grep -qE '^[0-9]+$' || [ "$ref_choice" -lt 1 ] || [ "$ref_choice" -gt "$((i - 1))" ] || [ "$ref_choice" -eq "$monitor_choice" ]; then
|
|
|
|
printf "%b\n" "${RED}Invalid selection.${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
ref_monitor=$(echo "$monitor_array" | cut -d' ' -f"$ref_choice")
|
2024-08-05 20:24:05 +01:00
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
if confirm_action "Arrange ${YELLOW}$monitor_name${RC} ${position} ${YELLOW}$ref_monitor${RC}?"; then
|
|
|
|
printf "%b\n" "${GREEN}Arranging $monitor_name ${position} $ref_monitor${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
execute_command "xrandr --output $monitor_name $position $ref_monitor"
|
2024-09-12 21:14:50 +01:00
|
|
|
printf "%b\n" "${GREEN}Arrangement updated successfully.${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
else
|
2024-09-12 21:14:50 +01:00
|
|
|
printf "%b\n" "${RED}Action canceled.${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Call the manage_arrangement function
|
|
|
|
manage_arrangement
|