-
-
Save malconfig/1c20494143379075529730a36510f11f to your computer and use it in GitHub Desktop.
Crude quarter tiling tool for elementary OS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Crude quarter tiling tool | |
| # Installation: | |
| # Move file to: /usr/local/bin/quarter-tiler | |
| # Make executable: sudo chmod +x /usr/local/bin/quarter-tiler | |
| # Assign keyboard shortcuts to commands like "quarter-tiler topleft" | |
| # Margins around windows (elementary OS native apps) | |
| # Suitable for 1600x900px standard displays | |
| MARGIN_TOP=43 | |
| MARGIN_RIGHT=40 | |
| MARGIN_BOTTOM=41 | |
| MARGIN_LEFT=40 | |
| # Desktops info | |
| INFO=$(wmctrl -d | head -1) | |
| # Desktop size | |
| [[ $INFO =~ 'DG: '([0-9]+)'x'([0-9]+) ]] | |
| WIDTH=${BASH_REMATCH[1]} | |
| HEIGHT=${BASH_REMATCH[2]} | |
| # Available width height, and offsets see: $ wmctrl -d | |
| [[ $INFO =~ 'WA: '([0-9]+)','([0-9]+)' '([0-9]+)'x'([0-9]+) ]] | |
| OFFSET_X=${BASH_REMATCH[1]} | |
| OFFSET_Y=${BASH_REMATCH[2]} | |
| AV_WIDTH=${BASH_REMATCH[3]} | |
| AV_HEIGHT=${BASH_REMATCH[4]} | |
| X_LEFT=$((0-($MARGIN_RIGHT+$OFFSET_X))) | |
| X_CENTER=$(($AV_WIDTH/2+$MARGIN_RIGHT+$MARGIN_LEFT)) | |
| HALF_WIDTH=$X_CENTER | |
| Y_TOP=$((0-($MARGIN_TOP-$OFFSET_Y))) | |
| Y_CENTER=$(($Y_TOP+$HEIGHT/2)) | |
| HALF_HEIGHT=$(($AV_HEIGHT/2+$MARGIN_TOP+$MARGIN_BOTTOM)) | |
| SIZE=$HALF_WIDTH,$HALF_HEIGHT | |
| case "$1" in | |
| topleft) | |
| CMD="wmctrl -r :ACTIVE: -e 0,$X_LEFT,$Y_TOP,$SIZE" | |
| ;; | |
| topright) | |
| CMD="wmctrl -r :ACTIVE: -e 0,$X_CENTER,$Y_TOP,$SIZE" | |
| ;; | |
| bottomleft) | |
| CMD="wmctrl -r :ACTIVE: -e 0,$X_LEFT,$Y_CENTER,$SIZE" | |
| ;; | |
| bottomright) | |
| CMD="wmctrl -r :ACTIVE: -e 0,$X_CENTER,$Y_CENTER,$SIZE" | |
| ;; | |
| esac | |
| # In case window is tiled, disable tile | |
| wmctrl -r :ACTIVE: -b remove,maximized_vert | |
| # Wait for transition | |
| sleep 0.1s | |
| eval $($CMD) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment