From 84872dc1038135b658c4a154e6cf2f3666c2846c Mon Sep 17 00:00:00 2001 From: Raine Date: Sat, 14 Oct 2023 22:38:10 +0200 Subject: [PATCH] refactor(dwm): lock, start update, segregate status, etc. --- files/dwm/config.h | 4 ++-- files/dwm/dwm-lock.sh | 5 +++++ files/dwm/dwm-start.sh | 25 ++----------------------- files/dwm/dwm-status.sh | 26 ++++++++++++++++++++++++++ scripts/30-dwm.sh | 4 ++++ 5 files changed, 39 insertions(+), 25 deletions(-) create mode 100755 files/dwm/dwm-lock.sh create mode 100755 files/dwm/dwm-status.sh diff --git a/files/dwm/config.h b/files/dwm/config.h index b92e5a0..d957645 100644 --- a/files/dwm/config.h +++ b/files/dwm/config.h @@ -81,7 +81,7 @@ static const char *dmenucmd[] = { static const char *termcmd[] = { "alacritty", NULL }; // general & sys -static const char *locksaver[] = { "i3lock", "-c", "#000000", NULL }; +static const char *locksaver[] = { "/usr/local/bin/dwm-lock", NULL }; static const char *vol_up[] = { "amixer", "set", "Master", "5%+", NULL }; static const char *vol_down[] = { "amixer", "set", "Master", "5%-", NULL }; static const char *vol_mute[] = { "amixer", "set", "Master", "toggle", NULL }; @@ -121,7 +121,7 @@ static Key keys[] = { { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, { 0, XK_Print, spawn, {.v = screenshot } }, - { Mod1Mask, XK_Print, spawn, {.v = screenshot_partial } }, + { Mod1Mask, XK_Print, spawn, {.v = screenshot_partial } }, { 0, XF86XK_AudioRaiseVolume, spawn, {.v = vol_up } }, { 0, XF86XK_AudioLowerVolume, spawn, {.v = vol_down } }, { 0, XF86XK_AudioMute, spawn, {.v = vol_mute } }, diff --git a/files/dwm/dwm-lock.sh b/files/dwm/dwm-lock.sh new file mode 100755 index 0000000..2ce99e0 --- /dev/null +++ b/files/dwm/dwm-lock.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +touch /tmp/$USER-screen.lock +i3lock ${@:--nefc "#000000"} +rm -f /tmp/$USER-screen.lock diff --git a/files/dwm/dwm-start.sh b/files/dwm/dwm-start.sh index 5243da3..88c7cd4 100755 --- a/files/dwm/dwm-start.sh +++ b/files/dwm/dwm-start.sh @@ -4,29 +4,6 @@ LITE=${LITE:-no} xsetroot -solid black -#while loop to update statusbar with some goodies -while true; do - #memfreak to get it in MB - memfree=$(grep MemFree /proc/meminfo | awk '{ print $2 }') - memtotal=$(grep MemTotal /proc/meminfo | awk '{ print $2 }') - memfreak=$(((memtotal - memfree) / 1024)) - #time - CLK=$(date +'%a %b %d %R:%S %Z') - #volume - VOL=$(amixer get Master | tail -1 | awk '{ print $5 }' | tr -d '[]') - #loadavg - AVG=$(cat /proc/loadavg | cut -d ' ' -f -3) - #network stats in Bytes - NW=$(dstat -n --nocolor 1 1 | tail -1 | awk '{ print $1, $2}') - battper=$(cat /sys/class/power_supply/BAT0/capacity) - #this one is not so good, increases a delay of 1-2s of the updating. - #put it in the xsetrootname plz (tip of the day, do not put | as first char after " - xsetroot -name "$AVG | $memfreak MB | Bat: $battper% | Vol: $VOL | $CLK | " - sleep 1 -done & - -feh -z -Z --bg-scale $HOME/Pictures/background.* - start_apps() { nm-applet & flameshot & @@ -34,6 +11,8 @@ start_apps() { firefox & } +[ "$LITE" = "yes" ] || /usr/local/bin/dwm-status & [ "$LITE" = "yes" ] || (sleep 1 && start_apps) & +feh -zZ --bg-scale $HOME/Pictures/background.* [ "${NO_DWM:-no}" = "yes" ] || exec dwm >/dev/null diff --git a/files/dwm/dwm-status.sh b/files/dwm/dwm-status.sh new file mode 100755 index 0000000..bfa8a91 --- /dev/null +++ b/files/dwm/dwm-status.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +xsetroot -solid black -name "starting dwm..." + +#while loop to update statusbar with some goodies +while true; do + sleep 1 + [ -f /tmp/$USER-screen.lock ] && continue + #memfreak to get it in MB + memfree=$(grep MemFree /proc/meminfo | awk '{ print $2 }') + memtotal=$(grep MemTotal /proc/meminfo | awk '{ print $2 }') + memfreak=$(((memtotal - memfree) / 1024)) + #time + CLK=$(date +'%a %b %d %R:%S %Z') + #volume + VOL=$(amixer get Master | tail -1 | awk '{ print $5 }' | tr -d '[]') + #loadavg + AVG=$(cat /proc/loadavg | cut -d ' ' -f -3) + #network stats in Bytes + NW=$(dstat -n --nocolor 1 1 | tail -1 | awk '{ print $1, $2}') + battper=$(cat /sys/class/power_supply/BAT0/capacity) + #this one is not so good, increases a delay of 1-2s of the updating. + #put it in the xsetrootname plz (tip of the day, do not put | as first char after " + xsetroot -name "$AVG | $memfreak MB | Bat: $battper% | Vol: $VOL | $CLK |" +done + diff --git a/scripts/30-dwm.sh b/scripts/30-dwm.sh index 7eda15e..10a440a 100644 --- a/scripts/30-dwm.sh +++ b/scripts/30-dwm.sh @@ -35,7 +35,11 @@ popd chmod +x ./files/dwm/*.sh $SUDO cp ./files/dwm/dwm-start.sh /usr/local/bin/dwm-start +$SUDO cp ./files/dwm/dwm-status.sh /usr/local/bin/dwm-status $SUDO cp ./files/dwm/dwm-sync.sh /usr/local/bin/dwm-sync +$SUDO cp ./files/dwm/dwm-lock.sh /usr/local/bin/dwm-lock + +$SUDO chmod +x /usr/local/bin/dwm-* # DM entry $SUDO cp ./files/dwm/dwm.desktop /usr/share/xsessions/dwm.desktop