From d0ecb2a9d770b1987e3be7cdc549d46880b89c5e Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Sun, 22 Feb 2015 17:15:39 +0100 Subject: Moved from stow to dotfiles for dotfile management --- config/herbstluftwm/autostart | 191 ++++++++++++++++++++++++++++++++ config/herbstluftwm/dependencylist | 15 +++ config/herbstluftwm/lock.sh | 7 ++ config/herbstluftwm/notify.sh | 19 ++++ config/herbstluftwm/panel.sh | 160 ++++++++++++++++++++++++++ config/herbstluftwm/panel_indicators.sh | 127 +++++++++++++++++++++ config/herbstluftwm/popup.sh | 46 ++++++++ config/herbstluftwm/start.sh | 13 +++ config/herbstluftwm/theme.sh | 33 ++++++ 9 files changed, 611 insertions(+) create mode 100755 config/herbstluftwm/autostart create mode 100644 config/herbstluftwm/dependencylist create mode 100755 config/herbstluftwm/lock.sh create mode 100755 config/herbstluftwm/notify.sh create mode 100755 config/herbstluftwm/panel.sh create mode 100644 config/herbstluftwm/panel_indicators.sh create mode 100755 config/herbstluftwm/popup.sh create mode 100755 config/herbstluftwm/start.sh create mode 100644 config/herbstluftwm/theme.sh (limited to 'config/herbstluftwm') diff --git a/config/herbstluftwm/autostart b/config/herbstluftwm/autostart new file mode 100755 index 0000000..78e9af8 --- /dev/null +++ b/config/herbstluftwm/autostart @@ -0,0 +1,191 @@ +#!/bin/bash + +# this is a simple config for herbstluftwm + +hc() { + herbstclient "$@" +} + +#Include the theming script +dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +source "$dir/theme.sh" + +#Detect monitors +hc set auto_detect_monitors 1 +hc detect_monitors + +#Panel and window_p +monitor_w=($(hc list_monitors | sed 's/^[0-9]: \([0-9]*\)x.*$/\1/')) +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 $color_bg -nf $color_fg -sb $color_accent -sf $color_bg" + +# remove all existing keybindings +hc keyunbind --all + +# keybindings +Mod=Mod4 # Use the super key as the main modifier + +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 $dmenu_opts +hc keybind XF86AudioLowerVolume spawn amixer set Master 1%- +hc keybind XF86AudioRaiseVolume spawn amixer set Master 1%+ + +# basic movement +# focusing clients +hc keybind $Mod-Left focus left +hc keybind $Mod-Down focus down +hc keybind $Mod-Up focus up +hc keybind $Mod-Right focus right +hc keybind $Mod-h focus left +hc keybind $Mod-j focus down +hc keybind $Mod-k focus up +hc keybind $Mod-l focus right + +# moving clients +hc keybind $Mod-Shift-Left shift left +hc keybind $Mod-Shift-Down shift down +hc keybind $Mod-Shift-Up shift up +hc keybind $Mod-Shift-Right shift right +hc keybind $Mod-Shift-h shift left +hc keybind $Mod-Shift-j shift down +hc keybind $Mod-Shift-k shift up +hc keybind $Mod-Shift-l shift right + +# splitting frames +# create an empty frame at the specified direction +hc keybind $Mod-u split bottom 0.5 +hc keybind $Mod-o split right 0.5 +# let the current frame explode into subframes +hc keybind $Mod-Control-space split explode + +# resizing frames +resizestep=0.05 +hc keybind $Mod-Control-h resize left +$resizestep +hc keybind $Mod-Control-j resize down +$resizestep +hc keybind $Mod-Control-k resize up +$resizestep +hc keybind $Mod-Control-l resize right +$resizestep +hc keybind $Mod-Control-Left resize left +$resizestep +hc keybind $Mod-Control-Down resize down +$resizestep +hc keybind $Mod-Control-Up resize up +$resizestep +hc keybind $Mod-Control-Right resize right +$resizestep + +# tags +tag_names=( I II III IV V VI VII VIII IX X ) +tag_keys=( {1..9} 0 ) + +# Selecting workspaces +hc keybind Alt-Control-Left use_index -1 +hc keybind Alt-Control-Right use_index +1 +hc rename default "${tag_names[0]}" || true +for i in ${!tag_names[@]} ; do + hc add "${tag_names[$i]}" + key="${tag_keys[$i]}" + if ! [ -z "$key" ] ; then + hc keybind "$Mod-$key" use_index "$i" + hc keybind "$Mod-Shift-$key" move_index "$i" + fi +done + +# cycle through tags +hc keybind $Mod-period use_index +1 --skip-visible +hc keybind $Mod-comma use_index -1 --skip-visible + +# layouting +hc keybind $Mod-r remove +hc keybind $Mod-space cycle_layout 1 +hc keybind $Mod-s floating toggle +hc keybind $Mod-f fullscreen toggle +hc keybind $Mod-p pseudotile toggle + +# mouse +hc mouseunbind --all +hc mousebind $Mod-Button1 move +hc mousebind $Mod-Button2 zoom +hc mousebind $Mod-Button3 resize + +# focus +hc keybind $Mod-BackSpace cycle_monitor +hc keybind $Mod-Tab cycle_all +1 +hc keybind $Mod-Shift-Tab cycle_all -1 +hc keybind $Mod-c cycle +hc keybind $Mod-i jumpto urgent +hc set focus_follows_mouse 1 + +# theme +hc attr theme.tiling.reset 1 +hc attr theme.floating.reset 1 +hc set frame_border_width 0 +hc set always_show_frame 0 +hc set frame_bg_transparent 1 +hc set frame_normal_opacity 0 +hc set frame_active_opacity 0 +hc set frame_transparent_width 0 +hc set frame_gap 0 + +hc attr theme.active.color $color_accent +hc attr theme.normal.color $color_bg +hc attr theme.urgent.color orange +hc attr theme.inner_width 1 +hc attr theme.inner_color $color_bg +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 $color_bg +hc attr theme.active.inner_color $color_bg +hc attr theme.active.outer_color $color_bg +hc attr theme.background_color $color_bg + +hc set window_gap $window_p +hc set frame_padding 0 +hc set smart_window_surroundings 0 +hc set smart_frame_surroundings 1 +hc set mouse_recenter_gap 1 + +# rules +hc unrule -F +hc rule focus=on # normally focus new clients + +#hc rule windowtype~'_NET_WM_WINDOW_TYPE_(DIALOG|UTILITY|SPLASH)' pseudotile=on +hc rule windowtype='_NET_WM_WINDOW_TYPE_DIALOG' focus=on +hc rule windowtype~'_NET_WM_WINDOW_TYPE_(NOTIFICATION|DOCK|DESKTOP)' manage=off + +hc rule --class~'(.*[Ss]team.*)' --tag=IX --focus=off +hc rule --class~'(.*[Hh]exchat.*)' --tag=X --focus=off +hc rule --class~'(.*[Ss]potify.*)' --tag=X --focus=off +hc rule --class~'(.*[Ss]kype.*)' --tag=VIII --focus=off + +# unlock, just to be sure +hc unlock + +herbstclient set tree_style '╾│ ├└╼─┐' + +#Start panel in all monitors +start_panel() { + for monitor in $(herbstclient list_monitors | cut -d: -f1) ; do + "$1" $monitor& + done +} + +# find the panel +panel=$dir/panel.sh +[ -x "$panel" ] || panel=/etc/xdg/herbstluftwm/panel.sh +if pgrep panel.sh >> /dev/null +then + kill $(pgrep panel.sh) + start_panel $panel +else + start_panel $panel +fi + +pulseaudio --start + +$dir/start.sh "xautolock -time 5 -locker $dir/lock.sh" +$dir/start.sh "feh --bg-fill $wallpaper" +$dir/start.sh "compton --config $HOME/.compton" +$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 "$dir/notify.sh $dir/popup.sh" diff --git a/config/herbstluftwm/dependencylist b/config/herbstluftwm/dependencylist new file mode 100644 index 0000000..7d3babf --- /dev/null +++ b/config/herbstluftwm/dependencylist @@ -0,0 +1,15 @@ +alsa-utils +bar-aint-recursive +bc +compton +dmenu2 +feh +i3lock +playerctl +pulseaudio +pulseaudio-alsa +scrot +sed +stlarch_font +wireless_tools +xautolock diff --git a/config/herbstluftwm/lock.sh b/config/herbstluftwm/lock.sh new file mode 100755 index 0000000..04c4638 --- /dev/null +++ b/config/herbstluftwm/lock.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +SCREENCAP="/tmp/lock.png" +scrot $SCREENCAP +convert -gaussian-blur "12x3" $SCREENCAP $SCREENCAP +i3lock -i $SCREENCAP +rm $SCREENCAP diff --git a/config/herbstluftwm/notify.sh b/config/herbstluftwm/notify.sh new file mode 100755 index 0000000..40c5330 --- /dev/null +++ b/config/herbstluftwm/notify.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +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 + $1 -m "Battery level critical: $bat_lvl%%" -u "high" + elif [[ $bat_lvl -eq 10 && $bat_stat == "Discharging" ]]; then + $1 -m "Battery level low: $bat_lvl%%" + elif [[ $bat_lvl -eq 50 && $bat_stat == "Discharging" ]]; then + $1 -m "Battery level at $bat_lvl%%" + elif [[ $bat_lvl -eq 100 && $bat_stat == "Charging" ]]; then + $1 -m "Battery fully charged" + fi + + sleep 60; +done diff --git a/config/herbstluftwm/panel.sh b/config/herbstluftwm/panel.sh new file mode 100755 index 0000000..763c668 --- /dev/null +++ b/config/herbstluftwm/panel.sh @@ -0,0 +1,160 @@ +#!/bin/bash + +hc() { + "${herbstclient_command[@]:-herbstclient}" "$@" ; +} + +dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +source "$dir/theme.sh" +source "$dir/panel_indicators.sh" + +monitor=${1:-0} + +geometry=( $(herbstclient monitor_rect "$monitor") ) +if [ -z "$geometry" ] ;then + echo "Invalid monitor $monitor" + exit 1 +fi +# geometry has the format W H X Y +x=$(echo "${geometry[0]} + $window_p" | bc) +y=$(echo "${geometry[1]} + $window_p" | bc) +panel_width=$(echo "${geometry[2]} - (2 * $window_p)" | bc) +bar_opts="-g ${panel_width}x${panel_h}+${x}+${y} -f $font,$font_sec -u 2 -B $acolor_bg -F $acolor_fg" + +hc pad $monitor $(echo "$panel_h + $window_p" | bc) + +if awk -Wv 2>/dev/null | head -1 | grep -q '^mawk'; then + # mawk needs "-W interactive" to line-buffer stdout correctly + # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593504 + uniq_linebuffered() { + awk -W interactive '$0 != l { print ; l=$0 ; fflush(); }' "$@" + } +else + # other awk versions (e.g. gawk) issue a warning with "-W interactive", so + # we don't want to use it there. + uniq_linebuffered() { + awk '$0 != l { print ; l=$0 ; fflush(); }' "$@" + } +fi + +{ + ### Event generator ### + # \t [...] + # e.g. + # date ^fg(#efefef)18:33^fg(#909090), 2013-10-^fg(#efefef)29 + while true ; do + music + volume + network + battery + clock + sleep 1 || break + done > >(uniq_linebuffered) & + childpid=$! + hc --idle + kill $childpid +} 2> /dev/null | { + + IFS=$'\t' read -ra tags <<< "$(hc tag_status $monitor)" + visible=true + date="" + volume="" + battery="" + net="" + windowtitle="" + while true ; do + separator="%{F$acolor_accent}|%{F-}" + # draw tags + for i in "${tags[@]}" ; do + case ${i:0:1} in + '#') + echo -n "%{U$acolor_accent+u}%{F$acolor_fg}" + ;; + '+') + echo -n "%{U$acolor_fg+u}%{F$acolor_fg}" + ;; + ':') + echo -n "%{F$acolor_fg}" + ;; + '!') + echo -n "%{B$acolor_accent}%{U$acolor_accent+u}%{F$acolor_bg}" + ;; + *) + echo -n "%{F$acolor_fg}" + ;; + esac + echo -n "%{A:tag,${i:1}:} ${i:1} %{A}%{F-}%{U-u}%{B-}" + done + echo -n "$separator%{F-}%{B-} " + echo -n "${windowtitle//^/^^}" + + #Right part of panel + right="$music$volume$net$battery$date " + echo -n "%{r}$right" + + #DO NOT REMOVE THIS ECHO + echo + + # wait for next event + IFS=$'\t' read -ra cmd || break + case "${cmd[0]}" in + tag*) + #echo "resetting tags" >&2 + IFS=$'\t' read -ra tags <<< "$(hc tag_status $monitor)" + ;; + music) + music="${cmd[@]:1}" + if [ $music == "off" ] ; then + music="" + else + music="$music $separator%{B-} " + fi + ;; + volume) + volume="${cmd[@]:1}" + if [ $volume == "off" ] ; then + volume="" + else + volume="$volume $separator%{B-} " + fi + ;; + net) + net="${cmd[@]:1}" + if [ $net = "off" ] ; then + net="" + else + net="$net $separator%{B-} " + fi + ;; + battery) + battery="${cmd[@]:1}" + if [ $battery == "off" ] ; then + battery="" + else + battery="$battery $separator%{B-} " + fi + ;; + date) + #echo "resetting date" >&2 + date="${cmd[@]:1}" + ;; + focus_changed|window_title_changed) + windowtitle="${cmd[@]:2}" + ;; + esac + done +} 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 "${c[0]}: not valid command" + ;; + esac + done +} diff --git a/config/herbstluftwm/panel_indicators.sh b/config/herbstluftwm/panel_indicators.sh new file mode 100644 index 0000000..e450337 --- /dev/null +++ b/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/config/herbstluftwm/popup.sh b/config/herbstluftwm/popup.sh new file mode 100755 index 0000000..eda37f5 --- /dev/null +++ b/config/herbstluftwm/popup.sh @@ -0,0 +1,46 @@ +#!/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" + echo -e " -u LEVEL\t\tUrgency level (info or high)" +} + +dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +source "$dir/theme.sh" + +timeout=10 +message="" +urgency="info" + +while getopts ":m:t:x:y:w:h:u:" opt; do + case $opt in + m) message=$OPTARG ;; + t) timeout=$OPTARG ;; + u) urgency=$OPTARG ;; + esac +done + +if test ! $message; then + help +else + + 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) + + if [ $urgency == "info" ]; then + prefix="Info:" + elif [ $urgency == "high" ]; then + prefix="!!WARNING:" + fi + + { + echo "%{F$acolor_accent} $prefix %{F$acolor_fg}$message %{F$acolor_fg}($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 diff --git a/config/herbstluftwm/theme.sh b/config/herbstluftwm/theme.sh new file mode 100644 index 0000000..c40f94a --- /dev/null +++ b/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/Wallpapers/snake.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 10) +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