diff --git a/Makefile b/Makefile index f5c96d7..043fe63 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,44 @@ # Installation paths PREFIX ?= /usr/local BINDIR ?= $(PREFIX)/bin +LIBEXECDIR ?= $(PREFIX)/libexec SYSCONFDIR := $(PREFIX)/etc # Compilers and tools GO ?= go +# Compiler flags +GOOS ?= $(shell $(GO) env | grep '^GOOS' | cut -d'=' -f2 | tr -d "'") +GOARCH ?= $(shell $(GO) env | grep '^GOARCH' | cut -d'=' -f2 | tr -d "'") +LDFLAGS ?= -w + # Build-time variables VERSION ?= $(shell git describe --tags --dirty) -build: - mkdir -p build - cd src; $(GO) build -ldflags "-w -X 'main.StormfetchVersion=$(VERSION)' -X 'main.SystemConfigDir=$(SYSCONFDIR)'" -o ../build/stormfetch stormfetch +build: build-stormfetch build-stormfetch-monitor-detection -install: build/stormfetch config/ - # Create directoriy +build-stormfetch: + install -d build + cd src/stormfetch; GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build -ldflags "$(LDFLAGS) -X 'main.StormfetchVersion=$(VERSION)' -X 'main.SystemConfigDir=$(SYSCONFDIR)' -X 'main.LibexecDir=$(LIBEXECDIR)'" -o ../../build/stormfetch + +build-stormfetch-monitor-detection: + install -d build + cd src/stormfetch-monitor-detection; GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build -ldflags "$(LDFLAGS)" -o ../../build/stormfetch-monitor-detection + +install: install-stormfetch install-stormfetch-monitor-detection install-config + +install-stormfetch: build/stormfetch + # Create directory install -dm755 $(DESTDIR)$(BINDIR) # Install binary install -m755 build/stormfetch $(DESTDIR)$(BINDIR)/stormfetch +install-stormfetch-monitor-detection: build/stormfetch-monitor-detection + # Create directory + install -dm755 $(DESTDIR)$(LIBEXECDIR) + # Install binary + install -m755 build/stormfetch-monitor-detection $(DESTDIR)$(LIBEXECDIR)/stormfetch-monitor-detection + install-config: # Create directory install -dm755 $(DESTDIR)$(SYSCONFDIR) @@ -27,9 +47,10 @@ install-config: uninstall: -rm -f $(DESTDIR)$(BINDIR)/stormfetch + -rm -f $(DESTDIR)$(LIBEXEDIR)/stormfetch-monitor-detection -rm -rf $(DESTDIR)$(SYSCONFDIR)/stormfetch clean: rm -r build/ -.PHONY: build install install-config uninstall clean +.PHONY: build build-stormfetch build-stormfetch-monitor-detection install install-config uninstall clean diff --git a/src/stormfetch-monitor-detection/go.mod b/src/stormfetch-monitor-detection/go.mod new file mode 100644 index 0000000..43839c2 --- /dev/null +++ b/src/stormfetch-monitor-detection/go.mod @@ -0,0 +1,5 @@ +module stormfetch-monitor-detection + +go 1.24.0 + +require github.com/go-gl/glfw/v3.3/glfw v0.0.0-20260406072232-3ac4aa2bb164 diff --git a/src/stormfetch-monitor-detection/go.sum b/src/stormfetch-monitor-detection/go.sum new file mode 100644 index 0000000..2c0f4d9 --- /dev/null +++ b/src/stormfetch-monitor-detection/go.sum @@ -0,0 +1,2 @@ +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20260406072232-3ac4aa2bb164 h1:ddtotcEXIT7dFhSeXIWjK8YMFYl5bB2NdYQwgv6Uqjk= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20260406072232-3ac4aa2bb164/go.mod h1:SyRD8YfuKk+ZXlDqYiqe1qMSqjNgtHzBTG810KUagMc= diff --git a/src/stormfetch-monitor-detection/main.go b/src/stormfetch-monitor-detection/main.go new file mode 100644 index 0000000..8cf6647 --- /dev/null +++ b/src/stormfetch-monitor-detection/main.go @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "os" + "strconv" + + "github.com/go-gl/glfw/v3.3/glfw" +) + +func main() { + defer func() { + if r := recover(); r != nil { + os.Exit(1) + } + }() + + err := glfw.Init() + if err != nil { + os.Exit(1) + } + + for _, monitor := range glfw.GetMonitors() { + mode := monitor.GetVideoMode() + + fmt.Print(monitor.GetName() + ",") + fmt.Print(strconv.Itoa(mode.Width) + ",") + fmt.Print(strconv.Itoa(mode.Height) + ",") + fmt.Print(strconv.Itoa(mode.RefreshRate)) + fmt.Println() + } + defer glfw.Terminate() +} diff --git a/src/color.go b/src/stormfetch/color.go similarity index 100% rename from src/color.go rename to src/stormfetch/color.go diff --git a/src/config.go b/src/stormfetch/config.go similarity index 100% rename from src/config.go rename to src/stormfetch/config.go diff --git a/src/go.mod b/src/stormfetch/go.mod similarity index 86% rename from src/go.mod rename to src/stormfetch/go.mod index d537214..ecf4388 100644 --- a/src/go.mod +++ b/src/stormfetch/go.mod @@ -3,7 +3,6 @@ module stormfetch go 1.24.0 require ( - github.com/go-gl/glfw/v3.3/glfw v0.0.0-20250301202403-da16c1255728 github.com/jackmordaunt/ghw v1.0.5 github.com/mitchellh/go-ps v1.0.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/src/go.sum b/src/stormfetch/go.sum similarity index 64% rename from src/go.sum rename to src/stormfetch/go.sum index 2bc6f11..4155462 100644 --- a/src/go.sum +++ b/src/stormfetch/go.sum @@ -1,13 +1,5 @@ -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+xzxf1jTJKMKZw3H0swfWk9RpWbBbDK5+0= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20250301202403-da16c1255728 h1:RkGhqHxEVAvPM0/R+8g7XRwQnHatO0KAuVcwHo8q9W8= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20250301202403-da16c1255728/go.mod h1:SyRD8YfuKk+ZXlDqYiqe1qMSqjNgtHzBTG810KUagMc= -github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= -github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= -github.com/jackmordaunt/ghw v1.0.4 h1:as+COFuPuXaNQC3WqzoHS/E2JYWZU7gN8ompNTUxNxs= -github.com/jackmordaunt/ghw v1.0.4/go.mod h1:4dReYvJ36CoAzIxlEx8du25Qi/YqKYvEGE9QJoRXiK8= github.com/jackmordaunt/ghw v1.0.5 h1:3rTXwu0D9RkungV7/WlhC8HVuDlPaq0aKY8u0I51jLY= github.com/jackmordaunt/ghw v1.0.5/go.mod h1:VpFlLXnJErgoRttR3WOxun4v5EE8/xfB4cK26G5q2U0= github.com/jackmordaunt/pcidb v1.0.1 h1:uLLZa6kD5P39r2cwMyJJkxmuHfH9Wq19gYQEbYcB0Z4= @@ -21,10 +13,7 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg= -golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= -golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk= golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/src/hardware.go b/src/stormfetch/hardware.go similarity index 80% rename from src/hardware.go rename to src/stormfetch/hardware.go index dbe2b25..c2cc453 100644 --- a/src/hardware.go +++ b/src/stormfetch/hardware.go @@ -3,11 +3,12 @@ package main import ( "fmt" "os" + "os/exec" + "path" "slices" "strconv" "strings" - "github.com/go-gl/glfw/v3.3/glfw" "github.com/jackmordaunt/ghw" ) @@ -29,6 +30,7 @@ type GPU struct { } type Monitor struct { + Name string Width int Height int RefreshRate int @@ -195,22 +197,55 @@ func GetMotherboardModel() string { func GetMonitors() []Monitor { var monitors []Monitor + if GetDisplayProtocol() != "" { - err := glfw.Init() - if err != nil { - panic(err) + // Find stormfetch-monitor-detection program + execPath, _ := os.Executable() + possiblePaths := []string{ + path.Join(path.Dir(execPath), "stormfetch-monitor-detection"), + path.Join(LibexecDir, "stormfetch-monitor-detection"), } - for _, monitor := range glfw.GetMonitors() { - mode := monitor.GetVideoMode() + monitorDetectionPath := "" + for _, path := range possiblePaths { + if _, err := os.Stat(path); err == nil { + monitorDetectionPath = path + break + } + } + if monitorDetectionPath == "" { + return nil + } + + // Get monitor detection program output + output, err := exec.Command(monitorDetectionPath).Output() + if err != nil { + return nil + } + + // Parse output + for line := range strings.SplitSeq(strings.TrimSpace(string(output)), "\n") { + lineSplit := strings.Split(line, ",") + if len(lineSplit) != 4 { + continue + } + + name := lineSplit[0] + width, err := strconv.Atoi(lineSplit[1]) + height, err := strconv.Atoi(lineSplit[2]) + refreshRate, err := strconv.Atoi(lineSplit[3]) + if err != nil { + continue + } monitors = append(monitors, Monitor{ - Width: mode.Width, - Height: mode.Height, - RefreshRate: mode.RefreshRate, + Name: name, + Width: width, + Height: height, + RefreshRate: refreshRate, }) } - defer glfw.Terminate() } + return monitors } diff --git a/src/main.go b/src/stormfetch/main.go similarity index 99% rename from src/main.go rename to src/stormfetch/main.go index 725bdb8..863a1bd 100644 --- a/src/main.go +++ b/src/stormfetch/main.go @@ -12,6 +12,7 @@ import ( // Build-time variables var StormfetchVersion = "dev" var SystemConfigDir = "/etc/" +var LibexecDir = "/libexec/" // Flag variables var ShowVersion = false diff --git a/src/memory.go b/src/stormfetch/memory.go similarity index 100% rename from src/memory.go rename to src/stormfetch/memory.go diff --git a/src/modules.go b/src/stormfetch/modules.go similarity index 97% rename from src/modules.go rename to src/stormfetch/modules.go index 9bcf035..cf350f3 100644 --- a/src/modules.go +++ b/src/stormfetch/modules.go @@ -405,15 +405,15 @@ func initializeModuleMap() { RegisterModule(dewmModule) // Monitors module - monitorsModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "monitors", Format: "%3Monitor: %4${MONITOR_WIDTH}x${MONITOR_HEIGHT} ${MONITOR_REFRESH_RATE}Hz"}, Execute: func(sm StormfetchModule) string { + monitorsModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "monitors", Format: "%3Monitor ${MONITOR_NAME}: %4${MONITOR_WIDTH}x${MONITOR_HEIGHT} ${MONITOR_REFRESH_RATE}Hz"}, Execute: func(sm StormfetchModule) string { builder := strings.Builder{} monitors := GetMonitors() - for i, monitor := range monitors { + for _, monitor := range monitors { expanded := os.Expand(sm.Format, func(s string) string { switch s { - case "MONITOR_NUM": - return strconv.Itoa(i + 1) + case "MONITOR_NAME": + return monitor.Name case "MONITOR_WIDTH": return strconv.Itoa(monitor.Width) case "MONITOR_HEIGHT": diff --git a/src/network.go b/src/stormfetch/network.go similarity index 100% rename from src/network.go rename to src/stormfetch/network.go diff --git a/src/partitions.go b/src/stormfetch/partitions.go similarity index 100% rename from src/partitions.go rename to src/stormfetch/partitions.go diff --git a/src/pms.go b/src/stormfetch/pms.go similarity index 100% rename from src/pms.go rename to src/stormfetch/pms.go diff --git a/src/system.go b/src/stormfetch/system.go similarity index 100% rename from src/system.go rename to src/stormfetch/system.go diff --git a/src/user.go b/src/stormfetch/user.go similarity index 100% rename from src/user.go rename to src/stormfetch/user.go diff --git a/src/utils.go b/src/stormfetch/utils.go similarity index 100% rename from src/utils.go rename to src/stormfetch/utils.go