Skip to content

Commit

Permalink
Migrated to dzen
Browse files Browse the repository at this point in the history
  • Loading branch information
livibetter committed Dec 4, 2010
1 parent 84121d7 commit aa33b5a
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 5 deletions.
17 changes: 17 additions & 0 deletions dotfiles/dzen/status-clock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

width=600
font_pixelsize=16
line_height=$((font_pixelsize + 4))
lines=8
height=$((line_height * (lines + 1)))

bottom_gap=20
read _ s_width <<< "$(xwininfo -root | egrep Width)"
read _ s_height <<< "$(xwininfo -root | egrep Height)"

{
echo '^fg(#a00)Calendar^fg()'
cal -3s
echo '^uncollapse()'
} | dzen2 -x $((s_width - width)) -y $((s_height - height - bottom_gap)) -w $width -l $lines -h $line_height -sa center -fn "Envy Code R:pixelsize=$font_pixelsize" -e 'leaveslave=exit;button3=exit;button4=scrollup;button5=scrolldown;onstart=scrollhome' -p
5 changes: 5 additions & 0 deletions dotfiles/dzen/status-cpu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

urxvtc -name 'dzen-status-cpu' -title 'CPU Status' \
-geometry "160x40" +sb \
-e htop --sort-key PERCENT_CPU
24 changes: 24 additions & 0 deletions dotfiles/dzen/status-fs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

width=600
font_pixelsize=16
line_height=$((font_pixelsize + 4))
lines=10
height=$((line_height * (lines + 1)))

bottom_gap=20
read _ s_width <<< "$(xwininfo -root | egrep Width)"
read _ s_height <<< "$(xwininfo -root | egrep Height)"

{
echo '^fg(#a00)Filesystems Status^fg()'
df -h | while read fs size used avail usep mountp; do
if [[ "$fs" == "Filesystem" ]]; then
# Header
printf "^fg(#00a)%-10s %8s %8s %8s %8s %-10s^fg()\n" "$fs" $size $used $avail $usep "$mountp"
else
printf "^fg(#aaa)%-10s %8s %8s %8s %8s %-10s^fg()\n" "$fs" $size $used $avail $usep "$mountp"
fi
done
echo '^uncollapse()'
} | dzen2 -x $((s_width - width)) -y $((s_height - height - bottom_gap)) -w $width -l $lines -h $line_height -sa center -fn "Envy Code R:pixelsize=$font_pixelsize" -e 'leaveslave=exit;button3=exit;button4=scrollup;button5=scrolldown;onstart=scrollhome' -p
5 changes: 5 additions & 0 deletions dotfiles/dzen/status-mem.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

urxvtc -name 'dzen-status-mem' -title 'CPU Status' \
-geometry "160x40" +sb \
-e htop --sort-key PERCENT_MEM
36 changes: 36 additions & 0 deletions dotfiles/dzen/status-mpd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
# $1 is the timeout (`dzen2 -p $1` doesn't seem to work in this script)

width=720
font_pixelsize=16
line_height=$((font_pixelsize + 4))
lines=3
height=$((line_height * (lines + 1) + 5 * 2))

bottom_gap=20
read _ s_width <<< "$(xwininfo -root | egrep Width)"
read _ s_height <<< "$(xwininfo -root | egrep Height)"

[[ $1 -gt 0 ]] && end_time=$(($(date +%s%N) + $1 * 1000000000))

while :; do
# Update last fm play count and cover art
lf-playcount-image.sh
playcount=$(cut -f 2 -d \ "/tmp/lf-playcount-image")
# Preparing cover art
image_filename="/tmp/lf-images/$(cut -f 4 -d \ "/tmp/lf-playcount-image" | tr -t \/ -)"
image_filename_xpm="${image_filename%.*}.xpm"
[[ ! -f "$image_filename_xbm" ]] && convert -scale 80x80 "$image_filename" "$image_filename_xpm"

echo -n '^ib(1)'
i=0
mpc -f '%artist% - %title% - %album%' | while read line; do
echo -n "^pa(5;$((i*line_height + 5)))$line"
((i++))
done
i=3
echo -n "^pa(5;$((i*line_height + 5)))Played $playcount times"
echo "^pa($((width-80-5));5)^i($image_filename_xpm)"
sleep 1
[[ $1 -gt 0 ]] && [[ $(date +%s%N) > "$end_time" ]] && break
done | dzen2 -x $((s_width - width)) -y $((s_height - height - bottom_gap)) -w $width -h $height -ta left -fn "Envy Code R:pixelsize=$font_pixelsize" -e 'leavetitle=exit;button3=exit;button4=scrollup;button5=scrolldown;onstart=uncollapse'
189 changes: 189 additions & 0 deletions dotfiles/dzen/status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
#!/bin/bash
# Copyright 2010 Yu-Jie Lin
# BSD License
#
# * update_cpu() is a partially ported version of gcpubar.c from dzen source
# code, which is licensed under the MIT/X Consortium License,
# copyright Robert Manea.

# Configuration
###############

BG='#303030'
FG='#aaa'
FONT='Envy Code R-9'

# UI = update interval, PAD is for padding nano seconds
PAD="000000000"
ui_cpu="1$PAD"
ui_mem="10$PAD"
ui_fs="60$PAD"
ui_thm="10$PAD"
ui_sound="200000000"
ui_clock="1$PAD"
ui_mpd="1$PAD"
# Controlling final refresh rate, the following is 0.2 seconds
ui_output="200000000"

# Interval of each iteration of main loop, should be equal to or smaller than $ui_output
SLEEP=0.2

# Should not be changed
ui_network="1$PAD"
unset PAD

# Components update functions
#############################

update_cpu () {
# Ported from gcpubar.c
local ncpu cpu_val cpu_maxval
# 0 1:user 2:unice 3:sys 4:idle 5:iowait
ncpu=($(grep 'cpu ' /proc/stat))

ncpu[1]=$((ncpu[1]+ncpu[2]))
cpu_val=$((ncpu[1]-ocpu[1] + ncpu[3]-ocpu[3] + ncpu[5]-ocpu[5]))
cpu_maxval=$((cpu_val + ncpu[4]-ocpu[4]))

cpu_percentage=$((100 * cpu_val / cpu_maxval))

ocpu=("${ncpu[@]}")

printf -v cpu_dzen "^ca(1,./status-cpu.sh)^i(icons/cpu.xbm)^ca() %3s%%" $cpu_percentage
update_next_ts cpu
}

update_mem () {
read _ _ mem_used mem_free <<< "$(free -b | grep -)"

mem_total=$((mem_used + mem_free))
mem_used_MB=$((mem_used / 1024 / 1024))
mem_used_percentage=$((100 * mem_used / mem_total))

printf -v mem_dzen "^ca(1,./status-mem.sh)^i(icons/mem.xbm)^ca() %sMB %s%%" ${mem_used_MB} ${mem_used_percentage}

update_next_ts mem
}

update_fs () {
# 0:dev 1:size 2:used 3:free 4:percentage 5:mount point
read _ _ fs_root_used _ fs_root_percentage _ <<< "$(df -h / | tail -1)"

fs_dzen="^ca(1,./status-fs.sh)^i(icons/diskette.xbm)^ca() ${fs_root_used}B $fs_root_percentage"

update_next_ts fs
}

update_thm () {
read _ thm _ </proc/acpi/thermal_zone/THM/temperature
thm_dzen="^i(icons/temp.xbm) ${thm}°C"

update_next_ts thm
}

update_clock () {
clock_dzen="^ca(1,./status-clock.sh)^i(icons/clock.xbm)^ca() $(date +'%A, %B %d, %Y %H:%M:%S')"

update_next_ts clock
}

update_sound () {
read _ _ _ _ volume _ sound_enabled <<< "$(amixer get Master | grep 'Front Left:')"

volume=${volume#[}
volume=${volume%]}
sound_enabled=${sound_enabled#[}
sound_enabled=${sound_enabled%]}

sound_dzen="^ca(1,urxvtc -name 'dzen-status-sound' -title 'Sound Mixer' -geometry 160x40 -e alsamixer)^i(icons/spkr_01.xbm)^ca() "
[[ "$sound_enabled" == "on" ]] && sound_dzen="$sound_dzen^fg(#0a0)" || sound_dzen="$sound_dzen^fg(#a00)"
sound_dzen="$sound_dzen$volume^fg()"

update_next_ts sound
}

update_network () {
local ifx=ppp0 n_rxb n_txb
read n_rxb < /sys/class/net/$ifx/statistics/rx_bytes
read n_txb < /sys/class/net/$ifx/statistics/tx_bytes
rx_rate=$(((n_rxb - rxb) / 1024))
tx_rate=$(((n_txb - txb) / 1024))
rxb=$n_rxb
txb=$n_txb

printf -v network_dzen "^i(icons/net_wired.xbm) %3s/%3s KB/s" $tx_rate $rx_rate
update_next_ts network
}

update_mpd () {
local mpd_text
pgrep mpd &>/dev/null && {
mpd_text="$(mpc -f '[%title% [- %artist%]]' | head -1)"
printf -v mpd_dzen "^ca(1,./status-mpd.sh)^i(icons/note.xbm) ^fg(#aa0)%-32s^fg()^ca()" "${mpd_text::32}"
if [[ "$mpd_text" != "$old_mpd_text" ]]; then
# New song, popup info box!
killall status-mpd.sh &>/dev/null
./status-mpd.sh 10 &
old_mpd_text="$mpd_text"
fi
} || {
mpd_dzen="^ca(1,mpd;mpdscribble)^fg(#888)^i(icons/note.xbm)^fg()^ca()"
}
update_next_ts mpd
}

# Controlling timestamp functions
#################################

update_ts_current () {
ts_current=$(date +%s%N)
}

update_next_ts () {
# $1 is the variable name
eval "next_$1=\$((ts_current+ui_$1))"
}

# Initialization
################

cd ~/.dzen

update_ts_current
update_cpu
update_mem
update_fs
update_network
update_thm
update_clock
update_sound
update_mpd

# Main loop
###########

read _ s_width <<< "$(xwininfo -root | egrep Width)"

while :; do
update_ts_current
# Time to output?
if [[ "$next_output" < "$ts_current" ]]; then
# Update each component
[[ "$next_cpu" < "$ts_current" ]] && update_cpu
[[ "$next_mem" < "$ts_current" ]] && update_mem
[[ "$next_fs" < "$ts_current" ]] && update_fs
[[ "$next_network" < "$ts_current" ]] && update_network
[[ "$next_thm" < "$ts_current" ]] && update_thm
[[ "$next_sound" < "$ts_current" ]] && update_sound
[[ "$next_clock" < "$ts_current" ]] && update_clock
[[ "$next_mpd" < "$ts_current" ]] && update_mpd

# Composing a new output
output="$cpu_dzen $mem_dzen $fs_dzen $network_dzen $thm_dzen $mpd_dzen $sound_dzen $clock_dzen "
[[ "$last_output" != "$output" ]] && echo "$output" && last_output=output
update_next_ts output
fi
# Using built-in `read` with timeout instead of external `sleep $SLEEP`
#read -t $SLEEP
sleep $SLEEP
done | dzen2 -bg "$BG" -fg "$FG" -fn "$FONT" -w $((s_width / 2)) -x $((s_width / 2)) -y -1 -ta right -e 'button3='
6 changes: 6 additions & 0 deletions dotfiles/fluxbox/apps
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@
[app] (title=.*Minefield)
[app] (title=.*Vimperator)
[end]

# dzen
[app] (name=dzen-status-.*)
[Position] (CENTER) {0 0}
[Layer] {2}
[end]
4 changes: 2 additions & 2 deletions dotfiles/fluxbox/init
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ session.screen0.clientMenu.usePixmap: true
session.screen0.titlebar.left:
session.screen0.titlebar.right: Minimize Maximize Close
session.screen0.menu.alpha: 216
session.screen0.toolbar.widthPercent: 100
session.screen0.toolbar.widthPercent: 50
session.screen0.toolbar.autoHide: false
session.screen0.toolbar.tools: clock, iconbar, systemtray
session.screen0.toolbar.tools: systemtray, iconbar
session.screen0.toolbar.onhead: 1
session.screen0.toolbar.layer: Dock
session.screen0.toolbar.height: 0
Expand Down
3 changes: 2 additions & 1 deletion dotfiles/fluxbox/startup
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ sleep 1
#nm-applet &
#gkrellm -w &
#mpd
conky -q &
# conky -q &
dzen-status.sh &
# urxvtc -e screen &
#start-pulseaudio-x11
[[ $(lsusb -v | grep -i mouse) ]] && synclient TouchpadOff=1
Expand Down
4 changes: 2 additions & 2 deletions dotfiles/fluxbox/styles/3am
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ menu.hilite.color: #404040

################################################################### TOOLBAR ###

toolbar.bevelWidth: 1
toolbar.borderWidth: 1
toolbar.bevelWidth: 0
toolbar.borderWidth: 0

toolbar.button.picColor: #c0c0c0
toolbar.button.pressed.picColor:#000000
Expand Down

0 comments on commit aa33b5a

Please sign in to comment.