From 45a360f52b725e944faff19b2c73049a6a2612ed Mon Sep 17 00:00:00 2001 From: danix Date: Wed, 6 Nov 2024 12:54:24 +0100 Subject: [PATCH] major update and addition of various config files. Reorganized a few directories --- etc/bash_completion.d/sbopkg.bash | 84 + home-bin/betterlockscreen | 942 ++++++++ home-bin/blackpearl-appsmenu.sh | 5 + home-bin/blackpearl-emoji.sh | 4 + home-bin/blackpearl-notes.sh | 28 + home-bin/blackpearl-powermenu.sh | 39 + home-bin/blackpearl-runner.sh | 4 + home-bin/blackpearl-scrotmenu.sh | 19 + home-bin/blackpearl-sshmenu.sh | 4 + home-bin/blackpearl-symbols.sh | 1 + home-bin/blackpearl-utilsmenu.sh | 20 + home-bin/blackpearl-window.sh | 12 + home-bin/change_wallpaper.sh | 127 + home-bin/dunst-snooze.sh | 14 + home-bin/dunst_vol_brig.sh | 87 + home-bin/feh-blur | 412 ++++ home-bin/gify.sh | 170 ++ home-bin/hideIt.sh | 686 ++++++ home-bin/hidebars.sh | 10 + home-bin/i3-exit | 24 + home-bin/i3-scrot | 73 + home-bin/i3lock-blur | 8 + home-bin/i3lock-fancy | 141 ++ home-bin/i3suspend | 7 + home-bin/info-airqualityindex.sh | 41 + home-bin/is_installed | 123 + home-bin/lightsOn.sh | 240 ++ home-bin/maiumin | 18 + home-bin/mkpass | 54 + home-bin/mvb | 164 ++ home-bin/my_netstat | 8 + home-bin/nopy.sh | 77 + home-bin/nospaces | 14 + home-bin/notes | 726 ++++++ home-bin/polybar-kdeconnect.sh | 123 + home-bin/qwalwal.sh | 131 + home-bin/run-polybar.sh | 37 + home-bin/send-to-device.sh | 54 + home-bin/slack-updates | 36 + home-bin/speedtest | Bin 0 -> 2613400 bytes home-bin/superenalotto.sh | 37 + home-bin/symbols.sh | 80 + home-bin/vt-color-scheme.py | 59 + home-bin/wacom | 22 + home-bin/wal.sh | 30 + home-bin/wallpaper.sh | 127 + home-bin/walogram | 173 ++ home-bin/walwal.sh | 131 + home-config/i3/config | 352 +++ home-config/picom/picom.conf | 431 ++++ home-config/polybar/config | 118 + home-config/polybar/config.ini-original | 423 ++++ home-config/polybar/config.ini-vecchio | 383 +++ home-config/polybar/config.ini.boh | 333 +++ home-config/polybar/modules/airquality.ini | 5 + home-config/polybar/modules/battery.ini | 39 + home-config/polybar/modules/cpu.ini | 15 + home-config/polybar/modules/date.ini | 8 + home-config/polybar/modules/duckstation.ini | 10 + home-config/polybar/modules/dunst-snooze.ini | 6 + home-config/polybar/modules/filesys.ini | 18 + home-config/polybar/modules/gmail-0.ini | 10 + home-config/polybar/modules/gmail-1.ini | 10 + home-config/polybar/modules/gmail-2.ini | 10 + home-config/polybar/modules/gmail/.gitignore | 1 + home-config/polybar/modules/gmail/LICENSE | 21 + home-config/polybar/modules/gmail/README.md | 67 + home-config/polybar/modules/gmail/auth.py | 27 + .../polybar/modules/gmail/client_secrets.json | 1 + .../modules/gmail/credentials_65d85.json | 1 + .../modules/gmail/credentials_danixland.json | 1 + .../modules/gmail/credentials_itdm.json | 1 + home-config/polybar/modules/gmail/launch.py | 67 + .../polybar/modules/gmail/list_labels.py | 18 + home-config/polybar/modules/gmail/poetry.lock | 412 ++++ home-config/polybar/modules/gmail/preview.png | Bin 0 -> 497 bytes .../polybar/modules/gmail/pyproject.toml | 22 + home-config/polybar/modules/i3.ini | 34 + home-config/polybar/modules/kdeconnect.ini | 5 + home-config/polybar/modules/keyboard.ini | 20 + home-config/polybar/modules/memory.ini | 6 + home-config/polybar/modules/network.ini | 16 + home-config/polybar/modules/pulseaudio.ini | 13 + home-config/polybar/modules/slackware.ini | 10 + home-config/polybar/modules/temperature.ini | 54 + home-config/polybar/modules/tray.ini | 6 + home-config/polybar/modules/weather.ini | 10 + .../modules/weather/openweathermap-simple.sh | 329 +++ .../weather/openweathermap-simple.sh.old | 59 + home-config/polybar/modules/windowlist.ini | 5 + home-config/polybar/modules/windows.ini | 11 + home-config/polybar/modules/workspaces.ini | 37 + .../polybar/scripts/windowlist/LICENSE | 22 + .../polybar/scripts/windowlist/Makefile | 26 + .../polybar/scripts/windowlist/README.md | 229 ++ .../scripts/windowlist/click-actions/close | Bin 0 -> 32392 bytes .../scripts/windowlist/click-actions/close.c | 46 + .../scripts/windowlist/click-actions/minimize | Bin 0 -> 25160 bytes .../windowlist/click-actions/minimize.c | 22 + .../scripts/windowlist/click-actions/raise | Bin 0 -> 32512 bytes .../scripts/windowlist/click-actions/raise.c | 47 + .../polybar/scripts/windowlist/config.toml | 52 + home-config/polybar/scripts/windowlist/main | Bin 0 -> 178608 bytes home-config/polybar/scripts/windowlist/main.c | 450 ++++ .../polybar/scripts/windowlist/screenshot.png | Bin 0 -> 2759 bytes .../polybar/scripts/windowlist/toml-c.h | 2132 +++++++++++++++++ .../polybar/scripts/windowlist/windowlist.c | 284 +++ .../polybar/scripts/windowlist/windowlist.h | 12 + .../polybar/scripts/windowlist/windowlist.o | Bin 0 -> 31096 bytes home-config/rofi/darknix/appmenu.rasi | 164 ++ home-config/rofi/darknix/appslist.rasi | 94 + home-config/rofi/darknix/i3exit.rasi | 63 + home-config/rofi/darknix/libs/reset.rasi | 11 + home-config/rofi/darknix/libs/settings.rasi | 19 + home-config/rofi/darknix/main.rasi | 53 + home-config/rofi/darknix/notes.rasi | 59 + home-config/rofi/darknix/powermenu.rasi | 53 + home-config/rofi/darknix/runner.rasi | 57 + home-config/rofi/darknix/scrotmenu.rasi | 53 + home-config/rofi/darknix/sshmenu.rasi | 154 ++ home-config/rofi/darknix/utilsmenu.rasi | 53 + home-config/rofi/rofi-symbols/1.math.symbols | 39 + .../rofi-symbols/2.greek(distinct).symbols | 49 + picom/picom.conf | 431 ++++ polybar/config | 118 + polybar/config.ini-original | 423 ++++ polybar/config.ini-vecchio | 383 +++ polybar/config.ini.boh | 333 +++ polybar/modules/airquality.ini | 5 + polybar/modules/battery.ini | 39 + polybar/modules/cpu.ini | 15 + polybar/modules/date.ini | 8 + polybar/modules/duckstation.ini | 10 + polybar/modules/dunst-snooze.ini | 6 + polybar/modules/filesys.ini | 18 + polybar/modules/gmail-0.ini | 10 + polybar/modules/gmail-1.ini | 10 + polybar/modules/gmail-2.ini | 10 + polybar/modules/gmail/.gitignore | 1 + polybar/modules/gmail/LICENSE | 21 + polybar/modules/gmail/README.md | 67 + polybar/modules/gmail/auth.py | 27 + polybar/modules/gmail/client_secrets.json | 1 + polybar/modules/gmail/credentials_65d85.json | 1 + .../modules/gmail/credentials_danixland.json | 1 + polybar/modules/gmail/credentials_itdm.json | 1 + polybar/modules/gmail/launch.py | 67 + polybar/modules/gmail/list_labels.py | 18 + polybar/modules/gmail/poetry.lock | 412 ++++ polybar/modules/gmail/preview.png | Bin 0 -> 497 bytes polybar/modules/gmail/pyproject.toml | 22 + polybar/modules/i3.ini | 34 + polybar/modules/kdeconnect.ini | 5 + polybar/modules/keyboard.ini | 20 + polybar/modules/memory.ini | 6 + polybar/modules/network.ini | 16 + polybar/modules/pulseaudio.ini | 13 + polybar/modules/slackware.ini | 10 + polybar/modules/temperature.ini | 54 + polybar/modules/tray.ini | 6 + polybar/modules/weather.ini | 10 + .../modules/weather/openweathermap-simple.sh | 329 +++ .../weather/openweathermap-simple.sh.old | 59 + polybar/modules/windowlist.ini | 5 + polybar/modules/windows.ini | 11 + polybar/modules/workspaces.ini | 37 + polybar/scripts/windowlist/LICENSE | 22 + polybar/scripts/windowlist/Makefile | 26 + polybar/scripts/windowlist/README.md | 229 ++ .../scripts/windowlist/click-actions/close | Bin 0 -> 32392 bytes .../scripts/windowlist/click-actions/close.c | 46 + .../scripts/windowlist/click-actions/minimize | Bin 0 -> 25160 bytes .../windowlist/click-actions/minimize.c | 22 + .../scripts/windowlist/click-actions/raise | Bin 0 -> 32512 bytes .../scripts/windowlist/click-actions/raise.c | 47 + polybar/scripts/windowlist/config.toml | 52 + polybar/scripts/windowlist/main | Bin 0 -> 178608 bytes polybar/scripts/windowlist/main.c | 450 ++++ polybar/scripts/windowlist/screenshot.png | Bin 0 -> 2759 bytes polybar/scripts/windowlist/toml-c.h | 2132 +++++++++++++++++ polybar/scripts/windowlist/windowlist.c | 284 +++ polybar/scripts/windowlist/windowlist.h | 12 + polybar/scripts/windowlist/windowlist.o | Bin 0 -> 31096 bytes 183 files changed, 19489 insertions(+) create mode 100644 etc/bash_completion.d/sbopkg.bash create mode 100644 home-bin/betterlockscreen create mode 100644 home-bin/blackpearl-appsmenu.sh create mode 100644 home-bin/blackpearl-emoji.sh create mode 100644 home-bin/blackpearl-notes.sh create mode 100644 home-bin/blackpearl-powermenu.sh create mode 100644 home-bin/blackpearl-runner.sh create mode 100644 home-bin/blackpearl-scrotmenu.sh create mode 100644 home-bin/blackpearl-sshmenu.sh create mode 100644 home-bin/blackpearl-symbols.sh create mode 100644 home-bin/blackpearl-utilsmenu.sh create mode 100644 home-bin/blackpearl-window.sh create mode 100644 home-bin/change_wallpaper.sh create mode 100644 home-bin/dunst-snooze.sh create mode 100644 home-bin/dunst_vol_brig.sh create mode 100644 home-bin/feh-blur create mode 100644 home-bin/gify.sh create mode 100644 home-bin/hideIt.sh create mode 100644 home-bin/hidebars.sh create mode 100644 home-bin/i3-exit create mode 100644 home-bin/i3-scrot create mode 100644 home-bin/i3lock-blur create mode 100644 home-bin/i3lock-fancy create mode 100644 home-bin/i3suspend create mode 100644 home-bin/info-airqualityindex.sh create mode 100644 home-bin/is_installed create mode 100644 home-bin/lightsOn.sh create mode 100644 home-bin/maiumin create mode 100644 home-bin/mkpass create mode 100644 home-bin/mvb create mode 100644 home-bin/my_netstat create mode 100644 home-bin/nopy.sh create mode 100644 home-bin/nospaces create mode 100644 home-bin/notes create mode 100644 home-bin/polybar-kdeconnect.sh create mode 100644 home-bin/qwalwal.sh create mode 100644 home-bin/run-polybar.sh create mode 100644 home-bin/send-to-device.sh create mode 100644 home-bin/slack-updates create mode 100644 home-bin/speedtest create mode 100644 home-bin/superenalotto.sh create mode 100644 home-bin/symbols.sh create mode 100644 home-bin/vt-color-scheme.py create mode 100644 home-bin/wacom create mode 100644 home-bin/wal.sh create mode 100644 home-bin/wallpaper.sh create mode 100644 home-bin/walogram create mode 100644 home-bin/walwal.sh create mode 100644 home-config/i3/config create mode 100644 home-config/picom/picom.conf create mode 100644 home-config/polybar/config create mode 100644 home-config/polybar/config.ini-original create mode 100644 home-config/polybar/config.ini-vecchio create mode 100644 home-config/polybar/config.ini.boh create mode 100644 home-config/polybar/modules/airquality.ini create mode 100644 home-config/polybar/modules/battery.ini create mode 100644 home-config/polybar/modules/cpu.ini create mode 100644 home-config/polybar/modules/date.ini create mode 100644 home-config/polybar/modules/duckstation.ini create mode 100644 home-config/polybar/modules/dunst-snooze.ini create mode 100644 home-config/polybar/modules/filesys.ini create mode 100644 home-config/polybar/modules/gmail-0.ini create mode 100644 home-config/polybar/modules/gmail-1.ini create mode 100644 home-config/polybar/modules/gmail-2.ini create mode 100644 home-config/polybar/modules/gmail/.gitignore create mode 100644 home-config/polybar/modules/gmail/LICENSE create mode 100644 home-config/polybar/modules/gmail/README.md create mode 100755 home-config/polybar/modules/gmail/auth.py create mode 100644 home-config/polybar/modules/gmail/client_secrets.json create mode 100644 home-config/polybar/modules/gmail/credentials_65d85.json create mode 100644 home-config/polybar/modules/gmail/credentials_danixland.json create mode 100644 home-config/polybar/modules/gmail/credentials_itdm.json create mode 100755 home-config/polybar/modules/gmail/launch.py create mode 100755 home-config/polybar/modules/gmail/list_labels.py create mode 100644 home-config/polybar/modules/gmail/poetry.lock create mode 100644 home-config/polybar/modules/gmail/preview.png create mode 100644 home-config/polybar/modules/gmail/pyproject.toml create mode 100644 home-config/polybar/modules/i3.ini create mode 100644 home-config/polybar/modules/kdeconnect.ini create mode 100644 home-config/polybar/modules/keyboard.ini create mode 100644 home-config/polybar/modules/memory.ini create mode 100644 home-config/polybar/modules/network.ini create mode 100644 home-config/polybar/modules/pulseaudio.ini create mode 100644 home-config/polybar/modules/slackware.ini create mode 100644 home-config/polybar/modules/temperature.ini create mode 100644 home-config/polybar/modules/tray.ini create mode 100644 home-config/polybar/modules/weather.ini create mode 100755 home-config/polybar/modules/weather/openweathermap-simple.sh create mode 100755 home-config/polybar/modules/weather/openweathermap-simple.sh.old create mode 100644 home-config/polybar/modules/windowlist.ini create mode 100644 home-config/polybar/modules/windows.ini create mode 100644 home-config/polybar/modules/workspaces.ini create mode 100644 home-config/polybar/scripts/windowlist/LICENSE create mode 100644 home-config/polybar/scripts/windowlist/Makefile create mode 100644 home-config/polybar/scripts/windowlist/README.md create mode 100755 home-config/polybar/scripts/windowlist/click-actions/close create mode 100644 home-config/polybar/scripts/windowlist/click-actions/close.c create mode 100755 home-config/polybar/scripts/windowlist/click-actions/minimize create mode 100644 home-config/polybar/scripts/windowlist/click-actions/minimize.c create mode 100755 home-config/polybar/scripts/windowlist/click-actions/raise create mode 100644 home-config/polybar/scripts/windowlist/click-actions/raise.c create mode 100644 home-config/polybar/scripts/windowlist/config.toml create mode 100755 home-config/polybar/scripts/windowlist/main create mode 100644 home-config/polybar/scripts/windowlist/main.c create mode 100644 home-config/polybar/scripts/windowlist/screenshot.png create mode 100644 home-config/polybar/scripts/windowlist/toml-c.h create mode 100644 home-config/polybar/scripts/windowlist/windowlist.c create mode 100644 home-config/polybar/scripts/windowlist/windowlist.h create mode 100644 home-config/polybar/scripts/windowlist/windowlist.o create mode 100644 home-config/rofi/darknix/appmenu.rasi create mode 100644 home-config/rofi/darknix/appslist.rasi create mode 100644 home-config/rofi/darknix/i3exit.rasi create mode 100644 home-config/rofi/darknix/libs/reset.rasi create mode 100644 home-config/rofi/darknix/libs/settings.rasi create mode 100644 home-config/rofi/darknix/main.rasi create mode 100644 home-config/rofi/darknix/notes.rasi create mode 100644 home-config/rofi/darknix/powermenu.rasi create mode 100644 home-config/rofi/darknix/runner.rasi create mode 100644 home-config/rofi/darknix/scrotmenu.rasi create mode 100644 home-config/rofi/darknix/sshmenu.rasi create mode 100644 home-config/rofi/darknix/utilsmenu.rasi create mode 100644 home-config/rofi/rofi-symbols/1.math.symbols create mode 100644 home-config/rofi/rofi-symbols/2.greek(distinct).symbols create mode 100644 picom/picom.conf create mode 100644 polybar/config create mode 100644 polybar/config.ini-original create mode 100644 polybar/config.ini-vecchio create mode 100644 polybar/config.ini.boh create mode 100644 polybar/modules/airquality.ini create mode 100644 polybar/modules/battery.ini create mode 100644 polybar/modules/cpu.ini create mode 100644 polybar/modules/date.ini create mode 100644 polybar/modules/duckstation.ini create mode 100644 polybar/modules/dunst-snooze.ini create mode 100644 polybar/modules/filesys.ini create mode 100644 polybar/modules/gmail-0.ini create mode 100644 polybar/modules/gmail-1.ini create mode 100644 polybar/modules/gmail-2.ini create mode 100644 polybar/modules/gmail/.gitignore create mode 100644 polybar/modules/gmail/LICENSE create mode 100644 polybar/modules/gmail/README.md create mode 100755 polybar/modules/gmail/auth.py create mode 100644 polybar/modules/gmail/client_secrets.json create mode 100644 polybar/modules/gmail/credentials_65d85.json create mode 100644 polybar/modules/gmail/credentials_danixland.json create mode 100644 polybar/modules/gmail/credentials_itdm.json create mode 100755 polybar/modules/gmail/launch.py create mode 100755 polybar/modules/gmail/list_labels.py create mode 100644 polybar/modules/gmail/poetry.lock create mode 100644 polybar/modules/gmail/preview.png create mode 100644 polybar/modules/gmail/pyproject.toml create mode 100644 polybar/modules/i3.ini create mode 100644 polybar/modules/kdeconnect.ini create mode 100644 polybar/modules/keyboard.ini create mode 100644 polybar/modules/memory.ini create mode 100644 polybar/modules/network.ini create mode 100644 polybar/modules/pulseaudio.ini create mode 100644 polybar/modules/slackware.ini create mode 100644 polybar/modules/temperature.ini create mode 100644 polybar/modules/tray.ini create mode 100644 polybar/modules/weather.ini create mode 100755 polybar/modules/weather/openweathermap-simple.sh create mode 100755 polybar/modules/weather/openweathermap-simple.sh.old create mode 100644 polybar/modules/windowlist.ini create mode 100644 polybar/modules/windows.ini create mode 100644 polybar/modules/workspaces.ini create mode 100644 polybar/scripts/windowlist/LICENSE create mode 100644 polybar/scripts/windowlist/Makefile create mode 100644 polybar/scripts/windowlist/README.md create mode 100755 polybar/scripts/windowlist/click-actions/close create mode 100644 polybar/scripts/windowlist/click-actions/close.c create mode 100755 polybar/scripts/windowlist/click-actions/minimize create mode 100644 polybar/scripts/windowlist/click-actions/minimize.c create mode 100755 polybar/scripts/windowlist/click-actions/raise create mode 100644 polybar/scripts/windowlist/click-actions/raise.c create mode 100644 polybar/scripts/windowlist/config.toml create mode 100755 polybar/scripts/windowlist/main create mode 100644 polybar/scripts/windowlist/main.c create mode 100644 polybar/scripts/windowlist/screenshot.png create mode 100644 polybar/scripts/windowlist/toml-c.h create mode 100644 polybar/scripts/windowlist/windowlist.c create mode 100644 polybar/scripts/windowlist/windowlist.h create mode 100644 polybar/scripts/windowlist/windowlist.o diff --git a/etc/bash_completion.d/sbopkg.bash b/etc/bash_completion.d/sbopkg.bash new file mode 100644 index 0000000..8ec81ca --- /dev/null +++ b/etc/bash_completion.d/sbopkg.bash @@ -0,0 +1,84 @@ +# bash completion for sbopkg tool + +_sbopkg() +{ + COMPREPLY=() + + local cur="${COMP_WORDS[COMP_CWORD]}" + local prev="${COMP_WORDS[COMP_CWORD-1]}" + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-b -c -d -e -f -g -h -i -k -l \ + -o -P -p -q -R -r -s -u -V -v' -- "$cur" ) ) + return 0 + fi + + case $prev in + -e) + COMPREPLY=( $( compgen -W 'ask continue stop' -- "$cur" ) ) + return 0 + ;; + -f) + COMPREPLY=( $( compgen -f -- "$cur" ) ) + return 0 + ;; + -d) + COMPREPLY=( $( compgen -d -- "$cur" ) ) + return 0 + ;; + -V) + COMPREPLY=( $( compgen -W "? \ + $(sbopkg -V ? 2>&1 | cut -s -f1)" -- "$cur" ) ) + return 0 + ;; + -i|-b) + ;; + *) + return 0 + ;; + esac + + local config="/etc/sbopkg/sbopkg.conf" + + for (( i=${#COMP_WORDS[@]}-1; i>0; i-- )); do + if [[ "${COMP_WORDS[i]}" == -f ]]; then + config="${COMP_WORDS[i+1]}" + break + fi + done + + if [ ! -r "$config" ]; then + return 0 + fi + + . $config + + for (( i=1; i<${#COMP_WORDS[@]}; i++ )); do + case "${COMP_WORDS[i]}" in + -V) + REPO_NAME="${COMP_WORDS[i+1]%%/*}" + REPO_BRANCH="${COMP_WORDS[i+1]#*/}" + ;; + -d) + REPO_ROOT="${COMP_WORDS[i+1]}" + ;; + esac + done + + if [ -d "$QUEUEDIR" ]; then + local queues=($(cd $QUEUEDIR; compgen -f -X "!*.sqf" -- "$cur")) + fi + + if [ -r "$REPO_ROOT/$REPO_NAME/$REPO_BRANCH/SLACKBUILDS.TXT" ]; then + COMPREPLY=($(sed -ne "/^SLACKBUILD NAME: $cur/{s/^SLACKBUILD NAME: //;p}" \ + $REPO_ROOT/$REPO_NAME/$REPO_BRANCH/SLACKBUILDS.TXT) + ${queues[@]}) + elif [ -d "$REPO_ROOT/$REPO_NAME/" ]; then + COMPREPLY=($(find $REPO_ROOT/$REPO_NAME \ + \! -path $REPO_ROOT/$REPO_NAME/'.git/*' \ + -mindepth 2 -maxdepth 2 \ + -type d -name $cur\* \ + -printf '%f\n') + ${queues[@]}) + fi +} && complete -o filenames -F _sbopkg sbopkg diff --git a/home-bin/betterlockscreen b/home-bin/betterlockscreen new file mode 100644 index 0000000..0b92ad9 --- /dev/null +++ b/home-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/home-bin/blackpearl-appsmenu.sh b/home-bin/blackpearl-appsmenu.sh new file mode 100644 index 0000000..6c499c4 --- /dev/null +++ b/home-bin/blackpearl-appsmenu.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +# rofi -no-lazy-grab -show drun -theme blackpearl/appmenu +rofi -no-lazy-grab -show drun -theme darknix/appmenu.rasi + diff --git a/home-bin/blackpearl-emoji.sh b/home-bin/blackpearl-emoji.sh new file mode 100644 index 0000000..a240225 --- /dev/null +++ b/home-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/home-bin/blackpearl-notes.sh b/home-bin/blackpearl-notes.sh new file mode 100644 index 0000000..a11244a --- /dev/null +++ b/home-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/home-bin/blackpearl-powermenu.sh b/home-bin/blackpearl-powermenu.sh new file mode 100644 index 0000000..fad6b19 --- /dev/null +++ b/home-bin/blackpearl-powermenu.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# rofi_command="rofi -theme blackpearl/powermenu.rasi" +rofi_command="rofi -theme darknix/powermenu.rasi" + +### Options ### +power_off="" +reboot="" +lock="" +#suspend="⏾" +log_out="󰿅" +# Variable passed to rofi +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 + /usr/bin/loginctl poweroff + ;; + $reboot) + notify-send 'rebooting the system' 'the system is going to reboot now' + sleep 1 + /usr/bin/loginctl reboot + ;; + $lock) + sleep 1 + i3lock-fancy + ;; +# $suspend) +# sleep 1 +# i3suspend +# ;; + $log_out) + i3-exit + ;; +esac + diff --git a/home-bin/blackpearl-runner.sh b/home-bin/blackpearl-runner.sh new file mode 100644 index 0000000..36517d1 --- /dev/null +++ b/home-bin/blackpearl-runner.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +rofi -no-lazy-grab -show run -theme darknix/runner.rasi + diff --git a/home-bin/blackpearl-scrotmenu.sh b/home-bin/blackpearl-scrotmenu.sh new file mode 100644 index 0000000..dbafcb7 --- /dev/null +++ b/home-bin/blackpearl-scrotmenu.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +rofi_command="rofi -theme darknix/scrotmenu.rasi" + +### Options ### +screen="" +area="" +# Variable passed to rofi +options="$screen\n$area" + +chosen="$(echo -e "$options" | $rofi_command -dmenu -selected-row 1)" +case $chosen in + $screen) + i3-scrot -d 3 + ;; + $area) + i3-scrot -s + ;; +esac diff --git a/home-bin/blackpearl-sshmenu.sh b/home-bin/blackpearl-sshmenu.sh new file mode 100644 index 0000000..b70d4b9 --- /dev/null +++ b/home-bin/blackpearl-sshmenu.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +rofi -no-lazy-grab -show ssh -no-parse-known-hosts -theme darknix/sshmenu.rasi + diff --git a/home-bin/blackpearl-symbols.sh b/home-bin/blackpearl-symbols.sh new file mode 100644 index 0000000..5723bd1 --- /dev/null +++ b/home-bin/blackpearl-symbols.sh @@ -0,0 +1 @@ +rofi -no-lazy-grab -show sym -modes "sym:symbols.sh" -theme darknix/runner.rasi diff --git a/home-bin/blackpearl-utilsmenu.sh b/home-bin/blackpearl-utilsmenu.sh new file mode 100644 index 0000000..8c2beaa --- /dev/null +++ b/home-bin/blackpearl-utilsmenu.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +rofi_command="rofi -theme darknix/utilsmenu.rasi" + +### Options ### +wpaper="" +webdevel="" +# Variable passed to rofi +options="$wpaper\n$webdevel" + +chosen="$(echo -e "$options" | $rofi_command -dmenu -selected-row 1)" +case $chosen in + $wpaper) + qwalwal.sh + ;; + $webdevel) + webdevel + ;; +esac + diff --git a/home-bin/blackpearl-window.sh b/home-bin/blackpearl-window.sh new file mode 100644 index 0000000..68d4d4f --- /dev/null +++ b/home-bin/blackpearl-window.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +case $1 in + all ) + 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/appslist.rasi + ;; +esac + + diff --git a/home-bin/change_wallpaper.sh b/home-bin/change_wallpaper.sh new file mode 100644 index 0000000..e3d293a --- /dev/null +++ b/home-bin/change_wallpaper.sh @@ -0,0 +1,127 @@ +#! /bin/bash + +# uncomment for debug +# set -x + +PID=$$ +PIDFILE=${PIDFILE:-/tmp/wallpaper.pid} +WAIT_CYCLE="5m" +INPUT=$1 + +trap "rm -f $PIDFILE" SIGTERM + +WP_SETTER="/usr/bin/feh" +QARMA="/usr/bin/qarma" + +function set_wp() { + NEW_WP=$1 + $WP_SETTER --bg-fill $NEW_WP +} + +# set background function (requires input) +function wpapers() { + if [[ -f $1 ]]; then + # We have a single file as input + set_wp $1 + exit 0 + elif [[ -d $1 ]]; then + # directory as input + while true; do + BGIMG=$(find $1 -type f -print | shuf -n1) + set_wp ${BGIMG} + sleep $WAIT_CYCLE + done + fi +} + +function file_or_dir() { + if [[ -f /tmp/choice ]]; then + rm /tmp/choice + fi + + FOD=$($QARMA --list --text="single image or directory?" --hide-header "file" "directory" > /tmp/choice) + case $? in + 0 ) + file_chooser $(cat /tmp/choice) + ;; + 1 ) + $QARMA --info --title="Exiting!" --text="No wallpaper was changed." + ;; + -1 ) + $QARMA --error --title="Ooops!!" --text="Something unexpected happened." + ;; + esac +} + +function file_chooser() { + case $1 in + "file" ) + FILE="$($QARMA --file-selection --title='Choose your Wallpaper')" + case $? in + 0 ) + wpapers $FILE + ;; + 1 ) + $QARMA --info --title="Exiting!" --text="No wallpaper was changed." + ;; + -1 ) + $QARMA --error --title="Ooops!!" --text="Something unexpected happened." + esac + ;; + "directory" ) + FILE="$($QARMA --file-selection --directory --title='Choose your Wallpaper directory')" + case $? in + 0 ) + wpapers $FILE + ;; + 1 ) + $QARMA --info --title="Exiting!" --text="No wallpaper was changed." + ;; + -1 ) + $QARMA --error --title="Ooops!!" --text="Something unexpected happened." + esac + ;; + * ) + $QARMA --error --title="Ooops!!" --text="Something unexpected happened." + ;; + esac +} + +function run() { + if [[ $(basename $0) == "wallpaper.sh" ]]; then + # we were called as wallpaper.sh, so simple wallpaper setter without qarma interaction + 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?" + case $? in + 0 ) + file_or_dir + ;; + 1 ) + $QARMA --info --title="Exiting!" --text="No wallpaper was changed." + ;; + -1 ) + $QARMA --error --title="Ooops!!" --text="Something unexpected happened." + esac + fi +} + +if [[ -r $PIDFILE ]]; then + # PIDFILE exists, so I guess there's already an instance running + # 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 + +if [[ ! -z $1 ]]; then + run $1 +else + run +fi + diff --git a/home-bin/dunst-snooze.sh b/home-bin/dunst-snooze.sh new file mode 100644 index 0000000..59bf6b0 --- /dev/null +++ b/home-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/home-bin/dunst_vol_brig.sh b/home-bin/dunst_vol_brig.sh new file mode 100644 index 0000000..a255d34 --- /dev/null +++ b/home-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/home-bin/feh-blur b/home-bin/feh-blur new file mode 100644 index 0000000..da1f499 --- /dev/null +++ b/home-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/home-bin/gify.sh b/home-bin/gify.sh new file mode 100644 index 0000000..ee38bc0 --- /dev/null +++ b/home-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)