Files
local-bin/setup_screen_hypr.sh

38 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
set -eu
handle() {
case $1 in
monitoradded*)
disable_integrated_display_if_connected_to_external_monitors
;;
monitorremoved*)
disable_integrated_display_if_connected_to_external_monitors
;;
esac
}
disable_integrated_display_if_connected_to_external_monitors() {
MONITORS=$(hyprctl monitors all -j | jq ".[] | {name: .name, mode: .availableModes[0]}")
NUMBER_OF_MONITORS=$(echo "$MONITORS" | grep -c "name")
if [ "$NUMBER_OF_MONITORS" -gt 1 ]; then
hyprctl keyword monitor eDP-1, disabled
else
hyprctl keyword monitor eDP-1, highres highrr, auto, 1
fi
pkill waybar || true
waybar &
# reload the inputs, as they somehow get lost when a second monitor is attached
sleep 2
sudo udevadm trigger --action=remove --subsystem-match=input
sleep 0.5
sudo udevadm trigger --action=add --subsystem-match=input
}
disable_integrated_display_if_connected_to_external_monitors
socat -U - "UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" | while read -r line; do handle "$line"; done