Remove display counts
This commit is contained in:
+1
-124
@@ -2,9 +2,6 @@ package page
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-gl/gl/v3.3-core/gl"
|
||||
@@ -26,98 +23,11 @@ type Home struct {
|
||||
licenseInfoHeading StringItem
|
||||
emailDisplay StringItem
|
||||
licenseKeyDisplay StringItem
|
||||
displayStatus StringItem
|
||||
sdlDisplayStatus StringItem
|
||||
hasLicenseInfo bool
|
||||
lastDisplayUpdate time.Time
|
||||
drmDisplayCount int
|
||||
sdlDisplayCount int
|
||||
baseFontSize int // cached from db at init
|
||||
}
|
||||
|
||||
// countConnectedDisplays returns the number of connected displays via DRM
|
||||
func countConnectedDisplays() int {
|
||||
matches, err := filepath.Glob("/sys/class/drm/card*/status")
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
connected := 0
|
||||
for _, path := range matches {
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
status := strings.TrimSpace(string(content))
|
||||
if status == "connected" {
|
||||
connected++
|
||||
}
|
||||
}
|
||||
|
||||
return connected
|
||||
}
|
||||
|
||||
// countSDLDisplays returns the number of displays detected by SDL
|
||||
func countSDLDisplays() int {
|
||||
numDisplays, err := sdl.GetNumVideoDisplays()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return numDisplays
|
||||
}
|
||||
|
||||
// updateDisplayCounts updates the display count textures
|
||||
func (p *Home) updateDisplayCounts() error {
|
||||
var err error
|
||||
// Get font
|
||||
fm := fontManager.Get()
|
||||
font, ok := fm.GetFont("Roboto-Regular")
|
||||
if !ok {
|
||||
return fmt.Errorf("unable to fetch font")
|
||||
}
|
||||
|
||||
// Get base font size
|
||||
baseFontSize := p.Base.Context.CfgPtr.StandardFontSize
|
||||
|
||||
// Update DRM count
|
||||
p.drmDisplayCount = countConnectedDisplays()
|
||||
|
||||
// Delete old texture
|
||||
if p.displayStatus.ID != 0 {
|
||||
gl.DeleteTextures(1, &p.displayStatus.ID)
|
||||
}
|
||||
|
||||
// Create new texture
|
||||
displayStatusText := fmt.Sprintf("Connected Displays: %d", p.drmDisplayCount)
|
||||
p.displayStatus, err = NewStringItem(displayStatusText, font, colors.White)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create display status texture: %w", err)
|
||||
}
|
||||
|
||||
displayStatusScale := float32(24) / float32(baseFontSize)
|
||||
p.displayStatus.Scale(displayStatusScale)
|
||||
|
||||
// Update SDL count
|
||||
p.sdlDisplayCount = countSDLDisplays()
|
||||
|
||||
// Delete old texture
|
||||
if p.sdlDisplayStatus.ID != 0 {
|
||||
gl.DeleteTextures(1, &p.sdlDisplayStatus.ID)
|
||||
}
|
||||
|
||||
// Create new texture
|
||||
sdlDisplayStatusText := fmt.Sprintf("SDL Displays Detected: %d", p.sdlDisplayCount)
|
||||
p.sdlDisplayStatus, err = NewStringItem(sdlDisplayStatusText, font, colors.White)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create SDL display status texture: %w", err)
|
||||
}
|
||||
|
||||
p.sdlDisplayStatus.Scale(displayStatusScale)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Init performs basic page initialization and creation of static assets.
|
||||
func (p *Home) Init(ctx *PageCtx) error {
|
||||
|
||||
@@ -163,12 +73,6 @@ func (p *Home) Init(ctx *PageCtx) error {
|
||||
return fmt.Errorf("unable to create note string texture: %w", err)
|
||||
}
|
||||
|
||||
// Initialize display counts
|
||||
p.lastDisplayUpdate = time.Now()
|
||||
if err := p.updateDisplayCounts(); err != nil {
|
||||
return fmt.Errorf("unable to update display counts: %w", err)
|
||||
}
|
||||
|
||||
// Create license info textures if data exists
|
||||
if p.Base.Context.CfgPtr.EmailAddress != "" || p.Base.Context.CfgPtr.LicenseKey != "" {
|
||||
p.hasLicenseInfo = true
|
||||
@@ -230,12 +134,6 @@ func (p *Home) HandleEvent(event *sdl.Event) error {
|
||||
|
||||
// Update updates animations and changing textures and other changes using `dt` which represents a time delta in float32.
|
||||
func (p *Home) Update(dt float32) error {
|
||||
// Update display counts every 2 seconds
|
||||
if time.Since(p.lastDisplayUpdate) >= 2*time.Second {
|
||||
if err := p.updateDisplayCounts(); err != nil {
|
||||
}
|
||||
p.lastDisplayUpdate = time.Now()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -291,22 +189,7 @@ func (p *Home) Render() error {
|
||||
titlePos := mgl32.Vec2{float32(titleX), float32(titleY)}
|
||||
versionPos := mgl32.Vec2{float32(versionX), float32(versionY)}
|
||||
|
||||
// 6) Position display status in bottom left corner
|
||||
displayStatusDim := p.displayStatus.RawDimensions()
|
||||
displayStatusH := displayStatusDim[1]
|
||||
|
||||
// sdlDisplayStatusDim := p.sdlDisplayStatus.RawDimensions()
|
||||
// sdlDisplayStatusH := sdlDisplayStatusDim[1]
|
||||
|
||||
displayStatusMargin := int32(5)
|
||||
|
||||
p.displayStatus.X = 15
|
||||
p.displayStatus.Y = 15
|
||||
|
||||
p.sdlDisplayStatus.X = 15
|
||||
p.sdlDisplayStatus.Y = 15 + int32(displayStatusH) + displayStatusMargin
|
||||
|
||||
// 7) Position license info at bottom center
|
||||
// 6) Position license info at bottom center
|
||||
if p.hasLicenseInfo {
|
||||
licenseInfoMargin := int32(10)
|
||||
bottomMargin := int32(20)
|
||||
@@ -372,10 +255,6 @@ func (p *Home) Render() error {
|
||||
p.Base.RenderTexture(textShader, p.prompt.ID, p.prompt.Position(), promptDim, color)
|
||||
p.Base.RenderTexture(textShader, p.note.ID, p.note.Position(), p.note.RawDimensions(), color)
|
||||
|
||||
// Render display status
|
||||
p.Base.RenderTexture(textShader, p.displayStatus.ID, p.displayStatus.Position(), p.displayStatus.RawDimensions(), color)
|
||||
p.Base.RenderTexture(textShader, p.sdlDisplayStatus.ID, p.sdlDisplayStatus.Position(), p.sdlDisplayStatus.RawDimensions(), color)
|
||||
|
||||
// Render license info if it exists
|
||||
if p.hasLicenseInfo {
|
||||
p.Base.RenderTexture(textShader, p.licenseInfoHeading.ID, p.licenseInfoHeading.Position(), p.licenseInfoHeading.RawDimensions(), color)
|
||||
@@ -396,8 +275,6 @@ func (p *Home) Destroy() error {
|
||||
gl.DeleteTextures(1, &p.version.ID)
|
||||
gl.DeleteTextures(1, &p.prompt.ID)
|
||||
gl.DeleteTextures(1, &p.note.ID)
|
||||
gl.DeleteTextures(1, &p.displayStatus.ID)
|
||||
gl.DeleteTextures(1, &p.sdlDisplayStatus.ID)
|
||||
|
||||
if p.hasLicenseInfo {
|
||||
gl.DeleteTextures(1, &p.licenseInfoHeading.ID)
|
||||
|
||||
Reference in New Issue
Block a user