...
1 package xorg
2
3 import (
4 "fmt"
5 "time"
6
7 "github.com/jezek/xgb"
8 )
9
10 const (
11 xConnectAttempts = 16
12 xConnectIntervalMilliseconds = 500
13 )
14
15 func GetXGBConnection() (*xgb.Conn, error) {
16 for i := 1; i <= xConnectAttempts; i++ {
17 XConn, err := xgb.NewConn()
18 if err == nil {
19 return XConn, err
20 }
21 time.Sleep(xConnectIntervalMilliseconds * time.Millisecond)
22 }
23 return nil, fmt.Errorf("failed to reach X server after %d attempts", xConnectAttempts)
24 }
25
View as plain text