Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This script assumes a monitor is divided up into the following sections:
- #
- # 25% 50% 25%
- # +----------+--------------------+----------+
- # | | | |
- # | 1 | | 4 |
- # | | | |
- # +----------+ 3 +----------+
- # | | | |
- # | 2 | | 5 |
- # | | | |
- # +----------+--------------------+----------+
- # How to use:
- # Pass in the Panel #, along with the value you need:
- # e.g. panel_finder.sh -p 1 -v startX
- #
- # The following values are available:
- #
- # startX - The starting X value (top-left)
- # startY - The starting Y value (top-left)
- # width - The width of the panel
- # height - the height of the panel
- #
- # You can also pass in an optional -l flag for layout, giving 3 or 5
- # the default is 5 panels
- #
- # @TODO: Add convenience functions to give bottom-right X,Y
- # @TODO: Add gap functionality
- # -------------------- RND --------------------
- round()
- {
- echo $(printf %.2f $(echo "scale=$2;((10^$2)*$1)+0.5)/(10^$2)" | bc))
- };
- #### Get initial values
- gap=5
- layout=5
- herbstString=false
- # % of width of side columns, expressed as a decimal
- sideColumnWidthRatio=".25"
- # number of rows in each Side column. Current Max = 2
- numSideColumnRows=2
- # use xrandr utility + awk to get the screen width & height in pixels
- screenWidth=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1)
- screenHeight=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2)
- # Determine actual width of columns, based on GAP and requested ratio size
- # this is what we want to achieve, but because bash doesn't support floating-point,
- # we have to get creative
- # sideColumnWidth=$(( $screenWidth * $sideColumnWidthRatio - $gap | bc -l))
- sw=$( echo "$screenWidth*$sideColumnWidthRatio" | bc -l)
- # After we get the value, we basically FLOOR by dropping everything .+*
- sw=${sw%.*}
- sideColumnWidth=$(( $sw - $gap ))
- mainColumnWidth=$(( $screenWidth - $sideColumnWidth * 2))
- # determine side column panel heights, adjusting for Number of Rows and Gaps (NumRows-1)
- sideColumnPanelHeight=$(( $screenHeight / $numSideColumnRows - $gap * ($numSideColumnRows - 1) ))
- #-----------------------------------------------------------------------------------------------
- # Layouts
- # ----------------------------------------------------------------------------------------------
- #
- # 5 Panel Layout
- # -------------------- Panel 1 --------------------
- panel5_1_startX=0
- panel5_1_startY=0
- panel5_1_width=$sideColumnWidth
- panel5_1_height=$sideColumnPanelHeight
- # -------------------- Panel 2 --------------------
- panel5_2_startX=0
- panel5_2_startY=$(( $panel1_height + $gap ))
- panel5_2_width=$sideColumnWidth
- panel5_2_height=$sideColumnPanelHeight
- # -------------------- Panel 3 --------------------
- panel5_3_startX=$(( $sideColumnWidth + $gap))
- panel5_3_startY=0
- panel5_3_width=$mainColumnWidth
- panel5_3_height=$screenHeight
- # -------------------- Panel 4 --------------------
- panel5_4_startX=$(( $sideColumnWidth + $mainColumnWidth + $gap * 2))
- panel5_4_startY=0
- panel5_4_width=$sideColumnWidth
- panel5_4_height=$sideColumnPanelHeight
- # -------------------- Panel 5 --------------------
- panel5_5_startX=$panel4_startX
- panel5_5_startY=$(( $panel4_height + $gap ))
- panel5_5_width=$sideColumnWidth
- panel5_5_height=$sideColumnPanelHeight
- # ===========================================================
- # 3 Panel Layout
- # ===========================================================
- # -------------------- Panel 1 --------------------
- panel3_1_startX=0
- panel3_1_startY=0
- panel3_1_width=$sideColumnWidth
- panel3_1_height=$screenHeight
- #--------------------- Panel 2 --------------------
- panel3_2_startX=$(( $sideColumnWidth + $gap))
- panel3_2_startY=0
- panel3_2_width=$mainColumnWidth
- panel3_2_height=$screenHeight
- #--------------------- Panel 3 --------------------
- panel3_3_startX=$(( $sideColumnWidth + $mainColumnWidth + $gap *2))
- panel3_3_startY=0
- panel3_3_width=$sideColumnWidth
- panel3_3_height=$screenHeight
- # -------------------- MAIN --------------------
- while getopts p:v:l:h: flag
- do
- case "${flag}" in
- p) panel_number=${OPTARG};;
- v) value=${OPTARG};;
- l) layout=${OPTARG:-layout};;
- h) herbst=${OPTARG:-herbstString};;
- esac
- done
- panel_name="panel${layout}_${panel_number}_${value}"
- #varName="${pane}_${value}"
- #echo "${!varName}"
- # Display the result for a single value
- # or optionally for `herbstclient setmonitors <STR>`
- if [ "$herbst" = false ] ; then
- echo "${!panel_name}"
- exit 1
- fi
- # Build the herbst string; widthXHeight+offset+0
- # I think the last 0 is for a tag, but I really don't know
- echo "${panel3_1_width}x${panel3_1_height}+0+0 ${panel3_2_width}x${panel3_2_height}+${panel3_2_startX}+0 ${panel3_3_width}x${panel3_3_height}+${panel3_3_startX}+0"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement