hyprland: make monitor config dependent on config.monitors

This commit is contained in:
2026-07-19 09:08:50 +02:00
parent de081fe38f
commit 76ad137946
3 changed files with 23 additions and 24 deletions
+16 -3
View File
@@ -60,9 +60,13 @@
wf-recorder wf-recorder
wl-clipboard wl-clipboard
(pkgs.writeShellScriptBin "toggle-screen-mirroring" ( (pkgs.writeShellScriptBin "toggle-screen-mirroring"
builtins.readFile ./toggle-screen-mirroring.sh (
)) 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" ( (pkgs.writeShellScriptBin "correct-workspace-locations" (
lib.concatStringsSep "\n" ( lib.concatStringsSep "\n" (
@@ -108,6 +112,15 @@
'' ''
+ "-- Main config from `hyprland.lua`\n" + "-- Main config from `hyprland.lua`\n"
+ builtins.readFile ./hyprland.lua + 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" + "-- Assign workspaces to monitors\n"
+ lib.concatStringsSep "\n" ( + lib.concatStringsSep "\n" (
builtins.concatLists ( builtins.concatLists (
@@ -1,16 +1,3 @@
------------------
---- MONITORS ----
------------------
-- See https://wiki.hypr.land/Configuring/Basics/Monitors/
hl.monitor({
output = "",
mode = "preferred",
position = "auto",
scale = "auto",
mirror = "",
})
------------------- -------------------
---- AUTOSTART ---- ---- AUTOSTART ----
------------------- -------------------
@@ -2,18 +2,17 @@
# A hyprland script for a laptop-external-monitor setup, toggling between which is in use # A hyprland script for a laptop-external-monitor setup, toggling between which is in use
# TODO: Detect these instead of hardcoding them INTERNAL_MONITOR="@INTERNAL_MONITOR@"
INTERNAL_MONITOR="eDP-1" EXTERNAL_MONITOR="@EXTERNAL_MONITOR@"
EXTERNAL_MONITOR="HDMI-A-1"
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 "current setting: "
echo $MIRROR_SETTING echo $MIRROR_SETTING
if [ "$MIRROR_SETTING" = "none" ]; then if [ "$MIRROR_SETTING" = "none" ]; then
echo "mirroring..." echo "mirroring..."
hyprctl eval "hl.monitor({output=\"$EXTERNAL_MONITOR\", mode=\"preferred\", position=\"auto\", scale=\"auto\", mirror=\"$INTERNAL_MONITOR\"})" hyprctl eval "hl.monitor({output=\"$EXTERNAL_MONITOR\", mode=\"preferred\", position=\"auto\", scale=\"auto\", mirror=\"$INTERNAL_MONITOR\"})"
else else
# hyprctl keyword monitor "$EXTERNAL_MONITOR, disable" # shortly disable monitor so waybar recognizes the new monitor again # TODO: find better solution # 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 eval "hl.monitor({output=\"$EXTERNAL_MONITOR\", mode=\"preferred\", position=\"auto\", scale=\"auto\", mirror=\"\"})"
fi fi