From f691f01606af95670e0983884062a1d70ec7bce9 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Sat, 15 Nov 2014 23:29:05 +0100 Subject: Moved some panel code to seperate file --- herbstluftwm/.config/herbstluftwm/autostart | 5 +- herbstluftwm/.config/herbstluftwm/notify.sh | 21 +--- herbstluftwm/.config/herbstluftwm/panel.sh | 98 ++-------------- .../.config/herbstluftwm/panel_indicators.sh | 127 +++++++++++++++++++++ herbstluftwm/.config/herbstluftwm/popup.sh | 26 +---- herbstluftwm/.config/herbstluftwm/theme | 35 ------ herbstluftwm/.config/herbstluftwm/theme.sh | 33 ++++++ 7 files changed, 181 insertions(+), 164 deletions(-) create mode 100644 herbstluftwm/.config/herbstluftwm/panel_indicators.sh delete mode 100644 herbstluftwm/.config/herbstluftwm/theme create mode 100644 herbstluftwm/.config/herbstluftwm/theme.sh (limited to 'herbstluftwm') diff --git a/herbstluftwm/.config/herbstluftwm/autostart b/herbstluftwm/.config/herbstluftwm/autostart index 9ec12f8..c93ff15 100755 --- a/herbstluftwm/.config/herbstluftwm/autostart +++ b/herbstluftwm/.config/herbstluftwm/autostart @@ -6,8 +6,9 @@ hc() { herbstclient "$@" } +#Include the theming script dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -source "$dir/theme" +source "$dir/theme.sh" #Detect monitors hc set auto_detect_monitors 1 @@ -186,4 +187,4 @@ $dir/start.sh "xrdb -load $HOME/.Xresources" $dir/start.sh "xset +fp /usr/share/fonts/local" $dir/start.sh "xset fp rehash" $dir/start.sh "dropboxd" -#$dir/start.sh "$dir/notify.sh $monitor_w $window_p $panel_h $dir/popup.sh" +#$dir/start.sh "$dir/notify.sh $dir/popup.sh" diff --git a/herbstluftwm/.config/herbstluftwm/notify.sh b/herbstluftwm/.config/herbstluftwm/notify.sh index 190d496..40c5330 100755 --- a/herbstluftwm/.config/herbstluftwm/notify.sh +++ b/herbstluftwm/.config/herbstluftwm/notify.sh @@ -1,29 +1,18 @@ #!/bin/bash -monitor_w=$1 -window_p=$2 -panel_h=$3 - -popup_w=$(echo "$monitor_w - (2 * $window_p)" | bc) -popup_h=$panel_h -popup_x=$window_p -popup_y=$window_p - -popup_opts="-w $popup_w -h $popup_h -x $popup_x -y $popup_y" - while true; do bat_lvl=$(cat /sys/class/power_supply/BAT1/capacity) bat_stat=$(cat /sys/class/power_supply/BAT1/status) - + if [[ $bat_lvl -le 5 && $bat_stat == "Discharging" ]]; then - $4 -m "Battery level critical: $bat_lvl%%" -u "high" $popup_opts + $1 -m "Battery level critical: $bat_lvl%%" -u "high" elif [[ $bat_lvl -eq 10 && $bat_stat == "Discharging" ]]; then - $4 -m "Battery level low: $bat_lvl%%" $popup_opts + $1 -m "Battery level low: $bat_lvl%%" elif [[ $bat_lvl -eq 50 && $bat_stat == "Discharging" ]]; then - $4 -m "Battery level at $bat_lvl%%" $popup_opts + $1 -m "Battery level at $bat_lvl%%" elif [[ $bat_lvl -eq 100 && $bat_stat == "Charging" ]]; then - $4 -m "Battery fully charged" + $1 -m "Battery fully charged" fi sleep 60; diff --git a/herbstluftwm/.config/herbstluftwm/panel.sh b/herbstluftwm/.config/herbstluftwm/panel.sh index 9b8fb48..763c668 100755 --- a/herbstluftwm/.config/herbstluftwm/panel.sh +++ b/herbstluftwm/.config/herbstluftwm/panel.sh @@ -5,7 +5,8 @@ hc() { } dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -source "$dir/theme" +source "$dir/theme.sh" +source "$dir/panel_indicators.sh" monitor=${1:-0} @@ -41,97 +42,12 @@ fi # \t [...] # e.g. # date ^fg(#efefef)18:33^fg(#909090), 2013-10-^fg(#efefef)29 - while true ; do - # Music - player_status=$(playerctl status) - if [ $player_status = "Playing" ]; then - player_artist=$(playerctl metadata artist) - player_title=$(playerctl metadata title) - playing="$player_title - $player_artist" - - if [ "$current" != "$playing" ] ; then - current=$playing - scrolling=$current - elif [ ${#scrolling} -gt "24" ] ; then - scrolling=${scrolling:1} - else - scrolling=$current - fi - - echo -e "music\t\ue05c ${scrolling:0:24}" - else - echo -e "music\toff" - fi - - # Volume - if pgrep pulseaudio >> /dev/null ; then - volumes=$(\ - amixer get Master | \ - grep "Front Right: Playback"\ - ) - vol=$(\ - echo $volumes | \ - sed "s/.*\[\([0-9]*\)%\].*/\1/"\ - ) - if [ -z $vol ] ; then - echo -e "volume\toff" - else - echo -e "volume\t%{F$acolor_fg}\ue05d $vol%%%{F-}" - fi - else - echo -e "volume\toff" - fi - - # Network - read lo int1 int2 <<< `ip link | sed -n 's/^[0-9]: \(.*\):.*$/\1/p'` - if iwconfig $int1 >/dev/null 2>&1; then - wifi=$int1 - eth=$int2 - else - wifi=$int2 - eth=$int1 - fi - - ip link show $eth | grep 'state UP' >/dev/null && int=$eth || int=$wifi - - if [ $int == "wlp3s0" ] ; then - iwconfig=$(iwconfig $int) - ssid=$(\ - echo $iwconfig | \ - sed "s/.*ESSID:\(\".*\"\).*/\1/" | \ - sed "s/.*\(off\/any\).*/\"\1\"/" | \ - sed "s/.*\"\(.*\)\".*/\1/"\ - ) - - if [ $ssid != "off/any" ] ; then - echo -e "net\t\ue0f3 $ssid" - else - echo -e "net\toff" - fi - - elif [ $int == "enp2s0" ] ; then - echo -e "net\t\ue0af ethernet" - else - echo -e "net\toff" - fi - - # Battery - if $(test -e /sys/class/power_supply/BAT1) ; then - bat_lvl=$(cat /sys/class/power_supply/BAT1/capacity) - if [ $bat_lvl -lt 15 ] ; then - bat_color=$acolor_accent - else - bat_color=$acolor_fg - fi - state=$(cat /sys/class/power_supply/BAT1/status) - echo -e "battery\t%{F$acolor_fg}\ue03b %{F$bat_color}$bat_lvl%{F$acolor_fg}%%%{F-}" - else - echo -e "battery\toff" - fi - - # Time - echo -e $(date +$"date\t%{F$acolor_fg}%H:%M:%S %{F$acolor_fg}(%d-%m-%Y)%{F-}") + music + volume + network + battery + clock sleep 1 || break done > >(uniq_linebuffered) & childpid=$! diff --git a/herbstluftwm/.config/herbstluftwm/panel_indicators.sh b/herbstluftwm/.config/herbstluftwm/panel_indicators.sh new file mode 100644 index 0000000..e450337 --- /dev/null +++ b/herbstluftwm/.config/herbstluftwm/panel_indicators.sh @@ -0,0 +1,127 @@ +#!/bin/bash +battery_icon=("\ue113" "\ue114" "\ue115" "\ue116" "\ue042") +network_icon=("\ue0f1" "\ue0f2" "\ue0f3" "\ue0af") +music_icon="\ue05c" + +music() +{ + # Music + player_status=$(playerctl status) + if [ $player_status = "Playing" ]; then + player_artist=$(playerctl metadata artist) + player_title=$(playerctl metadata title) + playing="$player_title - $player_artist" + + if [ "$current" != "$playing" ] ; then + current=$playing + scrolling=$current + elif [ ${#scrolling} -gt "24" ] ; then + scrolling=${scrolling:1} + else + scrolling=$current + fi + + echo -e "music\t$music_icon ${scrolling:0:24}" + else + echo -e "music\toff" + fi +} + +volume() +{ + # Volume + if pgrep pulseaudio >> /dev/null ; then + volumes=$(\ + amixer get Master | \ + grep "Front Right: Playback"\ + ) + vol=$(\ + echo $volumes | \ + sed "s/.*\[\([0-9]*\)%\].*/\1/"\ + ) + if [ -z $vol ] ; then + echo -e "volume\toff" + else + echo -e "volume\t%{F$acolor_fg}\ue05d $vol%%%{F-}" + fi + else + echo -e "volume\toff" + fi +} + +network() +{ + # Network + read lo int1 int2 <<< `ip link | sed -n 's/^[0-9]: \(.*\):.*$/\1/p'` + if iwconfig $int1 >/dev/null 2>&1; then + wifi=$int1 + eth=$int2 + else + wifi=$int2 + eth=$int1 + fi + + ip link show $eth | grep 'state UP' >/dev/null && int=$eth || int=$wifi + + if [ $int == $wifi ] ; then + iwconfig=$(iwconfig $int) + ssid=$( + echo $iwconfig | \ + sed "s/.*ESSID:\(\".*\"\).*/\1/" | \ + sed "s/.*\(off\/any\).*/\"\1\"/" | \ + sed "s/.*\"\(.*\)\".*/\1/" + ) + + quality=$( \ + echo $iwconfig | \ + sed "s/^.*Link Quality=\([0-9]*\)\/\([0-9]*\) .*$/(\1*100)\/\2/" | \ + bc + ) + + if [ $ssid == "off/any" ] ; then + echo -e "net\toff" + elif [ $quality -lt 33 ] ; then + echo -e "net\t${network_icon[0]} $ssid" + elif [ $quality -lt 66 ] ; then + echo -e "net\t${network_icon[1]} $ssid" + else + echo -e "net\t${network_icon[2]} $ssid" + fi + + elif [ $int == $eth ] ; then + echo -e "net\t${network_icon[3]} ethernet" + else + echo -e "net\toff" + fi +} + +battery() +{ + # Battery + if $(test -e /sys/class/power_supply/BAT1) ; then + + bat_lvl=$(cat /sys/class/power_supply/BAT1/capacity) + bat_state=$(cat /sys/class/power_supply/BAT1/status) + + if [ $bat_state == "Charging" ] ; then + bat_status="${battery_icon[4]}" + elif [ $bat_lvl -lt 10 ] ; then + bat_status="${F$acolor_accent}${battery_icon[0]}${F-}" + elif [ $bat_ -lt 33 ] ; then + bat_status="${battery_icon[1]}" + elif [ $bat_lvl -lt 66 ] ; then + bat_status="${battery_icon[2]}" + else + bat_status="${battery_icon[3]}" + fi + + echo -e "battery\t$bat_status $bat_lvl%%%{F-}" + else + echo -e "battery\toff" + fi +} + +clock() +{ + echo -e $(date +$"date\t%{F$acolor_fg}%H:%M:%S %{F$acolor_fg}(%d-%m-%Y)%{F-}") +} diff --git a/herbstluftwm/.config/herbstluftwm/popup.sh b/herbstluftwm/.config/herbstluftwm/popup.sh index 41c5e9c..eda37f5 100755 --- a/herbstluftwm/.config/herbstluftwm/popup.sh +++ b/herbstluftwm/.config/herbstluftwm/popup.sh @@ -7,29 +7,20 @@ help () { echo -e "Options:" echo -e " -m MESSAGE\t\tSpecifies message to be displayed" echo -e " -t TIMEOUT\t\tAmount of time in seconds the popup is displayed" + echo -e " -u LEVEL\t\tUrgency level (info or high)" } -add_alpha_channel(){ - echo "$1" | \ - sed "s/.*#\([0-9a-fA-F]*\).*/#ff\1/" -} +dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +source "$dir/theme.sh" timeout=10 message="" -x=0 -y=0 -width=120 -height=90 urgency="info" while getopts ":m:t:x:y:w:h:u:" opt; do case $opt in m) message=$OPTARG ;; t) timeout=$OPTARG ;; - x) x=$OPTARG ;; - y) y=$OPTARG ;; - w) width=$OPTARG ;; - h) height=$OPTARG ;; u) urgency=$OPTARG ;; esac done @@ -37,13 +28,8 @@ done if test ! $message; then help else - light=$(add_alpha_channel $WM_LIGHT) - llight=$(add_alpha_channel $WM_LLIGHT) - accent=$(add_alpha_channel $WM_ACCENT) - ldark=$(add_alpha_channel $WM_LDARK) - dark=$(add_alpha_channel $WM_DARK) - font="-*-fixed-medium-*-*-*-$(echo "$height - 10" | bc)-*-*-*-*-*-*-*" - bar_opts="-f ${font} -B $dark -F $light -g ${width}x${height}+${x}+${y} -u 2" + + bar_opts="-f $font,$font_sec -B $acolor_bg -F $acolor_fg -g ${popup_width}x${height}+${popup_x}+${popup_y} -u 2" t=$(date +%T) @@ -54,7 +40,7 @@ else fi { - echo "%{F$accent} $prefix %{F$light}$message %{F$llight}($t)%{F-}" + echo "%{F$acolor_accent} $prefix %{F$acolor_fg}$message %{F$acolor_fg}($t)%{F-}" sleep $timeout } | bar $bar_opts fi diff --git a/herbstluftwm/.config/herbstluftwm/theme b/herbstluftwm/.config/herbstluftwm/theme deleted file mode 100644 index 810c5d2..0000000 --- a/herbstluftwm/.config/herbstluftwm/theme +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -# Get color from ~/.Xresources -get_x_color() { - xresources=$(cat ~/.Xresources) - color=$(echo $xresources | sed "s/.*\*color$1: \(#[0-9A-Fa-f]*\).*/\1/") - echo $color -} - -# Add alpha channel to a hexadecimal color -add_alpha_channel(){ - echo "$1" | \ - sed "s/.*#\([0-9a-fA-F]*\).*/#ff\1/" -} - -# Wallpaper -wallpaper="/home/tom/Pictures/fall1.jpg" - -# Padding -window_p=20 - -# Panel -panel_h=24 -font="-*-fixed-medium-*-*-*-14-*-*-*-*-*-*-*" -font_sec="-*-stlarch-medium-*-*-*-10-*-*-*-*-*-*-*" - -# Colors -color_fg=$(get_x_color 15) -color_accent=$(get_x_color 9) -color_bg=$(get_x_color 0) - -# Alpha Colors for use with bar -acolor_fg=$(add_alpha_channel $color_fg) -acolor_accent=$(add_alpha_channel $color_accent) -acolor_bg=$(add_alpha_channel $color_bg) diff --git a/herbstluftwm/.config/herbstluftwm/theme.sh b/herbstluftwm/.config/herbstluftwm/theme.sh new file mode 100644 index 0000000..bcbc6f7 --- /dev/null +++ b/herbstluftwm/.config/herbstluftwm/theme.sh @@ -0,0 +1,33 @@ +# Get color from ~/.Xresources +get_x_color() { + xresources=$(cat ~/.Xresources) + color=$(echo $xresources | sed "s/.*\*color$1: \(#[0-9A-Fa-f]*\).*/\1/") + echo $color +} + +# Add alpha channel to a hexadecimal color +add_alpha_channel(){ + echo "$1" | \ + sed "s/.*#\([0-9a-fA-F]*\).*/#ff\1/" +} + +# Wallpaper +wallpaper="/home/tom/Pictures/fall1.jpg" + +# Padding +window_p=20 + +# Panel +panel_h=24 +font="-*-fixed-medium-*-*-*-14-*-*-*-*-*-*-*" +font_sec="-*-stlarch-medium-*-*-*-10-*-*-*-*-*-*-*" + +# Colors +color_fg=$(get_x_color 15) +color_accent=$(get_x_color 9) +color_bg=$(get_x_color 0) + +# Alpha Colors for use with bar +acolor_fg=$(add_alpha_channel $color_fg) +acolor_accent=$(add_alpha_channel $color_accent) +acolor_bg=$(add_alpha_channel $color_bg) -- cgit v1.2.3