diff --git a/config.example.json b/config.example.json index 7edf44d..3175b03 100644 --- a/config.example.json +++ b/config.example.json @@ -3,6 +3,7 @@ "log_level": "info", "default_page": "main", "font": "medium", + "show_label_background": true, "devices": [ { "serial": "", diff --git a/daemon.go b/daemon.go index 2c70492..cbd7cb9 100644 --- a/daemon.go +++ b/daemon.go @@ -57,6 +57,7 @@ func Run(ctx context.Context, cfg *config.Config, opts RunOptions) error { for i, d := range decks { pageMgrs[i] = NewPageManager(d) pageMgrs[i].defaultFont = cfg.Font + pageMgrs[i].showLabelBackground = cfg.ShowLabelBackground pageMgrs[i].LoadPages(cfg.Pages) } primaryPM := pageMgrs[0] @@ -230,6 +231,7 @@ func Run(ctx context.Context, cfg *config.Config, opts RunOptions) error { activePages = append(activePages, pm.ActivePageName()) pm.stopPeriodicKeys() pm.defaultFont = cfg.Font + pm.showLabelBackground = cfg.ShowLabelBackground pm.LoadPages(cfg.Pages) } ge.ReloadTiming(cfg.Timing.LongPressMs, cfg.Timing.DoubleTapMs) @@ -315,6 +317,7 @@ func reconnectDeck(ctx context.Context, cfg *config.Config, pm **PageManager, as if err == nil { *pm = NewPageManager(newDeck) (*pm).defaultFont = cfg.Font + (*pm).showLabelBackground = cfg.ShowLabelBackground (*pm).LoadPages(cfg.Pages) (*pm).ActivatePage(cfg.DefaultPage) (*pm).startPeriodicKeys() diff --git a/internal/config/config.go b/internal/config/config.go index ec39581..6314aaa 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -11,15 +11,16 @@ import ( ) type Config struct { - Version int `json:"version"` - LogLevel string `json:"log_level"` - DefaultPage string `json:"default_page"` - Font string `json:"font,omitempty"` - Devices []DeviceConfig `json:"devices"` - Pages []PageConfig `json:"pages"` - AutoSwitch []SwitchRule `json:"auto_switch"` - Screensaver ScreensaverCfg `json:"screensaver"` - Timing TimingConfig `json:"timing,omitempty"` + Version int `json:"version"` + LogLevel string `json:"log_level"` + DefaultPage string `json:"default_page"` + Font string `json:"font,omitempty"` + ShowLabelBackground bool `json:"show_label_background"` + Devices []DeviceConfig `json:"devices"` + Pages []PageConfig `json:"pages"` + AutoSwitch []SwitchRule `json:"auto_switch"` + Screensaver ScreensaverCfg `json:"screensaver"` + Timing TimingConfig `json:"timing,omitempty"` } type TimingConfig struct { @@ -113,9 +114,10 @@ type ScreensaverCfg struct { func DefaultConfig() *Config { return &Config{ - Version: 1, - LogLevel: "info", - DefaultPage: "default", + Version: 1, + LogLevel: "info", + DefaultPage: "default", + ShowLabelBackground: true, Pages: []PageConfig{ { Name: "default", diff --git a/render.go b/render.go index e0ba49a..825714c 100644 --- a/render.go +++ b/render.go @@ -13,7 +13,7 @@ import ( "streamdeck-lets-go/internal/config" ) -func RenderKeyToImage(k *config.KeyConfig, keySize int) image.Image { +func RenderKeyToImage(k *config.KeyConfig, keySize int, showLabelBackground bool) image.Image { if k == nil { return blankImage(keySize, color.RGBA{0, 0, 0, 255}) } @@ -46,7 +46,7 @@ func RenderKeyToImage(k *config.KeyConfig, keySize int) image.Image { if k.FontSize != nil { fontSize = *k.FontSize } - return composeImageWithLabel(img, k.Label, keySize, fontSize) + return composeImageWithLabel(img, k.Label, keySize, fontSize, showLabelBackground) } g := gift.New(gift.Resize(keySize, keySize, gift.LanczosResampling)) rgba := image.NewRGBA(image.Rect(0, 0, keySize, keySize)) @@ -79,7 +79,7 @@ func blankImage(size int, c color.Color) image.Image { return img } -func composeImageWithLabel(src image.Image, text string, keySize int, fontSize float64) image.Image { +func composeImageWithLabel(src image.Image, text string, keySize int, fontSize float64, showLabelBackground bool) image.Image { g := gift.New(gift.Resize(keySize, keySize, gift.LanczosResampling)) rgba := image.NewRGBA(image.Rect(0, 0, keySize, keySize)) g.Draw(rgba, src) @@ -89,7 +89,9 @@ func composeImageWithLabel(src image.Image, text string, keySize int, fontSize f barHeight = 18 } barRect := image.Rect(0, keySize-barHeight, keySize, keySize) - draw.Draw(rgba, barRect, &image.Uniform{color.RGBA{0, 0, 0, 180}}, image.Point{}, draw.Over) + if showLabelBackground { + draw.Draw(rgba, barRect, &image.Uniform{color.RGBA{0, 0, 0, 180}}, image.Point{}, draw.Over) + } if text != "" { face, err := parseDisplayFace(fontSize) diff --git a/static/app.js b/static/app.js index 7a932ec..04f4b64 100644 --- a/static/app.js +++ b/static/app.js @@ -119,6 +119,7 @@ document.addEventListener('alpine:init', () => { this.settingsForm = { brightness: this.getDeviceConfig(this.activeDeckSerial)?.brightness ?? 75, font: this.config.font || 'medium', + show_label_background: this.config.show_label_background ?? true, screensaver_enabled: this.config.screensaver?.enabled || false, screensaver_idle: this.config.screensaver?.idle_seconds || 30, screensaver_brightness: this.config.screensaver?.brightness || 10, @@ -598,6 +599,7 @@ document.addEventListener('alpine:init', () => { } dev.brightness = parseInt(this.settingsForm.brightness) this.config.font = this.settingsForm.font || 'medium' + this.config.show_label_background = this.settingsForm.show_label_background this.config.screensaver = { enabled: this.settingsForm.screensaver_enabled, idle_seconds: parseInt(this.settingsForm.screensaver_idle) || 30, diff --git a/static/index.html b/static/index.html index 977a152..907c504 100644 --- a/static/index.html +++ b/static/index.html @@ -122,6 +122,10 @@ +
+ + +
diff --git a/web.go b/web.go index 812434c..1ad10f6 100644 --- a/web.go +++ b/web.go @@ -404,7 +404,7 @@ func (s *WebServer) handleRender(w http.ResponseWriter, r *http.Request) { kc.Background = bg } - img := RenderKeyToImage(kc, keySize) + img := RenderKeyToImage(kc, keySize, s.cfg.ShowLabelBackground) w.Header().Set("Content-Type", "image/png") w.Header().Set("Cache-Control", "no-cache")