1
0
Fork 0
mirror of https://github.com/Luzifer/streamdeck.git synced 2024-12-20 17:51:21 +00:00

Implement relative movement through page-stack

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-10-30 20:00:01 +01:00
parent bee78d006c
commit d5d2169d53
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
2 changed files with 23 additions and 5 deletions

View file

@ -1,6 +1,10 @@
package main
import "github.com/pkg/errors"
import (
"math"
"github.com/pkg/errors"
)
func init() {
registerAction("page", actionPage{})
@ -9,10 +13,18 @@ func init() {
type actionPage struct{}
func (actionPage) Execute(attributes map[string]interface{}) error {
name, ok := attributes["name"].(string)
if !ok {
return errors.New("No page name supplied")
name, nameOk := attributes["name"].(string)
relative, relativeOk := attributes["relative"].(int)
if nameOk && name != "" {
return errors.Wrap(togglePage(name), "switch page")
}
return errors.Wrap(togglePage(name), "Unable to switch page")
if absRel := int(math.Abs(float64(relative))); relativeOk && absRel != 0 && absRel < len(pageStack) {
nextPage := pageStack[absRel]
pageStack = pageStack[absRel+1:]
return errors.Wrap(togglePage(nextPage), "switch relative page")
}
return errors.New("no page name or relative move supplied")
}

View file

@ -34,6 +34,7 @@ var (
activePageCtxCancel context.CancelFunc
activePageName string
activeLoops []refreshingDisplayElement
pageStack []string
sd *streamdeck.Client
@ -245,6 +246,11 @@ func togglePage(page string) error {
}(idx, kd)
}
pageStack = append([]string{page}, pageStack...)
if len(pageStack) > 100 {
pageStack = pageStack[:100]
}
return nil
}