package xorg import ( "fmt" "time" "github.com/jezek/xgb" ) const ( xConnectAttempts = 16 xConnectIntervalMilliseconds = 500 ) func GetXGBConnection() (*xgb.Conn, error) { for i := 1; i <= xConnectAttempts; i++ { XConn, err := xgb.NewConn() if err == nil { return XConn, err } time.Sleep(xConnectIntervalMilliseconds * time.Millisecond) } return nil, fmt.Errorf("failed to reach X server after %d attempts", xConnectAttempts) }