configuring a clamshell mode in hyprland
i've been using hyprland as my wayland compositor + window manager for several weeks now, and it's been pretty good so far. the project is pushing new releases often, and they have a very active discord server. there's a strong chance that this tip won't be relevant for very long, but here it is for what it's worth.
hyprland provides documentation for configuring multi-monitor setups, but i found that it didn't "just work" when it came to using my laptop in a clamshell configuration - that is, connecting an external monitor, keyboard, and mouse, and then closing the lid of the laptop. the expected behavior would be for the laptop screen to turn off, and shift all of the existing workspaces to the external monitor. in actuality, hyprland does not intelligently do this out of the box, but a small script can address the issue.
the hyprctl
utility provides an easy way of getting some information about connected hardware. by running hyprctl monitors
i can see that my laptop's built in monitor is called eDP-1
and my external desk monitor is DP-5
. in my hyprland.conf, they are configured like this:
monitor=eDP-1,1920x1080,2560x0,1
monitor=DP-5,2560x1440,0x0,1
this means that, when both monitors are connected, my laptop's screen is at an offset equal to the width of my desk monitor's horizontal resolution, placing it to the right of my desktop screen. when the laptop is disconnected from an external display, the offset is ignored.
with that said, here's a simple bash script that appropriately enables or disables the laptop screen when my desk monitor is present:
#!/usr/bin/env zsh
if [[ "$(hyprctl monitors)" =~ "\sDP-[0-9]+" ]]; then
if [[ $1 == "open" ]]; then
hyprctl keyword monitor "eDP-1,1920x1080,2560x0,1"
else
hyprctl keyword monitor "eDP-1,disable"
fi
fi
this script will fire when the lid is opened or closed. if my external monitor is present, and the argument passed to the script is "open," my laptop's monitor will be enabled.
as for how it runs when the lid is opened/closed, hyprland allows binds to the lid switch event, like so:
# Clamshell mode configuration
## Lid is opened
bindl=,switch:off:Lid Switch,exec,~/.config/hypr/lid.sh open
## Lid is closed
bindl=,switch:on:Lid Switch,exec,~/.config/hypr/lid.sh close
that's it! clamshell mode for hyprland.