Skip to content

Commit

Permalink
Added executeDBusMethod action
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Jul 19, 2019
1 parent aeb60d5 commit 3e91889
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions deck.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"log"
"os/exec"
"strings"

"github.com/godbus/dbus"
)

type Deck struct {
Expand All @@ -26,6 +28,14 @@ func LoadDeck(deck string) (*Deck, error) {
return &d, nil
}

// executes a dbus method
func executeDBusMethod(object, path, method, args string) {
call := dbusConn.Object(object, dbus.ObjectPath(path)).Call(method, 0, args)
if call.Err != nil {
log.Printf("dbus call failed: %s", call.Err)
}
}

// executes a command
func executeCommand(cmd string) {
args := strings.Split(cmd, " ")
Expand Down Expand Up @@ -54,6 +64,9 @@ func (d *Deck) triggerAction(index uint8) {
deck = d
deck.updateWidgets()
}
if a.DBus.Method != "" {
executeDBusMethod(a.DBus.Object, a.DBus.Path, a.DBus.Method, a.DBus.Value)
}
if a.Exec != "" {
executeCommand(a.Exec)
}
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"time"

"github.com/davecgh/go-spew/spew"
"github.com/godbus/dbus"
"github.com/muesli/streamdeck"
)

var (
dev streamdeck.Device
dbusConn *dbus.Conn
deck *Deck
x Xorg
recentWindows []Window
Expand Down Expand Up @@ -66,6 +68,11 @@ func main() {
log.Fatal(err)
}

dbusConn, err = dbus.SessionBus()
if err != nil {
panic(err)
}

x = Connect(os.Getenv("DISPLAY"))
defer x.Close()

Expand Down

0 comments on commit 3e91889

Please sign in to comment.