Skip to content

Instantly share code, notes, and snippets.

@aron-hoogeveen
Last active November 29, 2025 16:54
Show Gist options
  • Select an option

  • Save aron-hoogeveen/217b6d5d7e25bfda606eee94347ba6b6 to your computer and use it in GitHub Desktop.

Select an option

Save aron-hoogeveen/217b6d5d7e25bfda606eee94347ba6b6 to your computer and use it in GitHub Desktop.
Hyprland disable/enable display on HDMI connect/disconnect

A small setup for Hyprland to disable a monitor (e.g. the laptop buildin screen) using hyprctl when a second screen is connected, and to re-enable the screen when all external displays have been disconnected.

  1. Create the file switcher.sh in your preferred directory (e.g. /home/yourusername/scripts/).
  2. Create the file hypr-display-switcher.service in /etc/systemd/user/.
  3. Create the file hyprland-display-switcher.rules in /etc/udev/rules.d/.
  4. (optional) Make sure that on every login the environment value HYPR_BUILDIN_MON is set to your preferred settings.
  5. Add exec-once = /path/to/switcher.sh to your hyprland config, so it get's set up when you log in.
  6. Reload the systemd daemon with systemctl daemon-reload.
  7. Test the setup by (un)plugging a display to your computer.

See also

https://wiki.archlinux.org/title/Udev

RedHat systemd documentation

[Unit]
Description=Enables/disables the buildin display when connecting/disconnecting an HDMI cable.
[Service]
Type=oneshot
ExecStart=/full/path/to/switcher.sh
ACTION=="change", SUBSYSTEM=="drm", TAG+="systemd", ENV{SYSTEMD_USER_WANTS}="hypr-display-switcher.service"
#!/bin/sh
# This script uses an optional environment variable $HYPR_BUILDIN_MON. If it is available, it is
# used to re-enable your display. Otherwise, the default setting ($DEFAULT_BUILDIN_ENABLE) is
# used.
BUILDIN_DISPLAY_NAME="eDP-2" # Get the name of your buildin display using "hyprctl monitors all"
DEFAULT_BUILDIN_ENABLE="$BUILDIN_DISPLAY_NAME, highresxhighrr, 0x0, 1"
num_of_monitors=$(hyprctl monitors all | grep Monitor | wc -l) # this might break in the feature
# or for different setups.
if [[ $num_of_monitors -gt 1 ]]; then
# disable buildin monitor
hyprctl keyword monitor "$BUILDIN_DISPLAY_NAME, disable"
else
# re-enable buildin monitor
if [[ -z "$HYPR_BUILDIN_MON" ]]; then
# use default settings
hyprctl keyword monitor "$DEFAULT_BUILDIN_ENABLE"
else
# use environment settings
hyprctl keyword monitor "$HYPR_BUILDIN_MON"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment