From 5a4d4a06a287985fbf5b458056881d3d0a0c71aa Mon Sep 17 00:00:00 2001 From: xero Date: Sun, 22 Jan 2017 23:22:55 -0500 Subject: add wmutils setup --- wmutils/bin/snap.sh | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 wmutils/bin/snap.sh (limited to 'wmutils/bin/snap.sh') diff --git a/wmutils/bin/snap.sh b/wmutils/bin/snap.sh new file mode 100755 index 0000000..6089ff1 --- /dev/null +++ b/wmutils/bin/snap.sh @@ -0,0 +1,80 @@ +#!/bin/sh +# +# wmutils/contrib>: snap.sh, 9/12/15 kekler +# snaps focued window to the left, right, top, or bottom edge + +usage() { + echo "usage: $(basename $0) " >&2 + exit 1 +} + +# default values for gaps and master area +TOP_PANEL=${PANEL:-20} +GAP=${GAP:-5} + +# get current window id and its borderwidth +PFW=$(pfw) +BW=$(wattr b $PFW) + +# get root window's size +ROOT=$(lsw -r) +SW=$(wattr w $ROOT) +SH=$(wattr h $ROOT) + +# calculate usable screen size (without borders and gaps) +SH=$((SH - TOP_PANEL)) + +snap_up() +{ + wtp $GAP $((GAP + TOP_PANEL)) $((SW - 2*GAP - 2*BW)) $((SH/2 - 2*BW - GAP - GAP/2)) $PFW +} + +snap_right() +{ + wtp $((SW - SW/2 + GAP/2)) $((GAP + TOP_PANEL)) $((SW/2 - 2*BW - GAP - GAP/2)) $((SH - 2*BW - 2*GAP)) $PFW +} + +snap_down() +{ + wtp $GAP $((SH - SH/2 + GAP/2 + TOP_PANEL)) $((SW - 2*GAP - 2*BW)) $((SH/2 - 2*BW - GAP - GAP/2)) $PFW +} + +snap_left() +{ + wtp $GAP $((GAP + TOP_PANEL)) $((SW/2 - 2*BW - GAP - GAP/2)) $((SH - 2*BW - 2*GAP)) $PFW +} + +HSW=$((SW/2 - 2*BW - GAP - GAP/2)) +HSH=$((SH/2 - 2*BW - GAP - GAP/2)) + +snap_tr() +{ + wtp $((SW - SW/2 + GAP/2)) $((GAP + TOP_PANEL)) $HSW $HSH $PFW +} + +snap_br() +{ + wtp $((SW - SW/2 + GAP/2)) $((SH - SH/2 + GAP/2 + TOP_PANEL)) $HSW $HSH $PFW +} + +snap_tl() +{ + wtp $GAP $((GAP + TOP_PANEL)) $HSW $HSH $PFW +} + +snap_bl() +{ + wtp $GAP $((SH - SH/2 + GAP/2 + TOP_PANEL)) $HSW $HSH $PFW +} + +case $1 in + h|a|east|left) snap_left ;; + j|s|south|down) snap_down ;; + k|w|north|up) snap_up ;; + l|d|west|right) snap_right ;; + tr|northeast) snap_tr ;; + br|southeast) snap_br ;; + tl|northwest) snap_tl ;; + bl|southwest) snap_bl ;; +esac + -- cgit v1.2.1