-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmain.go
64 lines (52 loc) · 1.27 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 (
"flag"
"fmt"
"log/slog"
"os"
"os/exec"
"runtime"
"github.com/swaywm/go-wlroots/wlroots"
)
var (
command = flag.String("s", "", "startup command")
programLevel = new(slog.LevelVar) // Info by default
)
func fatal(msg string, err error) {
fmt.Printf("error %s: %s\n", msg, err)
os.Exit(1)
}
func init() {
// lock the main goroutine onto the current OS thread
// we need to do this because EGL uses thread local storage
runtime.LockOSThread()
}
func main() {
// set global logger with custom options
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: programLevel})))
flag.Parse()
// set up logging
// programLevel.Set(slog.LevelDebug)
wlroots.OnLog(wlroots.LogImportanceDebug, nil)
// start the server
server, err := NewServer()
if err != nil {
fatal("initializing server", err)
}
if err = server.Start(); err != nil {
fatal("starting server", err)
}
// run the startup command if given
if *command != "" {
cmd := exec.Command("/bin/sh", "-c", *command)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err = cmd.Start(); err != nil {
fatal("running startup command", err)
}
}
// start the wayland event loop
if err = server.Run(); err != nil {
fatal("running server", err)
}
}