-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (52 loc) · 1.2 KB
/
main.go
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
package main
import (
"fmt"
"go.i3wm.org/i3/v4"
"os"
"os/exec"
"log"
)
func RunCommand(command string) {
_, err := i3.RunCommand(command)
if err != nil && !i3.IsUnsuccessful(err) {
log.Fatalf("i3.RunCommand() failed with %s\n", err)
}
}
func main() {
if len(os.Args) == 1 {
log.Fatalf("Arguments required\n")
}
tree, err := i3.GetTree()
if err != nil {
log.Fatalf("i3.GetTree failed with %s\n", err)
}
var nodes []*i3.Node
focused := tree.Root.FindFocused(func(n *i3.Node) bool {
nodes = append(nodes, n)
return n.Focused
})
if focused == nil {
log.Fatalf("Could not locate focused node\n")
}
focusedParent := nodes[len(nodes)-2]
if focusedParent.Type == i3.FloatingCon {
log.Fatalf("Floating windows not supported\n")
}
oldLayout := focusedParent.Layout
if oldLayout == i3.SplitH || oldLayout == i3.SplitV {
RunCommand("split v, layout stacking")
} else {
log.Fatalf("Layout %s not supported\n", oldLayout)
}
cmd := exec.Command(os.Args[1], os.Args[2:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
log.Printf("cmd.Run() failed with %s\n", err)
}
RunCommand(fmt.Sprintf("layout %s", oldLayout))
if err != nil {
os.Exit(1)
}
}