From c132453f4e06ed5e6815834583bbc0e4a6b3e438 Mon Sep 17 00:00:00 2001 From: Von Random Date: Sat, 27 Jun 2015 18:13:58 +0300 Subject: [PATCH] added my own bspwm config --- bspwm/bspwmrc | 44 ++++++++++ bspwm/common | 24 ++++++ bspwm/panel | 207 +++++++++++++++++++++++++++++++++++++++++++++ bspwm/panel_status | 54 ++++++++++++ bspwm/sxhkdrc | 78 +++++++++++++++++ bspwm/testscript | 3 + 6 files changed, 410 insertions(+) create mode 100755 bspwm/bspwmrc create mode 100755 bspwm/common create mode 100755 bspwm/panel create mode 100755 bspwm/panel_status create mode 100644 bspwm/sxhkdrc create mode 100755 bspwm/testscript diff --git a/bspwm/bspwmrc b/bspwm/bspwmrc new file mode 100755 index 0000000..10076e3 --- /dev/null +++ b/bspwm/bspwmrc @@ -0,0 +1,44 @@ +#!/usr/bin/env zsh +export BSPWM_SOCKET='/tmp/bspwm_sock' +bspwm& +until [[ -e $BSPWM_SOCKET ]]; do + sleep 1 +done +export bspwm_config_dir="$HOME/vdotfiles/bspwm-zsh" +source $bspwm_config_dir/common +# bspwm general settings +/usr/bin/bspc config focused_border_color $colors_bg_focused +/usr/bin/bspc config normal_border_color $colors_bg_normal +/usr/bin/bspc config urgent_border_color $colors_urgent +/usr/bin/bspc config focused_sticky_border_color $colors_sticky_focused +/usr/bin/bspc config top_padding 18 +/usr/bin/bspc config border_width 1 +/usr/bin/bspc config window_gap 5 +/usr/bin/bspc config focus_follows_pointer true +/usr/bin/bspc config pointer_follows_monitor true +/usr/bin/bspc config split_ratio 0.50 +/usr/bin/bspc config borderless_monocle true +/usr/bin/bspc config gapless_monocle true +/usr/bin/bspc config focus_by_distance true +/usr/bin/bspc config ignore_ewmh_focus true +# bspwm window placement rules +/usr/bin/bspc rule -a URxvt desktop=^2 follow=on floating=on +/usr/bin/bspc rule -a Steam desktop=^4 follow=off floating=on +# bspwm create tags +/usr/bin/bspc monitor -d 1 2 3 4 5 +# the rest of it +job_list=() +# sxhkd kill / spawn (there can only be one) +/usr/bin/pkill sxhkd 2>&1 >/dev/null +/usr/bin/sxhkd -f 60 -c $bspwm_config_dir/sxhkdrc& +# panel +fontdir="$HOME/.fonts/terminus/PCF" +/usr/bin/xset +fp $fontdir +$bspwm_config_dir/panel& +# trap to kill all the jobs when killing the script itself +trap 'cleanup' EXIT TERM INT +function cleanup +{ + eval "kill ${${jobstates##*:*:}%=*}" +} +wait diff --git a/bspwm/common b/bspwm/common new file mode 100755 index 0000000..4335738 --- /dev/null +++ b/bspwm/common @@ -0,0 +1,24 @@ +# vim: ft=sh +# common config +# fonts +font_norm='-*-terminus-medium-*-normal-*-14-*-*-*-*-*-iso10646-*' +font_bold='-*-terminus-bold*-normal-*-14-*-*-*-*-*-iso10646-*' +# colors +colors_fg_normal='#f9f9f9' +colors_fg_focused=$colors_fg_normal +colors_bg_normal='#2d2d2d' +colors_bg_focused='#00612b' +colors_urgent='#610000' +colors_sticky_focused='#030061' +# date format +date_format='+%a %d %H:%M' + +# panel config +panel_fifo="/tmp/panel$DISPLAY-sock" +bspwm_sock="/tmp/bspwm$DISPLAY-sock" +panel_h='14' +panel_show_empty_tags=0 +# taskbar +panel_taskbar_enable=1 +panel_taskbar_max_length=160 +panel_taskbar_max_title=32 diff --git a/bspwm/panel b/bspwm/panel new file mode 100755 index 0000000..d92208f --- /dev/null +++ b/bspwm/panel @@ -0,0 +1,207 @@ +#!/usr/bin/env zsh +source $bspwm_config_dir/common + +cleanup() { + jobs=${${jobstates##*:*:}%=*} + + if [[ "$jobs" ]]; then + eval "kill $jobs" + fi + + bspc config top_padding 0 +} + +get_line() { + declare counter=0 line=$1 + + while read; do + if (( counter == line )); then + printf '%s\n' "$REPLY" + return 0 + fi + + (( counter++ )) + done +} + +parse_fifo_data() { + declare msg desktop_spec + declare -g win_name misc bspwm_status + + while read; do + case "$REPLY" in + cmd::*) + read -r cmd args <<< "${REPLY#cmd::}" + + case "$cmd" in + redraw) + printf 'Redraw triggered\n' + sleep 1 + printf '%s\n' "$msg" + ;; + respawn) + printf 'Dying...\n' + sleep 1 + rexec + ;; + run) + $args + rexec + ;; + esac + ;; + updates::*) updates="${REPLY#*updates::}";; + date::*) date="${REPLY#*date::}";; + T*) + if (( panel_taskbar_enable )); then + unset win_title + unset taskbar taskbar_windows taskbar_length + + panel_taskbar_max_title_current=$panel_taskbar_max_title + + while read -r _ _ _ wid _ _ _ _ focus; do + if [[ "$wid" =~ [0-9]x[0-9A-F] ]]; then + if [[ "$focus" == '*' ]]; then + taskbar_windows+=( "$wid::F" ) + else + taskbar_windows+=( "$wid::u" ) + fi + fi + done < <( bspc query -T -d focused ) + + taskbar_windows_n="${#taskbar_windows[@]}" + + if (( taskbar_windows_n )); then + until (( taskbar_length )) && (( taskbar_length <= panel_taskbar_max_length )); do + unset taskbar + taskbar_length=$(( (taskbar_windows_n * 2) + 2 )) + + for w in "${taskbar_windows[@]}"; do + IFS='::' read -r wid _ state <<< "$w" + win_title=$( xtitle -f '%s' -t "${panel_taskbar_max_title_current}" "$wid" ) + win_title_length="${#win_title}" + + taskbar_length=$(( taskbar_length + win_title_length )) + + if [[ "$state" == 'F' ]]; then + taskbar+=" %{B${colors_bg_focused}}%{F${colors_bg_normal}}%{F-} ${win_title} %{B-}%{F${colors_bg_focused}}%{F-}" + else + taskbar+=" %{A:bspc window -f ${wid}:} ${win_title} %{A}" + fi + done + + (( panel_taskbar_max_title_current-- )) + done + fi + else + win_title="${REPLY#*T}" + if [[ "$win_title" ]]; then + taskbar=" %{B${colors_bg_focused}}%{F${colors_bg_normal}}%{F-} ${win_title} %{B-}%{F${colors_bg_focused}}%{F-}" + else + unset taskbar + fi + fi + ;; + WM*) + unset desktop_spec + IFS=':' read -A bspwm_status <<< "$REPLY" + + for i in "${bspwm_status[@]}"; do + if [[ "$i" =~ ^[oOfFuU].+ ]]; then + n="${i#*[oOfFuU]}" + + case "$i" in + O*|F*|U*) desktop_spec+="%{B${colors_bg_focused}} $n %{B-}";; + u*) desktop_spec+="%{B${colour_urgent}}%{A:bspc desktop -f $n:} $n %{A}%{B-}";; + o*) desktop_spec+="%{B-}%{A:bspc desktop -f $n:} $n %{A}";; + f*) + (( panel_show_empty_tags )) && { + desktop_spec+="%{B-} $n " + } + ;; + esac + fi + done + + read _ _ _ _ layout float _ < <( bspc query -T -d focused | get_line 1 ) + + if [[ "$float" == 'f' ]]; then + float_flag='f' + else + float_flag='' + fi + + case "$layout" in + T) layout_flag='t';; + M) layout_flag='m';; + esac + + desktop_spec+=" %{A:bsptl:}[${layout_flag}${float_flag}]%{A}" + ;; + esac + + msg="$desktop_spec" + + [[ "$taskbar" ]] && { msg+="$taskbar"; } + + msg+="%{r}%{F${colors_bg_focused}}%{F-}%{B${colors_bg_focused}} $updates $date " + msg+='%{B-}%{F-}' + + printf '%s\n' "$msg" + done < "$panel_fifo" +} + +misc_status() { + declare ip msg date + + while sleep 1; do + date=$( date +%A,\ %Y.%m.%d\ %H:%M:%S ) + msg="[ $date ]" + printf 'S:%s\n' "$msg" + done +} + +rexec() { + eval "kill ${${jobstates##*:*:}%=*[@]}" + exec "$0" +} + +function panel_geometry +{ + xrandr|grep -Eo '[[:digit:]]+x[[:digit:]]+\+[[:digit:]]+\+[[:digit:]]+'|awk -F'x|+' '{print $1,$2,$3,$4}'|read -A screen_geometry + ((panel_h)) || panel_h=20 + ((panel_w)) || panel_w=$screen_geometry[2] + ((panel_l)) || panel_l=$screen_geometry[3] + ((panel_d)) || panel_d=$screen_geometry[4] +} + +main() { + trap 'cleanup' EXIT TERM INT + trap 'rexec' HUP + + [[ -e "$panel_fifo" ]] && { + rm "$panel_fifo" || { return 1; } + } + + mkfifo "$panel_fifo" + + if (( panel_taskbar_enable )); then + xtitle -s -t "$panel_taskbar_max_title" -f 'T%s' > "$panel_fifo" & + else + xtitle -s -f 'T%s' > "$panel_fifo" & + fi + + bspc control --subscribe > "$panel_fifo" & + $bspwm_config_dir/panel_status & + + bspc config top_padding "$(( panel_h + bspwm_window_gap ))" + + parse_fifo_data | lemonbar -g "${panel_w}x${panel_h}+${panel_l}+${panel_d}" \ + -f "$font_norm" \ + -f "$font_bold" \ + -F "$colors_fg_normal" \ + -B "$colors_bg_normal" | zsh & + wait +} + +main diff --git a/bspwm/panel_status b/bspwm/panel_status new file mode 100755 index 0000000..d38fd00 --- /dev/null +++ b/bspwm/panel_status @@ -0,0 +1,54 @@ +#!/usr/bin/env zsh + +source $bspwm_config_dir/common + +status::date() { + while true; do + printf 'date::%%{T2}%s%%{T}\n' "$(date '+%a %d %H:%M:%S')" + sleep 1 + done +} + +status::updates() { + declare pkgs + + while true; do + pkgs=( $(pacman -Qqu) ) + pkgs_n=${#pkgs[@]} + + if (( pkgs_n )); then + printf 'updates::[ Updates: %s ]\n' "${#pkgs[@]}" + else + printf 'updates::[ No updates ]\n' + fi + + sleep 5 + done +} + +cleanup() { + eval "kill ${${jobstates##*:*:}%=*}" +} + +rexec() { + eval "kill ${${jobstates##*:*:}%=*}" + exec "$0" +} + +main() { + declare msg date + typeset -a modules + + trap cleanup EXIT TERM INT + trap rexec HUP + + modules=( date ) + + for i in "${modules[@]}"; do + "status::${i}" > "$panel_fifo" & + done + + wait +} + +main diff --git a/bspwm/sxhkdrc b/bspwm/sxhkdrc new file mode 100644 index 0000000..699992f --- /dev/null +++ b/bspwm/sxhkdrc @@ -0,0 +1,78 @@ +# +# bspwm hotkeys +# + +alt + control + c + bspc window -c + +alt + control + k + bspc window -k + +alt + Return + bspc window -t fullscreen + +alt + {j,k} + bspc window -f {next,prev} + +alt + shift + {j,l} + bspc window -e {down,right} +32 + +alt + shift + {k,h} + bspc window -e {down,right} -32 + +alt + Tab + bspc window -t floating + +alt + Return + bspc window -s biggest + +alt + {1-9} + bspc desktop -f {1-9} + +alt + shift + {1-9} + bspc window -d {1-9} + +alt + t + bspc desktop -R 90 + +alt + m + bspc desktop -l next + +alt + f + /home/von/.config/bspwm/bsptf + +~button{1-3} + bspc pointer -g focus + +alt + button{1-3} + bspc pointer -g {move,resize_side,resize_corner} + +alt + !button{1-3} + bspc pointer -t %i %i + +alt + @button{1-3} + bspc pointer -u + +alt + x + termite + +alt + {r,u} + /home/von/.config/bspwm/bspmenu_{run,url} + +alt + F2 + dmenu_run + +alt + z + bash -c "until i3lock -entc 661111 -i /home/von/Pictures/wallpaper.png; do :; done" + +Print + xfce4-screenshooter + +alt + shift + F12 + /home/von/vscripts/compton_toggle + +alt + {Left,Up,Right,Down} + bspc window --presel {left,up,right,down} + +alt + o + bspc monitor -f {right,left} diff --git a/bspwm/testscript b/bspwm/testscript new file mode 100755 index 0000000..7989e2d --- /dev/null +++ b/bspwm/testscript @@ -0,0 +1,3 @@ +#!/usr/bin/env zsh +/usr/bin/sxhkd -f 60& +wait