Skip to content

Instantly share code, notes, and snippets.

@ortango
Created February 8, 2024 23:59
Show Gist options
  • Save ortango/9cd5c9b15ebcb1d20c5ff00cd452233b to your computer and use it in GitHub Desktop.
Save ortango/9cd5c9b15ebcb1d20c5ff00cd452233b to your computer and use it in GitHub Desktop.

Revisions

  1. ortango created this gist Feb 8, 2024.
    47 changes: 47 additions & 0 deletions alt-strut-handling.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    #!/bin/bash
    getrootgeo() {
    xwininfo -root | awk '$1 ~ /-geometry/{
    split($2, a, "[x+-]", s);
    printf("%d\n%d\n",a[1],a[2]);
    printf("%s%d\n%s%d\n",s[2],a[3],s[3],a[4]);'
    }
    getbspwminfo() {
    < <(bspc wm -d) \
    jq -r --arg m "$1" '
    .monitors[] | select(.name == $m) |
    (.rectangle | .height, .y), (.padding | .top, .bottom)'
    }
    strut2padding() {
    declare -a strut mon_info root_geo
    local a d
    a="$(xprop -id $wid _NET_WM_STRUT_PARTIAL)"
    [[ "$a" =~ "not found."$ ]] && return 1
    IFS=',' read -ra strut <<<"${a/_NET_WM_STRUT_PARTIAL(CARDINAL) =/}"
    readarray -t mon_info < <(getbspwminfo "$1")
    for a in 2 3; do
    (( strut[$a] == 0 )) && continue
    case "$a" in
    2)
    d=$(( strut[2] - mon_info[1] ))
    d=$(( mon_info[2] < 0 ? d + mon_info[2] : ( d > mon_info[2] ? d : mon_info[2] ) ))
    [[ "$d" != "${mon_info[2]}" ]] && bspc config -m "$1" top_padding "$d"
    ;;
    3)
    root_geo=( $(getrootgeo) )
    d=$(( (mon_info[1] + mon_info[0]) - root_geo[1] + strut[3] ))
    d=$(( mon_info[3] < 0 ? d + mon_info[3] : (d > mon_info[3] ? d : mon_info[3]) ))
    [[ "$d" != "${mon_info[3]}" ]] && bspc config -m "$1" bottom_padding "$d"
    ;;
    esac
    done
    }
    wid=$1 class=$2 instance=$3

    case "${class}:${instance}" in
    'Polybar:polybar')
    title="$(xprop -id "$wid" WM_NAME)"
    title="${title/WM_NAME(STRING) = \"/}"
    title="${title::-1}"
    strut2padding "${title##*_}"
    ;;
    esac