summaryrefslogtreecommitdiffstats
path: root/wpos.sh
diff options
context:
space:
mode:
authorGravatar Robin Obůrka <r.oburka@gmail.com> 2015-08-23 12:53:33 +0200
committerGravatar Robin Obůrka <r.oburka@gmail.com> 2015-08-23 12:53:33 +0200
commit5ff2649a797d130f276cfa41c29ca9977e6d4b49 (patch)
treea83994bb613c66772fc3f6402c21b48ccbb33f00 /wpos.sh
parentAdd 2displays command (diff)
downloaddisplay_autoset-5ff2649a797d130f276cfa41c29ca9977e6d4b49.tar.xz
wpos: Make some pieces of code more generic
Diffstat (limited to 'wpos.sh')
-rwxr-xr-xwpos.sh23
1 files changed, 16 insertions, 7 deletions
diff --git a/wpos.sh b/wpos.sh
index 2695f15..1fecd4d 100755
--- a/wpos.sh
+++ b/wpos.sh
@@ -15,19 +15,28 @@ if [ -n "$2" ]; then
PROFILE="$2"
fi
+query() {
+ wmctrl -lxG
+}
+
+parse() {
+ LINE="$1"
+ ID="$(echo "$LINE" | awk '{ print $1 }')"
+ GRAVITY="$(echo "$LINE" | awk '{ print $2 }')"
+ POSX="$(echo "$LINE" | awk '{ print $3 }')"
+ POSY="$(echo "$LINE" | awk '{ print $4 }')"
+ WIDTH="$(echo "$LINE" | awk '{ print $5 }')"
+ HEIGHT="$(echo "$LINE" | awk '{ print $6 }')"
+}
+
if [ "$1" = "save" ]; then
- wmctrl -lxG > "$SAVEPATH/$PROFILE"
+ query > "$SAVEPATH/$PROFILE"
exit 0
elif [ "$1" = "restore" ]; then
cat "$SAVEPATH/$PROFILE" | while read LINE; do
## Parse records in savefile
- ID="$(echo "$LINE" | awk '{ print $1 }')"
- GRAVITY="$(echo "$LINE" | awk '{ print $2 }')"
- POSX="$(echo "$LINE" | awk '{ print $3 }')"
- POSY="$(echo "$LINE" | awk '{ print $4 }')"
- WIDTH="$(echo "$LINE" | awk '{ print $5 }')"
- HEIGHT="$(echo "$LINE" | awk '{ print $6 }')"
+ parse "$LINE"
## Check few important values
[ "$GRAVITY" -lt 0 ] && continue