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
|
@ -20,6 +20,8 @@ type config struct {
|
||||||
|
|
||||||
type page 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 {
|
type keyDefinition struct {
|
||||||
|
|
|
@ -167,7 +167,7 @@ func main() {
|
||||||
offTimer.Reset(userConfig.DisplayOffTime)
|
offTimer.Reset(userConfig.DisplayOffTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
kd, ok := activePage.Keys[evt.Key]
|
kd, ok := activePage.GetKeyDefinitions(userConfig)[evt.Key]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ func main() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var nextPage = userConfig.DefaultPage
|
nextPage := userConfig.DefaultPage
|
||||||
if _, ok := userConfig.Pages[activePageName]; ok {
|
if _, ok := userConfig.Pages[activePageName]; ok {
|
||||||
nextPage = activePageName
|
nextPage = activePageName
|
||||||
}
|
}
|
||||||
|
@ -229,19 +229,16 @@ func togglePage(page string) error {
|
||||||
activePageCtx, activePageCtxCancel = context.WithCancel(context.Background())
|
activePageCtx, activePageCtxCancel = context.WithCancel(context.Background())
|
||||||
sd.ClearAllKeys()
|
sd.ClearAllKeys()
|
||||||
|
|
||||||
for idx := range activePage.Keys {
|
for idx, kd := range activePage.GetKeyDefinitions(userConfig) {
|
||||||
if activePage.Keys[idx].Display.Type == "" {
|
if kd.Display.Type == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
go func(idx int) {
|
go func(idx int, kd keyDefinition) {
|
||||||
var (
|
keyLogger := log.WithFields(log.Fields{
|
||||||
kd = activePage.Keys[idx]
|
|
||||||
keyLogger = log.WithFields(log.Fields{
|
|
||||||
"key": idx,
|
"key": idx,
|
||||||
"page": activePageName,
|
"page": activePageName,
|
||||||
})
|
})
|
||||||
)
|
|
||||||
|
|
||||||
if err := callDisplayElement(activePageCtx, idx, kd); err != nil {
|
if err := callDisplayElement(activePageCtx, idx, kd); err != nil {
|
||||||
keyLogger.WithError(err).Error("Unable to execute display element")
|
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")
|
keyLogger.WithError(err).Error("Unable to execute error display element")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(idx)
|
}(idx, kd)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
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