screenlock: Add support for niri
This commit is contained in:
50
tree/.local/bin/screenlock
Executable file
50
tree/.local/bin/screenlock
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/fish
|
||||
|
||||
# configured for wayland
|
||||
set LOCKPROG swaylock
|
||||
set OPTIONAL_CMDS rg sed grim lockscreen-blur
|
||||
set CONFIG "$HOME/.config/sway/swaylock.config"
|
||||
set DEFAULT_ARGS --daemonize --ignore-empty-password --show-failed-attempts --color 302f3b --config $CONFIG
|
||||
set BLUR_FACTOR 40
|
||||
|
||||
# check if lock program is running
|
||||
if ps -e | grep " $LOCKPROG\$"
|
||||
echo "$LOCKPROG is already running"
|
||||
exit 1
|
||||
end
|
||||
|
||||
# check if we have programs required to take a screenshot and do cool stuff with it
|
||||
for cmd in $OPTIONAL_CMDS
|
||||
if not command -v $cmd &>/dev/null
|
||||
echo "$cmd could not be found, falling back to basic mode."
|
||||
$LOCKPROG $DEFAULT_ARGS
|
||||
exit 0
|
||||
end
|
||||
end
|
||||
|
||||
# get a list of outputs/monitors
|
||||
switch $XDG_CURRENT_DESKTOP
|
||||
case Hyprland
|
||||
set outputs (hyprctl monitors | rg Monitor | sed 's/Monitor //' | sed 's/ (ID.*$//')
|
||||
case sway
|
||||
set outputs (swaymsg -t get_outputs -r | rg "name" | sed 's/^.*"name": "//' | sed 's/",$//')
|
||||
case niri
|
||||
set outputs (niri msg outputs | rg --pcre2 -o '[^" ]+(?=")')
|
||||
case '*'
|
||||
echo "unsupported compositor, falling back to basic mode."
|
||||
$LOCKPROG $DEFAULT_ARGS
|
||||
exit 0
|
||||
end
|
||||
|
||||
# take one screenshot of each output
|
||||
for output in $outputs
|
||||
set img "/tmp/lock-$output.png"
|
||||
grim -o $output -t ppm - | lockscreen-blur -o $img -b $BLUR_FACTOR --stamp ~/.config/wallpapers/ferris-stamp.png &
|
||||
set -a images --image
|
||||
set -a images "$output:$img"
|
||||
end
|
||||
|
||||
# wait for all screenshot jobs to complete
|
||||
wait
|
||||
|
||||
$LOCKPROG $DEFAULT_ARGS $images
|
||||
@ -1,47 +0,0 @@
|
||||
#!/usr/bin/fish
|
||||
|
||||
# configured for wayland
|
||||
set LOCKPROG swaylock
|
||||
set OPTIONAL_CMDS grep sed grim lockscreen-blur
|
||||
set CONFIG "$HOME/.config/sway/swaylock.config"
|
||||
set DEFAULT_ARGS --daemonize --color "302f3b" --config $CONFIG
|
||||
set BLUR_FACTOR 40
|
||||
|
||||
# check if lock program is running
|
||||
if ps -e | grep " $LOCKPROG\$"
|
||||
echo "$LOCKPROG is already running"
|
||||
exit 1
|
||||
end
|
||||
|
||||
for cmd in $OPTIONAL_CMDS
|
||||
if not command -v $cmd &>/dev/null
|
||||
echo "$cmd could not be found, falling back to basic mode."
|
||||
$LOCKPROG $DEFAULT_ARGS
|
||||
exit 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
{% if hostname == "buran" %}
|
||||
# list display outputs using hyprctl
|
||||
set outputs (hyprctl monitors | rg Monitor | sed 's/Monitor //' | sed 's/ (ID.*$//')
|
||||
{% elif hostname == "sputnik" %}
|
||||
# list display outputs using hyprctl
|
||||
set outputs (hyprctl monitors | rg Monitor | sed 's/Monitor //' | sed 's/ (ID.*$//')
|
||||
{% else %}
|
||||
# list display outputs using swaymsg
|
||||
set outputs (swaymsg -t get_outputs -r | grep "name" | sed 's/^.*"name": "//' | sed 's/",$//')
|
||||
{% end %}
|
||||
|
||||
# take one screenshot of each output
|
||||
for output in $outputs
|
||||
set img "/tmp/lock-$output.png"
|
||||
grim -o $output -t ppm - | lockscreen-blur -o $img -b $BLUR_FACTOR --stamp ~/.config/wallpapers/ferris-stamp.png &
|
||||
set -a images "--image"
|
||||
set -a images "$output:$img"
|
||||
end
|
||||
|
||||
wait
|
||||
|
||||
$LOCKPROG $DEFAULT_ARGS $images
|
||||
|
||||
Reference in New Issue
Block a user