From 76ad137946ab5a6d414ee2dea9ee277e4ea8e009 Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Sun, 19 Jul 2026 09:08:50 +0200 Subject: [PATCH] hyprland: make monitor config dependent on config.monitors --- homes/julian/features/hyprland/default.nix | 19 ++++++++++++++++--- homes/julian/features/hyprland/hyprland.lua | 13 ------------- .../hyprland/toggle-screen-mirroring.sh | 15 +++++++-------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/homes/julian/features/hyprland/default.nix b/homes/julian/features/hyprland/default.nix index d7c735c..dbebb4f 100644 --- a/homes/julian/features/hyprland/default.nix +++ b/homes/julian/features/hyprland/default.nix @@ -60,9 +60,13 @@ wf-recorder wl-clipboard - (pkgs.writeShellScriptBin "toggle-screen-mirroring" ( - builtins.readFile ./toggle-screen-mirroring.sh - )) + (pkgs.writeShellScriptBin "toggle-screen-mirroring" + ( + builtins.replaceStrings + ["@INTERNAL_MONITOR@" "@EXTERNAL_MONITOR@"] + [(builtins.elemAt config.monitors 0).name (builtins.elemAt config.monitors 1).name] + (builtins.readFile ./toggle-screen-mirroring.sh) + )) (pkgs.writeShellScriptBin "correct-workspace-locations" ( lib.concatStringsSep "\n" ( @@ -108,6 +112,15 @@ '' + "-- Main config from `hyprland.lua`\n" + builtins.readFile ./hyprland.lua + + "-- Monitor config\n" + + lib.concatStringsSep "\n" ( + map ( + monitor: "hl.monitor({ output = \"${monitor.name}\", mode = \"preferred\", position = \"auto\", scale = \"auto\", mirror = \"\"})" + ) + config.monitors + ) + + "\n-- For plugging in random monitors\n" + + "hl.monitor({ output = \"\", mode = \"preferred\", position = \"auto\", scale = \"auto\", mirror = \"\"})\n" + "-- Assign workspaces to monitors\n" + lib.concatStringsSep "\n" ( builtins.concatLists ( diff --git a/homes/julian/features/hyprland/hyprland.lua b/homes/julian/features/hyprland/hyprland.lua index 0b8cae5..d0680c0 100644 --- a/homes/julian/features/hyprland/hyprland.lua +++ b/homes/julian/features/hyprland/hyprland.lua @@ -1,16 +1,3 @@ ------------------- ----- MONITORS ---- ------------------- - --- See https://wiki.hypr.land/Configuring/Basics/Monitors/ -hl.monitor({ - output = "", - mode = "preferred", - position = "auto", - scale = "auto", - mirror = "", -}) - ------------------- ---- AUTOSTART ---- ------------------- diff --git a/homes/julian/features/hyprland/toggle-screen-mirroring.sh b/homes/julian/features/hyprland/toggle-screen-mirroring.sh index 32ebc22..c1d9db1 100644 --- a/homes/julian/features/hyprland/toggle-screen-mirroring.sh +++ b/homes/julian/features/hyprland/toggle-screen-mirroring.sh @@ -2,18 +2,17 @@ # A hyprland script for a laptop-external-monitor setup, toggling between which is in use -# TODO: Detect these instead of hardcoding them -INTERNAL_MONITOR="eDP-1" -EXTERNAL_MONITOR="HDMI-A-1" +INTERNAL_MONITOR="@INTERNAL_MONITOR@" +EXTERNAL_MONITOR="@EXTERNAL_MONITOR@" -MIRROR_SETTING=$(hyprctl monitors all -j | jq -r '.[] | select(.name == "HDMI-A-1") | .mirrorOf') +MIRROR_SETTING=$(hyprctl monitors all -j | jq -r --arg EXTERNAL "$EXTERNAL_MONITOR" '.[] | select(.name == $EXTERNAL) | .mirrorOf') echo "current setting: " echo $MIRROR_SETTING if [ "$MIRROR_SETTING" = "none" ]; then - echo "mirroring..." - hyprctl eval "hl.monitor({output=\"$EXTERNAL_MONITOR\", mode=\"preferred\", position=\"auto\", scale=\"auto\", mirror=\"$INTERNAL_MONITOR\"})" + echo "mirroring..." + hyprctl eval "hl.monitor({output=\"$EXTERNAL_MONITOR\", mode=\"preferred\", position=\"auto\", scale=\"auto\", mirror=\"$INTERNAL_MONITOR\"})" else - # hyprctl keyword monitor "$EXTERNAL_MONITOR, disable" # shortly disable monitor so waybar recognizes the new monitor again # TODO: find better solution - hyprctl eval "hl.monitor({output=\"$EXTERNAL_MONITOR\", mode=\"preferred\", position=\"auto\", scale=\"auto\", mirror=\"\"})" + # hyprctl keyword monitor "$EXTERNAL_MONITOR, disable" # shortly disable monitor so waybar recognizes the new monitor again # TODO: find better solution + hyprctl eval "hl.monitor({output=\"$EXTERNAL_MONITOR\", mode=\"preferred\", position=\"auto\", scale=\"auto\", mirror=\"\"})" fi