2024-04-16 16:03:13 +02:00
|
|
|
#!/bin/bash
|
2024-05-24 10:42:28 +02:00
|
|
|
# shellcheck disable=SC1090
|
2024-04-16 16:03:13 +02:00
|
|
|
|
|
|
|
# This script is used to apply monitor profiles based on the connected monitors and USB devices.
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2024-05-24 10:42:28 +02:00
|
|
|
# Source the utility functions
|
|
|
|
source ~/.local/share/dabruh/libs/bash/x.sh
|
|
|
|
source ~/.local/share/dabruh/libs/bash/i3.sh
|
|
|
|
source ~/.local/share/dabruh/libs/bash/usb.sh
|
2024-04-16 16:03:13 +02:00
|
|
|
|
|
|
|
main() {
|
2024-05-24 10:42:28 +02:00
|
|
|
local primary_monitor monitor_count monitors=() profile_found=false
|
2024-04-16 16:03:13 +02:00
|
|
|
primary_monitor=$(get_monitors primary | cut -d',' -f1)
|
|
|
|
monitor_count=$(get_monitors connected | wc -l)
|
|
|
|
echo "Monitors connected: $monitor_count"
|
|
|
|
|
|
|
|
if [ "$monitor_count" -eq 1 ]; then
|
|
|
|
echo "Applying laptop-only profile"
|
|
|
|
xrandr --auto
|
2024-04-17 16:05:25 +02:00
|
|
|
profile_found=true
|
2024-04-18 19:46:27 +02:00
|
|
|
elif usb_devices_exist all exact "HP, Inc HP USB-C Universal Dock" >/dev/null 2>&1; then
|
2024-04-17 16:05:25 +02:00
|
|
|
monitors=(
|
|
|
|
"eDP-1,DVI-I-1-1,DVI-I-2-2"
|
|
|
|
"eDP-1,DVI-I-2-2,DVI-I-3-3"
|
|
|
|
)
|
|
|
|
|
|
|
|
for monitor in "${monitors[@]}"; do
|
|
|
|
IFS=',' read -r -a monitor_array <<<"$monitor"
|
2024-04-17 18:33:43 +02:00
|
|
|
if monitors_exist "${monitor_array[@]}" >/dev/null; then
|
2024-04-18 19:46:27 +02:00
|
|
|
echo "Applying work profile for ${monitor_array[*]}"
|
2024-04-17 16:05:25 +02:00
|
|
|
xrandr \
|
|
|
|
--output "${monitor_array[0]}" --mode 1920x1200 --rotate normal --pos 1200x1474 --primary \
|
|
|
|
--output "${monitor_array[1]}" --mode 1920x1200 --rotate left --pos 0x0 \
|
|
|
|
--output "${monitor_array[2]}" --mode 1920x1200 --rotate normal --pos 1200x274
|
|
|
|
profile_found=true
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2024-04-18 19:46:27 +02:00
|
|
|
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
|
|
|
|
echo "Applying home profile for ${monitor_array[*]}"
|
|
|
|
xrandr \
|
|
|
|
--output "${monitor_array[0]}" --mode 2560x1440 --rotate normal --pos 0x480 --primary \
|
|
|
|
--output "${monitor_array[1]}" --mode 3440x1440 --rotate normal --pos 2560x480 \
|
|
|
|
--output "${monitor_array[2]}" --mode 1920x1200 --rotate right --pos 6000x0
|
2024-04-19 08:35:27 +02:00
|
|
|
profile_found=true
|
|
|
|
fi
|
|
|
|
|
2024-04-26 10:07:02 +02:00
|
|
|
monitors=(
|
|
|
|
"DP-3-3,eDP-1,DP-3-1"
|
|
|
|
"DP-1-3,eDP-1,DP-1-1"
|
|
|
|
)
|
|
|
|
|
|
|
|
for monitor in "${monitors[@]}"; do
|
|
|
|
IFS=',' read -r -a monitor_array <<<"$monitor"
|
2024-04-19 08:35:27 +02:00
|
|
|
if monitors_exist "${monitor_array[@]}" >/dev/null; then
|
|
|
|
xrandr \
|
|
|
|
--output "${monitor_array[0]}" --mode 3440x1440 --pos 0x480 --rotate normal \
|
|
|
|
--output "${monitor_array[1]}" --mode 1920x1200 --pos 3440x720 --rotate normal --primary \
|
|
|
|
--output "${monitor_array[2]}" --mode 1920x1200 --pos 5360x0 --rotate right
|
|
|
|
profile_found=true
|
2024-04-18 19:46:27 +02:00
|
|
|
fi
|
2024-04-26 10:07:02 +02:00
|
|
|
done
|
2024-04-17 16:05:25 +02:00
|
|
|
fi
|
|
|
|
|
2024-04-19 08:40:40 +02:00
|
|
|
if ! "$profile_found"; then
|
2024-04-16 16:03:13 +02:00
|
|
|
echo "No profile found"
|
2024-04-17 16:05:25 +02:00
|
|
|
return 1
|
2024-04-16 16:03:13 +02:00
|
|
|
fi
|
|
|
|
|
2024-04-19 08:40:40 +02:00
|
|
|
disable_disconnected_monitors
|
2024-04-16 16:03:13 +02:00
|
|
|
move_nonexistent_i3_workspaces "$primary_monitor" 10
|
2024-04-17 16:03:36 +02:00
|
|
|
i3-msg restart >/dev/null
|
2024-04-16 16:03:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Run if invoked directly
|
|
|
|
if [ "$0" = "${BASH_SOURCE[0]}" ]; then
|
|
|
|
main
|
|
|
|
fi
|