hypr-dotfiles/hypr/scripts/monitor-mirror.sh
Jeena 496fd6fc67 hypr: migrate runtime IPC calls to the Hyprland 0.56 Lua syntax
Hyprland 0.56 removed the string form of `hyprctl dispatch` and
`hyprctl keyword` entirely: the argument is now evaluated as Lua
(hl.dispatch expects a dispatcher object from hl.dsp.*), and `setprop`
lost the `noborder` property in favour of border_size 0. Everything
that shelled out to these silently broke — wlogout's logout button
did nothing, idle screen-off and lid-close DPMS died, borders stopped
tracking single-window workspaces, and display mirroring was gone.

All callers now use the documented forms: `hyprctl dispatch
"hl.dsp.*"` for dispatchers and `hyprctl eval "hl.monitor(...)"` for
monitor rules. dynamic-borders.sh gets a set_border() helper around
the new window.set_prop dispatcher.

wlogout layouts additionally cannot contain escaped quotes at all:
it parses them with jsmn, which never unescapes strings, so \" used
to reach the shell verbatim and break the command with a syntax
error. Actions now use single quotes only.
2026-09-20 14:03:30 +09:00

27 lines
1,019 B
Bash
Executable file

#!/usr/bin/env bash
# Toggle: mirror the internal display to the first connected external monitor.
# Travel use case — plug into a conference room TV/projector via HDMI, press
# the bound key, and the external mirrors the laptop. Press again to revert
# to the host's default monitor layout (via hyprctl reload).
set -u
internal="eDP-1"
external=$(hyprctl monitors -j | jq -r ".[] | select(.name != \"$internal\") | .name" | head -n1)
if [[ -z "$external" ]]; then
notify-send "Mirror" "No external display connected"
exit 0
fi
mirror_of=$(hyprctl monitors -j | jq -r ".[] | select(.name == \"$external\") | .mirrorOf // \"\"")
if [[ -n "$mirror_of" ]]; then
hyprctl reload
notify-send "Mirror" "Off — reverted to default layout"
else
# hl.monitor via eval replaces the removed `hyprctl keyword` (Hyprland 0.56)
hyprctl eval "hl.monitor({output='$external', mode='preferred', position='auto', scale=1, mirror='$internal'})"
notify-send "Mirror" "On — $internal$external"
fi