-
Notifications
You must be signed in to change notification settings - Fork 1
polybar
budRich edited this page May 14, 2022
·
2 revisions
This is a custom polybar module that was created for a screencast on the budlabs youtube channel.
- polify used to update the module.
- bwp for wallpaper selecting
- i3menu OR dmenu for displaying menus
- i3lock to lock the screen (optional)
[module/bwpmodule]
type = custom/ipc
hook-0 = polify --module bwpmodule
format = <output>
click-left = bwpcontrol toggle
click-middle = bwp --lock --wallpaper
click-right = bwp --blur
scroll-up = bwpcontrol next
scroll-down = bwpcontrol prev
initial = 1
Also make sure the following setting is present in the bar section of your polybar config:
[bar/example]
...
enable-ipc = true
...
; for FontAweseom to work these font settings are required
font-1 = FontAwesome5Free:style=Solid:pixelsize=10:antialias=true;3
font-2 = FontAwesome5Brands:style=Solid:pixelsize=10:antialias=true;3
Below is the bash script needed for this to work, save it as bwpcontrol, make it executable and available in your $PATH.
#!/usr/bin/env bash
: "${BWP_DIR:=$HOME/.cache/wallpapers}"
_polybarmodule=bwpmodule
declare -A buttons
# customize icons and actions here
# (default icons are from fontawesome)
buttons[prev]="%{A1:bwpcontrol prev:}%{A}"
buttons[next]="%{A1:bwpcontrol next:}%{A}"
buttons[edit]="%{A1:bwpcontrol edit:}%{A}"
buttons[delete]="%{A1:bwpcontrol delete:}%{A}"
buttons[random]="%{A1:bwpcontrol random:}%{A}"
# CURRENTWALL string will get replaced by the name
# of the currentwallpaper
buttons[text]="%{A1:bwpcontrol menu:}CURRENTWALL%{A}"
[[ -n $(polify --module "$_polybarmodule") ]] && _state=controls
main() {
case "$1" in
( update )
[[ $_state = controls ]] && updatemodule
;;
( toggle )
if [[ $_state = controls ]]; then
polify --module "$_polybarmodule" --clear
else
updatemodule
fi
;;
( next|prev|random|delete )
bwp -f"${1:0:1}"
[[ $_state = controls ]] && updatemodule
;;
( edit ) rename_wallpaper ;;
( menu ) select_wallpaper ;;
esac
}
select_wallpaper() {
local newwall wdir
wdir="$BWP_DIR/walls"
newwall="$(
find "$wdir" ! -path "$wdir" -printf '%f\n' \
| if command -v i3menu > /dev/null ; then
i3menu \
--orientation vertical \
--width 300 \
--ypos 25 \
--layout mouse \
--anchor 2 \
--height 350 \
else
dmenu
fi
)"
[[ -n $newwall ]] && {
bwp "$newwall"
updatemodule
}
}
rename_wallpaper() {
local xpos newname
_curpth="$(readlink "$BWP_DIR/currentwall")"
_curnam="${_curpth##*/}"
# adjust the xposition depending on the
# visibility of the "next button"
[[ $_curnam = $(head -1 "$BWP_DIR/history") ]] \
&& xpos=55 \
|| xpos=68
newname="$(
echo -n | if command -v i3menu > /dev/null ; then
i3menu \
--layout mouse \
--filter "$_curnam" \
--ypos 1 \
--xoffset $xpos \
--width 350 \
else
dmenu
fi
)"
[[ -n $newname ]] && {
bwp --rename "$newname"
updatemodule
}
}
updatemodule() {
local ne pr ip in ie id ir it lbl
_curpth="$(readlink "$BWP_DIR/currentwall")"
_curnam="${_curpth##*/}"
# this test hides the next button if the
# currentwall is the first in history. And hides
# the prevbutton if the current wall is last in
# history.
[[ -f "$BWP_DIR/history" ]] && {
ne='' pr=''
[[ $_curnam = $(head -1 "$BWP_DIR/history") ]] && unset ne
[[ $_curnam = $(tail -1 "$BWP_DIR/history") ]] && unset pr
}
ip=${buttons[prev]}
in=${buttons[next]}
ie=${buttons[edit]}
id=${buttons[delete]}
ir=${buttons[random]}
it=${buttons[text]/CURRENTWALL/$_curnam}
# lbl is the module content
lbl="%{A1::} ${pr+$ip }$ie $id $ir ${ne+$in }$it%{A}"
polify --module "$_polybarmodule" "$lbl"
}
main "${@}"