color toggle
This commit is contained in:
parent
bb64a10d10
commit
ce7e86edbc
|
@ -8,10 +8,12 @@ PROTOCOL="${PROTOCOL:-1}" # Protocol to use (0: X11, 1: Wayland/wlroots)
|
|||
LOAD_CONFIG="${LOAD_CONFIG:-true}" # Load config (0/1)
|
||||
WALLPAPER_CONFIG_FILE="${WALLPAPER_CONFIG_FILE:-$HOME/.config/spmenu/wallpaper/config}" # Use same directory as spmenu
|
||||
WALLPAPER_CONFIG_DIR="$(dirname "$WALLPAPER_CONFIG_FILE")"
|
||||
WALLPAPER_DIR="${WALLPAPER_DIR:-~/Wallpapers}" # Default wallpaper directory
|
||||
WALLPAPER_DIR="${WALLPAPER_DIR:-$HOME/Wallpapers}" # Default wallpaper directory
|
||||
DEFAULT_FEATURE="${DEFAULT_FEATURE:-pw}"
|
||||
DEFAULT_MODE="${DEFAULT_MODE:-fill}"
|
||||
ASK_MODE="${ASK_MODE:-false}"
|
||||
PREVIEW_IMAGE="${PREVIEW_IMAGE:-true}"
|
||||
COLOR="${COLOR:-always}"
|
||||
|
||||
die() { printf "%s\n" "$*" && exit 1; }
|
||||
remove_arg() { args="$(printf "%s\n" "$args" | sed "s|$1||g")"; }
|
||||
|
@ -48,10 +50,10 @@ read_args() {
|
|||
}
|
||||
|
||||
check_deps() {
|
||||
if [ -n "$DISPLAY" ]; then
|
||||
PROTOCOL="0"
|
||||
elif [ -n "$WAYLAND_DISPLAY" ]; then
|
||||
if [ -n "$WAYLAND_DISPLAY" ]; then
|
||||
PROTOCOL="1"
|
||||
elif [ -n "$DISPLAY" ]; then
|
||||
PROTOCOL="0"
|
||||
else
|
||||
die "no valid display server running, is \$DISPLAY or \$WAYLAND_DISPLAY set?"
|
||||
fi
|
||||
|
@ -75,9 +77,11 @@ cat << EOF > "$WALLPAPER_CONFIG_FILE"
|
|||
PROTOCOL="${PROTOCOL}" # Default protocol to use (0: X11, 1: Wayland w/ wlroots)
|
||||
WALLPAPER_DIR="${WALLPAPER_DIR}" # Default wallpaper directory, can be set on runtime
|
||||
|
||||
COLOR="${COLOR}" # Color the entries (always/never)
|
||||
DEFAULT_MODE="${DEFAULT_MODE}" # Default mode (stretch/fit/fill/center/tile)
|
||||
ASK_MODE="${ASK_MODE}" # Ask how the wallpaper should be set (true/false)
|
||||
DEFAULT_FEATURE="${DEFAULT_FEATURE}" # Default feature (sw/pw)
|
||||
PREVIEW_IMAGE="${PREVIEW_IMAGE}" # Enable image previews (true/false)
|
||||
EOF
|
||||
}
|
||||
|
||||
|
@ -91,11 +95,32 @@ read_config() {
|
|||
|
||||
write_script() {
|
||||
rm -f "$WALLPAPER_CONFIG_DIR/set_wallpaper.sh"
|
||||
|
||||
command -v pre_write_script > /dev/null && pre_write_script
|
||||
|
||||
if [ "$PROTOCOL" = "0" ]; then
|
||||
cat << EOF > "$WALLPAPER_CONFIG_DIR/set_wallpaper.sh"
|
||||
#!/bin/sh
|
||||
xwallpaper --stretch "${selwal}"
|
||||
EOF
|
||||
else
|
||||
cat << EOF > "$WALLPAPER_CONFIG_DIR/set_wallpaper.sh"
|
||||
#!/bin/sh
|
||||
swaybg -i "${selwal}" -m fill &
|
||||
EOF
|
||||
fi
|
||||
|
||||
command -v post_write_script > /dev/null && post_write_script "${selwal}"
|
||||
|
||||
chmod +x "$WALLPAPER_CONFIG_DIR/set_wallpaper.sh"
|
||||
}
|
||||
|
||||
set_wallpaper() {
|
||||
[ ! -f "$WALLPAPER_CONFIG_DIR/set_wallpaper.sh" ] && return 1
|
||||
|
||||
"$WALLPAPER_CONFIG_DIR/set_wallpaper.sh" > /dev/null
|
||||
}
|
||||
|
||||
pick_wallpaper() {
|
||||
pick_wallpaper_file
|
||||
[ -z "$selwal" ] && exit 1 # No file was picked
|
||||
|
@ -106,6 +131,7 @@ pick_wallpaper() {
|
|||
ln -s "$selwal" "$WALLPAPER_CONFIG_DIR/currentwallpaper"
|
||||
|
||||
write_script
|
||||
set_wallpaper
|
||||
}
|
||||
|
||||
pick_wallpaper_file() {
|
||||
|
@ -116,11 +142,12 @@ pick_wallpaper_file() {
|
|||
listing_files() {
|
||||
command -v pre_list_func > /dev/null && pre_list_func
|
||||
|
||||
ls --color=always > /tmp/spmenu_ls_list
|
||||
ls --color="$COLOR" > /tmp/spmenu_ls_list
|
||||
printf "..\n" >> /tmp/spmenu_ls_list
|
||||
|
||||
while read -r l; do
|
||||
command -v line_func > /dev/null && line_fnc "$(pwd)/$l"
|
||||
[ "$PREVIEW_IMAGE" != "false" ] && printf "img://%s\t" "$(pwd)/$l" | sed -e 's/\x1b\[[0-9;]*m//g'
|
||||
printf "%s\n" "$l"
|
||||
done < "/tmp/spmenu_ls_list"; rm -f /tmp/spmenu_ls_list
|
||||
|
||||
|
@ -160,8 +187,6 @@ main() {
|
|||
"pw") pick_wallpaper ;;
|
||||
esac
|
||||
|
||||
printf "%s\n" "$selwal"
|
||||
|
||||
return $?
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue