Advertisement
Twilypastes

split.grid

Jan 24th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.47 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Author:       Twily                                                     2015
  4. # Description:  Cut window in half and spawn a terminal in its remaining space
  5. # Requires:     wmctrl, xdotool, xwininfo, urxvt
  6. # Useage:       $ sh ./split.grid
  7. #               (Eg.: Bind script to trigger on hotkey W-s)
  8. #
  9.  
  10. ACT=$(xdotool getactivewindow)
  11.  
  12. G=24            # Gap between windows
  13. D=0             # Decoration height
  14. M=0             # Border width
  15.  
  16. let M=$M*2
  17. if [ "$D" -gt "0" ]; then D=$(( $D + ( $M / 2 ) )); fi
  18.  
  19. unset X Y W H
  20. eval $(xwininfo -id $ACT |
  21.     sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/X=\1/p" \
  22.            -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/Y=\1/p" \
  23.            -e "s/^ \+Width: \+\([0-9]\+\).*/W=\1/p" \
  24.            -e "s/^ \+Height: \+\([0-9]\+\).*/H=\1/p" )
  25.  
  26.     X=$(( $X - ( $M / 2 ) ))
  27.     Y=$(( $Y - ( $M / 2 ) - $D ))
  28.  
  29. if [ "$W" -gt "$H" ]; then
  30.     # Spawn right
  31.     aW=$(( $W / 2 - ( $G / 2 ) - $M ))
  32.  
  33.     wmctrl -i -r $ACT -e 0,$X,$Y,$aW,$H
  34.  
  35.     X=$(( $X + $aW + $G + $M ))
  36.     W=$(( $W - $aW - $G - $M ))
  37. else
  38.     # Spawn below
  39.     aH=$(( $H / 2 - ( $G / 2 ) - ( $M / 2 ) - $D ))
  40.  
  41.     wmctrl -i -r $ACT -e 0,$X,$Y,$W,$aH
  42.  
  43.     Y=$(( $Y + $aH + $G + $D + $M ))
  44.     H=$(( $H - $aH - $G - $D - $M ))
  45. fi
  46.  
  47. urxvt -g "1x1+"$X"+"$Y &
  48.  
  49. for i in {0..49}; do # timeout
  50.     if ps -p $! >/dev/null; then
  51.         sleep .1
  52.  
  53.         wmctrl -r :ACTIVE: -e 0,$X,$Y,$W,$H
  54.         break
  55.     fi
  56. done
  57.  
  58. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement