-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwinsnap
executable file
·263 lines (222 loc) · 6.32 KB
/
winsnap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#! /bin/sh
#-- winsnap --#
# Original script from `https://github.com/Dareka826/floating_wm_tiles`
# Modified to take a window id instead of the default focused window.
# Dependencies:
# - xdotool
# ~ ADIGEN
# If no arguments, re-run self with help
[ $# = 0 ] && exec $0 help
wid=${2:-`xdotool getactivewindow`}
# Screen size for calculations
SCREEN_W=1920
SCREEN_H=1080
# Padding from screen sides (for things like docks)
PADDING_TOP=35
PADDING_BOTTOM=0
PADDING_LEFT=0
PADDING_RIGHT=0
# Gap size
GAPS=10
# Window decorations introduce offset
WIN_DECOR_SIZE_TOP=2
WIN_DECOR_SIZE_BOTTOM=2
WIN_DECOR_SIZE_LEFT=2
WIN_DECOR_SIZE_RIGHT=2
# Window set size & position
# Args:
# $1 - x
# $2 - y
# $3 - w
# $4 - h
# $5 - wid
winssp() {
[ $# -lt 4 ] && return 1 # Exit if not enough args
xdotool windowsize $5 \
$(( $3 - WIN_DECOR_SIZE_LEFT - WIN_DECOR_SIZE_RIGHT )) \
$(( $4 - WIN_DECOR_SIZE_TOP - WIN_DECOR_SIZE_BOTTOM )) \
windowmove $5 $1 $2
}
# Screen width and height without padding and outer gaps
SWWP=$(( SCREEN_W - PADDING_LEFT - PADDING_RIGHT - 2 * GAPS ))
SHWP=$(( SCREEN_H - PADDING_TOP - PADDING_BOTTOM - 2 * GAPS ))
case "$1" in
"help")
echo "winsnap.sh [snap position]"
echo ""
echo "Snap positions:"
echo " fullwin One window layout"
echo " center Center window without changing size"
echo ""
echo " vhalfl 2-window vertical split (left)"
echo " vhalfr 2-window vertical split (right)"
echo ""
echo " hhalft 2-window horizontal split (top)"
echo " hhalfb 2-window horizontal split (bottom)"
echo ""
echo " 4gridlt 4-window grid (left top)"
echo " 4gridrt 4-window grid (right top)"
echo " 4gridlb 4-window grid (left bottom)"
echo " 4gridrb 4-window grid (right bottom)"
echo ""
echo " 3vgridl 3-window vertical split (left)"
echo " 3vgridm 3-window vertical split (middle)"
echo " 3vgridr 3-window vertical split (right)"
echo ""
echo " 6hgridtl 3x2 layout (top left)"
echo " 6hgridtm 3x2 layout (top middle)"
echo " 6hgridtr 3x2 layout (top right)"
echo " 6hgridbl 3x2 layout (bottom left)"
echo " 6hgridbm 3x2 layout (bottom middle)"
echo " 6hgridbr 3x2 layout (bottom right)"
echo ""
;;
"center")
WIN_SIZE=$(xdotool getwindowgeometry $wid \
| grep -o "[0-9]*x[0-9]*")
WIN_W=$(echo $WIN_SIZE | cut -dx -f1)
WIN_H=$(echo $WIN_SIZE | cut -dx -f2)
ACTUAL_WIN_W=$(( WIN_W + WIN_DECOR_SIZE_LEFT + WIN_DECOR_SIZE_RIGHT ))
ACTUAL_WIN_H=$(( WIN_H + WIN_DECOR_SIZE_TOP + WIN_DECOR_SIZE_BOTTOM ))
xdotool windowmove $wid \
$(( PADDING_LEFT + ( SCREEN_W - PADDING_LEFT - PADDING_RIGHT - ACTUAL_WIN_W ) / 2 )) \
$(( PADDING_TOP + ( SCREEN_H - PADDING_TOP - PADDING_BOTTOM - ACTUAL_WIN_H ) / 2 ))
;;
# +---------+
# | |
# | |
# | |
# +---------+
"fullwin") winssp \
$(( PADDING_LEFT + GAPS )) \
$(( PADDING_TOP + GAPS )) \
$(( SWWP )) \
$(( SHWP )) $wid ;;
# +----+----+
# | | |
# | | |
# | | |
# +----+----+
# Vertical half left
"vhalfl") winssp \
$(( PADDING_LEFT + GAPS )) \
$(( PADDING_TOP + GAPS )) \
$(( ( SWWP - GAPS ) / 2 )) \
$SHWP $wid ;;
# Vertical half right
"vhalfr") winssp \
$(( PADDING_LEFT + ( SWWP + 3 * GAPS ) / 2 )) \
$(( PADDING_TOP + GAPS )) \
$(( ( SWWP - GAPS ) / 2 )) \
$SHWP $wid ;;
# +---------+
# | |
# +---------+
# | |
# +---------+
# Horizontal half top
"hhalft") winssp \
$(( PADDING_LEFT + GAPS )) \
$(( PADDING_TOP + GAPS )) \
$SWWP \
$(( ( SHWP - GAPS ) / 2 )) $wid ;;
# Horizontal half bottom
"hhalfb") winssp \
$(( PADDING_LEFT + GAPS )) \
$(( PADDING_TOP + ( SHWP + 3 * GAPS ) / 2 )) \
$SWWP \
$(( ( SHWP - GAPS ) / 2 )) $wid ;;
# +----+----+
# | | |
# +----+----+
# | | |
# +----+----+
# 4-grid left top
"4gridlt") winssp \
$(( PADDING_LEFT + GAPS )) \
$(( PADDING_TOP + GAPS )) \
$(( ( SWWP - GAPS ) / 2 )) \
$(( ( SHWP - GAPS ) / 2 )) $wid ;;
# 4-grid left bottom
"4gridlb") winssp \
$(( PADDING_LEFT + GAPS )) \
$(( PADDING_TOP + ( SHWP + 3 * GAPS ) / 2 )) \
$(( ( SWWP - GAPS ) / 2 )) \
$(( ( SHWP - GAPS ) / 2 )) $wid ;;
# 4-grid right top
"4gridrt") winssp \
$(( PADDING_LEFT + ( SWWP + 3 * GAPS ) / 2 )) \
$(( PADDING_TOP + GAPS )) \
$(( ( SWWP - GAPS ) / 2 )) \
$(( ( SHWP - GAPS ) / 2 )) $wid ;;
# 4-grid right bottom
"4gridrb") winssp \
$(( PADDING_LEFT + ( SWWP + 3 * GAPS ) / 2 )) \
$(( PADDING_TOP + ( SHWP + 3 * GAPS ) / 2 )) \
$(( ( SWWP - GAPS ) / 2 )) \
$(( ( SHWP - GAPS ) / 2 )) $wid ;;
# +---+---+---+
# | | | |
# | | | |
# | | | |
# +---+---+---+
# 3-grid vertical left
"3vgridl") winssp \
$(( PADDING_LEFT + GAPS )) \
$(( PADDING_TOP + GAPS )) \
$(( ( SWWP - 2 * GAPS ) / 3 )) \
$SHWP $wid ;;
# 3-grid vertical middle
"3vgridm") winssp \
$(( PADDING_LEFT + ( SWWP + 4 * GAPS ) / 3 )) \
$(( PADDING_TOP + GAPS )) \
$(( ( SWWP - 2 * GAPS ) / 3 )) \
$SHWP $wid ;;
# 3-grid vertical right
"3vgridr") winssp \
$(( PADDING_LEFT + ( 2 * SWWP + 5 * GAPS ) / 3 )) \
$(( PADDING_TOP + GAPS )) \
$(( ( SWWP - 2 * GAPS ) / 3 )) \
$SHWP $wid ;;
# +---+---+---+
# | | | |
# +---+---+---+
# | | | |
# +---+---+---+
# 6-grid horizontal top left
"6hgridtl") winssp \
$(( PADDING_LEFT + GAPS )) \
$(( PADDING_TOP + GAPS )) \
$(( ( SWWP - 2 * GAPS ) / 3 )) \
$(( ( SHWP - GAPS ) / 2 )) $wid ;;
# 6-grid horizontal top middle
"6hgridtm") winssp \
$(( PADDING_LEFT + ( SWWP + 4 * GAPS ) / 3 )) \
$(( PADDING_TOP + GAPS )) \
$(( ( SWWP - 2 * GAPS ) / 3 )) \
$(( ( SHWP - GAPS ) / 2 )) $wid ;;
# 6-grid horizontal top right
"6hgridtr") winssp \
$(( PADDING_LEFT + ( 2 * SWWP + 5 * GAPS) / 3 )) \
$(( PADDING_TOP + GAPS )) \
$(( ( SWWP - 2 * GAPS ) / 3 )) \
$(( ( SHWP - GAPS ) / 2 )) $wid ;;
# 6-grid horizontal bottom left
"6hgridbl") winssp \
$(( PADDING_LEFT + GAPS )) \
$(( PADDING_TOP + ( SHWP + 3 * GAPS ) / 2 )) \
$(( ( SWWP - 2 * GAPS ) / 3 )) \
$(( ( SHWP - GAPS ) / 2 )) $wid ;;
# 6-grid horizontal bottom middle
"6hgridbm") winssp \
$(( PADDING_LEFT + 2 * GAPS + ( SWWP - 2 * GAPS ) / 3 )) \
$(( PADDING_TOP + ( SHWP + 3 * GAPS ) / 2 )) \
$(( ( SWWP - 2 * GAPS ) / 3 )) \
$(( ( SHWP - GAPS ) / 2 )) $wid ;;
# 6-grid horizontal bottom right
"6hgridbr") winssp \
$(( PADDING_LEFT + ( 2 * SWWP + 5 * GAPS) / 3 )) \
$(( PADDING_TOP + ( SHWP + 3 * GAPS ) / 2 )) \
$(( ( SWWP - 2 * GAPS ) / 3 )) \
$(( ( SHWP - GAPS ) / 2 )) $wid ;;
esac