Add a displays widget for monitor layout and per-monitor wallpapers
This commit is contained in:
Executable
+81
@@ -0,0 +1,81 @@
|
||||
#!/bin/bash
|
||||
|
||||
# blob:summary=Assign a wallpaper to one monitor, leaving the others alone
|
||||
# blob:args=<--list|--clear-all|<output> <image>|<output> --clear>
|
||||
# blob:examples=blob bg monitor DP-1 ~/wallpapers/astronaut2.jpg
|
||||
|
||||
set -e
|
||||
|
||||
state_dir="$HOME/.local/state/blob/backgrounds"
|
||||
mkdir -p "$state_dir"
|
||||
|
||||
usage() {
|
||||
cat <<USAGE
|
||||
Usage: blob-bg-monitor <output> <image> assign a wallpaper to one monitor
|
||||
blob-bg-monitor <output> --clear fall back to the global wallpaper
|
||||
blob-bg-monitor --list show current assignments
|
||||
blob-bg-monitor --clear-all drop every assignment
|
||||
|
||||
Monitors with no assignment show the global wallpaper set by blob-bg-set.
|
||||
Output names are what 'hyprctl monitors' reports, such as DP-1 or eDP-1.
|
||||
USAGE
|
||||
}
|
||||
|
||||
notify_shell() {
|
||||
blob-shell -q background refresh
|
||||
}
|
||||
|
||||
known_output() {
|
||||
hyprctl monitors all -j 2>/dev/null | jq -e --arg name "$1" 'any(.[]; .name == $name)' >/dev/null
|
||||
}
|
||||
|
||||
case "${1-}" in
|
||||
--list)
|
||||
found=false
|
||||
for link in "$state_dir"/*; do
|
||||
[[ -e $link ]] || continue
|
||||
found=true
|
||||
printf '%-12s %s\n' "$(basename "$link")" "$(readlink -f "$link")"
|
||||
done
|
||||
[[ $found == true ]] || echo "No per-monitor wallpapers assigned."
|
||||
exit 0
|
||||
;;
|
||||
--clear-all)
|
||||
rm -f "$state_dir"/*
|
||||
notify_shell
|
||||
echo "Cleared every per-monitor wallpaper."
|
||||
exit 0
|
||||
;;
|
||||
""|--help|-h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
output="$1"
|
||||
image="${2-}"
|
||||
|
||||
if [[ -z $image ]]; then
|
||||
usage >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! known_output "$output"; then
|
||||
echo "Warning: '$output' is not a connected monitor right now." >&2
|
||||
fi
|
||||
|
||||
if [[ $image == --clear ]]; then
|
||||
rm -f "$state_dir/$output"
|
||||
notify_shell
|
||||
echo "Cleared $output; it follows the global wallpaper again."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ ! -f $image ]]; then
|
||||
echo "Not a file: $image" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ln -sfn "$(realpath "$image")" "$state_dir/$output"
|
||||
notify_shell
|
||||
echo "Set $output to $(basename "$image")"
|
||||
Executable
+68
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
|
||||
# blob:summary=Apply a monitor layout at runtime without touching monitors.lua
|
||||
# blob:args=<list|apply <keyword>...|reset>
|
||||
# blob:examples=blob display arrange apply 'DP-1,1920x1080@60,0x0,1'
|
||||
|
||||
set -e
|
||||
|
||||
action="${1-}"
|
||||
shift || true
|
||||
|
||||
usage() {
|
||||
cat <<USAGE
|
||||
Usage: blob-display-arrange <command>
|
||||
|
||||
list print the current layout as monitor keywords
|
||||
apply <keyword>... apply one or more monitor keywords now
|
||||
reset reload the Hyprland config, restoring monitors.lua
|
||||
|
||||
A keyword is Hyprland's own monitor form:
|
||||
|
||||
<name>,<mode>,<x>x<y>,<scale>[,transform,<n>][,mirror,<name>]
|
||||
<name>,disable
|
||||
|
||||
Changes made with apply are runtime only. They last until the config is
|
||||
reloaded or the session ends; monitors.lua is never written.
|
||||
USAGE
|
||||
}
|
||||
|
||||
case "$action" in
|
||||
list)
|
||||
hyprctl monitors all -j | jq -r '
|
||||
.[]
|
||||
| if .disabled then "\(.name),disable"
|
||||
else
|
||||
"\(.name),\(.width)x\(.height)@\((.refreshRate * 100 | round) / 100),\(.x)x\(.y),\(.scale)"
|
||||
+ (if .transform != 0 then ",transform,\(.transform)" else "" end)
|
||||
+ (if .mirrorOf != "none" then ",mirror,\(.mirrorOf)" else "" end)
|
||||
end
|
||||
'
|
||||
;;
|
||||
apply)
|
||||
if (( $# == 0 )); then
|
||||
echo "apply needs at least one monitor keyword" >&2
|
||||
exit 1
|
||||
fi
|
||||
for keyword in "$@"; do
|
||||
if [[ $keyword != *,* ]]; then
|
||||
echo "Not a monitor keyword: $keyword" >&2
|
||||
exit 1
|
||||
fi
|
||||
hyprctl keyword monitor "$keyword" >/dev/null
|
||||
echo "applied $keyword"
|
||||
done
|
||||
;;
|
||||
reset)
|
||||
hyprctl reload >/dev/null
|
||||
echo "reloaded; monitors.lua is authoritative again"
|
||||
;;
|
||||
""|--help|-h)
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
echo "Unknown command: $action" >&2
|
||||
usage >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user