-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager_ifc.go
More file actions
104 lines (92 loc) · 2.16 KB
/
manager_ifc.go
File metadata and controls
104 lines (92 loc) · 2.16 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"io/ioutil"
"strings"
)
var prevConnected []OutputInfo
func (m *Manager) ListConnectedOutput() []OutputInfo {
m.outputLocker.Lock()
defer m.outputLocker.Unlock()
connected := m.outputInfos.ListConnectionOutputs()
var infos []OutputInfo
for _, output := range connected {
//if !canReadEDID(output.Name) || output.Crtc.Width == 0 || output.Crtc.Height == 0 {
if output.Crtc.Width == 0 || output.Crtc.Height == 0 {
continue
}
infos = append(infos, OutputInfo{
Name: output.Name,
X: output.Crtc.X,
Y: output.Crtc.Y,
Width: output.Crtc.Width,
Height: output.Crtc.Height,
})
}
prevConnected = infos
return infos
}
const drmClassPath = "/sys/class/drm/"
func canReadEDID(name string) bool {
return canReadProp(name, "edid")
}
func canReadModes(name string) bool {
return canReadProp(name, "modes")
}
func canReadProp(card, prop string) bool {
list := getCardByName(card)
logger.Debug("[canReadProp] card list:", list)
logger.Debugf("[canReadProp] will read prop %q for %q:", prop, card)
if len(list) == 0 {
return false
}
for _, card := range list {
var file = drmClassPath + card + "/" + prop
content, err := ioutil.ReadFile(file)
if err != nil {
logger.Errorf("Read edid file '%s' failed: %v", file, err)
continue
}
if len(content) != 0 {
return true
}
}
return false
}
func getCardByName(name string) []string {
cards := getAllCards()
if len(cards) == 0 {
return nil
}
logger.Debug("[getCardByName] all cards:", cards)
if strings.Contains(name, "-") {
array := strings.Split(name, "-")
name = strings.Join(array, "")
}
var list []string
for _, card := range cards {
array := strings.Split(card, "-")
tmp := strings.Join(array[1:], "")
if tmp == name {
list = append(list, card)
}
}
return list
}
func getAllCards() []string {
finfos, err := ioutil.ReadDir(drmClassPath)
if err != nil {
logger.Error("Read card list failed:", err)
return nil
}
var cards []string
for _, finfo := range finfos {
if !strings.Contains(finfo.Name(), "card") {
continue
}
if finfo.Name() == "card0" {
continue
}
cards = append(cards, finfo.Name())
}
return cards
}