1
0
Fork 0
mirror of https://github.com/Luzifer/streamdeck.git synced 2024-12-20 09:41:19 +00:00

Add support for over/underlays

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-09-20 02:41:09 +02:00
parent 05c9852c24
commit eb65da6377
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
3 changed files with 47 additions and 14 deletions

View file

@ -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 {

View file

@ -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
View 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
}