Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # t2 - PLACEMENT DAY
- # Special thanks to grocid for gtile, on which this project is heavily based.
- # https://github.com/grocid/gtile
- # Usage: t2 PLACEMENT [margin]
- # The script takes one mandatory argument: a 4-character string that defines
- # the placement of the window. The substrings are explained in the code comments
- # that accompany each variable.
- # The optional second argument defines the padding margin between
- # windows. The default value is wide but maintains decent readability on
- # large screens.
- # The script is generally pretty easy to extend for more general cases,
- # such as using more than 2 non-fullscreen vertical slices to tile or using
- # hexadecimal letters to allow for more than 9 horizontal slices.
- # I may eventually write them in myself if demand is there, but note that
- # these exceed my own use case, so motivation is weak at the moment.
- # Since it was written especially with MATE in mind, it has a built-in
- # safeguard to prevent accidentally tiling the Caja desktop window, but this
- # can easily be accomplished for the desktop/root-like windows of other
- # environments as well.
- if [ "$(xdotool getactivewindow getwindowname)" = "x-caja-desktop" ]
- then
- echo "Yeah, not movin' that one."
- exit 2
- fi
- # Config - Change these to match your own environment ##########################
- # You guessed it.
- screen_width=7680
- # If and only if you have a *bottom* panel.
- panel_height=24
- # This is a stupid way to format this, but it's also in prep to re-write
- # it to be grabbed by xrandr.
- screen_height=$(( 2160 - $panel_height ))
- # Tiling preferences ###########################################################
- # [0-9] Number of horizontal tile slices
- divs=${1:0:1}
- # [0-9] First horizontal slice to occupy
- x0=$(( ${1:1:1} - 1 ))
- # [0-9] Last horizontal slice to occupy
- # (Note that the script will fail out if $x0 > $x1.
- # $x0 = $x1 is acceptable and gives a single-slice-width
- # window.
- x1=$(( ${1:2:1} - 1 ))
- # [fhl] Vertical placement
- # l=lower half-screen
- # h=higher half-screen
- # f=fullscreen
- yp=${1:3:1}
- margin=${margin:-48}
- if [ ! -z "$2" ]
- then
- margin="$2"
- fi
- # Window Placement #############################################################
- # Basic (/single-)tile width.
- t_width=$(( $(( $screen_width / $divs )) - $(( $(( $divs + 1 )) * $margin )) / $divs ))
- # Horizontal placement of the left edge.
- c=$(( $x0 * $(( $t_width + $margin )) + $margin ))
- width=$(( $(( $x1 - $x0 + 1 )) * $t_width + $(( $(( $x1 - $x0 )) * $margin )) ))
- case "$yp" in
- "h")
- height=$(( $(( $screen_height - $(( 3 * $margin )) )) / 2 ))
- # Vertical placement of the upper edge.
- d=$margin
- ;;
- "f")
- height=$(( $screen_height - $(( 2 * $margin )) ))
- d=$margin
- ;;
- "l")
- height=$(( $(( $screen_height - $(( 3 * $margin )) )) / 2 ))
- d=$(( $height + 2 * $margin ))
- ;;
- *)
- echo "Usage: $(basename $0) [0-9][0-9][0-9][flh]"
- exit 3
- ;;
- esac
- xdotool getactivewindow windowsize $width $height windowmove $c $d
- unset width height c d
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement