mirror of
https://github.com/Luzifer/streamdeck.git
synced 2024-12-20 17:51:21 +00:00
Add support for over/underlays
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
05c9852c24
commit
eb65da6377
3 changed files with 47 additions and 14 deletions
|
@ -19,7 +19,9 @@ type config struct {
|
|||
}
|
||||
|
||||
type page struct {
|
||||
Keys map[int]keyDefinition `yaml:"keys"`
|
||||
Keys map[int]keyDefinition `yaml:"keys"`
|
||||
Overlay string `yaml:"overlay"`
|
||||
Underlay string `yaml:"underlay"`
|
||||
}
|
||||
|
||||
type keyDefinition struct {
|
||||
|
|
|
@ -167,7 +167,7 @@ func main() {
|
|||
offTimer.Reset(userConfig.DisplayOffTime)
|
||||
}
|
||||
|
||||
kd, ok := activePage.Keys[evt.Key]
|
||||
kd, ok := activePage.GetKeyDefinitions(userConfig)[evt.Key]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ func main() {
|
|||
continue
|
||||
}
|
||||
|
||||
var nextPage = userConfig.DefaultPage
|
||||
nextPage := userConfig.DefaultPage
|
||||
if _, ok := userConfig.Pages[activePageName]; ok {
|
||||
nextPage = activePageName
|
||||
}
|
||||
|
@ -229,19 +229,16 @@ func togglePage(page string) error {
|
|||
activePageCtx, activePageCtxCancel = context.WithCancel(context.Background())
|
||||
sd.ClearAllKeys()
|
||||
|
||||
for idx := range activePage.Keys {
|
||||
if activePage.Keys[idx].Display.Type == "" {
|
||||
for idx, kd := range activePage.GetKeyDefinitions(userConfig) {
|
||||
if kd.Display.Type == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
go func(idx int) {
|
||||
var (
|
||||
kd = activePage.Keys[idx]
|
||||
keyLogger = log.WithFields(log.Fields{
|
||||
"key": idx,
|
||||
"page": activePageName,
|
||||
})
|
||||
)
|
||||
go func(idx int, kd keyDefinition) {
|
||||
keyLogger := log.WithFields(log.Fields{
|
||||
"key": idx,
|
||||
"page": activePageName,
|
||||
})
|
||||
|
||||
if err := callDisplayElement(activePageCtx, idx, kd); err != nil {
|
||||
keyLogger.WithError(err).Error("Unable to execute display element")
|
||||
|
@ -250,7 +247,7 @@ func togglePage(page string) error {
|
|||
keyLogger.WithError(err).Error("Unable to execute error display element")
|
||||
}
|
||||
}
|
||||
}(idx)
|
||||
}(idx, kd)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
34
cmd/streamdeck/page.go
Normal file
34
cmd/streamdeck/page.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
func (p page) GetKeyDefinitions(cfg config) map[int]keyDefinition {
|
||||
var (
|
||||
defMaps []map[int]keyDefinition
|
||||
result = make(map[int]keyDefinition)
|
||||
)
|
||||
|
||||
// First process underlay if defined
|
||||
if p.Underlay != "" {
|
||||
defMaps = append(defMaps, cfg.Pages[p.Underlay].Keys)
|
||||
}
|
||||
|
||||
// Process current definition
|
||||
defMaps = append(defMaps, p.Keys)
|
||||
|
||||
// Last process overlay if defined
|
||||
if p.Overlay != "" {
|
||||
defMaps = append(defMaps, cfg.Pages[p.Overlay].Keys)
|
||||
}
|
||||
|
||||
// Assemble combination of keys
|
||||
for _, pageDef := range defMaps {
|
||||
for idx, kd := range pageDef {
|
||||
if kd.Display.Type == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
result[idx] = kd
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
Loading…
Reference in a new issue