#!/bin/sh # speedwm-core # This script handles the systray and other things necessary for keybinds. # Set binary directory if not set already. if [ -e "/usr/share/speedwm/bindir" ]; then BINDIR=$(cat /usr/share/speedwm/bindir) # Set binary directory to the contents of this variable. else BINDIR="/usr/bin/" fi TINT="#222222" # Default tint EDGE="top" # Part of the screen where your systray will be placed GET_EDGE_AUTO="true" # Get edge automatically (true/false) SYSTRAY_COL=1 # When using pywal, set color to background (1) or backgroundmid (0) USE_SRG=false # Use $SYSTRAY-srg (available in Gentoo repos and AUR as $SYSTRAY-srg-git) instead of $SYSTRAY adding more features (true/false) USE_DEFAULT_TINT=false # Use default $TINT or use $SYSTRAY_COL ALPHA=0 # Opacity of the systray (0 is opaque, 255 is fully transparent) HIDE_BAR_WHEN_SYSTRAY_SHOW=false # Hide the speedwm bar when the systray is running. ALPHA_BARHIDDEN=255 # Opacity of the systray when the speedwm bar is hidden (0 is opaque, 255 is fully transparent) TRANSPARENT=true # Transparent or not (true/false) EXPORTDIR=$HOME/.config/speedwm-de/systray # Config directory HEIGHT=18 # Height of the systray WIDTH=30 # Width of the systray SHOW_SYSTRAY_WHEN_BARPADDING=true # Show systray if vertical barpadding is enabled mkdir -p $EXPORTDIR # Load config if available and override settings if [ -e "$EXPORTDIR/config" ]; then . $EXPORTDIR/config else printf "TINT=$TINT # Tint when pywal is not used." > $EXPORTDIR/config printf "\nEDGE=$EDGE # Part of the screen where your systray will be placed" >> $EXPORTDIR/config printf "\nGET_EDGE_AUTO=$GET_EDGE_AUTO # Get edge automatically (true/false)" >> $EXPORTDIR/config printf "\nSYSTRAY_COL=$SYSTRAY_COL # When using pywal, set color to background (1) or backgroundmid (0)" >> $EXPORTDIR/config printf "\nALPHA=$ALPHA # Opacity of the systray (0 is opaque, 255 is fully transparent)" >> $EXPORTDIR/config printf "\nALPHA_BARHIDDEN=$ALPHA_BARHIDDEN # Opacity of the systray when the speedwm bar is hidden (0 is opaque, 255 is fully transparent)" >> $EXPORTDIR/config printf "\nTRANSPARENT=true # Transparent or not (true/false)" >> $EXPORTDIR/config printf "\nHIDE_BAR_WHEN_SYSTRAY_SHOW=$HIDE_BAR_WHEN_SYSTRAY_SHOW # Hide the speedwm bar when the systray is running." >> $EXPORTDIR/config printf "\nUSE_SRG=$USE_SRG # Use $SYSTRAY-srg (available in Gentoo repos and AUR as $SYSTRAY-srg-git) instead of $SYSTRAY adding more features (true/false)" >> $EXPORTDIR/config printf "\nUSE_DEFAULT_TINT=$USE_DEFAULT_TINT # Use default $TINT or use $SYSTRAY_COL" >> $EXPORTDIR/config printf "\nSHOW_SYSTRAY_WHEN_BARPADDING=$SHOW_SYSTRAY_WHEN_BARPADDING # Show systray if vertical barpadding is enabled" >> $EXPORTDIR/config printf "\nHEIGHT=$HEIGHT # Height of the systray" >> $EXPORTDIR/config printf "\nWIDTH=$WIDTH # Width of the systray\n" >> $EXPORTDIR/config fi TINT="$(echo $TINT | sed "s|#||g")" OPT=$1 # Pywal tint PYWAL_TINT() { # Pywal tint if [ "$USE_DEFAULT_TINT" = "false" ]; then if [ -e "$HOME/.cache/wal/colors" ]; then if [ "$SYSTRAY_COL" = "1" ]; then TINT=$(sed -n 1,1p $HOME/.cache/wal/colors | sed "s|#||g") elif [ "$SYSTRAY_COL" = "0" ]; then TINT=$(sed -n 13,13p $HOME/.cache/wal/colors | sed "s|#||g") fi fi fi } # Set edge SETEDGE() { if [ "$GET_EDGE_AUTO" = "true" ]; then if [ -e "/usr/share/speedwm/topbar" ]; then EDGE="top" else EDGE="bottom" fi fi } # Set alpha SETALPHA() { if [ "$HIDE_BAR_WHEN_SYSTRAY_SHOW" = "true" ]; then ALPHA=$ALPHA_BARHIDDEN else ALPHA=$ALPHA fi } PYWAL_TINT SETEDGE SETALPHA # Set systray if [ "$USE_SRG" = "true" ]; then SYSTRAY=trayer-srg else SYSTRAY=trayer fi USE() { echo USE # Toggle TOGGLE() { if [ -e "/tmp/systray-started" ]; then OPT="-stop" else OPT="-start" fi } # Update speedwm UPDATE() { FAIL_SOURCEDOESNOTEXIST() { echo "The speedwm source code directory could not be located. This means an automatic update cannot be performed. Clone a new build (instructions on https://speedie.gq/speedwm) and update manually." exit 1 } FAIL_NOT_INSTALLED_USING_GIT() { echo "Your build of speedwm was likely not installed through Git (maybe installed using a tarball?) so therefore the update cannot continue. Clone a new build (instructions on https://speedie.gq/speedwm) and update manually." exit 1 } FAIL_NO_AUTH() { echo "Failed to authenticate." exit 1 } SOURCEDIR=$(cat /usr/share/speedwm/sourcedir) test $SOURCEDIR || FAIL_SOURCEDOESNOTEXIST # Check if Git is available if [ -e "${BINDIR}git" ]; then echo "Git found!" else echo "Git was not found, therefore the speedwm update cannot continue." ; exit 1 fi cd $SOURCEDIR make patch_remove git stash git pull || FAIL_NOT_INSTALLED_USING_GIT make patch_install clear printf "speedwm requires root permissions briefly to run the following command:\nmake clean install\nEnter your password to allow this.\n" su -c "make clean install" || FAIL_NO_AUTH echo 'speedwm has been updated!' exit 0 } case "$OPT" in "-toggle") TOGGLE ;; "-update-speedwm") UPDATE ;; esac case "$OPT" in "-start") $SYSTRAY --edge $EDGE --align right --SetDockType true --SetPartialStrut true --expand true --width $WIDTH --transparent $TRANSPARENT --alpha $ALPHA --tint 0x${TINT} --height $HEIGHT & touch /tmp/systray-started ; pgrep -x status && pkill status ; status & if [ "$HIDE_BAR_WHEN_SYSTRAY_SHOW" = "true" ]; then xsetroot -name "fsignal:23" fi ;; "-stop") rm -f /tmp/systray-started ; pkill $SYSTRAY ; pgrep -x status && pkill status ; status & if [ "$HIDE_BAR_WHEN_SYSTRAY_SHOW" = "true" ]; then xsetroot -name "fsignal:23" fi ;; "") echo "speedwm-core\n-start | Start the systray and restart status\n-stop | Stop the systray and restart status\n-toggle | Toggle systray and restart status\n-update-speedwm | Update speedwm using git\n-curl-weather | Curl wttr.in in a readable format\n-curl-cheatsheet | Ask the user what cheatsheet they want and then curl it." ;; esac } case "$OPT" in "-curl-weather") clear ; curl -s wttr.in | head -n 38 | tail -n 37 && sleep 60 ;; "-curl-cheatsheet") clear ; echo -n "What cheatsheet do you want to view?\nExample: vim\n > " ; read CHEATSHEET ; curl -s cheat.sh/$(echo $CHEATSHEET | tr '[:upper:]' '[:lower:]') > /tmp/cheatsheet grep "Unknown topic." /tmp/cheatsheet && $0 -curl-cheatsheet && exit 0 less /tmp/cheatsheet ;; esac OPT=$1 # Start systray if [ -e "${BINDIR}$SYSTRAY" ]; then if [ -e "$HOME/.config/speedwm-de/speedwmrc" ]; then if [ "$SHOW_SYSTRAY_WHEN_BARPADDING" = "true" ]; then USE else grep "barpaddingv" $HOME/.config/speedwm-de/speedwmrc > /tmp/out grep -q "0" /tmp/out > /dev/null && USE fi else USE fi else echo "Trayer not installed." && USE fi