Make the statusbar clickable and output some info.

This commit is contained in:
2014-04-19 04:25:17 +02:00
parent 6552c8e4fa
commit 36eb0cc93b
5 changed files with 198 additions and 131 deletions

View File

@@ -1,5 +1,4 @@
# vim:set filetype=conkyrc:
# TODO: coloring of LOAD should depend on number of cpus, as it scales accordingly
out_to_console yes
out_to_ncurses no
out_to_stderr no
@@ -18,79 +17,12 @@ update_interval_on_battery 1.0
TEXT
[
{ "full_text" : "  ${cpu cpu0}%\
" , "color" : "\
${if_match ${cpu cpu0} <= 25}\#00FF00\
${else}${if_match ${cpu cpu0} <= 75}\#FFFF00\
${else}\#FF0000\
${endif}\
${endif}\
" , "min_width" : "CPU 00%" },\
\
\
\
{ "full_text" : "  ${mem}/${memmax} (${memperc}%)\
" , "color" : "\
${if_match ${memperc} <= 50}\#00FF00\
${else}${if_match ${memperc} <= 75}\#FFFF00\
${else}\#FF0000\
${endif}\
${endif}\
" },\
\
\
\
${if_mounted /}\
{ "full_text" : "  \
/: ${fs_used /}/${fs_size /} (${fs_used_perc /}%)\
" , "color" : "\
${if_match ${fs_used_perc /} <= 70}\#00FF00\
${else}${if_match ${fs_used_perc /} <= 90}\#FFFF00\
${else}\#FF0000\
${endif}\
${endif}\
" },\
${endif}\
\
\
\
${if_mounted /home}\
{ "full_text" : " \
/home: ${fs_used /home}/${fs_size /home} (${fs_used_perc /home}%)\
" , "color" : "\
${if_match ${fs_used_perc /home} <= 70}\#00FF00\
${else}${if_match ${fs_used_perc /home} <= 90}\#FFFF00\
${else}\#FF0000\
${endif}\
${endif}\
" },\
${endif}\
\
\
\
{ "full_text" : " \
${if_match "${swapperc}" != "No swap"}\
SWAP: ${swap}/${swapmax} (${swapperc}%)\
${else}\
no swap\
${endif}\
" , "color" : "\
${if_match "${swapperc}" == "No swap"}\#FFFFFF\
${else}${if_match ${swapperc} <= 50}\#00FF00\
${else}${if_match ${swapperc} <= 75}\#FFFF00\
${else}\#FF0000\
${endif}\
${endif}\
${endif}\
" },\
\
\
\
{ "full_text" : " " }, \
${if_existing /sys/class/net/wlp2s0}\
{ "full_text" : "  \
{ "full_text" : "  \
${if_up wlp2s0}\
${if_match "${addr wlp2s0}" != "No Address"}\
${addr wlp2s0} @ ${wireless_essid wlp2s0} (${wireless_link_qual_perc wlp2s0}%)\
${wireless_essid wlp2s0} (${wireless_link_qual_perc wlp2s0}%)\
${else}\
No Address\
${endif}\
@@ -105,14 +37,14 @@ ${if_match ${wireless_link_qual_perc wlp2s0} <= 25}\
${else}${if_match ${wireless_link_qual_perc wlp2s0} <= 50}\
\#FFFF00\
${else}\
\#00FF00\
\#FFFFFF\
${endif}\
${endif}\
${else}\#FFFF00\
${endif}\
${else}\#FF0000\
${endif}\
" },\
" , "name" : "wireless" },\
${endif}
\
\
@@ -177,45 +109,33 @@ ${endif}
\
\
\
{ "full_text" : "  ${loadavg 2}\
" , "color" : "\
${if_match ${loadavg 2} <= 0.7}\#00FF00\
${else}${if_match ${loadavg 2} <= 1}\#FFFF00\
${else}\#FF0000)\
${endif}\
${endif}\
" },\
\
\
\
{ "full_text" : "  \
${if_match ${mixer} == 0}\
mute\
${else}\
${mixer}%\
${endif}\
" , "color" : "\#FFFFFF" },\
${pre_exec bash $HOME/.i3/scripts/pa-volume.bash status} " , "color" : "\#FFFFFF" , "name" : "volume" },\
\
\
\
${if_existing /sys/class/power_supply/BAT1}\
{ "full_text" : "  ${execi 5 head -c 1 /sys/class/power_supply/BAT1/status} ${execi 5 cat /sys/class/power_supply/BAT1/capacity}% " , "color" : "\#FFFFFF" },\
${execi 10 bash $HOME/.i3/scripts/status.d/battery.bash conky}\
${endif}\
\
\
\
{ "full_text" : "  ${kernel} " , "color" : "\#FFFFFF" },\
{ "full_text" : "  ${kernel} " , "color" : "\#FFFFFF" , "name" : "sysinfo" },\
\
\
\
{ "full_text" : " $nodename " , "color" : "\#FFFFFF" },\
{ "full_text" : " ${execi 60 bash ~/.i3/scripts/status.d/conky_pacman.bash} " , "color" : "\#FFFFFF" , "name" : "pacman" },\
\
\
\
{ "full_text" : "  $uptime_short " , "color" : "\#FFFFFF" },\
{ "full_text" : "  $uptime_short " , "color" : "\#FFFFFF" , "name" : "sysinfo" },\
\
\
\
{ "full_text" : " ${time %a %F %T} " , "color" : "\#FFFFFF" , "name" : "time" }\
{ "full_text" : " ${time %a %F %T} " , "color" : "\#FFFFFF" , "name" : "time" },\
\
\
\
{ "full_text" : "" }\
],

View File

@@ -1,28 +0,0 @@
#!/usr/bin/env bash
line="$1"
log(){
echo $* >> ~/.i3/logs/output_i3bar.log
}
# I'm sorry.
getval(){
echo $(echo "$1" | grep -Po "\"$2\":.*?," | awk -F ':' '{print $2}' | tr -d '",')
}
log "line: $line"
name="$(getval "$line" "name")"
log "name: $name"
case "$name" in
"time")
log "starting dzen with cal"
(echo "$(cal -1m)" ; sleep 15s) | dzen2 -w 100 -l 10 -x 1700 -y 20 &
;;
"mpd_status")
mpc toggle
;;
esac

View File

@@ -1,6 +0,0 @@
#!/usr/bin/env bash
while read line; do
echo $line
echo $line >> ~/.i3/output_i3bar.log
done

View File

@@ -1,8 +1,59 @@
#!/usr/bin/env bash
# From http://i3wm.org/docs/user-contributed/conky-i3bar.html
# the height of the i3bar in pixels. used to align the yad windows.
I3BAR_HEIGHT=24
# the width of the screen in pixels.
X_MAX=1920
# paths to scripts used.
PA_VOLUME_SCRIPT="$HOME/.i3/scripts/pa-volume.bash"
I3BAR_UPDATE="$HOME/.i3/scripts/update-status.bash"
LOGFILE="$HOME/.i3/logs/output_i3bar.log"
SCRIPTS_SYSINFO="$HOME/.i3/scripts/status.d/sysinfo.bash"
SCRIPTS_WIRELESS="$HOME/.i3/scripts/status.d/wireless.bash"
SCRIPTS_BATTERY="$HOME/.i3/scripts/status.d/battery.bash"
SCRIPTS_PACMAN="$HOME/.i3/scripts/status.d/pacman.bash"
PIDFILE="$HOME/.i3/logs/conky.pid"
COLOR_FG="#FFFFFF"
COLOR_BG="#222222"
GTK_THEME="/usr/share/themes/Boje-Greyscale/gtk-2.0/gtkrc"
YAD_PREFIX="GTK2_RC_FILES=$GTK_THEME"
FONT="DejaVu Sans Mono 11"
echo > "$LOGFILE"
log() {
echo $* >> "$LOGFILE"
}
update() {
bash $I3BAR_UPDATE
}
get_x() {
x=$1
width=$2
pos=$(( $x - ($width / 2) ))
if [[ $(( $pos + $width )) -gt $X_MAX ]] ; then
log "window would exceed the right screen border. adjusting"
pos=$(( $X_MAX - $width ))
fi
echo $pos
}
# I'm sorry.
getval() {
echo $(echo "$1" | grep -Po "\"$2\":.*?," | awk -F ':' '{print $2}' | tr -d '",')
}
path_conkyrc="$1"
# end the header so that i3bar knows we want to use JSON:
echo '{ "version" : 1 , "click_events" : true }'
@@ -15,7 +66,136 @@ echo '[],'
# Now send blocks with information forever:
conky -c "$path_conkyrc" &
while read input ; do
bash ~/.i3/i3bar_clickparser.bash "$input"
echo $! > "$PIDFILE"
while read line ; do
# This part must not produce any output to stdout as this would be sent
# to i3bar and crash it due to wrong formatting.
log "line: $line"
name="$(getval "$line" "name")"
log "name: $name"
case "$name" in
"pacman")
width=500
height=700
x=$(get_x $(getval "$line" "x") $width)
bash "$SCRIPTS_PACMAN" | env $YAD_PREFIX yad \
--text-info \
--class=yad-status \
--button !gtk-apply:0 \
--button "update"!go-down:1 \
--button "reload"!gtk-refresh:2 \
--buttons-layout center \
--fore "$COLOR_FG" \
--back "$COLOR_BG" \
--fontname="$FONT" \
--geometry ${width}x${height}+${x}+${I3BAR_HEIGHT}
button=$?
if [[ $button == 1 ]] ; then
log "update requested"
urxvt -e sudo pacman -Syu
elif [[ $button == 2 ]] ; then
log "packagelist reload requested"
urxvt -e sudo pacman -Sy
fi
;;
"wireless")
width=500
height=700
x=$(get_x $(getval "$line" "x") $width)
bash "$SCRIPTS_WIRELESS" | env $YAD_PREFIX yad \
--text-info \
--class=yad-status \
--button !gtk-apply:0 \
--buttons-layout center \
--fore "$COLOR_FG" \
--back "$COLOR_BG" \
--fontname="$FONT" \
--geometry ${width}x${height}+${x}+${I3BAR_HEIGHT}
;;
"battery")
width=250
height=150
x=$(get_x $(getval "$line" "x") $width)
bash "$SCRIPTS_BATTERY" | env $YAD_PREFIX yad \
--text-info \
--class=yad-status \
--button !gtk-apply:0 \
--buttons-layout center \
--fore "$COLOR_FG" \
--back "$COLOR_BG" \
--fontname="$FONT" \
--geometry ${width}x${height}+${x}+${I3BAR_HEIGHT}
;;
"time")
width=300
height=0
x=$(get_x $(getval "$line" "x") $width)
env $YAD_PREFIX yad \
--calendar \
--class=yad-status \
--button !gtk-apply:0 \
--buttons-layout center \
--geometry ${width}x${height}+${x}+${I3BAR_HEIGHT} >/dev/null
;;
"mpd_status")
mpc toggle
;;
"sysinfo")
# i should rather write an extra script
width=600
height=800
x=$(get_x $(getval "$line" "x") $width)
bash "$SCRIPTS_SYSINFO" | env $YAD_PREFIX yad \
--text-info \
--class=yad-status \
--button !gtk-apply:0 \
--buttons-layout center \
--fore "$COLOR_FG" \
--back "$COLOR_BG" \
--fontname="$FONT" \
--geometry ${width}x${height}+${x}+${I3BAR_HEIGHT}
;;
"volume")
width=300
height=0
x=$(get_x $(getval "$line" "x") $width)
vol=$(bash $PA_VOLUME_SCRIPT get-vol)
log "got current volume: $vol"
is_muted=$(bash $PA_VOLUME_SCRIPT is-muted)
if [[ "$is_muted" == 0 ]] ; then
button_mute_text="mute"
else
button_mute_text="unmute"
fi
newvol=$(env $YAD_PREFIX yad \
--text=Volume: \
--scale \
--class=yad-status \
--button !gtk-apply:0 \
--button !gtk-cancel:1 \
--button ${button_mute_text}!:2 \
--buttons-layout center \
--value $vol \
--text-align center \
--min-value 0 \
--max-value 100 \
--step 1 \
--geometry ${width}x${height}+${x}+${I3BAR_HEIGHT}
)
button=$?
if [[ $button == 2 ]] ; then
bash $PA_VOLUME_SCRIPT mute-toggle
elif [[ $button == 0 ]] ; then
bash $PA_VOLUME_SCRIPT set-vol $newvol
fi
update
;;
esac
done

View File

@@ -0,0 +1 @@
kill -SIGUSR1 $(cat $HOME/.i3/logs/conky.pid)