-
-
Save rijesha/a34b5de5b929eca27da70387d946f185 to your computer and use it in GitHub Desktop.
Crude third-tiler tiling tool for elementary OS
This file contains 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/third-tiler | |
# Make executable: sudo chmod +x /usr/local/bin/third-tiler | |
# Assign keyboard shortcuts to commands like "third-tiler topleft" | |
APPNAME=$(wmctrl -lx | grep $(xprop -root | grep _NET_ACTIVE_WINDOW | head -1 | \ | |
awk '{print $5}' | sed 's/,//' | sed 's/^0x/0x0/') | cut -d " " -f 4) | |
echo $APPNAME | |
MARGIN_TOP=0 | |
MARGIN_RIGHT=0 | |
MARGIN_BOTTOM=0 | |
MARGIN_LEFT=0 | |
if [[ $APPNAME == io.elementary* ]] || [[ $APPNAME == gedit* ]] ; | |
then | |
echo $APPNAME | |
# Margins around windows (elementary OS native apps) (HiDPI) | |
MARGIN_TOP=130 | |
MARGIN_RIGHT=158 | |
MARGIN_BOTTOM=185 | |
MARGIN_LEFT=158 | |
fi | |
# Desktops info | |
INFO=$(wmctrl -d | head -1) | |
# Desktop size | |
RESOLUTIONS=$(wmctrl -d | head -1 | awk '{x=$4"x"$9; print x}') | |
j1=$(echo $RESOLUTIONS | cut -d'x' -f1) | |
j2=$(echo $RESOLUTIONS | cut -d'x' -f2) | |
j3=$(echo $RESOLUTIONS | cut -d'x' -f3) | |
j4=$(echo $RESOLUTIONS | cut -d'x' -f4) | |
AV_WIDTH=$j3 | |
AV_HEIGHT=$j4 | |
# Desktop size | |
WIDTH=$j1 | |
HEIGHT=$j2 | |
half_width=$(($WIDTH/2)) | |
half_height=$(($HEIGHT/2)) | |
third_lcentre=$(($WIDTH*1/3)) | |
third_centre=$(($WIDTH*2/3)) | |
third_right_lcentre=$(($WIDTH/6)) | |
third_right_rcentre=$(($WIDTH*2/3)) | |
echo $half_width | |
echo $half_height | |
echo $third_left_lcentre | |
echo $third_left_rcentre | |
echo $third_right_lcentre | |
echo $third_right_rcentre | |
X_LEFT=$((0-($MARGIN_RIGHT))) | |
X_CENTER=$(($AV_WIDTH/2+$MARGIN_RIGHT+$MARGIN_LEFT)) | |
HALF_WIDTH=$X_CENTER | |
Y_TOP=$((0-($MARGIN_TOP))) | |
Y_CENTER=$(($Y_TOP+$HEIGHT/2)) | |
HALF_HEIGHT=$(($AV_HEIGHT/2+$MARGIN_TOP+$MARGIN_BOTTOM)) | |
SIZE=$HALF_WIDTH,$HALF_HEIGHT | |
case "$1" in | |
lefttwothirds) | |
CMD="wmctrl -r :ACTIVE: -e 0,$X_LEFT,$(($Y_TOP-$MARGIN_TOP)),$(($WIDTH*2/3+$MARGIN_LEFT)),$(($HEIGHT+$MARGIN_BOTTOM))" | |
;; | |
rightonethirds) | |
CMD="wmctrl -r :ACTIVE: -e 0,$(($WIDTH*2/3)),$Y_TOP,$(($WIDTH*1/3+$MARGIN_LEFT)),$(($HEIGHT+$MARGIN_BOTTOM))" | |
;; | |
righttwothirds) | |
CMD="wmctrl -r :ACTIVE: -e 0,$(($WIDTH*1/3)),$Y_TOP,$(($WIDTH*2/3+$MARGIN_LEFT)),$(($HEIGHT+$MARGIN_BOTTOM))" | |
;; | |
leftonethirds) | |
CMD="wmctrl -r :ACTIVE: -e 0,$X_LEFT,$Y_TOP,$(($WIDTH*1/3+$MARGIN_LEFT)),$(($HEIGHT+$MARGIN_BOTTOM))" | |
;; | |
actualtopleft) | |
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,maximized_horz | |
# 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