34 lines
567 B
Go
34 lines
567 B
Go
|
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
|
||
|
}
|