@@ -3,11 +3,12 @@ package main
33import (
44 "fmt"
55 "os"
6+ "os/exec"
7+ "path"
68 "slices"
79 "strconv"
810 "strings"
911
10- "github.com/go-gl/glfw/v3.3/glfw"
1112 "github.com/jackmordaunt/ghw"
1213)
1314
@@ -29,6 +30,7 @@ type GPU struct {
2930}
3031
3132type Monitor struct {
33+ Name string
3234 Width int
3335 Height int
3436 RefreshRate int
@@ -195,22 +197,55 @@ func GetMotherboardModel() string {
195197
196198func GetMonitors () []Monitor {
197199 var monitors []Monitor
200+
198201 if GetDisplayProtocol () != "" {
199- err := glfw .Init ()
202+ // Find stormfetch-monitor-detection program
203+ execPath , _ := os .Executable ()
204+ possiblePaths := []string {
205+ path .Join (path .Dir (execPath ), "stormfetch-monitor-detection" ),
206+ path .Join (LibexecDir , "stormfetch-monitor-detection" ),
207+ }
208+
209+ monitorDetectionPath := ""
210+ for _ , path := range possiblePaths {
211+ if _ , err := os .Stat (path ); err == nil {
212+ monitorDetectionPath = path
213+ break
214+ }
215+ }
216+ if monitorDetectionPath == "" {
217+ return nil
218+ }
219+
220+ // Get monitor detection program output
221+ output , err := exec .Command (monitorDetectionPath ).Output ()
200222 if err != nil {
201- panic ( err )
223+ return nil
202224 }
203225
204- for _ , monitor := range glfw .GetMonitors () {
205- mode := monitor .GetVideoMode ()
226+ // Parse output
227+ for line := range strings .SplitSeq (strings .TrimSpace (string (output )), "\n " ) {
228+ lineSplit := strings .Split (line , "," )
229+ if len (lineSplit ) != 4 {
230+ continue
231+ }
232+
233+ name := lineSplit [0 ]
234+ width , err := strconv .Atoi (lineSplit [1 ])
235+ height , err := strconv .Atoi (lineSplit [2 ])
236+ refreshRate , err := strconv .Atoi (lineSplit [3 ])
237+ if err != nil {
238+ continue
239+ }
206240
207241 monitors = append (monitors , Monitor {
208- Width : mode .Width ,
209- Height : mode .Height ,
210- RefreshRate : mode .RefreshRate ,
242+ Name : name ,
243+ Width : width ,
244+ Height : height ,
245+ RefreshRate : refreshRate ,
211246 })
212247 }
213- defer glfw .Terminate ()
214248 }
249+
215250 return monitors
216251}
0 commit comments