-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsway_move
100 lines (89 loc) · 3.08 KB
/
sway_move
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
#!/usr/bin/env bash
# Copyright (C) 2020-2021 Bob Hepple <[email protected]>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# http://bhepple.freeshell.org
initialise() {
PROG=$(basename $0)
VERSION="1.0"
ARGUMENTS="top-right|bottom-right|bottom-left"
USAGE="move a floating window to the edges because sway lacks a way to do it!"
case $1 in
-h|--help)
echo "$USAGE"
exit 0
;;
top-left|top-center|top-right|center-left|center-center|center-right|bottom-left|bottom-center|bottom-right)
command="$1"
;;
*)
echo "$PROG: bad argument" >&2
exit 1
;;
esac
return 0
}
initialise "$@"
# width=$( swaymsg -t get_outputs | jq -r '.. | select(.focused?) | .rect | .width' )
# height=$( swaymsg -t get_outputs | jq -r '.. | select(.focused?) | .rect | .height' )
width=$(swaymsg -t get_outputs | jq -r .[].current_mode.width)
height=$(swaymsg -t get_outputs | jq -r .[].current_mode.height)
# scale=$(swaymsg -t get_outputs | jq -r '.. | select(.focused?) | .scale' )
scale=2.0
monitor_width=$(echo "${width}/$scale / 1" | bc)
monitor_height=$(echo "${height}/$scale / 1" | bc)
win_dim=( $( swaymsg -t get_tree |
jq '.. | select(.type?) | select(.type=="floating_con") | select(.focused?)|.rect.width, .rect.height, .deco_rect.height' ) )
win_width=${win_dim[0]}
win_height=${win_dim[1]}
deco_height=${win_dim[2]}
# spacing_x=5
# spacing_y=35
spacing_x=0
spacing_y=16
new_x=$spacing_x
new_y=0
case $command in
## top
top-center)
new_x=$(( (monitor_width - win_width)/2 ))
;;
top-right)
new_x=$(( monitor_width - win_width - 2*spacing_x ))
;;
## center
center-left)
new_y=$(( (monitor_height - win_height - deco_height - spacing_y)/2 ))
;;
center-center)
new_x=$(( (monitor_width - win_width)/2 ))
new_y=$(( (monitor_height - win_height - deco_height - spacing_y)/2 ))
;;
center-right)
new_x=$(( monitor_width - win_width -2*spacing_x ))
new_y=$(( (monitor_height - win_height - deco_height - spacing_y)/2 ))
;;
## bottom
bottom-left)
new_y=$(( monitor_height - win_height - deco_height - spacing_y ))
;;
bottom-center)
new_x=$(( (monitor_width - win_width)/2 ))
new_y=$(( monitor_height - win_height - deco_height - spacing_y ))
;;
bottom-right)
new_x=$(( monitor_width - win_width -2*spacing_x ))
new_y=$(( monitor_height - win_height - deco_height - spacing_y ))
;;
esac
swaymsg "move position $new_x $new_y"