I tried making a script to auto update display settings when pluging a second monitor
I made a rofi menu along with a script that auto updates display settings, I especially needed this because I use my laptop for uni and when doing presentations.
I have a second screen at home and when it's plugged, by default it works as "extend".
The problem I'm facing is when I put the settings as "mirror" and then put it as "extend", waybar disappears and sometimes even the wallpaper doesn't show up. I'm using awww as wallpaper manager.
This is my rofi script, can anyone help me with this?
#!/usr/bin/env bash
dir="$HOME/.config/rofi/displaymenu"
theme='config'
HYPRCONF="$HOME/.config/hypr/conf/monitors.conf"
# Auto detect external monitor
EXT_NAME=$(hyprctl monitors all -j | jq -r '[.[] | select(.name | test("eDP|LVDS|DSI") | not)] | .[0].name')
# Options
extend=' Extend'
mirror=' Mirror'
internal=' Internal Only'
external=' External Only'
rofi_cmd() {
rofi -dmenu \
-p " Display" \
-mesg "External: ${EXT_NAME:-not detected}" \
-theme ${dir}/${theme}.rasi
}
run_rofi() {
echo -e "$extend\n$mirror\n$internal\n$external" | rofi_cmd
}
# Check if external monitor is connected
check_external() {
if [ -z "$EXT_NAME" ] || [ "$EXT_NAME" == "null" ]; then
notify-send "Display" "No external monitor detected!"
exit 1
fi
}
chosen="$(run_rofi)"
case ${chosen} in
$extend)
check_external
echo "monitor=eDP-1,1920x1080@144.15,0x0,1.0
monitor=$EXT_NAME,preferred,1920x0,1.0
monitor=,preferred,auto,1" > "$HYPRCONF"
hyprctl reload
;;
$mirror)
check_external
echo "monitor=eDP-1,1920x1080@144.15,0x0,1.0
monitor=$EXT_NAME,preferred,0x0,1,mirror,eDP-1
monitor=,preferred,auto,1" > "$HYPRCONF"
hyprctl reload
;;
$internal)
echo "monitor=eDP-1,1920x1080@144.15,0x0,1.0
monitor=,disabled" > "$HYPRCONF"
hyprctl reload
;;
$external)
check_external
echo "monitor=eDP-1,disabled
monitor=$EXT_NAME,preferred,0x0,1.0
monitor=,preferred,auto,1" > "$HYPRCONF"
hyprctl reload
;;
esac
Posted Feb 25, 2026, 9:06 PM UTC
38