mirror of
https://gitlab.com/dabruh/dotfiles.git
synced 2024-12-26 03:48:12 +01:00
Compare commits
7 commits
4973b9f4d2
...
7128f6c74e
Author | SHA1 | Date | |
---|---|---|---|
|
7128f6c74e | ||
|
b433ef57d3 | ||
|
fc71836102 | ||
|
0cab2a6640 | ||
|
1888ec9c96 | ||
|
da28a0e96e | ||
|
1237dff14a |
1 changed files with 53 additions and 8 deletions
|
@ -4,19 +4,40 @@
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Get the number of monitors connected to the system
|
_monitors=() # Cache for the xrandr output
|
||||||
get_monitor_count() {
|
|
||||||
xrandr --listmonitors | head -n1 | cut -d' ' -f2
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get the list of connected and disconnected monitors.
|
# Get the list of connected and disconnected monitors.
|
||||||
# Includes information about the primary monitor
|
# Includes information about the primary monitor
|
||||||
# E.g:
|
# E.g:
|
||||||
# eDP-1,connected,primary
|
# eDP-1,connected,primary,1920x1080+0+0,enabled
|
||||||
# HDMI-1,disconnected
|
# HDMI-1,disconnected,1920x1080+1920+0,enabled
|
||||||
# DP-1,disconnected
|
# DP-1,disconnected,disabled
|
||||||
_get_monitors() {
|
_get_monitors() {
|
||||||
xrandr | grep -Eo '^.* ((dis|)connected)( primary|) ' | sed 's/ /,/g' | sed 's/,$//g'
|
local monitors enabled_regex="[[:digit:]]+x[[:digit:]]+\+[[:digit:]]+\+[[:digit:]]+" # Regex for enabled monitors
|
||||||
|
|
||||||
|
# Use caching to avoid multiple calls to xrandr
|
||||||
|
if [ ${#_monitors[@]} -eq 0 ]; then
|
||||||
|
# Get the list of connected and disconnected monitors
|
||||||
|
monitors=$(xrandr | grep -Eo "^.* ((dis|)connected)( primary|) ($enabled_regex|)" | sed 's/ /,/g' | sed 's/,$//g')
|
||||||
|
|
||||||
|
for monitor in $monitors; do
|
||||||
|
# Set "enabled" if it matches the enabled regex and remove the matching string, else set "disabled"
|
||||||
|
if [[ "$monitor" =~ $enabled_regex ]]; then
|
||||||
|
monitor="$monitor,enabled"
|
||||||
|
else
|
||||||
|
monitor="$monitor,disabled"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add to the list of monitors
|
||||||
|
_monitors+=("$monitor")
|
||||||
|
done
|
||||||
|
|
||||||
|
# _monitors="$monitors"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for monitor in "${_monitors[@]}"; do
|
||||||
|
echo "$monitor"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function that gets all monitors and takes an optional amount of arguments to filter the list.
|
# Function that gets all monitors and takes an optional amount of arguments to filter the list.
|
||||||
|
@ -82,6 +103,19 @@ monitors_exist() {
|
||||||
return 0
|
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")"
|
||||||
|
xrandr --output "$(cut -d',' -f1 <<<"$monitor")" --off
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# Get the list of USB devices using lsusb, outputs for example "06cb:00f0 Synaptics, Inc."
|
# Get the list of USB devices using lsusb, outputs for example "06cb:00f0 Synaptics, Inc."
|
||||||
get_usb_devices() {
|
get_usb_devices() {
|
||||||
lsusb | grep -Eo ' ID .*' | cut -d' ' -f3-
|
lsusb | grep -Eo ' ID .*' | cut -d' ' -f3-
|
||||||
|
@ -326,6 +360,16 @@ main() {
|
||||||
--output "${monitor_array[0]}" --mode 2560x1440 --rotate normal --pos 0x480 --primary \
|
--output "${monitor_array[0]}" --mode 2560x1440 --rotate normal --pos 0x480 --primary \
|
||||||
--output "${monitor_array[1]}" --mode 3440x1440 --rotate normal --pos 2560x480 \
|
--output "${monitor_array[1]}" --mode 3440x1440 --rotate normal --pos 2560x480 \
|
||||||
--output "${monitor_array[2]}" --mode 1920x1200 --rotate right --pos 6000x0
|
--output "${monitor_array[2]}" --mode 1920x1200 --rotate right --pos 6000x0
|
||||||
|
profile_found=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
monitor_array=(DP-3-3 eDP-1 DP-3-1)
|
||||||
|
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
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -334,6 +378,7 @@ main() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
disable_disconnected_monitors
|
||||||
move_nonexistent_i3_workspaces "$primary_monitor" 10
|
move_nonexistent_i3_workspaces "$primary_monitor" 10
|
||||||
i3-msg restart >/dev/null
|
i3-msg restart >/dev/null
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue