-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
56 lines (51 loc) · 1.29 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
package main
import "fmt"
import "os"
import "github.com/BurntSushi/xgbutil"
func main() {
if len(os.Args) != 2 {
printUsage()
return
}
windows := GetWindows()
if len(windows) == 0 {
fmt.Println("Unrecoverable error - couldn't find any Windows")
return
}
X, err := xgbutil.NewConn()
if err != nil {
fmt.Println("Unrecoverable error - couldn't connect to X")
return
}
wid := GetActiveWid(X)
if wid == 0 {
fmt.Println("Unrecoverable error - couldn't determine the active WID")
return
}
maybeActive := GetActiveWindow(wid, &windows)
if len(maybeActive) == 1 {
var nextWindow Window
active := maybeActive[0]
switch {
case os.Args[1] == "left":
nextWindow = active.getNextBy(&windows, -1, 0)
case os.Args[1] == "right":
nextWindow = active.getNextBy(&windows, 1, 0)
case os.Args[1] == "up":
nextWindow = active.getNextBy(&windows, 0, -1)
case os.Args[1] == "down":
nextWindow = active.getNextBy(&windows, 0, 1)
case os.Args[1] == "overlap":
nextWindow = active.getRandomOverlap(&windows)
case true:
printUsage()
return
}
nextWindow.Select(X)
} else {
fmt.Println("Unrecoverable error - couldn't find any Window with the active WID")
}
}
func printUsage () () {
fmt.Println("usage: xvinyl <direction>\n left, right, up, down, or overlap")
}