-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.go
75 lines (72 loc) · 1.69 KB
/
query.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
65
66
67
68
69
70
71
72
73
74
75
package edid
import (
"errors"
"runtime"
)
// QueryEDID - valid methods: "x11","i2c","setupapi","ioreg"
func QueryEDID(method string) ([]*EDID, error) {
var edids []*EDID
var errRet error
switch method {
case ``:
var queriers []func() ([]*EDID, error)
switch runtime.GOOS {
case `windows`:
queriers = append(queriers, queryEDIDSetupAPI, queryEDIDI2C, queryEDIDX11)
case `darwin`:
queriers = append(queriers, queryEDIDIOReg, queryEDIDI2C, queryEDIDX11, queryEDIDSetupAPI)
case `android`:
queriers = append(queriers, queryEDIDI2C, queryEDIDX11, queryEDIDSetupAPI)
default:
queriers = append(queriers, queryEDIDX11, queryEDIDI2C, queryEDIDSetupAPI)
}
var atLeastOneSucceededMethod bool
for _, querier := range queriers {
es, err := querier()
if err != nil {
continue
}
atLeastOneSucceededMethod = true
if len(es) == 0 {
continue
}
edids = append(edids, es...)
}
if len(edids) == 0 && !atLeastOneSucceededMethod {
edids, errRet = nil, errors.New(`all methods failed`)
}
case `windows`:
fallthrough
case `setupapi`:
edids, errRet = queryEDIDSetupAPI()
case `randr`: // TODO: x11 + wayland
fallthrough
case `x11`:
edids, errRet = queryEDIDX11()
case `i2c`:
edids, errRet = queryEDIDI2C()
case `darwin`:
fallthrough
case `ioreg`:
edids, errRet = queryEDIDIOReg()
default:
return nil, errors.New(`unknown method`)
}
// TODO tmp
var edidsRet []*EDID
for _, ed := range edids {
_ = ed.parse()
edidsRet = append(edidsRet, ed)
}
return edidsRet, errRet
}
func filterActive(edids []*EDID) ([]*EDID, error) {
var ret []*EDID
for _, ed := range edids {
if !ed.IsActive {
continue
}
ret = append(ret, ed)
}
return ret, nil
}