dotfiles/.local/bin/xmonconf

83 lines
3.0 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# shellcheck disable=SC1090
# This script is used to apply monitor profiles based on the connected monitors and USB devices.
set -euo pipefail
# 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
main() {
local primary_monitor monitor_count monitors=() profile_found=false
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
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
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"
if monitors_exist "${monitor_array[@]}" >/dev/null; then
2024-04-18 19:46:27 +02:00
echo "Applying work profile for ${monitor_array[*]}"
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
profile_found=true
fi
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"
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
done
fi
2024-04-19 08:40:40 +02:00
if ! "$profile_found"; then
echo "No profile found"
return 1
fi
2024-04-19 08:40:40 +02:00
disable_disconnected_monitors
move_nonexistent_i3_workspaces "$primary_monitor" 10
i3-msg restart >/dev/null
}
# Run if invoked directly
if [ "$0" = "${BASH_SOURCE[0]}" ]; then
main
fi