Skip to content

Commit ebff8ba

Browse files
committed
Added DBus to docs
1 parent 1f16b06 commit ebff8ba

File tree

5 files changed

+72
-32
lines changed

5 files changed

+72
-32
lines changed

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,29 @@ The actions you can have on a button are:
5454
- `url`: opens a url in your default browser via xdg
5555
- `brightness`: set the brightness of the streamdeck as a percentage
5656
- `switch_page`: change the active page on the streamdeck
57+
58+
59+
### D-Bus
60+
61+
There is a D-Bus interface built into the daemon, the service name and interface for D-Bus are `com.thejonsey.streamdeck` and `com/thejonsey/streamdeck` respectively, and is made up of the following methods/signals
62+
63+
#### Methods
64+
65+
- GetConfig - returns the current running config
66+
- SetConfig - sets the config, without saving to disk, takes in Stringified json, returns an error if anything breaks
67+
- ReloadConfig - reloads the config from disk
68+
- GetDeckInfo - Returns information about the active streamdeck in the format of
69+
```json
70+
{
71+
"icon_size": 72,
72+
"rows": 3,
73+
"cols": 5,
74+
"page": 0
75+
}
76+
```
77+
- SetPage - Set the page on the streamdeck to the number passed to it, returns an error if anything breaks
78+
- CommitConfig - Commits the currently active config to disk, returns an error if anything breaks
79+
80+
#### Signals
81+
82+
- Page - sends the number of the page switched to on the StreamDeck

dbus.go

+41-28
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,40 @@ import (
44
"encoding/json"
55
"fmt"
66
"github.com/godbus/dbus/v5"
7-
"github.com/godbus/dbus/v5/introspect"
87
"log"
98
"os"
109
)
1110

12-
const intro = `
13-
<node>
14-
<interface name="com.thejonsey.streamdeckd">
15-
<method name="GetDeckInfo">
16-
<arg direction="out" type="s"/>
17-
</method>
18-
<method name="GetConfig">
19-
<arg direction="out" type="s"/>
20-
</method>
21-
<method name="ReloadConfig">
22-
</method>
23-
<method name="SetPage">
24-
<arg direction="in" type"i"/>
25-
</method>
26-
<method name="SetConfig">
27-
<arg direction="in" type="s"/>
28-
</method>
29-
<method name="CommitConfig">
30-
</method>
31-
</interface>` + introspect.IntrospectDataString + `</node> `
11+
//const intro = `
12+
//<node>
13+
// <interface name="com.thejonsey.streamdeckd">
14+
// <method name="GetDeckInfo">
15+
// <arg direction="out" type="s"/>
16+
// </method>
17+
// <method name="GetConfig">
18+
// <arg direction="out" type="s"/>
19+
// </method>
20+
// <method name="ReloadConfig">
21+
// </method>
22+
// <method name="SetPage">
23+
// <arg direction="in" type"i"/>
24+
// </method>
25+
// <method name="SetConfig">
26+
// <arg direction="in" type="s"/>
27+
// </method>
28+
// <method name="CommitConfig">
29+
// </method>
30+
// </interface>` + introspect.IntrospectDataString + `</node> `
31+
32+
var conn *dbus.Conn
33+
34+
var s *StreamDeckDBus
3235

3336
type StreamDeckDBus struct {
3437
Cols int `json:"cols,omitempty"`
3538
Rows int `json:"rows,omitempty"`
36-
IconSize uint `json:"icon_size,omitempty"`
39+
IconSize int `json:"icon_size,omitempty"`
40+
Page int `json:"page"`
3741
}
3842

3943
func (s StreamDeckDBus) GetDeckInfo() (string, *dbus.Error) {
@@ -82,20 +86,20 @@ func (StreamDeckDBus) CommitConfig() *dbus.Error {
8286
}
8387

8488
func InitDBUS() {
85-
conn, err := dbus.SessionBus()
89+
var err error
90+
conn, err = dbus.SessionBus()
8691
if err != nil {
8792
log.Println(err)
8893
}
8994
defer conn.Close()
9095

91-
s := StreamDeckDBus{
96+
s = &StreamDeckDBus{
9297
Cols: int(dev.Columns),
9398
Rows: int(dev.Rows),
94-
IconSize: dev.Pixels,
99+
IconSize: int(dev.Pixels),
100+
Page: p,
95101
}
96-
conn.Export(s, "/com/thejonsey/streamdeckd", "com.thejonsey.streamdeckd")
97-
conn.Export(introspect.Introspectable(intro), "/com/thejonsey/streamdeckd",
98-
"org.freedesktop.DBus.Introspectable")
102+
conn.ExportAll(s, "/com/thejonsey/streamdeckd", "com.thejonsey.streamdeckd")
99103
reply, err := conn.RequestName("com.thejonsey.streamdeckd",
100104
dbus.NameFlagDoNotQueue)
101105
if err != nil {
@@ -106,4 +110,13 @@ func InitDBUS() {
106110
os.Exit(1)
107111
}
108112
select {}
113+
}
114+
115+
func EmitPage(page int) {
116+
if conn != nil {
117+
conn.Emit("/com/thejonsey/streamdeckd", "com.thejonsey.streamdeckd.Page", page)
118+
}
119+
if s != nil {
120+
s.Page = page
121+
}
109122
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.14
44

55
require (
66
github.com/fogleman/gg v1.3.0
7-
github.com/godbus/dbus/v5 v5.0.3
7+
github.com/godbus/dbus/v5 v5.0.4-0.20200513180336-df5ef3eb7cca
88
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
99
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
1010
github.com/unix-streamdeck/streamdeck v0.0.0-20200727161137-d2d416a422d2

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
2525
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
2626
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
2727
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
28-
github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME=
29-
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
28+
github.com/godbus/dbus/v5 v5.0.4-0.20200513180336-df5ef3eb7cca h1:ewc47M3S8MAZgSO1yEnPrbmHjtQz6caAhYWOQzPHBok=
29+
github.com/godbus/dbus/v5 v5.0.4-0.20200513180336-df5ef3eb7cca/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
3030
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
3131
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
3232
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=

interface.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func SetKey(currentKey *Key, i int) {
4848
} else {
4949
img, err := LoadImage(currentKey.Icon)
5050
if err != nil {
51-
log.Fatal(err)
51+
log.Panic(err)
5252
}
5353
currentKey.Buff = img
5454
}
@@ -92,6 +92,7 @@ func SetPage(config *Config, page int, dev streamdeck.Device) {
9292
SetImage(currentKey.Buff, i, p, dev)
9393
}
9494
}
95+
EmitPage(p)
9596
}
9697

9798
func HandleInput(key *Key, page int, index int, dev streamdeck.Device) {

0 commit comments

Comments
 (0)