polybar: Add pop-up calendar to date module

Added calendar (using gsimplecal) which appears on left-clicking the
date module. Previous long date format switching has been moved to
right-click.

Under the hood, the official date module has been exchanged with a
custom script which simply replicates the functionality but allows
arbitrary commands to be executed on interactions with the module (since
it is now a script module).
This commit is contained in:
Marty Oehme 2021-07-08 10:36:55 +02:00
parent 31a2c283df
commit 65b8fd4820
Signed by: Marty
GPG key ID: B7538B8F50A1C800
5 changed files with 48 additions and 6 deletions

View file

@ -37,6 +37,7 @@ gnome-keyring
go
gopls
grub
gsimplecal
hugo
i3-gaps
i3blocks

View file

@ -100,3 +100,4 @@ flexicurity
indices
Anthropocene
ecotourism
legitimation

View file

@ -56,9 +56,10 @@ height = 20
padding-left = 0
padding-right = 0
module-margin-left = 2
module-margin-right = 2
modules-left = sxhkdmode workspaces pomo papersdue
modules-center = music date
modules-center = music datecal
modules-right = dunstpaused networkspeed mail weather archupdates cpu temp volume battery
; do not use offsets for the bar, would only work with override-redirect
; and will mess up tray https://github.com/polybar/polybar/issues/1355
@ -222,7 +223,15 @@ time = %H:%M
; the module will toggle between formats
date-alt = %A, %d %B %Y (W %V)
time-alt = %H:%M:%S
label = %date%%{T2} %{T-}%time%
label = %date%%{T2}  %{T-}%time%
format-underline = ${colors.primary}
[module/datecal]
type = custom/script
exec = $XDG_CONFIG_HOME/polybar/scripts/poly-date
tail = true
click-left = gsimplecal
click-right = kill -USR1 %pid%
format-underline = ${colors.primary}
; display information on currently playing track, allows simple track manipulation
@ -268,7 +277,7 @@ format-underline = ${colors.primary}
[module/weather]
type = custom/script
exec = $XDG_CONFIG_HOME/polybar/scripts/poly-weather '?format=%t+%C+(%p)'
exec = $XDG_CONFIG_HOME/polybar/scripts/poly-weather 'Copenhagen?m&format=%t+%C+(%p)'
exec-if = type $XDG_CONFIG_HOME/polybar/scripts/poly-weather
interval = 60.0
; format-background = ${colors.primary}

View file

@ -0,0 +1,31 @@
#!/usr/bin/env sh
update_time=5
mode=${1:-0}
separator='  '
short_date_string='%d/%m'"${separator}"'%H:%M'
long_date_string='%A, %d %B %Y (CW %V)'"${separator}"'%H:%M:%S'
modetoggle() {
mode=$(((mode + 1) % 2))
}
trap "modetoggle" USR1
display_date() {
if [ "$1" = "long" ]; then
date +"${long_date_string}"
else
date +"${short_date_string}"
fi
}
while true; do
if [ $mode -eq 0 ]; then
display_date short
elif [ $mode -eq 1 ]; then
display_date long
fi
sleep $update_time &
wait
done

View file

@ -3,7 +3,7 @@
wttr() {
# change Paris to your default location
request="wttr.in/${1-~Leipzig}"
curl -s -H "Accept-Language: ${LANG%_*}" --compressed "$request"
curl -s -H "Accept-Language: ${LANG%_*}" --compressed "${request}"
}
wttr "$@"