about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2019-06-10 12:02:41 +0200
committerManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2019-06-10 12:02:41 +0200
commitc9a914e603607dab3d4455efe1ea0d05dbd15832 (patch)
tree9dd93bd6d98ae643caa040775fa620bf7ba54774
parentImproved gaps patch (diff)
downloaddwm-c9a914e603607dab3d4455efe1ea0d05dbd15832.tar.gz
dwm-c9a914e603607dab3d4455efe1ea0d05dbd15832.tar.bz2
dwm-c9a914e603607dab3d4455efe1ea0d05dbd15832.zip
Added status bar script
Diffstat (limited to '')
-rw-r--r--patches/dwm-statuscolors-20181008-b69c870.diff94
-rwxr-xr-xscripts/dwm-status122
2 files changed, 216 insertions, 0 deletions
diff --git a/patches/dwm-statuscolors-20181008-b69c870.diff b/patches/dwm-statuscolors-20181008-b69c870.diff
new file mode 100644
index 0000000..8c7869a
--- /dev/null
+++ b/patches/dwm-statuscolors-20181008-b69c870.diff
@@ -0,0 +1,94 @@
+From 35418d156fccb922710f6ca80a1f3972ba88b42f Mon Sep 17 00:00:00 2001
+From: Danny O'Brien <danny@spesh.com>
+Date: Mon, 8 Oct 2018 19:21:29 -0700
+Subject: [PATCH] Add colors to status message in bar.
+
+This patch matches the format used by
+https://dwm.suckless.org/patches/statuscolors/ -- An \x01 character
+switches to the normal foreground/color combo, \x02 switches to the
+color combo used for selected tags, \03 is set by default to black on
+yellow, \04 is white on red.
+
+These color settings are defined in the colors array in config.def.h.
+More can be added, but don't have more than 32, or you'll start hitting
+real ASCII.
+
+This applies cleanly on mainline dwm from commit 022d076 (Sat Jan 7
+17:21:29 2017 +0100) until at least b69c870 (Sat Jun 2 17:15:42 2018
++020).
+
+---
+ config.def.h | 13 ++++++++++---
+ dwm.c        | 18 ++++++++++++++++--
+ 2 files changed, 26 insertions(+), 5 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 1c0b587..df92695 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -12,10 +12,17 @@ static const char col_gray2[]       = "#444444";
+ static const char col_gray3[]       = "#bbbbbb";
+ static const char col_gray4[]       = "#eeeeee";
+ static const char col_cyan[]        = "#005577";
++static const char col_black[]       = "#000000";
++static const char col_red[]         = "#ff0000";
++static const char col_yellow[]      = "#ffff00";
++static const char col_white[]       = "#ffffff";
++
+ static const char *colors[][3]      = {
+-	/*               fg         bg         border   */
+-	[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
+-	[SchemeSel]  = { col_gray4, col_cyan,  col_cyan  },
++	/*					fg         bg          border   */
++	[SchemeNorm] =	 { col_gray3, col_gray1,  col_gray2 },
++	[SchemeSel]  =	 { col_gray4, col_cyan,   col_cyan },
++	[SchemeWarn] =	 { col_black, col_yellow, col_red },
++	[SchemeUrgent]=	 { col_white, col_red,    col_red },
+ };
+
+ /* tagging */
+diff --git a/dwm.c b/dwm.c
+index 4465af1..9d9d46f 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -59,7 +59,7 @@
+
+ /* enums */
+ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
+-enum { SchemeNorm, SchemeSel }; /* color schemes */
++enum { SchemeNorm, SchemeSel, SchemeWarn, SchemeUrgent }; /* color schemes */
+ enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
+        NetWMFullscreen, NetActiveWindow, NetWMWindowType,
+        NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
+@@ -699,13 +699,27 @@ drawbar(Monitor *m)
+ 	int boxs = drw->fonts->h / 9;
+ 	int boxw = drw->fonts->h / 6 + 2;
+ 	unsigned int i, occ = 0, urg = 0;
++    char *ts = stext;
++    char *tp = stext;
++    int tx = 0;
++    char ctmp;
+ 	Client *c;
+
+ 	/* draw status first so it can be overdrawn by tags later */
+ 	if (m == selmon) { /* status is only drawn on selected monitor */
+ 		drw_setscheme(drw, scheme[SchemeNorm]);
+ 		sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
+-		drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0);
++		while (1) {
++			if ((unsigned int)*ts > LENGTH(colors)) { ts++; continue ; }
++			ctmp = *ts;
++			*ts = '\0';
++			drw_text(drw, m->ww - sw + tx, 0, sw - tx, bh, 0, tp, 0);
++			tx += TEXTW(tp) -lrpad;
++			if (ctmp == '\0') { break; }
++			drw_setscheme(drw, scheme[(unsigned int)(ctmp-1)]);
++			*ts = ctmp;
++			tp = ++ts;
++		}
+ 	}
+
+ 	for (c = m->clients; c; c = c->next) {
+-- 
+2.19.1
+
diff --git a/scripts/dwm-status b/scripts/dwm-status
new file mode 100755
index 0000000..6ac3219
--- /dev/null
+++ b/scripts/dwm-status
@@ -0,0 +1,122 @@
+#!/bin/bash
+# Screenshot: http://s.natalian.org/2013-08-17/dwm_status.png
+# Network speed stuff stolen from http://linuxclues.blogspot.sg/2009/11/shell-script-show-network-speed.html
+
+# This function parses /proc/net/dev file searching for a line containing $interface data.
+# Within that line, the first and ninth numbers after ':' are respectively the received and transmited bytes.
+function get_bytes {
+# Find active network interface
+interface=$(ip route get 8.8.8.8 2>/dev/null| awk '{print $5}')
+line=$(grep $interface /proc/net/dev | cut -d ':' -f 2 | awk '{print "received_bytes="$1, "transmitted_bytes="$9}')
+eval $line
+now=$(date +%s%N)
+}
+
+# Function which calculates the speed using actual and old byte number.
+# Speed is shown in KByte per second when greater or equal than 1 KByte per second.
+# This function should be called each second.
+
+function get_velocity {
+value=$1
+old_value=$2
+now=$3
+
+timediff=$(($now - $old_time))
+velKB=$(echo "1000000000*($value-$old_value)/1024/$timediff" | bc)
+if test "$velKB" -gt 1024
+then
+	echo $(echo "scale=2; $velKB/1024" | bc)MB/s
+else
+	echo ${velKB}KB/s
+fi
+}
+
+# Get initial values
+get_bytes
+old_received_bytes=$received_bytes
+old_transmitted_bytes=$transmitted_bytes
+old_time=$now
+
+print_volume() {
+	volume="$(amixer get Master | tail -n1 | sed -r 's/.*\[(.*)%\].*/\1/')"
+	if test "$volume" -gt 0
+	then
+		echo -e "\uE05D${volume}"
+	else
+		echo -e "Mute"
+	fi
+}
+
+print_wifi() {
+	ip=$(ip route get 8.8.8.8 2>/dev/null|grep -Eo 'src [0-9.]+'|grep -Eo '[0-9.]+')
+
+	if=wlan0
+		while IFS=$': \t' read -r label value
+		do
+			case $label in SSID) SSID=$value
+				;;
+			signal) SIGNAL=$value
+				;;
+		esac
+	done < <(iw "$if" link)
+
+	echo -e "$SSID $SIGNAL $ip"
+}
+
+print_mem(){
+	memfree=$(($(grep -m1 'MemAvailable:' /proc/meminfo | awk '{print $2}') / 1024))
+	echo -e "$memfree"
+}
+
+print_temp(){
+	test -f /sys/class/thermal/thermal_zone0/temp || return 0
+	echo $(head -c 2 /sys/class/thermal/thermal_zone0/temp)C
+}
+
+print_bat(){
+	hash acpi || return 0
+	onl="$(grep "on-line" <(acpi -V))"
+	charge="$(awk '{ sum += $1 } END { print sum }' /sys/class/power_supply/BAT*/capacity)"
+	if test -z "$onl"
+	then
+		# suspend when we close the lid
+		#systemctl --user stop inhibit-lid-sleep-on-battery.service
+		echo -e "${charge}"
+	else
+		# On mains! no need to suspend
+		#systemctl --user start inhibit-lid-sleep-on-battery.service
+		echo -e "${charge}"
+	fi
+}
+
+print_date(){
+	date "+%a %m-%d %T%:::z"
+}
+
+show_record(){
+	test -f /tmp/r2d2 || return
+	rp=$(cat /tmp/r2d2 | awk '{print $2}')
+	size=$(du -h $rp | awk '{print $1}')
+	echo " $size $(basename $rp)"
+}
+
+while true
+do
+
+	# Get new transmitted, received byte number values and current time
+	get_bytes
+
+	# Calculates speeds
+	vel_recv=$(get_velocity $received_bytes $old_received_bytes $now)
+	vel_trans=$(get_velocity $transmitted_bytes $old_transmitted_bytes $now)
+
+	xsetroot -name "$(print_mem) $vel_recv $vel_trans $(print_temp) $(print_wifi) $(print_bat)$(show_record) $(print_date)"
+
+	# Update old values to perform new calculations
+	old_received_bytes=$received_bytes
+	old_transmitted_bytes=$transmitted_bytes
+	old_time=$now
+
+	sleep 1
+
+done