bspwm icon indicating copy to clipboard operation
bspwm copied to clipboard

Struggling with resizing split ratio

Open Twix53791 opened this issue 2 years ago • 1 comments

I am struggling with a problem since a while : finding a way to dynamically reset the split ratio in a stable and practical way. I would like to avoid using the mouse for it, as I am using mainly a touchpad on a laptop. The pointer_modifier setting is poorly designed for a touchpad, as it is quite difficult to use the right and middle click mouse down events. Using the bspc -r action to change the split ratio, on the other hand, is a mess : I did'nt find a way to make it reliable and stable. As the structure of the nodes tree don't seems always the same, sometimes getting the parent works, sometimes not, because in fact the windows nodes are not connected like before. And moreover, depending of how deep is the tree, the same key binding will alternatively move the horizontal split ratio then the vertical one, as it set the ratio between two brother nodes, from the parent one. Anyway, if any one has a clue to fix this, I will be glad to ear about. I think, maybe, this feature in bad designed in bspwm. It should be very easy and reliable to change the node split ratio of a target node. The problem comes from it is not possible (if I did'nt miss a thing!) to target a window node directly, but the ratio has to be set from the parent. It becomes then a mess when you have more than two windows on the screen, or even worse, hidden windows, sticky ones and so on...

Twix53791 avatar Apr 30 '22 17:04 Twix53791

EDIT: maybe I found an elegant way to resolve this puzzle! I still have to test it to see if it is reliable, but if it is, bspwm surprises me again with the range of its possibilities! Its principle is to grab the first common ancestor of the node focused and its nearest neighbour, the node on the west/east for the horizontal splitting, north/south for vertical splitting.

Here the script:

_get_common_parent (){
   for node in "$@"; do
      current=$node
      shift
      if grep $current <<< "$@"; then
         common+=($current)
      fi
   done
      com_parent="${common[0]}"
}
_splitratio (){
   focused=$(bspc query -N -n focused)
   from=$(bspc query -N -n .ancestor_of | tac)

      if [[ $1 == h ]]; then
         sidenode=$(bspc query -N -n west)
         [[ -z $sidenode ]] && sidenode=$(bspc query -N -n east)
      else
         sidenode=$(bspc query -N -n north)
         [[ -z $sidenode ]] && sidenode=$(bspc query -N -n south)
      fi

   [[ -n $sidenode ]] &&
      side=$(bspc node $sidenode -f;bspc query -N -n .ancestor_of | tac)
   bspc node $focused -f

   mapfile -t concat < <( cat <( echo "$from" && echo "$side") )
   _get_common_parent "${concat[@]}"

   bspc node $com_parent -r $2
}

case $1 in
   w) _splitratio h -0.1;;
   e) _splitratio h +0.1;;
   n) _splitratio v -0.1;;
   s) _splitratio v +0.1;;
esac

Twix53791 avatar May 01 '22 20:05 Twix53791