-
Notifications
You must be signed in to change notification settings - Fork 0
/
desktop.go
58 lines (50 loc) · 1.05 KB
/
desktop.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
//go:build linux
// +build linux
package linux
import (
"os"
"path"
"path/filepath"
"strconv"
"strings"
"github.com/alexcoder04/friendly"
)
func GetDisplayServer() string {
sessionType := os.Getenv("XDG_SESSION_TYPE")
if sessionType != "" {
return sessionType
}
if os.Getenv("WAYLAND_DISPLAY") != "" {
return "wayland"
}
if os.Getenv("DISPLAY") != "" {
return "x11"
}
return ""
}
func getRuntimeDir() string {
if os.Getenv("XDG_RUNTIME_DIR") != "" {
return os.Getenv("XDG_RUNTIME_DIR")
}
return filepath.Join("/run/user", strconv.Itoa(os.Getuid()))
}
func GuiRunning() bool {
dispServer := GetDisplayServer()
if dispServer == "" {
return false
}
if dispServer == "wayland" {
display := os.Getenv("WAYLAND_DISPLAY")
if display == "" {
return false
}
waySock := path.Join(getRuntimeDir(), display)
return friendly.IsFile(waySock)
}
display := strings.Replace(os.Getenv("DISPLAY"), ":", "", 1)
if display == "" {
return false
}
x11Sock := path.Join(os.TempDir(), ".X11-unix", "X"+display)
return friendly.IsFile(x11Sock)
}