Add module system (will add more of these modules tomorrow, add support

for statuscmd to stellar, add more modules to mouse.h
This commit is contained in:
speediegq 2022-10-08 02:31:35 +02:00
parent 00fbe94742
commit 122fc050bb
9 changed files with 208 additions and 12 deletions

View file

@ -40,7 +40,7 @@ clean:
dist: clean
mkdir -p speedwm-${VERSION}
cp -R *.mk *.c *.h *.png docs status LICENSE Makefile scripts speedwm-${VERSION}
cp -R *.mk *.c *.h *.png docs/ modules/ scripts/ status LICENSE Makefile speedwm-${VERSION}
tar -cf speedwm-${VERSION}.tar speedwm-${VERSION}
gzip speedwm-${VERSION}.tar
rm -rf speedwm-${VERSION} speedwm
@ -108,7 +108,15 @@ install: all
./scripts/speedwm-compatcheck
./scripts/speedwm-dm
[ -f speedwm.png ] && cp -f speedwm.png ${DESTDIR}${PREFIX}/share/pixmaps/speedwm.png || :
make modules_install
rm -f drw.o speedwm.o util.o speedwm speedwm-msg ; echo "Installed speedwm to ${DESTDIR}${PREFIX}/bin"
modules_install:
cp -f modules/module_date ${DESTDIR}${PREFIX}/bin ; chmod +x ${DESTDIR}${PREFIX}/bin/module_date
cp -f modules/module_time ${DESTDIR}${PREFIX}/bin ; chmod +x ${DESTDIR}${PREFIX}/bin/module_time
cp -f modules/module_ram ${DESTDIR}${PREFIX}/bin ; chmod +x ${DESTDIR}${PREFIX}/bin/module_ram
cp -f modules/module_vol ${DESTDIR}${PREFIX}/bin ; chmod +x ${DESTDIR}${PREFIX}/bin/module_vol
cp -f modules/module_weather ${DESTDIR}${PREFIX}/bin ; chmod +x ${DESTDIR}${PREFIX}/bin/module_weather
uninstall:
rm -rf ${DESTDIR}${PREFIX}/bin/speedwm \
@ -142,6 +150,7 @@ help:
@echo - Installation -
@echo install: Installs speedwm. You may need to run this as root.
@echo uninstall: Uninstalls speedwm. You may need to run this as root.
@echo modules_install: Install modules.
@echo
@echo - Patching -
@echo patch: Create a patch based on modifications to source code.
@ -256,4 +265,4 @@ readme:
chmod +x scripts/speedwm-help
./scripts/speedwm-mkpage -mk
.PHONY: all options clean dist install uninstall help docs page page_install page_release html markdown readme page_push upload release
.PHONY: all options clean dist install modules_install uninstall help docs page page_install page_release html markdown readme page_push upload release

35
modules/module_date Executable file
View file

@ -0,0 +1,35 @@
#!/bin/sh
# date module for status/stellar
# values
DATE_DAY="$(date +%d)" # day number
DATE_DAY_W_SHORT="$(date +%a)" # short day (ie. mon)
DATE_DAY_W_LONG="$(date +%A)" # long day (ie. monday)
DATE_MONTH="$(date +%m)" # month number
DATE_MONTH_W_SHORT="$(date +%b)" # short month (ie. oct)
DATE_MONTH_W_LONG="$(date +%B)" # long month (ie. october)
DATE_YEAR="$(date +%Y)" # year number
DATE_WEEK="$(date +%W)" # week number
DATE_WEEKDAY="$(date +%w)" # day of the week in number
ICON="$1" # icon is first argument
# no spacing if there's no icon
if [ "$ICON" != "" ]; then
ICONSPACING=" " # one character spacing
fi
# send the notification
SEND_NOTIF() {
FULL_DATE="$(printf "${ICON}${ICONSPACING}$DATE_DAY_W_LONG, $DATE_MONTH_W_LONG, $DATE_DAY $DATE_YEAR, Week $DATE_WEEK")"
notify-send "$FULL_DATE"
echo "Notification sent successfully!"
echo "INFO: $FULL_DATE"
exit 0
}
command -v notify-send > /dev/null && SEND_NOTIF
echo "FATAL: libnotify not installed, can't send notification."
exit 1

29
modules/module_ram Executable file
View file

@ -0,0 +1,29 @@
#!/bin/sh
# ram module for status/stellar
# values
RAM_USED="$(echo "$(free -h --giga | awk '/^Mem/ {print $3}')B")"
RAM_TOTAL="$(echo "$(free -h --giga | awk '/^Mem/ {print $2}')B")"
RAM_LEFT="$(echo "$(free -h --giga | awk '/^Mem/ {print $7}')B")"
ICON="$1"
# no spacing if there's no icon
if [ "$ICON" != "" ]; then
ICONSPACING=" \n" # one character spacing
fi
# send the notification
SEND_NOTIF() {
FULL_RAM="$(printf "${ICON}${ICONSPACING}Used: $RAM_USED\nFree: $RAM_LEFT\nTotal: $RAM_TOTAL\n")"
notify-send "$FULL_RAM"
echo "Notification sent successfully!"
echo "INFO: $FULL_RAM"
exit 0
}
command -v notify-send > /dev/null && SEND_NOTIF
echo "FATAL: libnotify not installed, can't send notification."
exit 1

31
modules/module_time Executable file
View file

@ -0,0 +1,31 @@
#!/bin/sh
# time module for status/stellar
# values
TIME_SECOND="$(date +%S)"
TIME_MINUTE="$(date +%M)"
TIME_HOUR="$(date +%H)"
TIME_FULL="$(date +%T)"
TIME_ZONE="$(date +%Z)"
ICON="$1"
# no spacing if there's no icon
if [ "$ICON" != "" ]; then
ICONSPACING=" " # one character spacing
fi
# send the notification
SEND_NOTIF() {
FULL_TIME="${ICON}${ICONSPACING}The time is $TIME_FULL $TIME_ZONE."
notify-send "$FULL_TIME"
echo "Notification sent successfully!"
echo "INFO: $FULL_TIME"
exit 0
}
command -v notify-send > /dev/null && SEND_NOTIF
echo "FATAL: libnotify not installed, can't send notification."
exit 1

39
modules/module_vol Executable file
View file

@ -0,0 +1,39 @@
#!/bin/sh
# ram module for status/stellar
# values
VOL_VOLUME="$(speedwm-audioctrl -getvol)"
VOL_ISPULSE="$(speedwm-audioctrl -getbackend)"
VOL_TERM="speedwm-audioctrl -runmixer"
ICON="$1"
TERM="$2"
# no spacing if there's no icon
if [ "$ICON" != "" ]; then
ICONSPACING=" " # one character spacing
fi
# use term if its defined
if [ "$TERM" != "" ]; then
echo "INFO: $VOL_TERM sent to $TERM."
$TERM -e "$VOL_TERM" && echo "INFO: $TERM returned 0" && exit 0
echo "FATAL: $TERM returned != 0"
exit 1
fi
# send the notification
SEND_NOTIF() {
FULL_VOL="${ICON}${ICONSPACING}$VOL_VOLUME"
notify-send "$FULL_VOL"
echo "Notification sent successfully!"
echo "INFO: $FULL_VOL"
exit 0
}
command -v notify-send > /dev/null && SEND_NOTIF
echo "FATAL: libnotify not installed, can't send notification."
exit 1

46
modules/module_weather Executable file
View file

@ -0,0 +1,46 @@
#!/bin/sh
# weather module for status/stellar
# values
WEATHER_TERM="speedwm-core -curl-weather"
ICON="$1"
TERM="$2"
# check if a forecast exists
# status script should create this
if [ -e "/tmp/wstatus" ]; then
FORECAST="$(cat /tmp/wstatus)"
else
echo "FATAL: No weather status available!"
exit 1
fi
# no spacing if there's no icon
if [ "$ICON" != "" ]; then
ICONSPACING=" " # one character spacing
fi
# use term if its defined
if [ "$TERM" != "" ]; then
echo "INFO: $WEATHER_TERM sent to $TERM."
$TERM -e "$WEATHER_TERM" && echo "INFO: $TERM returned 0" && exit 0
echo "FATAL: $TERM returned != 0"
exit 1
fi
# send the notification
SEND_NOTIF() {
FULL_WEATHER="${ICON}${ICONSPACING}$FORECAST"
notify-send "$FULL_WEATHER"
echo "Notification sent successfully!"
echo "INFO: $FULL_WEATHER"
exit 0
}
command -v notify-send > /dev/null && SEND_NOTIF
echo "FATAL: libnotify not installed, can't send notification."
exit 1

15
mouse.h
View file

@ -29,16 +29,19 @@ static const Button buttons[] = {
{ ClkTagBar, 0, Button5, view, {0} },
};
/* Commands that will run when a part of the status bar is pressed
* Built in status bar does not have support for this yet but you can add it by adding:
* '\<num>
/* Commands that will run when a part of the status bar is pressed. You can add:
* '\x<num>
* before you print anything. Keep in mind <num> MUST be two digits.
*
* It must also be wrapped in a printf. Example:
*
* Invalid: xsetroot -name "\x01This is a test"
* Valid: xsetroot -name "$(printf '\x01This is a test')"
*/
static const StatusCmd statuscmds[] = {
{ "notify-send 'Status item (1) was pressed.'", 1 },
{ "notify-send 'Status item (2) was pressed.'", 2 },
{ "notify-send 'Status item (3) was pressed.'", 3 },
{ "module_ram ", 1 },
{ "module_time ", 2 },
{ "module_date ", 3 },
{ "module_vol ", 4 },
{ "module_weather ", 5 },
};

View file

@ -5,6 +5,8 @@
STATUSBAR=$(cat /usr/share/speedwm/statusbar)
STATUSBAR2=$(grep speedwm.status: $HOME/.config/speedwm-de/speedwmrc | awk '{ print $2 }')
IN_ARGS="$@"
BUTTON="$BUTTON"
echo $BUTTON > /tmp/button
# check if the two values are the same, if not then we use the rc config
if [ "$STATUSBAR" != "$STATUSBAR2" ]; then

10
status
View file

@ -120,7 +120,7 @@ ITEM11_FULL_TEXT="Fully charged" # Text when fully charged (text)
#########################################################################
PRINT() {
$SETMETHOD "$ITEMS_TEXT"
$SETMETHOD "$(printf "$ITEMS_TEXT")"
}
SETCOLORS_CMD() {
@ -269,7 +269,7 @@ PRINT_TEXT() {
ITEMCMD10="$FSETCOLORCMD9$BSETCOLORCMD9$ITEMCMD10"
ITEMCMD11="$FSETCOLORCMD8$BSETCOLORCMD8$ITEMCMD11"
ITEMS_TEXT="$(echo "$ITEM_ORDER" | sed "s|@10|$ITEMCMD10|; s|@11|$ITEMCMD11|; s|@1|$ITEMCMD1|; s|@2|$ITEMCMD2|; s|@3|$ITEMCMD3|; s|@4|$ITEMCMD4|; s|@5|$ITEMCMD5|; s|@6|$ITEMCMD6|; s|@7|$ITEMCMD7|; s|@8|$ITEMCMD8|; s|@9|$ITEMCMD9|")"
ITEMS_TEXT="$(echo "$ITEM_ORDER" | sed "s|@10|\x10$ITEMCMD10|; s|@11|\x11$ITEMCMD11|; s|@1|\x01$ITEMCMD1|; s|@2|\x02$ITEMCMD2|; s|@3|\x03$ITEMCMD3|; s|@4|\x04$ITEMCMD4|; s|@5|\x05$ITEMCMD5|; s|@6|\x06$ITEMCMD6|; s|@7|\x07$ITEMCMD7|; s|@8|\x08$ITEMCMD8|; s|@9|\x09$ITEMCMD9|; s|%|%%|")"
# Auto-get character limit based on screen resolution
# This is pretty hacky, but it works as a default.
@ -418,15 +418,17 @@ ITEM5() {
if [ -e "${BINDIR}curl" ]; then
if [ -e "/tmp/itest" ]; then
if [ -e "/tmp/wstatus" ]; then
grep -q "<html>" /tmp/wstatus || cat /tmp/wstatus
grep -q "<html>" /tmp/wstatus || echo "$SEPARATOR $ITEM5_ICON $(cat /tmp/wstatus)"
else
echo "$SEPARATOR $ITEM5_ICON $(echo $(curl -s wttr.in/?format="%C"), $(curl -s wttr.in/?format=3 | sed 's/.* //; s/.*\(.....\)/\1/'))" > /tmp/wstatus
echo "$(curl -s wttr.in/?format="%C"), $(curl -s wttr.in/?format=3 | sed 's/.* //; s/.*\(.....\)/\1/')" > /tmp/wstatus
echo "$SEPARATOR $ITEM5_ICON $(cat /tmp/wstatus)"
fi
else
curl -so /tmp/itest wttr.in && hasinternet=true
if [ "$hasinternet" != "true" ]; then
rm -f /tmp/itest
rm -f /tmp/wstatus
ITEMCMD5=""
fi
fi