From d947956270b092df10637bb3531441caca698b86 Mon Sep 17 00:00:00 2001 From: Suleyman Farajli Date: Tue, 25 Nov 2025 18:47:27 +0400 Subject: feat: new api for scripts --- scripts/gui/sslock | 67 +++++++++++++++++++++--------------------------------- 1 file changed, 26 insertions(+), 41 deletions(-) (limited to 'scripts/gui/sslock') diff --git a/scripts/gui/sslock b/scripts/gui/sslock index 26ba2cf..8a3284e 100755 --- a/scripts/gui/sslock +++ b/scripts/gui/sslock @@ -1,59 +1,44 @@ #!/bin/sh -. slib +. "lib_common.sh" +. "lib_handle.sh" help() { cat << EOF -${0}: Wrapper script to take screenshots +${0}: Lock screen options: - -n Black screen - -b Blur - -c Take the current state of the desktop + -n Black screen lock -h Print this message and exit EOF - exit 0 } -check_program "slock" - -blur=0 -set_current_state=0 -current_wallpaper="${XDG_CACHE_HOME:-$HOME/.cache}/wallpaper/current" -while getopts "bcnh" option; do - case "${option}" in - b) - check_program "mogrify" "imagemagick must be installed" - blur=1 ;; - - c) - check_program "scrot" - set_current_state=1 - ;; - n) - slock - exit 0;; - - h) help ;; - - *) invalid_use -h ;; +trap 'rm -f "${lock_image}"' EXIT INT TERM HUP - esac -done - -shift $((OPTIND - 1)) +if [ "${#}" -eq 1 ]; then + [ "${1}" = "-h" ] && help + [ "${1}" = "-n" ] || invalid_use + screenlock_handle + exit 0 +fi -[ "${#}" -eq 0 ] || invalid_use +[ "${#}" -ne 0 ] && invalid_use -background="/tmp/$(date '+%b%d::%H%M%S').png" +mode=$(printf "Blank\nBlur\nWallpaper" | menu_handle default) +if [ "${mode}" = "Blank" ]; then + screenlock_handle + exit 0 +fi -if [ "$set_current_state" -eq 0 ]; then - # Avoid distorting the wallpaper when calling `mogrify` - cp "${current_wallpaper}" "${background}" -else - scrot -z "${background}" +lock_image=$(get_random_filename .png) +if [ "${mode}" = "Blur" ]; then + screenshot_handle fullscreen "${lock_image}" + image_handle blur "${lock_image}" fi -[ "${blur}" -eq 1 ] && mogrify -blur 0x8 "${background}" +if [ "${mode}" = "Wallpaper" ]; then + current_wallpaper="${XDG_CACHE_HOME:-$HOME/.cache}/wallpaper/current" + cp "${current_wallpaper}" "${lock_image}" +fi -slock -f "${background}" +screenlock_handle "${lock_image}" -- cgit v1.2.3