-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
864c97b
commit f14bb17
Showing
2 changed files
with
57 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package sysinfo | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
"path" | ||
"path/filepath" | ||
) | ||
|
||
// ANY error here will be ignored. All of the filepath querying | ||
// and such is done within /sys/, which is stored in memory. | ||
|
||
type Card struct { | ||
Path string | ||
Driver string | ||
Index int | ||
Embedded bool | ||
} | ||
|
||
const drmPath = "/sys/class/drm" | ||
var embeddedDisplays = []string{"eDP", "LVDS", "DP-2"} | ||
|
||
func Cards() (cards []Card) { | ||
drmCards, _ := filepath.Glob(path.Join(drmPath, "card[0-9]")) | ||
|
||
for i, c := range drmCards { | ||
d, _ := filepath.EvalSymlinks(path.Join(c, "device/driver")) | ||
d = path.Base(d) | ||
|
||
cards = append(cards, Card{ | ||
Path: c, | ||
Driver: d, | ||
Index: i, | ||
Embedded: embedded(c), | ||
}) | ||
} | ||
|
||
return | ||
} | ||
|
||
func embedded(cardPath string) (embed bool) { | ||
filepath.Walk(drmPath, func(p string, f os.FileInfo, err error) error { | ||
if !strings.HasPrefix(p, cardPath) { | ||
return nil | ||
} | ||
|
||
for _, hwd := range embeddedDisplays { | ||
if strings.Contains(p, hwd) { | ||
embed = true | ||
} | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters