Advertisement
Guest User

old_stripped script

a guest
Jul 17th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.31 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # settings
  4. TOP_MARGIN=0
  5. BOTTOM_MARGIN=35
  6. LEFT_MARGIN=0
  7. RIGHT_MARGIN=0
  8. TITLE_BAR_HEIGHT=17
  9.  
  10. #either set these in a file or calculate them from the screen properties
  11. MASTER_WIDTH=1344
  12. MASTER_HEIGHT=400
  13. #set the number of rows we want for the grid mode
  14. NUMBER_OF_ROWS=2
  15. #looks nice :)
  16. USELESS_GAPS=0
  17.  
  18. display_info="$(xwininfo -root)"
  19. #get the desktop parameters
  20. HEIGHT=`grep 'Height:' <<< "$display_info" | awk '{print $2}'`
  21. WIDTH=`grep 'Width:'   <<< "$display_info" | awk '{print $2}'`
  22.    
  23. #get the current desktop
  24. CURR_DESK=`wmctrl -d | grep '* DG:'| awk '{print $1}'`
  25.  
  26. #get the total number of windows.
  27. windows_info="$(wmctrl -lx)"
  28. #NOTE: we are not directly using grep to get the windows from the current desktop as it may serve up some false positives
  29. TOTAL_WINDOWS=`wc -l <<< "$windows_info"`
  30. #counter
  31. #Assume that there are no windows in the current desktop
  32. WINDOWS_IN_DESK=0
  33. while IFS= read -r CURR_LINE
  34. do
  35.     WIN_DESK=`echo $CURR_LINE | awk '{print $2}'`
  36.     if  [ $WIN_DESK  -eq  $CURR_DESK ] ; then
  37.         WIN_XID[$WINDOWS_IN_DESK]=`echo $CURR_LINE | awk '{print $1}'`
  38.         MAP_STATE=`xwininfo -id ${WIN_XID[$WINDOWS_IN_DESK]} | grep "Map State:" | awk '{print $3}'`
  39.         if [ "$MAP_STATE"  ==  "IsViewable" ]; then
  40.             WINDOWS_IN_DESK=$((WINDOWS_IN_DESK+1))
  41.         fi    
  42.     fi
  43. done <<< "$windows_info"
  44.  
  45. #find the number of windows in the top row and in each subsequent row except for the bottom row.
  46. NORMAL_ROW_WINDOWS=$((WINDOWS_IN_DESK/NUMBER_OF_ROWS))
  47. #the bottom row ould have as many windows as the top row and any left over
  48. BOTTOM_ROW_WINDOWS=$((NORMAL_ROW_WINDOWS + WINDOWS_IN_DESK%NUMBER_OF_ROWS))
  49. WINDOWS_NOT_IN_BOTTOM_ROW=$((WINDOWS_IN_DESK-BOTTOM_ROW_WINDOWS))
  50. #set the co-ordinates for the top row
  51. X=$LEFT_MARGIN
  52. Y=$TOP_MARGIN
  53. #the height of each window would remain the same regardless of which row it is in
  54. H=$(((HEIGHT-TOP_MARGIN-BOTTOM_MARGIN)/NUMBER_OF_ROWS - TITLE_BAR_HEIGHT))
  55. #Find the width of each window in the top row, this would be the same for each row except for the bottom row which may contain more windows
  56. NORMAL_ROW_WIDTH=$((((WIDTH-LEFT_MARGIN-RIGHT_MARGIN)/NORMAL_ROW_WINDOWS)-USELESS_GAPS*NORMAL_ROW_WINDOWS))
  57. BOTTOM_ROW_WIDTH=$((((WIDTH-LEFT_MARGIN-RIGHT_MARGIN)/BOTTOM_ROW_WINDOWS)-USELESS_GAPS*NORMAL_ROW_WINDOWS))
  58. #we havent processed any windows yet
  59. CURRENT_ROW_WINDOWS=0
  60. #we will be processing the 1st row
  61. CURRENT_ROW=1
  62. for((i=0; i < $WINDOWS_IN_DESK; i++))
  63. do
  64.     if  [[ "$CURRENT_ROW" -lt "$NUMBER_OF_ROWS" ]]; then
  65.         if [[ "$CURRENT_ROW_WINDOWS" -eq "NORMAL_ROW_WINDOWS " ]]; then
  66.             CURRENT_ROW=$((CURRENT_ROW+1))
  67.             if [[ "$CURRENT_ROW" -eq "$NUMBER_OF_ROWS" ]] ; then
  68.                 X=$LEFT_MARGIN
  69.                 Y=$((Y+H+TITLE_BAR_HEIGHT+USELESS_GAPS))
  70.                 W=$BOTTOM_ROW_WIDTH
  71.             else
  72.                 CURRENT_ROW_WINDOWS=0
  73.             fi    
  74.         fi
  75.         if [[ "$CURRENT_ROW_WINDOWS" -eq "0" ]] ; then
  76.             X=$LEFT_MARGIN
  77.             W=$NORMAL_ROW_WIDTH
  78.             if [[ "$CURRENT_ROW" -ne "1" ]]; then
  79.                 Y=$((Y+H+TITLE_BAR_HEIGHT+USELESS_GAPS))
  80.             fi    
  81.         fi        
  82.     fi
  83.   echo wmctrl  -i  -r ${WIN_XID[$i]} -e "0,$X,$Y,$W,$H"
  84.   X=$((X+W+USELESS_GAPS))
  85.   CURRENT_ROW_WINDOWS=$((CURRENT_ROW_WINDOWS+1))
  86. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement