Created
January 17, 2019 11:48
-
-
Save fbettag/93821efdda49f8fce26e42d57a6aaff4 to your computer and use it in GitHub Desktop.
tiling windows in cwm and other managers that don't support top-right, top-left etc. Works with multiple monitors using mmutils.
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
bind-key 4-Up "bin/tile.sh top" | |
bind-key 4-Down "bin/tile.sh bottom" | |
bind-key 4-Left "bin/tile.sh left" | |
bind-key 4-Right "bin/tile.sh right" | |
bind-key C4-Up "bin/tile.sh top-right" | |
bind-key C4-Left "bin/tile.sh top-left" | |
bind-key C4-Down "bin/tile.sh bottom-left" | |
bind-key C4-Right "bin/tile.sh bottom-right" |
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/sh | |
# pkg_add wmutils-core | |
# git clone https://github.com/pockata/mmutils | |
set -xe | |
# | |
### config | |
# | |
# gap size | |
GS=6 | |
# move mouse with window | |
MM=true | |
# | |
### error check | |
# | |
Err() { | |
if ! [ -x "$(command -v "$1")" ]; then | |
echo "error: $1 does not exist">&2 | |
echo "see wmutils: https://github.com/wmutils/core." | |
exit 1 | |
fi | |
} | |
# check if wmutils needed exist | |
Err wattr | |
Err lswin | |
Err pfw | |
Err wtp | |
Err wmp | |
# | |
### run | |
# | |
# get current window id, width and height | |
WID=$(pfw) | |
# WW="$(wattr w "$WID")" | |
# WH="$(wattr h "$WID")" | |
# get screen width and height | |
ROOT=$(pfm) | |
SW=$(mattr w "$ROOT") | |
SH=$(mattr h "$ROOT") | |
# move tile | |
mvtl() { | |
#$1 : x | |
#$2 : y | |
#$3 : width | |
#$4 : height | |
wtp "$1" "$2" "$3" "$4" "$WID" | |
#$5 : movemouse? (bool) | |
# move mouse with window flag is on | |
if [ "$5" = true ]; then | |
x="$(echo "$1 + $3 / 2 " | bc -l)" | |
y="$(echo "$2 + $4 / 2 " | bc -l)" | |
wmp "$x" "$y" | |
fi | |
} | |
case $1 in | |
top) | |
offset=$(mattr x "$ROOT") | |
x="$(echo "$offset + $GS" | bc)" | |
w="$(echo "$SW - $GS * 2" | bc -l)" | |
h="$(echo "$SH/2 - $GS * 3" | bc -l)" | |
mvtl "$x" "$GS" "$w" "$h" "$MM" | |
;; | |
top-left) | |
offset=$(mattr x "$ROOT") | |
x="$(echo "$offset + $GS" | bc)" | |
w="$(echo "$SW/2 - $GS * 2" | bc -l)" | |
h="$(echo "$SH/2 - $GS * 3" | bc -l)" | |
mvtl "$x" "$GS" "$w" "$h" "$MM" | |
;; | |
top-right) | |
offset=$(mattr x "$ROOT") | |
w="$(echo "$SW/2 - $GS * 1.5" | bc -l)" | |
h="$(echo "$SH/2 - $GS * 3" | bc -l)" | |
x="$(echo "$offset + $w + $GS * 2" | bc)" | |
mvtl "$x" $GS "$w" "$h" "$MM" | |
;; | |
bottom) | |
offset=$(mattr x "$ROOT") | |
x="$(echo "$offset + $GS" | bc)" | |
w="$(echo "$SW - $GS * 2" | bc -l)" | |
h="$(echo "$SH/2 - $GS" | bc -l)" | |
y="$(echo "$h + $GS " | bc -l)" | |
mvtl "$x" "$y" "$w" "$h" "$MM" | |
;; | |
bottom-left) | |
offset=$(mattr x "$ROOT") | |
x="$(echo "$offset + $GS" | bc)" | |
w="$(echo "$SW/2 - $GS * 2" | bc -l)" | |
h="$(echo "$SH/2 - $GS" | bc -l)" | |
y="$(echo "$h + $GS" | bc -l)" | |
mvtl "$x" "$y" "$w" "$h" "$MM" | |
;; | |
bottom-right) | |
offset=$(mattr x "$ROOT") | |
w="$(echo "$SW/2 - $GS * 1.5" | bc -l)" | |
h="$(echo "$SH/2 - $GS" | bc -l)" | |
x="$(echo "$offset + $w + $GS * 2" | bc)" | |
y="$(echo "$h + $GS" | bc -l)" | |
mvtl "$x" "$y" "$w" "$h" "$MM" | |
;; | |
left) | |
offset=$(mattr x "$ROOT") | |
w="$(echo "$SW/2 - $GS * 2" | bc -l)" | |
h="$(echo "$SH - $GS * 2" | bc -l)" | |
x="$(echo "$offset + $GS" | bc)" | |
mvtl "$x" "$GS" "$w" "$h" "$MM" | |
;; | |
right) | |
offset=$(mattr x "$ROOT") | |
w="$(echo "$SW/2 - $GS" | bc -l)" | |
h="$(echo "$SH - $GS * 2" | bc -l)" | |
x="$(echo "$offset + $GS + $w" | bc)" | |
mvtl "$x" "$GS" "$w" "$h" "$MM" | |
;; | |
*) | |
printf "usage: tile <option>\\noptions:\\ntop, top-left, top-right,bottom, bottom-left, bottom-right, left, right" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment