xrandr/config.go

34 lines
567 B
Go
Raw Normal View History

2023-12-18 23:08:42 +01:00
package xrandr
import (
"bytes"
"os/exec"
"git.milar.in/milarin/bufr"
)
type Config struct {
Displays []DisplayConfig
}
func GetCurrentConfig() (*Config, error) {
output, err := exec.Command("xrandr").Output()
if err != nil {
return nil, err
}
r := bufr.New(bytes.NewReader(output))
r.StringUntil(isNewLine)
configs := make([]DisplayConfig, 0)
for config, err := parseDisplayConfig(r); err == nil; config, err = parseDisplayConfig(r) {
configs = append(configs, *config)
}
if err != nil {
return nil, err
}
return &Config{configs}, nil
}