diff options
| author | Robert Günzler <r@gnzler.io> | 2020-12-07 19:05:12 +0100 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2020-12-07 19:28:05 +0100 |
| commit | 940eb7715c8ad113ff345e30d56438c2487421a3 (patch) | |
| tree | 56fdf429f250cc01c0b82bd547e84355a5e6a9a7 /bin | |
| parent | a4635f958e200a726dd5ef93127f43b56947ba6d (diff) | |
bin/centercon: overhaul
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/centercon | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/bin/centercon b/bin/centercon index db48f94..dff3cda 100755 --- a/bin/centercon +++ b/bin/centercon @@ -1,5 +1,6 @@ #!/bin/sh set -e +[ -n "$DEBUG" ] && set -x if [ "$1" = "-h" ]; then printf "usage: %s [RESIZE_PERC] [MODE]\n" "$(basename "$0")" @@ -9,17 +10,33 @@ if [ "$1" = "-h" ]; then fi con=$(swq current con) +con_width=$(echo "$con" | jq -r '.window_rect.width') +con_height=$(echo "$con" | jq -r '.window_rect.height') + ws=$(swq current workspace) ws_width=$(echo "$ws" | jq -r '.rect.width') ws_height=$(echo "$ws" | jq -r '.rect.height') -if [ -n "$1" ] && [ ! "$1" = "-" ]; then - perc="$1" - con_width=$(awk "BEGIN{print int($ws_width * $perc)}") - con_height=$(awk "BEGIN{print int($ws_height * $perc)}") +if [ "$1" = "-w" ]; then + shift + printf "scaling relative to workspace\n" + ratio=$(awk "BEGIN{print ($ws_width / $ws_height)}") + con_width=$ws_width + con_height=$ws_height else - con_width=$(echo "$con" | jq -r '.window_rect.width') - con_height=$(echo "$con" | jq -r '.window_rect.height') + printf "scaling relative to container\n" + ratio=$(awk "BEGIN{print ($con_width / $con_height)}") +fi + +if [ -n "$1" ] || [ ! "$1" = "-" ]; then + perc="$1" + con_height=$(awk "BEGIN{print int($con_height * $perc)}") + con_width=$(awk "BEGIN{print int($con_height * $ratio)}") +fi + +if (( perc >= 1 )); then + printf "scaling factor %.1f larger than 100%%, aborting...\n" "${perc}" + exit 1 fi case "$2" in @@ -55,7 +72,9 @@ lm) # left-middle tar_x=0 tar_y=$(awk "BEGIN{print int(($ws_height - $con_height)/2)}") ;; -*) # center +noop) # noop + ;; +c|*) # center tar_x=$(awk "BEGIN{print int(($ws_width - $con_width)/2)}") tar_y=$(awk "BEGIN{print int(($ws_height - $con_height)/2)}") esac @@ -64,5 +83,6 @@ echo "ws: $ws_width x $ws_height" echo "con: $con_width x $con_height" echo "moveto: $tar_x x $tar_y" -swaymsg resize set "$con_width" "$con_height" -swaymsg move position "$tar_x" "$tar_y" +con_id=$(echo "$con" | jq -r '.id') +swaymsg [con_id="$con_id"] resize set "$con_width" "$con_height" +swaymsg [con_id="$con_id"] move position "$tar_x" "$tar_y" |