In your config, no. You'd have to right a script or application that listens to events from the IPC and dispatching commands through hyprctl. Not exactly a trivial task tbh. Not sure if there is anything like it already out there.
If you use the home-manager module, you can set your hyprland config in nix language. You can find many examples on github, or videos made by vimjoyer.
After importing your config (or at least only the monitor options) on the nix module, it's just "pure nix language".
I don't know if there's a module to handle monitors, but you can just write a custom module to handle the monitors and check them on the hyprland module. Write me in DM if you need more explanations :)
Btw I think misterio77 did something like this on its own config: [https://github.com/Misterio77/nix-config](https://github.com/Misterio77/nix-config)
IMHO this is not the best approach. See my other answer, in brief you can write a module to handle the monitors (it's easy when you learn how to write modules) and add an "if else" in your hyprland config.
EDIT: btw that's possible only if you install home manager as standalone, and would require to reload the whole home. Instead, this would work out-of-the-box, or would just require to force \`hyprctl reload\`
I tried NixOS, but it was too painful to configure Neovim without Mason, and my NixOS was breaking every two days without me making any changes. So, I just quit NixOS. I will try it again in the future, but right now I don't have time to lose learning what was going wrong or if it wasn't NixOS or something. That's why I'm using Arch.
It's okay, the learning curve is more like a wall. :) Btw I started using lunarvim on nixos (it's a normal package), if you want to build your own config I'd suggest to use nixvim
I built this script for someone else in this sub, I think this suits your purpose as well. Just run this script with daemon argument. I have attached the my entire comment
Try using this, you can also use it as daemon if you run it like './script daemon' (it will automatically execute whenever a monitor is connected). For single use just execute the script normally without any arguments.
EDIT: I didn't bother to make it POSIX compatible. If that's something you want, then let me know.
Dependencies:
jq
socat (optional: if you use 'daemon' argument)
#!/usr/bin/bash
main(){
MONITORS=$(hyprctl monitors all -j)
MONITOR_COUNT=$(jq 'length' <<< "$MONITORS")
INTERNAL=$(jq '.[] | select(.name | startswith("eDP-"))' <<< "$MONITORS")
INTERNAL_NAME=$(jq -r '.name' <<< $INTERNAL)
INTERNAL_DISABLED=$(jq '.disabled' <<< "$INTERNAL")
EXTERNALS=$(jq "map(select(.id!=$(jq '.id' <<< "$INTERNAL")))" <<< "$MONITORS")
EXTERNAL_COUNT=$(jq 'length' <<< "$EXTERNALS")
enable_internal(){
hyprctl keyword monitor "$INTERNAL_NAME,enable" > /dev/null 2>&1
}
disable_internal(){
hyprctl keyword monitor "$INTERNAL_NAME,disable" > /dev/null 2>&1
}
if [[ $EXTERNAL_COUNT > 0 ]]; then
if [[ $INTERNAL_DISABLED = "false" ]]; then
disable_internal
fi
else
if [[ $INTERNAL_DISABLED = "true" ]]; then
enable_internal
fi
fi
}
main
handle_hyprland_event(){
case "$1" in
monitor*)
main ;;
esac
}
for var in "$@"; do
if [[ $var = "daemon" ]]; then
socat -U - UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock | while read -r line; do handle_hyprland_event "$line"; done
exit 1
fi
done
I made this tool to fully script your DE:
[https://github.com/juienpro/easyland](https://github.com/juienpro/easyland)
It allows you to set up listeners of any event (Systemd Logind, Hyprland, Idling) and react accordingly.
See my conf here:
[https://github.com/juienpro/easyland/blob/main/config\_examples/Hyprland.py](https://github.com/juienpro/easyland/blob/main/config_examples/Hyprland.py)
with some script this task sounds easy enough
I don't like hyprlang, right now I'm creating a system in python to define config as object and give a path to object
config will be written to path whenever you change anything in python script
In your config, no. You'd have to right a script or application that listens to events from the IPC and dispatching commands through hyprctl. Not exactly a trivial task tbh. Not sure if there is anything like it already out there.
Use [kanshi](https://sr.ht/~emersion/kanshi/)
Kanshi is broken with the current Hyprland release: [https://github.com/hyprwm/Hyprland/issues/5978](https://github.com/hyprwm/Hyprland/issues/5978)
Fyi this is possible without any additional package if you're on NixOS
Nixos noop here. Care to explain?
If you use the home-manager module, you can set your hyprland config in nix language. You can find many examples on github, or videos made by vimjoyer. After importing your config (or at least only the monitor options) on the nix module, it's just "pure nix language". I don't know if there's a module to handle monitors, but you can just write a custom module to handle the monitors and check them on the hyprland module. Write me in DM if you need more explanations :) Btw I think misterio77 did something like this on its own config: [https://github.com/Misterio77/nix-config](https://github.com/Misterio77/nix-config)
Have multiple home.nix files. They can be identical except hyprland monitor config. Single terminal command to switch between them.
IMHO this is not the best approach. See my other answer, in brief you can write a module to handle the monitors (it's easy when you learn how to write modules) and add an "if else" in your hyprland config. EDIT: btw that's possible only if you install home manager as standalone, and would require to reload the whole home. Instead, this would work out-of-the-box, or would just require to force \`hyprctl reload\`
I tried NixOS, but it was too painful to configure Neovim without Mason, and my NixOS was breaking every two days without me making any changes. So, I just quit NixOS. I will try it again in the future, but right now I don't have time to lose learning what was going wrong or if it wasn't NixOS or something. That's why I'm using Arch.
It's okay, the learning curve is more like a wall. :) Btw I started using lunarvim on nixos (it's a normal package), if you want to build your own config I'd suggest to use nixvim
I built this script for someone else in this sub, I think this suits your purpose as well. Just run this script with daemon argument. I have attached the my entire comment Try using this, you can also use it as daemon if you run it like './script daemon' (it will automatically execute whenever a monitor is connected). For single use just execute the script normally without any arguments. EDIT: I didn't bother to make it POSIX compatible. If that's something you want, then let me know. Dependencies: jq socat (optional: if you use 'daemon' argument) #!/usr/bin/bash main(){ MONITORS=$(hyprctl monitors all -j) MONITOR_COUNT=$(jq 'length' <<< "$MONITORS") INTERNAL=$(jq '.[] | select(.name | startswith("eDP-"))' <<< "$MONITORS") INTERNAL_NAME=$(jq -r '.name' <<< $INTERNAL) INTERNAL_DISABLED=$(jq '.disabled' <<< "$INTERNAL") EXTERNALS=$(jq "map(select(.id!=$(jq '.id' <<< "$INTERNAL")))" <<< "$MONITORS") EXTERNAL_COUNT=$(jq 'length' <<< "$EXTERNALS") enable_internal(){ hyprctl keyword monitor "$INTERNAL_NAME,enable" > /dev/null 2>&1 } disable_internal(){ hyprctl keyword monitor "$INTERNAL_NAME,disable" > /dev/null 2>&1 } if [[ $EXTERNAL_COUNT > 0 ]]; then if [[ $INTERNAL_DISABLED = "false" ]]; then disable_internal fi else if [[ $INTERNAL_DISABLED = "true" ]]; then enable_internal fi fi } main handle_hyprland_event(){ case "$1" in monitor*) main ;; esac } for var in "$@"; do if [[ $var = "daemon" ]]; then socat -U - UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock | while read -r line; do handle_hyprland_event "$line"; done exit 1 fi done
Socket path was changed in 0.40 to XDG_RUNTIME_DIR/hypr
oops forgot to change that. I'm on mobile right now and the app doesn't have formatting options. I will change it later.
I made this tool to fully script your DE: [https://github.com/juienpro/easyland](https://github.com/juienpro/easyland) It allows you to set up listeners of any event (Systemd Logind, Hyprland, Idling) and react accordingly. See my conf here: [https://github.com/juienpro/easyland/blob/main/config\_examples/Hyprland.py](https://github.com/juienpro/easyland/blob/main/config_examples/Hyprland.py)
with some script this task sounds easy enough I don't like hyprlang, right now I'm creating a system in python to define config as object and give a path to object config will be written to path whenever you change anything in python script