Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More control over wallpaper [2/2] #154

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions scripts/termux-wallpaper.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,55 @@ show_usage () {
echo "-h show this help"
echo "-f <file> set wallpaper from file"
echo "-u <url> set wallpaper from url resource"
echo "-l set wallpaper for lockscreen (Nougat and later)"
echo "-l [lock|home]"
echo " set for lockscreen or homescreen only (Nougat and later)"
echo "-c W{x:}H[+X+Y][%]"
echo " center visible area around rectangle of width W and height H,"
echo " X pixels from the top and Y pixels from the left or"
echo " centered if no offset is given,"
echo " : (instead of x) makes the size an aspect ratio,"
echo " % makes size relative to original image size and"
echo " offsets relative to remaining space"
exit 1
}

OPT_LS=""
OPT_CROP=""
OPT_FILE=""
OPT_URL=""

while getopts :h,:l,f:,u: option
while getopts :h,:l,f:,u:,c: option
do
case "$option" in
h) show_usage ;;
l) OPT_LS="true" ;;
l) #see https://stackoverflow.com/a/38697692
lock=${!OPTIND}
case "$lock" in
-*|"")
OPT_LS=true
;;
lock)
OPTIND=$((OPTIND + 1))
OPT_LS=true
;;
home)
OPTIND=$((OPTIND + 1))
OPT_LS=false
;;
*)
echo "$SCRIPTNAME: -l argument must be lock or home (if given)"
exit 1
;;
esac
;;
f) path="$(realpath "$OPTARG")"
if [[ ! -f "$path" ]]; then
echo "$SCRIPTNAME: $path is not a file!"
exit 1
fi
OPT_FILE="$path" ;;
u) OPT_URL="$OPTARG" ;;
c) OPT_CROP="$OPTARG" ;;
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1 ;;
esac
done
Expand All @@ -49,4 +78,5 @@ set --
[ -n "$OPT_LS" ] && set -- "$@" --ez lockscreen "$OPT_LS"
[ -n "$OPT_FILE" ] && set -- "$@" --es file "$OPT_FILE"
[ -n "$OPT_URL" ] && set -- "$@" --es url "$OPT_URL"
[ -n "$OPT_CROP" ] && set -- "$@" --es crop "$OPT_CROP"
@TERMUX_PREFIX@/libexec/termux-api Wallpaper "$@"