From 8478f288d3058ca191c24ca18cc94125af3aeaa1 Mon Sep 17 00:00:00 2001 From: danix Date: Wed, 6 Nov 2024 12:43:55 +0100 Subject: [PATCH] updated bin directory --- bin/betterlockscreen | 942 ++++++++++++++++++++++++++++++++++++ bin/blackpearl-emoji.sh | 4 + bin/blackpearl-notes.sh | 28 ++ bin/blackpearl-powermenu.sh | 18 +- bin/blackpearl-symbols.sh | 1 + bin/blackpearl-utilsmenu.sh | 2 +- bin/blackpearl-window.sh | 4 +- bin/change_wallpaper.sh | 14 +- bin/dunst-snooze.sh | 14 + bin/dunst_vol_brig.sh | 87 ++++ bin/executors/battery-level | 26 - bin/feh-blur | 412 ++++++++++++++++ bin/gify.sh | 170 +++++++ bin/hideIt.sh | 686 ++++++++++++++++++++++++++ bin/hidebars.sh | 10 + bin/i3lock-fancy | 193 +++++--- bin/i3suspend | 2 +- bin/info-airqualityindex.sh | 41 ++ bin/lightsOn.sh | 240 +++++++++ bin/maiumin | 18 + bin/mkpass | 54 +++ bin/mvb | 164 +++++++ bin/my_netstat | 8 + bin/nopy.sh | 77 +++ bin/nospaces | 14 + bin/notes | 726 +++++++++++++++++++++++++++ bin/polybar-kdeconnect.sh | 123 +++++ bin/qwalwal.sh | 131 +++++ bin/run-polybar.sh | 41 +- bin/send-to-device.sh | 0 bin/slack-updates | 1 + bin/speedtest | Bin 0 -> 2613400 bytes bin/superenalotto.sh | 37 ++ bin/symbols.sh | 80 +++ bin/wal.sh | 30 ++ bin/wallpaper.sh | 127 +++++ bin/walogram | 173 +++++++ bin/walwal.sh | 131 +++++ 38 files changed, 4724 insertions(+), 105 deletions(-) create mode 100644 bin/betterlockscreen create mode 100644 bin/blackpearl-emoji.sh create mode 100644 bin/blackpearl-notes.sh create mode 100644 bin/blackpearl-symbols.sh create mode 100644 bin/dunst-snooze.sh create mode 100644 bin/dunst_vol_brig.sh delete mode 100644 bin/executors/battery-level create mode 100644 bin/feh-blur create mode 100644 bin/gify.sh create mode 100644 bin/hideIt.sh create mode 100644 bin/hidebars.sh create mode 100644 bin/info-airqualityindex.sh create mode 100644 bin/lightsOn.sh create mode 100644 bin/maiumin create mode 100644 bin/mkpass create mode 100644 bin/mvb create mode 100644 bin/my_netstat create mode 100644 bin/nopy.sh create mode 100644 bin/nospaces create mode 100644 bin/notes create mode 100644 bin/polybar-kdeconnect.sh create mode 100644 bin/qwalwal.sh mode change 100755 => 100644 bin/send-to-device.sh create mode 100644 bin/speedtest create mode 100644 bin/superenalotto.sh create mode 100644 bin/symbols.sh create mode 100644 bin/wal.sh create mode 100644 bin/wallpaper.sh create mode 100644 bin/walogram create mode 100644 bin/walwal.sh diff --git a/bin/betterlockscreen b/bin/betterlockscreen new file mode 100644 index 0000000..0b92ad9 --- /dev/null +++ b/bin/betterlockscreen @@ -0,0 +1,942 @@ +#!/usr/bin/env bash + +# Author : Copyright (c) 2017-2023 Pavan Jadhaw, and others (https://github.com/betterlockscreen/betterlockscreen/graphs/contributors) +# Project Repository : https://github.com/betterlockscreen/betterlockscreen + +cmd_exists () { + command -v "$1" >/dev/null +} + +init_config () { + # default options + display_on=0 + span_image=false + lock_timeout=300 + fx_list=(dim blur dimblur pixel dimpixel color) + dim_level=40 + blur_level=1 + pixel_scale=10,1000 + solid_color=333333 + description="" + quiet=false + i3lockcolor_bin="i3lock-color" + suspend_command="systemctl suspend" + convert_command="magick" + composite_command="magick composite" + + if ! cmd_exists "$i3lockcolor_bin" && cmd_exists "i3lock"; then + i3lockcolor_bin="i3lock" + fi + + if ! cmd_exists "magick"; then + convert_command="convert" + composite_command="composite" + fi + + # default theme + loginbox=00000066 + loginshadow=00000000 + locktext="Type password to unlock..." + font="sans-serif" + ringcolor=ffffffff + insidecolor=00000000 + separatorcolor=00000000 + ringvercolor=ffffffff + insidevercolor=00000000 + ringwrongcolor=ffffffff + insidewrongcolor=d23c3dff + timecolor=ffffffff + time_format="%H:%M:%S" + greetercolor=ffffffff + layoutcolor=ffffffff + keyhlcolor=d23c3dff + bshlcolor=d23c3dff + veriftext="Verifying..." + verifcolor=ffffffff + wrongtext="Failure!" + wrongcolor=d23c3dff + modifcolor=d23c3dff + bgcolor=000000ff + wallpaper_cmd="feh --bg-fill" + + # read user config + USER_CONF_DIR="${XDG_CONFIG_HOME:-$HOME/.config}" + USER_CONF="$USER_CONF_DIR/betterlockscreenrc" + SYS_CONF="/etc/betterlockscreenrc" + XDG_USER_CONF_DIR="$USER_CONF_DIR/betterlockscreen" + XDG_USER_CONF="$XDG_USER_CONF_DIR/betterlockscreenrc" + + if [ -e "$SYS_CONF" ]; then + # shellcheck source=/dev/null + source "$SYS_CONF" + fi + + if [ -e "$USER_CONF" ]; then + echof error "Please, migrate your config $USER_CONF to $XDG_USER_CONF. Old location will soon be deprecated." + echof info "mkdir -p ~/.config/betterlockscreen/ && mv $USER_CONF $XDG_USER_CONF" + + # shellcheck source=/dev/null + source "$USER_CONF" + fi + + if [ -e "$XDG_USER_CONF" ]; then + # shellcheck source=/dev/null + source "$XDG_USER_CONF" + fi + + if ! cmd_exists "$i3lockcolor_bin"; then + echof error "Unable to find i3lock-color binary under detected/configured name: '$i3lockcolor_bin'!" + exit + fi + + # Please make sure to adjust this before release! + VERSION="4.3.0" + + # paths + CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/betterlockscreen" + CUR_DIR="$CACHE_DIR/current" + + # wallpaper + CUR_W_RESIZE="$CUR_DIR/wall_resize.png" + CUR_W_DIM="$CUR_DIR/wall_dim.png" + CUR_W_BLUR="$CUR_DIR/wall_blur.png" + CUR_W_DIMBLUR="$CUR_DIR/wall_dimblur.png" + CUR_W_PIXEL="$CUR_DIR/wall_pixel.png" + CUR_W_DIMPIXEL="$CUR_DIR/wall_dimpixel.png" + CUR_W_COLOR="$CUR_DIR/wall_color.png" + + # lockscreen + CUR_L_RESIZE="$CUR_DIR/lock_resize.png" + CUR_L_DIM="$CUR_DIR/lock_dim.png" + CUR_L_BLUR="$CUR_DIR/lock_blur.png" + CUR_L_DIMBLUR="$CUR_DIR/lock_dimblur.png" + CUR_L_PIXEL="$CUR_DIR/lock_pixel.png" + CUR_L_DIMPIXEL="$CUR_DIR/lock_dimpixel.png" + CUR_L_COLOR="$CUR_DIR/lock_color.png" + + # Original DPMS timeout + DEFAULT_TIMEOUT=$(cut -d ' ' -f4 <<< "$(xset q | sed -n '25p')") + # Original DPMS status + DEFAULT_DPMS=$(xset q | awk '/^[[:blank:]]*DPMS is/ {print $(NF)}') + + # Dunst + DUNST_INSTALLED=false && [[ -e "$(command -v dunstctl)" ]] && DUNST_INSTALLED=true + DUNST_IS_RUNNING=false && [[ "$DUNST_INSTALLED" == "true" ]] && [[ "$(pgrep -c dunst)" -gt 0 ]] && DUNST_IS_RUNNING=true + DUNST_IS_PAUSED=false && [[ "$DUNST_IS_RUNNING" == "true" ]] && DUNST_IS_PAUSED=$(dunstctl is-paused) + + # Feh + FEH_INSTALLED=false && [[ -e "$(command -v feh)" ]] && FEH_INSTALLED=true +} + +# called before screen is locked +prelock() { + # set dpms timeout + if [ "$DEFAULT_DPMS" == "Enabled" ]; then + xset dpms "$lock_timeout" + fi + + # If dusnt is already paused don't pause it again + if [[ "$DUNST_IS_RUNNING" == "true" && "$DUNST_IS_PAUSED" == "false" ]]; then + dunstctl set-paused true + fi + + if [ -e "$XDG_USER_CONF_DIR/custom-pre.sh" ]; then + # shellcheck source=/dev/null + source "$XDG_USER_CONF_DIR/custom-pre.sh" + fi +} + +# lock screen with specified image +lock() { + local image="$1" + local fontlg=32 + local fontmd=16 + local fontsm=12 + + if [ -f "$image" ]; then + echof act "Locking screen..." + else + echof act "Locking screen... (FAILSAFE MODE)" + fi + + $i3lockcolor_bin \ + ${image:+-i "$image"} \ + --color "$bgcolor" \ + ${display_on:+-S "$display_on"} \ + --ind-pos="x+310:y+h-80" \ + --radius=25 \ + --ring-width=5 \ + --inside-color="$insidecolor" \ + --ring-color="$ringcolor" \ + --separator-color=$separatorcolor \ + --insidever-color="$insidevercolor" \ + --insidewrong-color="$insidewrongcolor" \ + --ringver-color="$ringvercolor" \ + --ringwrong-color="$ringwrongcolor" \ + --line-uses-inside \ + --keyhl-color="$keyhlcolor" \ + --bshl-color="$bshlcolor" \ + --clock --force-clock \ + --time-pos="ix-265:iy-10" \ + --time-align 1 \ + --time-str "$time_format" \ + --time-color="$timecolor" \ + --time-font="$font" \ + --time-size="$fontlg" \ + --date-str "" \ + --greeter-pos="ix-265:iy+12" \ + --greeter-align 1 \ + --greeter-text "$locktext" \ + --greeter-color="$greetercolor" \ + --greeter-font="$font" \ + --greeter-size="$fontmd" \ + --layout-pos="ix-265:iy+32" \ + --layout-align 1 \ + --layout-color="$layoutcolor" \ + --layout-font="$font" \ + --layout-size="$fontsm" \ + --verif-pos="ix+35:iy-34" \ + --verif-align 2 \ + --verif-text="$veriftext" \ + --verif-color="$verifcolor" \ + --verif-font="$font" \ + --verif-size="$fontsm" \ + --wrong-pos="ix+24:iy-34" \ + --wrong-align 2 \ + --wrong-text="$wrongtext" \ + --wrong-color="$wrongcolor" \ + --wrong-font="$font" \ + --wrong-size="$fontsm" \ + --modif-pos="ix+45:iy+43" \ + --modif-align 2 \ + --modif-size="$fontsm" \ + --modif-color="$modifcolor" \ + --noinput-text="" \ + --pass-media-keys \ + --pass-screen-keys \ + --pass-volume-keys \ + --pass-power-keys \ + "${lockargs[@]}" +} + +# called after screen is unlocked +postlock() { + # restore default dpms timeout + if [ "$DEFAULT_DPMS" == "Enabled" ]; then + xset dpms "$DEFAULT_TIMEOUT" + fi + + # If dunst already paused before locking don't unpause dunst + if [[ "$DUNST_IS_RUNNING" == "true" && "$DUNST_IS_PAUSED" == "false" ]]; then + dunstctl set-paused false + fi + + if [ -e "$XDG_USER_CONF_DIR/custom-post.sh" ]; then + # shellcheck source=/dev/null + source "$XDG_USER_CONF_DIR/custom-post.sh" + fi +} + +# select effect and lock screen +lockinit() { + if pgrep -u "$USER" "$i3lockcolor_bin"; then + echof error "i3lock already running" + exit 1 + fi + + echof act "Running prelock..." + prelock + + if [[ $runsuspend ]]; then + lockselect "$@" & + $suspend_command + wait $! + else + lockselect "$@" + fi + + echof act "Running postlock..." + postlock +} + +lockselect() { + case "$1" in + dim) lock "$CUR_L_DIM" ;; + blur) lock "$CUR_L_BLUR" ;; + dimblur) lock "$CUR_L_DIMBLUR" ;; + pixel) lock "$CUR_L_PIXEL" ;; + dimpixel) lock "$CUR_L_DIMPIXEL" ;; + color) lock "$CUR_L_COLOR" ;; + *) lock "$CUR_L_RESIZE" ;; + esac +} + +# calculate adjustments for hidpi displays +logical_px() { + # $1: number of pixels to convert + # $2: 1 for width. 2 for height + local pixels="$1" + local direction="$2" + local dpi + + # use DPI set by user in .Xresources + dpi=$(xrdb -q | grep -oP '^\s*Xft.dpi:\s*\K\d+' | bc) + + # or get dpi value from xdpyinfo + if [ -z "$dpi" ]; then + dpi=$(xdpyinfo | sed -En "s/\s*resolution:\s*([0-9]*)x([0-9]*)\s.*/\\$direction/p" | head -n1) + fi + + # adjust scaling + if [ -n "$dpi" ]; then + local scale + scale=$(echo "scale=3; $dpi / 96.0" | bc) + echo "$scale * $pixels / 1" | bc + else + # return the default value if no DPI is set + echo "$pixels" + fi +} + +# get total resolution, sets $TOTAL_SIZE +get_total_size () { + TOTAL_SIZE=$(xdpyinfo | grep -w "dimensions" | sed -r 's/^[^0-9]*([0-9]+x[0-9]+).*$/\1/') +} + +# get list of displays, sets $DISPLAY_LIST +get_display_list () { + local count=0 + mapfile -t displays < <(xrandr --listactivemonitors) + for display in "${displays[@]:1}"; do + ((count++)) + display="$(echo "$display" | sed -r 's/\/[0-9]*//g')" + IFS=' ' read -r -a info <<< "$display" + DISPLAY_LIST+=("$count ${info[3]} ${info[2]}") + done +} + +# populate $WALL_LIST depending on number of displays and images passed +get_wall_list() { + local paths=("$@") + declare -ga WALL_LIST + + # multiple images and spanning conflict, bail out + if [ "${#paths[@]}" -gt 1 ] && [ "$span_image" = true ]; then + echof err "Can't use --span with multiple images!" + exit 1 + fi + + # if spanning return 1 image + if [ "$span_image" = true ]; then + get_image "${paths[0]}" + + # if # paths is 1 + elif [ "${#paths[@]}" -eq 1 ]; then + for ((i=0; i<${#DISPLAY_LIST[@]}; i++)); do + # add same image to $WALL_LIST for each display + get_image "${paths[0]}" + done + + # if # of paths equals # of displays + elif [ ${#paths[@]} -eq "${#DISPLAY_LIST[@]}" ]; then + for ((i=0; i<${#DISPLAY_LIST[@]}; i++)); do + # add each image to $WALL_LIST + get_image "${paths[$i]}" + done + + # if # of paths differ from # of display, bail out + else + echof err "${#paths[@]} images provided for ${#DISPLAY_LIST[@]} displays!" + exit 1 + fi +} + +# get image path, append to $WALL_LIST +get_image() { + local path="$1" + + # we have a file + if [ -f "$path" ]; then + WALL_LIST+=("$path") + return + # we have a directory + elif [ -d "$path" ]; then + dir=("$path"/*) + rdir="${dir[RANDOM % ${#dir[@]}]}" + get_image "$rdir" # <-- calls itself + # not file or directory, bail out + else + echof err "invalid path: $path" + exit 1 + fi + +} + +# scale base image and generate effects +resize_and_render () { + local base="$1" + local path="$2" + local resolution="$3" + + # resource paths + RES_RESIZE="$path/resize.png" + RES_DIM="$path/dim.png" + RES_BLUR="$path/blur.png" + RES_DIMBLUR="$path/dimblur.png" + RES_PIXEL="$path/pixel.png" + RES_DIMPIXEL="$path/dimpixel.png" + RES_COLOR="$path/color.png" + + # resize + base_resize "$base" "$RES_RESIZE" "$resolution" + + # effects + for effect in "${fx_list[@]}"; do + case $effect in + dim) fx_dim "$RES_RESIZE" "$RES_DIM";; + blur) fx_blur "$RES_RESIZE" "$RES_BLUR" "$resolution";; + dimblur) fx_dimblur "$RES_RESIZE" "$RES_DIMBLUR" "$resolution";; + pixel) fx_pixel "$RES_RESIZE" "$RES_PIXEL";; + dimpixel) fx_dimpixel "$RES_RESIZE" "$RES_DIMPIXEL";; + color) fx_color "$RES_COLOR" "$resolution";; + esac + done + +} + +# apply resize +base_resize() { + local input="$1" + local output="$2" + local size="$3" + + echof act "Resizing base image..." + eval $convert_command "$input" \ + -resize "$size""^" \ + -gravity center \ + -extent "$size" \ + "$output" +} + +# apply dim +fx_dim() { + local input="$1" + local output="$2" + + echof act "Rendering 'dim' effect..." + eval $convert_command "$input" \ + -fill black -colorize "$dim_level"% \ + "$output" +} + +# apply blur +fx_blur() { + local input="$1" + local output="$2" + local size="$3" + + echof act "Rendering 'blur' effect..." + blur_shrink=$(echo "scale=2; 20 / $blur_level" | bc) + blur_sigma=$(echo "scale=2; 0.6 * $blur_level" | bc) + eval $convert_command "$input" \ + -filter Gaussian \ + -resize "$blur_shrink%" \ + -define "filter:sigma=$blur_sigma" \ + -resize "$size^" -gravity center -extent "$size" \ + "$output" +} + +# apply dimblur +fx_dimblur() { + local input="$1" + local output="$2" + local size="$3" + + echof act "Rendering 'dimblur' effect..." + blur_shrink=$(echo "scale=2; 20 / $blur_level" | bc) + blur_sigma=$(echo "scale=2; 0.6 * $blur_level" | bc) + eval $convert_command "$input" \ + -fill black -colorize "$dim_level"% \ + -filter Gaussian \ + -resize "$blur_shrink%" \ + -define "filter:sigma=$blur_sigma" \ + -resize "$size^" -gravity center -extent "$size" \ + "$output" +} + +# pixelate +fx_pixel() { + local input="$1" + local output="$2" + + echof act "Rendering 'pixel' effect..." + IFS=',' read -ra range <<< "$pixel_scale" + eval $convert_command "$input" \ + -scale "${range[0]}"% -scale "${range[1]}"% \ + "$output" +} + +# apply dimpixel +fx_dimpixel() { + local input="$1" + local output="$2" + + echof act "Rendering 'dimpixel' effect..." + IFS=',' read -ra range <<< "$pixel_scale" + eval $convert_command "$input" \ + -fill black -colorize "$dim_level"% \ + -scale "${range[0]}"% -scale "${range[1]}"% \ + "$output" +} + +# create solid color +fx_color() { + local output="$1" + local size="$2" + + echof act "Rendering 'color' effect..." + eval $convert_command -size "$size" canvas:\#"$solid_color" "$RES_COLOR" +} + +# create loginbox rectangle, set "$RECTANGLE" +create_loginbox () { + RECTANGLE="$CUR_DIR/rectangle.png" + local shadow="$CUR_DIR/shadow.png" + local width height + width=$(logical_px 340 1) + height=$(logical_px 100 2) + $convert_command -size "$width"x"$height" xc:\#"$loginbox" -fill none "$RECTANGLE" + $convert_command "$RECTANGLE" \ + \( -clone 0 -background \#"$loginshadow" -shadow 100x5+0+0 \) +swap \ + -background none -layers merge +repage "$shadow" + $composite_command -compose Dst_Out -gravity center \ + "$RECTANGLE" "$shadow" -alpha Set "$shadow" + $convert_command "$shadow" "$RECTANGLE" -geometry +10+10 -composite "$RECTANGLE" + [[ "$shadow" ]] && rm "$shadow" +} + +# create rectangle with description, set "$DESCRECT" +create_description () { + DESCRECT="$CUR_DIR/description.png" + local shadow="$CUR_DIR/shadow.png" + $convert_command -background none -family "$(fc-match "$font" family)" -style Normal -pointsize 14 -fill \#"$greetercolor" label:"\ $description\ " -bordercolor \#"$loginbox" -border 10 "$DESCRECT" + $convert_command "$DESCRECT" \ + \( -clone 0 -background \#"$loginshadow" -shadow 100x5+0+0 \) +swap \ + -background none -layers merge +repage "$shadow" + $composite_command -compose Dst_Out -gravity center \ + "$DESCRECT" "$shadow" -alpha Set "$shadow" + $convert_command "$shadow" "$DESCRECT" -geometry +10+10 -composite "$DESCRECT" + [[ "$shadow" ]] && rm "$shadow" +} + +# delete and recreate directory +purge_cache () { + if [[ -d "$1" ]]; then + rm -r "$1" + fi + mkdir -p "$1" +} + +# update lockscreen and wallpaper images +update () { + local images=("$@") + + echof act "Updating image cache..." + mkdir -p "$CACHE_DIR" &>/dev/null + + get_display_list # DISPLAY_LIST + get_total_size # TOTAL_SIZE + echof info "Detected ${#DISPLAY_LIST[@]} display(s) @ $TOTAL_SIZE total resolution" + + get_wall_list "${images[@]}" # WALL_LIST + echof info "Original image(s): ${WALL_LIST[*]##*/}" + + # Prepare description box to obtain width for positioning + local descwidth + local descheight + if [ -z "$description" ]; then + descwidth=0 + descheight=0 + else + create_description + descwidth=$(identify -format "%[fx:w]" "$DESCRECT") + descheight=$(identify -format "%[fx:h]" "$DESCRECT") + fi + + for ((i=0; i<${#DISPLAY_LIST[@]}; i++)); do + display="${DISPLAY_LIST[$i]}" + USER_WALL="${WALL_LIST[$i]}" + + # escape spaces for IM + if echo "$USER_WALL" | grep -E -q "[[:space:]]"; then + USER_WALL="${USER_WALL// /\\ }" + fi + + IFS=' ' read -r -a dinfo <<< "$display" + local id="${dinfo[0]}" + local device="${dinfo[1]}" + local geometry="${dinfo[2]}" + + read -r -a cols <<< "${geometry//[x+-]/ }" + local position="${geometry#*"${cols[1]}"}" + local resolution="${geometry%"${position}"*}" + + if [[ $id -eq "$display_on" ]] || [[ "$display_on" -eq 0 ]]; then + + IFS='x' read -r -a dimension <<< "$resolution" + res_x="${dimension[0]}" + res_y="${dimension[1]}" + read -r -a val <<< "${position//[+-]/ }" + read -r -a sym <<< "${position//[0-9]/ }" + pos_x="${sym[0]}${val[0]}" + pos_y="${sym[1]}${val[1]}" + + rect_x=$((pos_x + $(logical_px 15 1))) + rect_y=$((pos_y + res_y - $(logical_px 140 2))) + positions+=("+$((rect_x))+$((rect_y))") + + descrect_x=$((pos_x + res_x - descwidth - $(logical_px 15 1))) + descrect_y=$((pos_y + res_y - descheight - $(logical_px 20 2))) + positions_desc+=("+$((descrect_x))+$((descrect_y))") + fi + + local path="$CACHE_DIR/$id-$device" + purge_cache "$path" + + if [ "$span_image" = true ]; then + if [ "$id" -gt 1 ]; then + continue + else + device="[span]" + id="*" + resolution="$TOTAL_SIZE" + fi + fi + + echof info "Processing display: $device ($id)" + echof info "Resolution: $resolution" + + if [ "$span_image" = true ]; then + resize_and_render "$USER_WALL" "$path" "$resolution" + else + resize_and_render "$USER_WALL" "$path" "$resolution" + + PARAM_RESIZE="$PARAM_RESIZE $RES_RESIZE -geometry $position -composite " + PARAM_DIM="$PARAM_DIM $RES_DIM -geometry $position -composite " + PARAM_BLUR="$PARAM_BLUR $RES_BLUR -geometry $position -composite " + PARAM_DIMBLUR="$PARAM_DIMBLUR $RES_DIMBLUR -geometry $position -composite " + PARAM_PIXEL="$PARAM_PIXEL $RES_PIXEL -geometry $position -composite " + PARAM_DIMPIXEL="$PARAM_DIMPIXEL $RES_DIMPIXEL -geometry $position -composite " + PARAM_COLOR="$PARAM_COLOR $RES_COLOR -geometry $position -composite " + fi + + done + + purge_cache "$CUR_DIR" + + if [ "$span_image" = true ] || [ ${#DISPLAY_LIST[@]} -lt 2 ]; then + echof act "Rendering final wallpaper images..." + [[ -f "$RES_RESIZE" ]] && eval "cp $RES_RESIZE $CUR_W_RESIZE" + [[ -f "$RES_DIM" ]] && eval "cp $RES_DIM $CUR_W_DIM" + [[ -f "$RES_BLUR" ]] && eval "cp $RES_BLUR $CUR_W_BLUR" + [[ -f "$RES_DIMBLUR" ]] && eval "cp $RES_DIMBLUR $CUR_W_DIMBLUR" + [[ -f "$RES_PIXEL" ]] && eval "cp $RES_PIXEL $CUR_W_PIXEL" + [[ -f "$RES_DIMPIXEL" ]] && eval "cp $RES_DIMPIXEL $CUR_W_DIMPIXEL" + [[ -f "$RES_COLOR" ]] && eval "cp $RES_COLOR $CUR_W_COLOR" + else + echof act "Creating canvas: $TOTAL_SIZE" + [[ -f "$RES_RESIZE" ]] && eval "$convert_command -size $TOTAL_SIZE 'xc:blue' $CUR_W_RESIZE" + [[ -f "$RES_DIM" ]] && eval "$convert_command -size $TOTAL_SIZE 'xc:blue' $CUR_W_DIM" + [[ -f "$RES_BLUR" ]] && eval "$convert_command -size $TOTAL_SIZE 'xc:blue' $CUR_W_BLUR" + [[ -f "$RES_DIMBLUR" ]] && eval "$convert_command -size $TOTAL_SIZE 'xc:blue' $CUR_W_DIMBLUR" + [[ -f "$RES_PIXEL" ]] && eval "$convert_command -size $TOTAL_SIZE 'xc:blue' $CUR_W_PIXEL" + [[ -f "$RES_DIMPIXEL" ]] && eval "$convert_command -size $TOTAL_SIZE 'xc:blue' $CUR_W_DIMPIXEL" + [[ -f "$RES_COLOR" ]] && eval "$convert_command -size $TOTAL_SIZE 'xc:blue' $CUR_W_COLOR" + + echof act "Rendering final wallpaper images..." + [[ -f "$CUR_W_RESIZE" ]] && eval "$convert_command $CUR_W_RESIZE $PARAM_RESIZE $CUR_W_RESIZE" + [[ -f "$CUR_W_DIM" ]] && eval "$convert_command $CUR_W_DIM $PARAM_DIM $CUR_W_DIM" + [[ -f "$CUR_W_BLUR" ]] && eval "$convert_command $CUR_W_BLUR $PARAM_BLUR $CUR_W_BLUR" + [[ -f "$CUR_W_DIMBLUR" ]] && eval "$convert_command $CUR_W_DIMBLUR $PARAM_DIMBLUR $CUR_W_DIMBLUR" + [[ -f "$CUR_W_PIXEL" ]] && eval "$convert_command $CUR_W_PIXEL $PARAM_PIXEL $CUR_W_PIXEL" + [[ -f "$CUR_W_DIMPIXEL" ]] && eval "$convert_command $CUR_W_DIMPIXEL $PARAM_DIMPIXEL $CUR_W_DIMPIXEL" + [[ -f "$CUR_W_COLOR" ]] && eval "$convert_command $CUR_W_COLOR $PARAM_COLOR $CUR_W_COLOR" + fi + + echof act "Rendering final lockscreen images..." + + create_loginbox + for pos in "${positions[@]}"; do + PARAM_RECT="$PARAM_RECT $RECTANGLE -geometry $pos -composite " + done + + if [ -n "$description" ]; then + create_description + for descpos in "${positions_desc[@]}"; do + PARAM_RECT="$PARAM_RECT $DESCRECT -geometry $descpos -composite " + done + fi + + [[ -f "$CUR_W_RESIZE" ]] && eval "$convert_command $CUR_W_RESIZE $PARAM_RECT $CUR_L_RESIZE" + [[ -f "$CUR_W_DIM" ]] && eval "$convert_command $CUR_W_DIM $PARAM_RECT $CUR_L_DIM" + [[ -f "$CUR_W_BLUR" ]] && eval "$convert_command $CUR_W_BLUR $PARAM_RECT $CUR_L_BLUR" + [[ -f "$CUR_W_DIMBLUR" ]] && eval "$convert_command $CUR_W_DIMBLUR $PARAM_RECT $CUR_L_DIMBLUR" + [[ -f "$CUR_W_PIXEL" ]] && eval "$convert_command $CUR_W_PIXEL $PARAM_RECT $CUR_L_PIXEL" + [[ -f "$CUR_W_DIMPIXEL" ]] && eval "$convert_command $CUR_W_DIMPIXEL $PARAM_RECT $CUR_L_DIMPIXEL" + [[ -f "$CUR_W_COLOR" ]] && eval "$convert_command $CUR_W_COLOR $PARAM_RECT $CUR_L_COLOR" + + [[ "$RECTANGLE" ]] && rm "$RECTANGLE" + [[ "$DESCRECT" ]] && rm "$DESCRECT" + + echof ok "Done" + +} + +# set wallpaper with effect +wallpaper() { + local effect="$1" + + # make wallpaper span displays + get_display_list + if [ "$span_image" = true ] || [[ "${#DISPLAY_LIST[@]}" -gt 1 ]]; then + wallpaper_cmd="$wallpaper_cmd --no-xinerama" + fi + + # set wallpaper + case "$effect" in + dim) wallpaper="$CUR_W_DIM";; + blur) wallpaper="$CUR_W_BLUR";; + dimblur) wallpaper="$CUR_W_DIMBLUR";; + pixel) wallpaper="$CUR_W_PIXEL";; + dimpixel) wallpaper="$CUR_W_DIMPIXEL";; + color) wallpaper="$CUR_W_COLOR";; + *) wallpaper="$CUR_W_RESIZE";; + esac + eval "$wallpaper_cmd $wallpaper" +} + +# wrap echo with fancy prefix +echof() { + local prefix="$1" + local message="$2" + + case "$prefix" in + header) msgpfx="[\e[1;95mB\e[m]";; + info) msgpfx="[\e[1;97m=\e[m]";; + act) msgpfx="[\e[1;92m*\e[m]";; + ok) msgpfx="[\e[1;93m+\e[m]";; + error) msgpfx="[\e[1;91m!\e[m]";; + *) msgpfx="";; + esac + [ "$quiet" != true ] && echo -e "$msgpfx $message" +} + +# help message +usage() { + echo + echo "Usage: betterlockscreen [-u ] [-l ] [-w ]" + echo + echo " -q --quiet" + echo " Do not produce any text output on locking" + echo + echo " -u --update " + echo " Update lock screen image" + echo + echo " -l --lock " + echo " Lock screen with cached image" + echo + echo " -w --wall " + echo " Set wallpaper with cached image" + echo + echo "Additional arguments:" + echo + echo " --display " + echo " Set display to draw loginbox" + echo + echo " --span" + echo " Scale image to span multiple displays" + echo + echo " --off " + echo " Turn display off after N seconds" + echo + echo " --fx " + echo " List of effects to generate" + echo + echo " --desc " + echo " Set a description for the new lock screen image" + echo " (Only has an effect in combination with --update)" + echo + echo " --show-layout" + echo " Show current keyboard layout" + echo + echo " --wallpaper-cmd " + echo " to set your custom wallpaper setter" + echo + echo " --time-format " + echo " to set the time format used by i3lock-color" + echo + echo " -- " + echo " Pass additional arguments to i3lock" + echo + echo "Effects arguments:" + echo + echo " --dim " + echo " Dim image N percent (0-100)" + echo + echo " --blur " + echo " Blur image N amount (0.0-1.0)" + echo + echo " --pixel " + echo " Pixelate image with N shrink and N grow (unsupported)" + echo + echo " --color " + echo " Solid color background with HEX" + echo + exit 1 +} + +lockargs=(-n) + +init_config + +# show usage when no arguments passed +[[ "$1" = "" ]] && usage + +# process arguments +for arg in "$@"; do + [[ "${arg:0:1}" = '-' ]] || continue + + case "$1" in + + -q | --quiet) + quiet=true + shift + ;; + + -u | --update) + runupdate=true + imagepaths+=("$2") + shift 2 + ;; + + -s | --suspend) + runsuspend=true + ;& + + -l | --lock) + runlock=true + if [[ ${2:0:1} = '-' ]]; then + shift 1 + else + lockstyle="$2"; shift 2 + fi + ;; + + -w | --wall) + wallpaper "$2" + shift 2 + ;; + + --wallpaper-cmd) + wallpaper_cmd="$2" + shift 2 + ;; + + --time-format) + time_format="$2" + shift 2 + ;; + + --display) + display_on="$2" + shift 2 + ;; + + --span) + span_image=true + shift 1 + ;; + + --off) + lock_timeout="$2" + shift 2 + ;; + + --text) + locktext="$2" + shift 2 + ;; + + --show-layout) + keylayout="$2"; + lockargs+=(--keylayout "${keylayout:-0}") + shift 2 + ;; + + --fx) + IFS=',' read -ra fx_list <<< "$2" + shift 2 + ;; + + --dim) + dim_level="$2" + shift 2 + ;; + + --blur) + blur_level="$2" + shift 2 + ;; + + --pixel) + pixel_scale="$2" + shift 2 + ;; + + --color) + solid_color="${2//\#/}" + shift 2 + ;; + + --desc) + description="$2" + shift 2 + ;; + + -v | --version) + echo + echo "Betterlockscreen: version: v$VERSION (dunst: $DUNST_INSTALLED, feh: $FEH_INSTALLED)" + $i3lockcolor_bin --version + $convert_command --version + + if [[ "$DUNST_INSTALLED" == "true" ]]; then + dunstctl debug + fi + + if [[ "$FEH_INSTALLED" == "true" ]]; then + feh --version + fi + + break + ;; + + --) + lockargs+=("${@:2}") + break + ;; + + -h | --help | *) + usage + ;; + esac +done + +echof header "Betterlockscreen" + +# Run image generation +[[ $runupdate ]] && update "${imagepaths[@]}" + +# Activate lockscreen +[[ $runlock ]] && lockinit "$lockstyle" + +exit 0 diff --git a/bin/blackpearl-emoji.sh b/bin/blackpearl-emoji.sh new file mode 100644 index 0000000..a240225 --- /dev/null +++ b/bin/blackpearl-emoji.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +rofi -no-lazy-grab -modi emoji -show emoji -theme darknix/runner.rasi + diff --git a/bin/blackpearl-notes.sh b/bin/blackpearl-notes.sh new file mode 100644 index 0000000..a11244a --- /dev/null +++ b/bin/blackpearl-notes.sh @@ -0,0 +1,28 @@ +#! /bin/bash + +rofi_command="rofi -theme darknix/notes.rasi" + +# list of existing notes passed to rofi +options=$(notes -pl) + +# how to run the script +PARAM="$1" +case $PARAM in + -a ) + alacritty --hold --class notes --title notes -e notes -a + ;; + -e ) + # note_ID + selected=$(echo -e "$options" | $rofi_command -p "edit note" -dmenu -selected-row 0 | cut -d " " -f1) + alacritty --hold --class notes --title notes -e notes -e ${selected} + ;; + -d ) + # note_ID + selected=$(echo -e "$options" | $rofi_command -p "delete note" -dmenu -selected-row 0 | cut -d " " -f1) + alacritty --hold --class notes --title notes -e notes -d ${selected} + ;; + * ) + selected=$(echo -e "$options" | $rofi_command -p "notes" -dmenu -selected-row 0 | cut -d " " -f1) + alacritty --hold --class notes --title notes -e notes -s $selected + ;; +esac diff --git a/bin/blackpearl-powermenu.sh b/bin/blackpearl-powermenu.sh index c81cfd6..fad6b19 100644 --- a/bin/blackpearl-powermenu.sh +++ b/bin/blackpearl-powermenu.sh @@ -7,31 +7,31 @@ rofi_command="rofi -theme darknix/powermenu.rasi" power_off="" reboot="" lock="" -suspend="⏾" -log_out="﫼" +#suspend="⏾" +log_out="󰿅" # Variable passed to rofi -options="$power_off\n$reboot\n$lock\n$suspend\n$log_out" +options="$power_off\n$reboot\n$lock\n$log_out" chosen="$(echo -e "$options" | $rofi_command -dmenu -selected-row 0)" case $chosen in $power_off) notify-send 'shutting down' 'the system is going to shutdown now' sleep 1 - sudo /sbin/shutdown -h now + /usr/bin/loginctl poweroff ;; $reboot) notify-send 'rebooting the system' 'the system is going to reboot now' sleep 1 - sudo /sbin/shutdown -r now + /usr/bin/loginctl reboot ;; $lock) sleep 1 i3lock-fancy ;; - $suspend) - sleep 1 - i3suspend - ;; +# $suspend) +# sleep 1 +# i3suspend +# ;; $log_out) i3-exit ;; diff --git a/bin/blackpearl-symbols.sh b/bin/blackpearl-symbols.sh new file mode 100644 index 0000000..5723bd1 --- /dev/null +++ b/bin/blackpearl-symbols.sh @@ -0,0 +1 @@ +rofi -no-lazy-grab -show sym -modes "sym:symbols.sh" -theme darknix/runner.rasi diff --git a/bin/blackpearl-utilsmenu.sh b/bin/blackpearl-utilsmenu.sh index 9bcab99..8c2beaa 100644 --- a/bin/blackpearl-utilsmenu.sh +++ b/bin/blackpearl-utilsmenu.sh @@ -11,7 +11,7 @@ options="$wpaper\n$webdevel" chosen="$(echo -e "$options" | $rofi_command -dmenu -selected-row 1)" case $chosen in $wpaper) - change_wallpaper.sh + qwalwal.sh ;; $webdevel) webdevel diff --git a/bin/blackpearl-window.sh b/bin/blackpearl-window.sh index eb4f161..68d4d4f 100644 --- a/bin/blackpearl-window.sh +++ b/bin/blackpearl-window.sh @@ -2,10 +2,10 @@ case $1 in all ) - rofi -no-lazy-grab -show window -theme darknix/main.rasi + rofi -no-lazy-grab -show window -theme darknix/appslist.rasi -window-format " [{w}] {c} {t:20}" -window-thumbnail ;; desktop ) - rofi -no-lazy-grab -show windowcd -theme darknix/main.rasi + rofi -no-lazy-grab -show windowcd -theme darknix/appslist.rasi ;; esac diff --git a/bin/change_wallpaper.sh b/bin/change_wallpaper.sh index dd93b23..e3d293a 100644 --- a/bin/change_wallpaper.sh +++ b/bin/change_wallpaper.sh @@ -1,8 +1,12 @@ #! /bin/bash +# uncomment for debug +# set -x + PID=$$ PIDFILE=${PIDFILE:-/tmp/wallpaper.pid} WAIT_CYCLE="5m" +INPUT=$1 trap "rm -f $PIDFILE" SIGTERM @@ -86,7 +90,7 @@ function file_chooser() { function run() { if [[ $(basename $0) == "wallpaper.sh" ]]; then # we were called as wallpaper.sh, so simple wallpaper setter without qarma interaction - wpapers $1 + wpapers "$1" elif [[ $(basename $0) == "change_wallpaper.sh" ]]; then # we use qarma to set the wallpaper $QARMA --question --title="Change Wallpaper" --text="Do you want to change the wallpaper?" @@ -108,10 +112,16 @@ if [[ -r $PIDFILE ]]; then # let's kill it and run again kill -s 15 $(cat $PIDFILE) > /dev/null 2>&1 # should already be deleted by trap, but just to be sure + rm /tmp/choice || true rm $PIDFILE fi # create PIDFILE echo $PID > $PIDFILE -run +if [[ ! -z $1 ]]; then + run $1 +else + run +fi + diff --git a/bin/dunst-snooze.sh b/bin/dunst-snooze.sh new file mode 100644 index 0000000..59bf6b0 --- /dev/null +++ b/bin/dunst-snooze.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +case "$1" in + --toggle) + dunstctl set-paused toggle + ;; + *) + if [ "$(dunstctl is-paused)" = "true" ]; then + echo "  " + else + echo "  " + fi + ;; +esac diff --git a/bin/dunst_vol_brig.sh b/bin/dunst_vol_brig.sh new file mode 100644 index 0000000..a255d34 --- /dev/null +++ b/bin/dunst_vol_brig.sh @@ -0,0 +1,87 @@ +#! /bin/bash +# See README.md for usage instructions +bar_color="#ffbf00" +volume_step=5 +brightness_step=10 + +# Uses regex to get volume from pactl +function get_volume { + pactl get-sink-volume @DEFAULT_SINK@ | grep -Po '[0-9]{1,3}(?=%)' | head -1 +} + +# Uses regex to get mute status from pactl +function get_mute { + pactl get-sink-mute @DEFAULT_SINK@ | grep -Po '(?<=Mute: )(yes|no)' +} + +# Uses regex to get brightness from xbacklight +function get_brightness { + xbacklight | grep -Po '[0-9]{1,3}(?=\.)' +} + +# Returns a mute icon, a volume-low icon, or a volume-high icon, depending on the volume +function get_volume_icon { + volume=$(get_volume) + mute=$(get_mute) + if [ $volume -eq 0 ] || [ $mute == "yes" ] ; then + volume_icon="" + elif [ $volume -lt 50 ]; then + volume_icon="" + else + volume_icon="" + fi +} + +# Always returns the same icon - I couldn't get the brightness-low icon to work with fontawesome +function get_brightness_icon { + brightness_icon="󰃠" +} + +# Displays a volume notification using dunstify +function show_volume_notif { + volume=$(get_volume) + get_volume_icon + if [ $volume -eq 0 ] || [ $mute == "yes" ] ; then + volstr="SHHH!!" + else + volstr=${volume}% + fi + dunstify -i audio-volume-muted -t 1000 -r 2593 -u normal "$volume_icon $volstr" -h int:value:$volume -h string:hlcolor:$bar_color +} + +# Displays a brightness notification using dunstify +function show_brightness_notif { + brightness=$(get_brightness) + get_brightness_icon + dunstify -t 1000 -r 2593 -u normal "$brightness_icon $brightness%" -h int:value:$brightness -h string:hlcolor:$bar_color +} + +# Main function - Takes user input, "volume_up", "volume_down", "brightness_up", or "brightness_down" +case $1 in + vol_u) + # Unmutes and increases volume, then displays the notification + pactl set-sink-mute @DEFAULT_SINK@ 0 + pactl set-sink-volume @DEFAULT_SINK@ +$volume_step% + show_volume_notif + ;; + vol_d) + # Raises volume and displays the notification + pactl set-sink-volume @DEFAULT_SINK@ -$volume_step% + show_volume_notif + ;; + mute) + # Toggles mute and displays the notification + pactl set-sink-mute @DEFAULT_SINK@ toggle + show_volume_notif + ;; + brig_u) + # Increases brightness and displays the notification + xbacklight -inc $brightness_step -time 0 + show_brightness_notif + ;; + brig_d) + # Decreases brightness and displays the notification + xbacklight -dec $brightness_step -time 0 + show_brightness_notif + ;; +esac diff --git a/bin/executors/battery-level b/bin/executors/battery-level deleted file mode 100644 index 4078b35..0000000 --- a/bin/executors/battery-level +++ /dev/null @@ -1,26 +0,0 @@ -#! /bin/bash - -BAT_LEVEL=$(acpi -b | awk ' { print ($4)-0}') -CHARGER_ON=$(acpi -a | grep -i "on") -CHARGER_OFF=$(acpi -a | grep -i "off") - -if [ "$BAT_LEVEL" -le "20" ] ; then - if [ "$CHARGER_OFF" ]; then - logger "battery not charging, we're gonna die soon." - notify-send -u critical -i dialog-error "BATTERY LOW" "battery level is below 20%, please plug the AC charger" - pactl set-sink-volume 0 100\% - pactl set-sink-mute 0 0 - play -q /usr/share/sounds/Oxygen-Sys-App-Error.ogg - else - logger "battery low but charging. It's all fine." - fi -elif [ "$BAT_LEVEL" -lt "10" ]; then - if [ "$CHARGER_ON" ]; then - logger "battery extremely low but charging. It's all fine." - else - notify-send -u critical -i dialog-error "BATTERY EXTREMELY LOW" "battery level is below 10%, the system is going to shutdown." - pactl set-sink-volume 0 100\% - pactl set-sink-mute 0 0 - play -q /usr/share/sounds/Oxygen-Sys-App-Error-Serious.ogg - fi -fi diff --git a/bin/feh-blur b/bin/feh-blur new file mode 100644 index 0000000..da1f499 --- /dev/null +++ b/bin/feh-blur @@ -0,0 +1,412 @@ +#!/usr/bin/env bash +# https://github.com/rstacruz/feh-blur + +if [[ "$1" != "--worker" ]]; then + # Where to write stuff + export CACHE_DIR="/tmp/feh-blur.$$" + + # How much to blur (--blur N) + export BLUR_STRENGTH="32" + + # Contrast (--uncontrast) + export REDUCE_CONTRAST="0" + + # How much to dim (--dim N) + export DIM_STRENGTH="32" + + # Dimmer + export DIM_COLOR="#000" + + # Where to write the final blurred image (--save-image PATH) + export BLUR_IMAGE_SAVE_LOCATION="" + + # Interval between frames in an animation + export ANIMATION_INTERVAL=0.005 + + # Fade in and out? + export ANIMATE_FADE=1 + + # Interval to check with wmctrl + export POLL_INTERVAL=0.3 + + # The verbosity. --verbose sets this to 2, and --quiet sets it to 0. + export VERBOSE=1 +fi + +# The name of this program +export BIN="$(basename "$0")" + +# Expression for proc grepping +PROC_EXPR="bash.*$(basename "$0")" + +# Run mode. -d sets this to background (daemon) mode. +# Values: background | foreground | noop +MODE=foreground + +# Guard so that do_cleanup will only be invoked once. +CLEANING_UP=0 + +# Image extension to use. 'ppm' is used because it's faster to read/write to, I +# think. +EXT="ppm" + +# The original source. +wall_original="$CACHE_DIR/original.$EXT" + +# Echo some info. Only if verbose=1 +info () { + if [[ "$VERBOSE" -gt 0 ]]; then + echo " $1" + fi +} + +head () { + if [[ "$VERBOSE" -gt 0 ]]; then + echo "" + echo -e " \033[31m>>\033[32m $1\033[0m" + fi +} + +# Log some debug info +debug () { + if [[ "$VERBOSE" -gt 1 ]]; then + echo " - $1" + fi +} + +# Generate a bunch of images +generate_blurred_images () { + mkdir -p "$CACHE_DIR" + local source="$1" + local original="$CACHE_DIR/original.$EXT" + + gm convert "$source" -resize 1920x "$original" + + head "Found wallpaper" + info "$source" + info "Generating blurred images..." + + local fx1="" + local fx2="" + local fx3="" + + if [[ "$BLUR_STRENGTH" != "0" ]]; then + fx1="$fx1 -scale 25% -blur 0x$(( "$BLUR_STRENGTH" / 4 )) -scale 400%" + fx2="$fx2 -scale 25% -blur 0x$(( "$BLUR_STRENGTH" / 2 )) -scale 400%" + fx3="$fx3 -scale 25% -blur 0x$(( "$BLUR_STRENGTH" / 1 )) -scale 400%" + fi + + if [[ "$REDUCE_CONTRAST" = "1" ]]; then + fx1="+contrast $fx1" + fx2="+contrast +contrast $fx2" + fx3="+contrast +contrast +contrast $fx3" + fi + + if [[ "$DIM_STRENGTH" != "0" ]]; then + fx1="$fx1 -fill $DIM_COLOR -colorize $(( "$DIM_STRENGTH" / 4 ))%" + fx2="$fx2 -fill $DIM_COLOR -colorize $(( "$DIM_STRENGTH" / 2 ))%" + fx3="$fx3 -fill $DIM_COLOR -colorize $(( "$DIM_STRENGTH" / 1 ))%" + fi + + gm convert "$original" \ + $fx1 \ + "$CACHE_DIR/blur-0.$EXT" + gm convert "$CACHE_DIR/blur-0.$EXT" \ + $fx2 \ + "$CACHE_DIR/blur-1.$EXT" + gm convert "$CACHE_DIR/blur-0.$EXT" \ + $fx3 \ + "$CACHE_DIR/blur-final.$EXT" + + if [[ -n "$BLUR_IMAGE_SAVE_LOCATION" ]]; then + gm convert \ + "$CACHE_DIR/blur-final.$EXT" \ + "$BLUR_IMAGE_SAVE_LOCATION" + fi + + info "Done." +} + +# Get current feh wallpaper +get_feh_wallpaper() { + tail -n1 "$HOME/.fehbg" | sed 's/--no-fehbg //g' | cut -d"'" -f2 +} + +# Get wallpaper mode like --bg-tile +get_feh_wallpaper_mode() { + tail -n1 "$HOME/.fehbg" | sed 's/--no-fehbg //g' | cut -d' ' -f2 +} + +# get_current_workspace => "2" +get_current_workspace() { + # 2 * DG: N/A VP: 0,0 WA: N/A Name + wmctrl -d | grep '\*' | cut -d' ' -f1 +} + +# get_open_windows_count() => "2" +get_open_windows_count() { + workspace="$(get_current_workspace)" + wmctrl -l | cut -d' ' -f3 | grep -c "$workspace" +} + +is_blank() { + count=$(get_open_windows_count) + [[ "$count" -eq 0 ]] +} + +set_blurred_wallpaper() { + debug "Setting blurred wallpaper" + local mode="$1" # --bg-tile + + if [[ "$ANIMATE_FADE" == 1 ]]; then + # We're going to redirect output to /dev/null to supress feh warnings + feh --no-fehbg "$mode" "$CACHE_DIR/blur-0.$EXT" &> /dev/null + sleep $ANIMATION_INTERVAL + feh --no-fehbg "$mode" "$CACHE_DIR/blur-1.$EXT" &> /dev/null + sleep $ANIMATION_INTERVAL + fi + + feh --no-fehbg "$mode" "$CACHE_DIR/blur-final.$EXT" &> /dev/null +} + +set_original_wallpaper() { + debug "Setting original wallpaper" + local mode="$1" # --bg-tile + + if [[ "$ANIMATE_FADE" == 1 ]]; then + feh --no-fehbg "$mode" "$CACHE_DIR/blur-1.$EXT" &> /dev/null + sleep $ANIMATION_INTERVAL + feh --no-fehbg "$mode" "$CACHE_DIR/blur-0.$EXT" &> /dev/null + sleep $ANIMATION_INTERVAL + fi + + feh --no-fehbg "$mode" "$wall_original" &> /dev/null +} + +kill_other_instances() { + if [[ "$(pgrep -fcl "$PROC_EXPR")" -gt 1 ]]; then + head "Stopping other instances of $BIN..." + + local count=1 + while [[ "$(pgrep -fcl "$PROC_EXPR")" -gt 1 ]]; do + count=$(( count + 1 )) + old_pid="$(pgrep -fo "$PROC_EXPR")" + + # Kill it; if it refuses after some time, force-stop it + if [[ "$count" -gt 10 ]]; then + kill -9 "$old_pid" + else + kill "$old_pid" + fi + sleep 0.1 + done + fi +} + +run_loop () { + prev_blank="-" + prev_wallpaper="-" + first_run="1" + + while true; do + wallpaper="$(get_feh_wallpaper)" + + # Check if wallpaper has changed. + if [[ "$prev_wallpaper" != "$wallpaper" ]]; then + wallpaper_mode="$(get_feh_wallpaper_mode)" + + # If there's no wallpaper, try again later. + if [[ -z "$wallpaper" ]]; then + sleep "$POLL_INTERVAL" + continue + else + generate_blurred_images "$wallpaper" + prev_wallpaper="$wallpaper" + prev_blank="" + fi + fi + + blank="$(is_blank && echo 1 || echo 0)" + if [[ "$prev_blank" != "$blank" ]]; then + if [[ "$blank" == 0 ]]; then + set_blurred_wallpaper "$wallpaper_mode" + elif [[ "$first_run" == "0" ]]; then + # Skip set_original_wallpaper if we were started without + # an active window so that the animation is skipped + set_original_wallpaper "$wallpaper_mode" + fi + prev_blank="$blank" + fi + + first_run=0 + sleep "$POLL_INTERVAL" + done +} + +show_help() { + echo "Usage: $BIN [-v|--verbose]" + echo '' + echo 'Options:' + echo ' -b, --blur N set blur strength to N (4...128, default 32)' + echo ' --darken N darken image by N (4...100, default 32)' + echo ' --lighten N lengthen image by N (4...100, default 0)' + echo ' -c, --uncontrast reduce contrast' + echo ' --save-image PATH save blurred image to PATH' + echo ' --no-animate skip fading animation' + echo '' + echo 'Daemon options:' + echo ' -d, --daemon run in background' + echo ' -s, --stop stop previously-ran daemon' + echo '' + echo 'Other options:' + echo ' -v, --verbose show more messages' + echo ' -q, --quiet supress messages' + echo '' +} + +parse_opts() { + while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in + -h | --help) + MODE=noop + show_help + ;; + -V | --version ) + MODE=noop + echo version + ;; + -b | --blur ) + shift + BLUR_STRENGTH="$1" + ;; + -c | --uncontrast ) + REDUCE_CONTRAST=1 + ;; + --save-image ) + shift + BLUR_IMAGE_SAVE_LOCATION="$1" + ;; + --no-animate ) + ANIMATE_FADE=0 + ;; + -D | --dim | --darken ) + shift + DIM_COLOR="#000" + DIM_STRENGTH="$1" + ;; + --lighten ) + shift + DIM_COLOR="#fff" + DIM_STRENGTH="$1" + ;; + --tint-color ) + shift + DIM_COLOR="$1" + ;; + --tint-strength ) + shift + DIM_STRENGTH="$1" + ;; + -d | --daemon ) + MODE=background + ;; + -s | --stop ) + MODE=stop + ;; + -q | --quiet ) + VERBOSE=0 + ;; + -v | --verbose ) + VERBOSE=2 + ;; + esac; shift; done + if [[ "$1" == '--' ]]; then shift; fi +} + +ensure_feh() { + if ! command -v feh >/dev/null; then + echo "$BIN requires Feh to set wallpapers." + exit + fi +} + +# Ensure that 'graphicsmagick' is available. +ensure_gm() { + if ! command -v gm >/dev/null; then + echo "$BIN requires GraphicsMagick to set wallpapers." + exit + fi +} + +ensure_wmctrl() { + if ! command -v wmctrl >/dev/null; then + echo "$BIN requires wmctrl to detect events." + exit + fi +} + +print_usage() { + head "Monitoring changes" + info "$BIN will now blur any wallpapers set using 'feh'." + info "To change your wallpaper, try:" + info "" + info " feh --bg-tile your-image.jpg" +} + +main() { + ensure_feh + ensure_gm + ensure_wmctrl + parse_opts "$@" + + case "$MODE" in + background) + kill_other_instances + print_usage + "$0" --worker --quiet & disown + + head "Background mode" + info "$BIN started in background mode!" + info "To stop, use '$BIN --stop'." + ;; + + stop) + kill_other_instances + ;; + + noop) + exit + ;; + + *) + kill_other_instances + print_usage + run_loop + ;; + esac +} + +# Perform cleanup operations before stopping. +do_cleanup () { + # Guard clause so that it's only ran once + if [[ "$CLEANING_UP" == "1" ]]; then return; fi + CLEANING_UP=1 + + rm -rf "$CACHE_DIR" + + # Restore original wallpaper before exiting + if [[ "$MODE" == "foreground" ]] && [[ -e "$HOME/.fehbg" ]]; then + head "Restoring original wallpaper" + source "$HOME/.fehbg" + fi +} + +finish () { + do_cleanup + exit 1 +} + +trap finish EXIT +trap finish SIGHUP +trap finish SIGINT +trap finish SIGTERM +main "$@" diff --git a/bin/gify.sh b/bin/gify.sh new file mode 100644 index 0000000..ee38bc0 --- /dev/null +++ b/bin/gify.sh @@ -0,0 +1,170 @@ +#! /bin/bash + + +# ERROR & EXIT STATUSES +SHOWHELP=61 +USERABORTED=62 + +E_INTERROR=71 +E_NOOPTS=72 +E_NOARGS=73 +E_FILEXISTS=74 +E_NOIMAGES=75 +E_UNKNOWNOPT=76 + +# TOOLS +PWD=$(pwd) +MOGRIFY=$(which mogrify) +CONVERT=$(which convert) + +# we need mogrify and convert from the imagemagik toolset for this script to work +if [[ ! -x $MOGRIFY || ! -x $CONVERT ]]; then + showerror missingdeps + exit $E_MISSINGDEPS +fi + + +# showhelp +showhelp () +{ +case $1 in + resize ) + echo "USAGE: $(basename $0) -r | --resize [width] [extension]" + ;; + gif ) + echo "USAGE: $(basename $0) -g | --gif [delay] [extension] [output file name]" + ;; + * ) + #|----------------------- TEXT MAX WIDTH - 80 CHARS ----------------------------| + echo -e "$(basename $0) - create animated gifs from images inside current directory" + echo -e "USAGE: $(basename $0)