Last active
April 12, 2024 07:49
-
-
Save dr0bz/4f8bf8b8829506cf26d4e2acc770e5af to your computer and use it in GitHub Desktop.
Hyprland waybar switch by monitor hotpluging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This script is for people like me running a laptop with external monitor and using the | |
# external monitor as the main output. As main output I want to have the waybar show up | |
# on it. With this script you get waybar on external monitor and when you unplug it - it | |
# will automatically change the display to Your display and vice versa. | |
# | |
# just put the following into your hyprland.conf: | |
# exec-once = waybar | |
# exec-once = ~/.config/hypr/scripts/waybar-monitor-switch.sh | |
# stop running it twice | |
scriptname=$(basename $0) | |
running_count=$(ps aux | grep -i "${scriptname}" | grep -v "grep" | wc -l) | |
if [ $running_count -gt 2 ]; then | |
exit | |
fi | |
external_output='"DP-5", "DP-6"' | |
laptop_output='"eDP-1"' | |
function handle { | |
case $1 in | |
monitoraddedv2*) | |
sed -i "s/\"output.*/\"output\": \[${external_output}\],/" ~/.config/waybar/config | |
sleep 2 | |
killall waybar ; waybar & | |
;; | |
monitorremoved*) | |
sed -i "s/\"output.*/\"output\": \[${laptop_output}\],/" ~/.config/waybar/config | |
sleep 2 | |
killall waybar ; waybar & | |
;; | |
esac | |
} | |
socat -U - UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock | while read -r line; do handle "$line"; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment