Add logic to disable disconnected monitors

This commit is contained in:
dabruh 2024-04-19 08:39:51 +02:00
parent 1237dff14a
commit da28a0e96e
1 changed files with 15 additions and 4 deletions

View File

@ -82,6 +82,18 @@ monitors_exist() {
return 0
}
# Disable all monitors that are not in the list of connected monitors
disable_disconnected_monitors() {
local connected_monitors
connected_monitors=$(get_monitors disconnected)
echo "Disabling disconnected monitors"
for monitor in $connected_monitors; do
echo "Disabling monitor $(cut -d',' -f1 <<<"$monitor")"
done
}
# Get the list of USB devices using lsusb, outputs for example "06cb:00f0 Synaptics, Inc."
get_usb_devices() {
lsusb | grep -Eo ' ID .*' | cut -d' ' -f3-
@ -309,7 +321,6 @@ main() {
for monitor in "${monitors[@]}"; do
IFS=',' read -r -a monitor_array <<<"$monitor"
if monitors_exist "${monitor_array[@]}" >/dev/null; then
# Add logic to disable disconnected monitors
echo "Applying work profile for ${monitor_array[*]}"
xrandr \
--output "${monitor_array[0]}" --mode 1920x1200 --rotate normal --pos 1200x1474 --primary \
@ -322,7 +333,6 @@ main() {
elif usb_devices_exist all exact "Lenovo ThinkPad USB-C Dock Audio" >/dev/null 2>&1; then
monitor_array=(eDP-1 DP-1-0.3 DP-1-0.1)
if monitors_exist "${monitor_array[@]}" >/dev/null; then
# Add logic to disable disconnected monitors
echo "Applying home profile for ${monitor_array[*]}"
xrandr \
--output "${monitor_array[0]}" --mode 2560x1440 --rotate normal --pos 0x480 --primary \
@ -333,7 +343,6 @@ main() {
monitor_array=(DP-3-3 eDP-1 DP-3-1)
if monitors_exist "${monitor_array[@]}" >/dev/null; then
# Add logic to disable disconnected monitors
xrandr \
--output "${monitor_array[0]}" --mode 3440x1440 --pos 0x480 --rotate normal \
--output "${monitor_array[1]}" --mode 1920x1200 --pos 3440x720 --rotate normal --primary \
@ -342,7 +351,9 @@ main() {
fi
fi
if ! "$profile_found"; then
if "$profile_found"; then
disable_disconnected_monitors
else
echo "No profile found"
return 1
fi