]> git.draconx.ca Git - fvwmconf.git/blob - scripts/resize.sh
Use mpdexec for key bindings.
[fvwmconf.git] / scripts / resize.sh
1 #!/bin/sh
2 #
3 # Copyright © 2008, 2015 Nick Bowler
4 #
5 # Emits an FVWM directed resize command based on the position of the mouse
6 # cursor within a window (mouseX, mouseY) and the width and height of the
7 # window (windowW, windowH).
8 #
9 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
10 # This is free software: you are free to do what the fuck you want to.
11 # There is NO WARRANTY, to the extent permitted by law.
12
13 if [ $# -lt 4 ]; then
14         printf 'usage: %s mouseX mouseY windowW windowH\n' "$0" 1>&2
15         exit 1
16 fi
17
18 # The window's area is divided into a 4x4 grid of equally sized rectangles.
19 # We return a resize direction depending on which rectangle was clicked,
20 # according to the following diagram:
21 #
22 #            ┏━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━┓
23 #            ┃ NorthWest │         North         │ NorthEast ┃
24 #            ┠───────────┼───────────┬───────────┼───────────┨
25 #            ┃           │ NorthWest │ NorthEast │           ┃
26 #            ┃   West    ├───────────┼───────────┤    East   ┃
27 #            ┃           │ SouthWest │ SouthEast │           ┃
28 #            ┠───────────┼───────────┴───────────┼───────────┨
29 #            ┃ SouthWest │         South         │ SouthEast ┃
30 #            ┗━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━┛
31
32 rect_w=$(($3/4))
33 rect_h=$(($4/4))
34 grid_x=$(($1/$rect_w))
35 grid_y=$(($2/$rect_h))
36
37 case $grid_x$grid_y in
38 11|00) dir=NorthWest ;;
39 21|30) dir=NorthEast ;;
40 12|03) dir=SouthWest ;;
41 22|33) dir=SouthEast ;;
42 ?0) dir=North ;;
43 0?) dir=West ;;
44 3?) dir=East ;;
45 ?3) dir=South ;;
46 *) exit 1 ;;
47 esac
48
49 printf 'Resize Direction %s\n' "$dir"