Skip to content

Commit

Permalink
Align triggerAction's happy path to the left edge
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Feb 5, 2022
1 parent 0330766 commit 7e11327
Showing 1 changed file with 39 additions and 37 deletions.
76 changes: 39 additions & 37 deletions deck.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,45 +202,47 @@ func executeCommand(cmd string) {
// triggerAction triggers an action.
func (d *Deck) triggerAction(dev *streamdeck.Device, index uint8, hold bool) {
for _, w := range d.Widgets {
if w.Key() == index {
var a *ActionConfig
if hold {
a = w.ActionHold()
} else {
a = w.Action()
}
if w.Key() != index {
continue
}

var a *ActionConfig
if hold {
a = w.ActionHold()
} else {
a = w.Action()
}

if a == nil {
w.TriggerAction(hold)
continue
}

if a != nil {
// fmt.Println("Executing overloaded action")
if a.Deck != "" {
d, err := LoadDeck(dev, filepath.Dir(d.File), a.Deck)
if err != nil {
fmt.Fprintln(os.Stderr, "Can't load deck:", err)
return
}
if err := dev.Clear(); err != nil {
fatal(err)
return
}

deck = d
deck.updateWidgets()
}
if a.Keycode != "" {
emulateKeyPresses(a.Keycode)
}
if a.Paste != "" {
emulateClipboard(a.Paste)
}
if a.DBus.Method != "" {
executeDBusMethod(a.DBus.Object, a.DBus.Path, a.DBus.Method, a.DBus.Value)
}
if a.Exec != "" {
go executeCommand(a.Exec)
}
} else {
w.TriggerAction(hold)
if a.Deck != "" {
d, err := LoadDeck(dev, filepath.Dir(d.File), a.Deck)
if err != nil {
fmt.Fprintln(os.Stderr, "Can't load deck:", err)
return
}
if err := dev.Clear(); err != nil {
fatal(err)
return
}

deck = d
deck.updateWidgets()
}
if a.Keycode != "" {
emulateKeyPresses(a.Keycode)
}
if a.Paste != "" {
emulateClipboard(a.Paste)
}
if a.DBus.Method != "" {
executeDBusMethod(a.DBus.Object, a.DBus.Path, a.DBus.Method, a.DBus.Value)
}
if a.Exec != "" {
go executeCommand(a.Exec)
}
}
}
Expand Down

0 comments on commit 7e11327

Please sign in to comment.