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:
parent
bee78d006c
commit
d5d2169d53
2 changed files with 23 additions and 5 deletions
|
@ -1,6 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/pkg/errors"
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerAction("page", actionPage{})
|
registerAction("page", actionPage{})
|
||||||
|
@ -9,10 +13,18 @@ func init() {
|
||||||
type actionPage struct{}
|
type actionPage struct{}
|
||||||
|
|
||||||
func (actionPage) Execute(attributes map[string]interface{}) error {
|
func (actionPage) Execute(attributes map[string]interface{}) error {
|
||||||
name, ok := attributes["name"].(string)
|
name, nameOk := attributes["name"].(string)
|
||||||
if !ok {
|
relative, relativeOk := attributes["relative"].(int)
|
||||||
return errors.New("No page name supplied")
|
|
||||||
|
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")
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ var (
|
||||||
activePageCtxCancel context.CancelFunc
|
activePageCtxCancel context.CancelFunc
|
||||||
activePageName string
|
activePageName string
|
||||||
activeLoops []refreshingDisplayElement
|
activeLoops []refreshingDisplayElement
|
||||||
|
pageStack []string
|
||||||
|
|
||||||
sd *streamdeck.Client
|
sd *streamdeck.Client
|
||||||
|
|
||||||
|
@ -245,6 +246,11 @@ func togglePage(page string) error {
|
||||||
}(idx, kd)
|
}(idx, kd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pageStack = append([]string{page}, pageStack...)
|
||||||
|
if len(pageStack) > 100 {
|
||||||
|
pageStack = pageStack[:100]
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue