From d9d9c28ed02611bdb2e37039fb62a19fc39815ad Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Sun, 5 Oct 2014 21:41:33 +0200 Subject: Added notifications --- .config/herbstluftwm/autostart | 118 ++++++++++++++--------------------------- .config/herbstluftwm/notify.sh | 30 +++++++++++ .config/herbstluftwm/panel.sh | 27 ++++------ .config/herbstluftwm/popup.sh | 60 +++++++++++++++++++++ .config/herbstluftwm/start.sh | 13 +++++ 5 files changed, 155 insertions(+), 93 deletions(-) create mode 100755 .config/herbstluftwm/notify.sh create mode 100755 .config/herbstluftwm/popup.sh create mode 100755 .config/herbstluftwm/start.sh (limited to '.config/herbstluftwm') diff --git a/.config/herbstluftwm/autostart b/.config/herbstluftwm/autostart index b5115cf..fb6d2e0 100755 --- a/.config/herbstluftwm/autostart +++ b/.config/herbstluftwm/autostart @@ -6,33 +6,30 @@ hc() { herbstclient "$@" } -#get colors from .Xresources -get_xcolor(){ - xresources=$(\ - cat ~/.Xresources\ - ) - color=$(\ - echo $xresources | \ - sed "s/.*\*color$1: \(#[0-9A-Fa-f]*\).*/\1/"\ - ) - echo $color +get_x_color() { + xresources=$(cat ~/.Xresources) + color=$(echo $xresources | sed "s/.*\*color$1: \(#[0-9A-Fa-f]*\).*/\1/") + echo $color } -#Wallpaper -WALLPAPER=/home/tom/Pictures/rocks.jpg +hlwm_scripts="$HOME/.config/herbstluftwm" + +#wallpaper +wallpaper=/home/tom/Pictures/rocks.jpg #Numix color palette -LIGHT=$(get_xcolor 15) -LLIGHT=$(get_xcolor 7) -ACCENT=$(get_xcolor 12) -LDARK=$(get_xcolor 8) -DARK=$(get_xcolor 0) - -#Panel and padding -padding=20 -monitor_width=$(hc list_monitors | sed 's/^[0-9]: \([0-9]*\)x.*$/\1/') -panel_height=24 -panel_width=$(echo "$monitor_width - (2 * $padding)" | bc) +export WM_LIGHT=$(get_x_color 15) +export WM_LLIGHT=$(get_x_color 7) +export WM_ACCENT=$(get_x_color 12) +export WM_LDARK=$(get_x_color 8) +export WM_DARK=$(get_x_color 0) + +#Panel and window_p +window_p=20 +monitor_w=$(hc list_monitors | sed 's/^[0-9]: \([0-9]*\)x.*$/\1/') +panel_h=24 +panel_w=$(echo "$monitor_w - (2 * $window_p)" | bc) +dmenu_opts="-h $panel_h -w $panel_w -x $window_p -y $window_p -p Run: -nb $WM_DARK -nf $WM_LIGHT -sb $WM_ACCENT -sf $WM_DARK" hc emir_hook reload @@ -46,7 +43,7 @@ hc keybind $Mod-Shift-q quit hc keybind $Mod-Shift-r reload hc keybind $Mod-Shift-c close hc keybind $Mod-Return spawn xterm -hc keybind $Mod-grave spawn dmenu_run -h $panel_height -w $panel_width -x $padding -y $padding -p "Run:" -nb $DARK -nf $LIGHT -sb $ACCENT -sf $DARK +hc keybind $Mod-grave spawn dmenu_run $dmenu_opts hc keybind XF86AudioLowerVolume spawn amixer set Master 5%- hc keybind XF86AudioRaiseVolume spawn amixer set Master 5%+ @@ -134,30 +131,30 @@ hc set focus_follows_mouse 1 # theme hc attr theme.tiling.reset 1 hc attr theme.floating.reset 1 -hc set frame_border_active_color $LDARK -hc set frame_border_normal_color $DARK -hc set frame_bg_normal_color $LDARK -hc set frame_bg_active_color $DARK +hc set frame_border_active_color $WM_LDARK +hc set frame_border_normal_color $WM_DARK +hc set frame_bg_normal_color $WM_LDARK +hc set frame_bg_active_color $WM_DARK hc set frame_border_width 0 hc set always_show_frame 0 hc set frame_bg_transparent 1 hc set frame_transparent_width 0 hc set frame_gap 0 -hc attr theme.active.color $ACCENT -hc attr theme.normal.color $DARK +hc attr theme.active.color $WM_ACCENT +hc attr theme.normal.color $WM_DARK hc attr theme.urgent.color orange hc attr theme.inner_width 1 -hc attr theme.inner_color $DARK +hc attr theme.inner_color $WM_DARK hc attr theme.border_width 3 hc attr theme.floating.border_width 4 hc attr theme.floating.outer_width 1 -hc attr theme.floating.outer_color $DARk -hc attr theme.active.inner_color $DARK -hc attr theme.active.outer_color $DARK -hc attr theme.background_color $DARK +hc attr theme.floating.outer_color $WM_DARK +hc attr theme.active.inner_color $WM_DARK +hc attr theme.active.outer_color $WM_DARK +hc attr theme.background_color $WM_DARK -hc set window_gap $padding +hc set window_gap $window_p hc set frame_padding 0 hc set smart_window_surroundings 0 hc set smart_frame_surroundings 1 @@ -179,20 +176,15 @@ hc unlock herbstclient set tree_style '╾│ ├└╼─┐' -# do multi monitor setup here, e.g.: -# hc set_monitors 1280x1024+0+0 1280x1024+1280+0 -# or simply: -# hc detect_monitors - #Start panel in all monitors start_panel() { for monitor in $(herbstclient list_monitors | cut -d: -f1) ; do - "$1" $monitor $panel_height $padding $LIGHT $LLIGHT $ACCENT $LDARK $DARK $2& + "$1" $monitor $panel_h $window_p & done } # find the panel -panel=~/.config/herbstluftwm/panel.sh +panel=$hlwm_scripts/panel.sh [ -x "$panel" ] || panel=/etc/xdg/herbstluftwm/panel.sh if pgrep panel.sh >> /dev/null then @@ -202,37 +194,9 @@ else start_panel $panel fi -#Wallpaper -feh --bg-fill $WALLPAPER - -#Start compton if not running -start_compton(){ compton --config ~/.compton & } -if pgrep compton >> /dev/null -then - kill $(pgrep compton) - start_compton -else - start_compton -fi - -#Load .Xresources -xrdb -load ~/.Xresources - -#Start pulseaudio -if pgrep pulseaudio >> /dev/null -then - kill $(pgrep pulseaudio) - pulseaudio --start -else - pulseaudio --start -fi - -#Start xscreensaver -if pgrep xscreensaver >> /dev/null -then - kill $(pgrep xscreensaver) - xscreensaver -no-splash& -else - xscreensaver -no-splash& -fi - +$hlwm_scripts/start.sh feh --bg-fill $wallpaper +$hlwm_scripts/start.sh compton --config ~/.compton +$hlwm_scripts/start.sh xrdb -load ~/.Xresources +$hlwm_scripts/start.sh pulseaudio --start +$hlwm_scripts/start.sh xscreensaver -no-splash +$hlwm_scripts/start.sh $hlwm_scripts/notify.sh $monitor_w $window_p $panel_h $hlwm_scripts/popup.sh diff --git a/.config/herbstluftwm/notify.sh b/.config/herbstluftwm/notify.sh new file mode 100755 index 0000000..190d496 --- /dev/null +++ b/.config/herbstluftwm/notify.sh @@ -0,0 +1,30 @@ +#!/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 + elif [[ $bat_lvl -eq 10 && $bat_stat == "Discharging" ]]; then + $4 -m "Battery level low: $bat_lvl%%" $popup_opts + elif [[ $bat_lvl -eq 50 && $bat_stat == "Discharging" ]]; then + $4 -m "Battery level at $bat_lvl%%" $popup_opts + elif [[ $bat_lvl -eq 100 && $bat_stat == "Charging" ]]; then + $4 -m "Battery fully charged" + fi + + sleep 60; +done diff --git a/.config/herbstluftwm/panel.sh b/.config/herbstluftwm/panel.sh index 4e35d0d..ac06100 100755 --- a/.config/herbstluftwm/panel.sh +++ b/.config/herbstluftwm/panel.sh @@ -13,11 +13,11 @@ monitor=${1:-0} panel_height=$2 padding=$3 -light=$(add_alpha_channel $4) -llight=$(add_alpha_channel $5) -accent=$(add_alpha_channel $6) -ldark=$(add_alpha_channel $7) -dark=$(add_alpha_channel $8) +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-*-*-*-14-*-*-*-*-*-*-*" #font="" @@ -36,6 +36,7 @@ fi x=$(echo "${geometry[0]} + $padding" | bc) y=$(echo "${geometry[1]} + $padding" | bc) panel_width=$(echo "${geometry[2]} - (2 * $padding)" | bc) +bar_opts="-g ${panel_width}x${panel_height}+${x}+${y} -f ${font} -u 2 -B ${normal_bg} -F ${normal_txt}" hc pad $monitor $(echo "$panel_height + $padding" | bc) @@ -102,14 +103,14 @@ fi # Battery if $(test -e /sys/class/power_supply/BAT1) ; then - charge=$(cat /sys/class/power_supply/BAT1/capacity) - if [ $charge -lt 15 ] ; then + bat_lvl=$(cat /sys/class/power_supply/BAT1/capacity) + if [ $bat_lvl -lt 15 ] ; then bat_color=$accent else bat_color=$normal_txt fi state=$(cat /sys/class/power_supply/BAT1/status) - echo -e "battery\t%{F$normal_txt}$state: %{F$bat_color}$charge%{F$normal_txt}%%%{F-}" + echo -e "battery\t%{F$normal_txt}$state: %{F$bat_color}$bat_lvl%{F$normal_txt}%%%{F-}" else echo -e "battery\toff" fi @@ -201,20 +202,14 @@ fi ;; esac done -} 2> /dev/null | \ - bar -g $panel_width\x$panel_height\+$x+$y \ - -f "$font" \ - -u 2 \ - -B "$normal_bg" \ - -F "$normal_txt" | \ -{ +} 2> /dev/null | bar $bar_opts | { #Handle clickable areas while read line; do IFS=',' read -a c <<< $(echo $line) case "${c[0]}" in tag) herbstclient use "${c[1]}" - echo "herbstclient use \"${c[1]}\"" + echo "herbstclient use \"${c[1]}\"" ;; *) echo "${c[0]}: not valid command" diff --git a/.config/herbstluftwm/popup.sh b/.config/herbstluftwm/popup.sh new file mode 100755 index 0000000..41c5e9c --- /dev/null +++ b/.config/herbstluftwm/popup.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +help () { + echo -e "Usage: popup.sh [OPTIONS]" + echo -e "Spawns a popup for a certain amount of time" + echo -e "" + 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" +} + +add_alpha_channel(){ + echo "$1" | \ + sed "s/.*#\([0-9a-fA-F]*\).*/#ff\1/" +} + +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 + +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" + + t=$(date +%T) + + if [ $urgency == "info" ]; then + prefix="Info:" + elif [ $urgency == "high" ]; then + prefix="!!WARNING:" + fi + + { + echo "%{F$accent} $prefix %{F$light}$message %{F$llight}($t)%{F-}" + sleep $timeout + } | bar $bar_opts +fi diff --git a/.config/herbstluftwm/start.sh b/.config/herbstluftwm/start.sh new file mode 100755 index 0000000..f10fca6 --- /dev/null +++ b/.config/herbstluftwm/start.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +opts=($@) + +program=$(echo ${opts[0]} | sed 's/^.*\/\(.*\)/\1/') + +if pgrep $program >> /dev/null +then + killall $program + ${opts[@]} & +else + ${opts[@]} & +fi -- cgit v1.2.3