diff --git a/info/info.go b/info/info.go index ccbae09..9eabb9e 100644 --- a/info/info.go +++ b/info/info.go @@ -159,14 +159,24 @@ func GetInfoString(options map[string]string) string { lines++ case "resolution": - resolution := getRawScreenResolution() + resolutions := getRawScreenResolutions() - output += formatAndColor( - "\x1b[%vG${caccent}Resolution${creset}: %v\n", - offset, - resolution, - ) - lines++ + for _, res := range resolutions { + output += formatAndColor( + "\x1b[%vG${caccent}Resolution${creset}: %v\n", + offset, + res, + ) + lines++ + } + + if len(resolutions) == 0 { + output += formatAndColor( + "\x1b[%vG${caccent}Resolution${creset}: n/a\n", + offset, + ) + lines++ + } case "cpu": cpu := getRawCpu() diff --git a/info/raw_darwin.go b/info/raw_darwin.go index 8b7dfa0..a6871e3 100644 --- a/info/raw_darwin.go +++ b/info/raw_darwin.go @@ -139,19 +139,19 @@ func getRawGpus() []string { } // Returns main screen resolution -func getRawScreenResolution() string { +func getRawScreenResolutions() []string { out, err := exec.Command("system_profiler", "SPDisplaysDataType").Output() if err != nil { - return "n/a" + return []string{} } contents := string(out) match := extractResolutionRegex.FindStringSubmatch(contents) if len(match) == 0 { - return "n/a" + return []string{} } - return match[1] + return []string{match[1]} } // Returns OS pretty name diff --git a/info/raw_linux.go b/info/raw_linux.go index 8d56461..bbfb2f9 100644 --- a/info/raw_linux.go +++ b/info/raw_linux.go @@ -36,6 +36,9 @@ var ( getGpuModelRegex = regexp.MustCompile(`.*\[(.*)\]`) ) +// Regex used to extract resolutions from "xrandr --nograb --current" +var getResolutionRegex = regexp.MustCompile(`connected(?: primary)? (\d+)x(\d+)`) + // Regex used to remove too much spaces between words var removeExtraSpacesRegex = regexp.MustCompile(`\s+`) @@ -216,13 +219,25 @@ func getRawGpus() []string { } // Returns main screen resolution -func getRawScreenResolution() string { - raw, err := os.ReadFile("/sys/class/graphics/fb0/virtual_size") +func getRawScreenResolutions() []string { + out, err := exec.Command("xrandr", "--nograb", "--current").Output() if err != nil { - return "n/a" + return []string{} + } + + contents := string(out) + match := getResolutionRegex.FindAllStringSubmatch(contents, -1) + if len(match) == 0 { + return []string{} + } + + resolutions := []string{} + + for _, resMatch := range match { + resolutions = append(resolutions, fmt.Sprintf("%vx%v", resMatch[1], resMatch[2])) } - return strings.Replace(string(raw), ",", "x", -1) + return resolutions } // Returns OS pretty name