From c6308045a4fb1aeeb0922026f5e21d759f646bf6 Mon Sep 17 00:00:00 2001 From: crater2150 Date: Mon, 25 Jul 2016 15:09:46 +0200 Subject: [PATCH] Add awsetbg for creating wallpaperrc --- awsetbg | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100755 awsetbg diff --git a/awsetbg b/awsetbg new file mode 100755 index 0000000..28dc4db --- /dev/null +++ b/awsetbg @@ -0,0 +1,84 @@ +#!/bin/zsh + +WALLPAPERRC=$(awesome-client <<<'return awful.util.getdir("config") .. "/wallpaperrc"' | sed -e 's/.*string "\(.*\)"/\1/') + +mode="-f" + +offset_x=(-x 0) +offset_y=(-y 0) +background=(-b "theme.bg_default") + +zparseopts -D -K h=help -help=help c=mode f=mode t=mode m=mode x:=offset_x y:=offset_y s:=screen i=ignore_aspect b:=background u=update U=reload r=reload + +wall=${1:a} + +if [ -n "$help" ] || [ -z "$wall" ]; then + echo "usage: $0 [opts] file +options: + -s screen number + -c centered + -f fit + -t tiled + -m maximized + -x, -y offset in x and y direction (for -t, -m) + -i ignore_aspect (for -m) + -b background color (for -c, -f) + -u update wallpaperrc + -U, -r reload from wallpaperrc" + exit 1 +fi + +if [[ -n "$reload" ]]; then + if [[ ! -e $WALLPAPERRC ]]; then + echo "No wallpaperrc found" + exit 1 + else + echo "dofile(\"$WALLPAPERRC\")" | awesome-client + exit 0 + fi +fi + +if [[ "${background[2]}" != "theme.bg_default" ]]; then + background[2]="'${background[2]}'" +fi + +case "$mode" in + -c) + method=centered + extra_args=", ${background[2]}" + ;; + -f) + method=fit + extra_args=", ${background[2]}" + ;; + -t) + method=tiled + extra_args=", {x = ${offset_x[2]}, y = ${offset_y[2]}}" + ;; + -m) + method=maximized + if [ -n "${ignore_aspect}" ]; then + ignore_aspect=true + else + ignore_aspect=false + fi + extra_args=", ${ignore_aspect}, {x = ${offset_x[2]}, y = ${offset_y[2]}}" + ;; + *) exit ;; +esac + +echo "require('gears').wallpaper.${method}(\"${wall}\",1${extra_args})" +echo "for s = 1, screen.count() do +require('gears').wallpaper.${method}(\"${wall}\",s${extra_args}) +end" | awesome-client + +if [[ -n "$update" ]]; then + echo "-- wallpaperrc generated by awsetbg + local wall=\"${wall}\" + local f = io.open(wall, \"r\") + if f~= nil then + for s = 1, screen.count() do + require('gears').wallpaper.${method}(wall,s${extra_args}) + end + end" > $WALLPAPERRC +fi