-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresize-toggle.go
More file actions
36 lines (30 loc) · 866 Bytes
/
resize-toggle.go
File metadata and controls
36 lines (30 loc) · 866 Bytes
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
package usrCmds
func init() {
register("resize-toggle", ResizeToggle)
}
// ResizeToggle toggles the width of the top-most split parent of the focused
// window, between 10-50-90% of the screen width.
func ResizeToggle(d DaemonAPI, _ map[string]string) (string, error) {
path, err := d.GetWinTreePath(d.FocusedWindow().ID)
if err != nil {
return "", err
}
space := path[0]
split := path[1]
// skip non-split splits
for i := 2; split.Rect.Width == space.Rect.Width && i < len(path); i++ {
split = path[i]
}
halfWidth := space.Rect.Width / 2
maxWidth := space.Rect.Width
targetWidth := int(0.9 * float32(maxWidth))
var ppt string
if split.Rect.Width == halfWidth {
ppt = "90ppt"
} else if split.Rect.Width < targetWidth {
ppt = "50ppt"
} else {
ppt = "10ppt"
}
return ppt, d.SwayMsg(`[con_id=%d] resize set width %s`, split.ID, ppt)
}