Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/custom-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ import "github.com/unix-streamdeck/api/v2"
func GetModule() api.Module {
return api.Module{
Name: "MyModule",
NewIcon: func() api.IconHandler { return &MyIconHandler{} },
NewKey: func() api.KeyHandler { return &MyKeyHandler{} },
IconFields: []api.Field{ /* ... */ },
KeyFields: []api.Field{ /* ... */ },
NewForeground: func() api.ForegroundHandler { return &MyForegroundHandler{} },
NewInput: func() api.InputHandler { return &MyInputHandler{} },
ForegroundFields: []api.Field{ /* ... */ },
InputFields: []api.Field{ /* ... */ },
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/linuxdeepin/go-x11-client v0.0.0-20240415051504-c8e43d028ff9
github.com/shirou/gopsutil/v3 v3.24.5
github.com/the-jonsey/pulseaudio v0.0.2-0.20260222211608-58a869b098fe
github.com/unix-streamdeck/api/v2 v2.0.15
github.com/unix-streamdeck/api/v2 v2.0.16
github.com/unix-streamdeck/driver v0.0.0-20260313153150-8a1327d02063
golang.org/x/sync v0.20.0
golang.org/x/sys v0.42.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ github.com/tklauser/go-sysconf v0.3.16 h1:frioLaCQSsF5Cy1jgRBrzr6t502KIIwQ0MArYI
github.com/tklauser/go-sysconf v0.3.16/go.mod h1:/qNL9xxDhc7tx3HSRsLWNnuzbVfh3e7gh/BmM179nYI=
github.com/tklauser/numcpus v0.11.0 h1:nSTwhKH5e1dMNsCdVBukSZrURJRoHbSEQjdEbY+9RXw=
github.com/tklauser/numcpus v0.11.0/go.mod h1:z+LwcLq54uWZTX0u/bGobaV34u6V7KNlTZejzM6/3MQ=
github.com/unix-streamdeck/api/v2 v2.0.15 h1:YugCSVZC0d+e/7jvCBamZEubgmw3jOiGm717jl242gg=
github.com/unix-streamdeck/api/v2 v2.0.15/go.mod h1:trzV1CEDHjSi9DAIkXOFhJyPETq7xCjg2sWjY6VtKYk=
github.com/unix-streamdeck/api/v2 v2.0.16 h1:d6CP2VJ9lKlIIyKD5ZRHsuPKC1yiyI7827IBLx6aI8c=
github.com/unix-streamdeck/api/v2 v2.0.16/go.mod h1:trzV1CEDHjSi9DAIkXOFhJyPETq7xCjg2sWjY6VtKYk=
github.com/unix-streamdeck/driver v0.0.0-20260313153150-8a1327d02063 h1:lpAT1zkHZHlpF/QC4y1jId4iw9y4uBSvP15JWDMRLlg=
github.com/unix-streamdeck/driver v0.0.0-20260313153150-8a1327d02063/go.mod h1:RiXT8GuYv4NQ0vZJ6eP2ksCD60vSYMD4wQFabALEbis=
github.com/unix-streamdeck/gg v0.0.0-20260313120600-9d60d38ce9f9 h1:sVzoJvwd1QtjQPsfsRYM+R7Ff0TxeWI6GunRqNH+w3U=
Expand Down
15 changes: 4 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ var isRunning = true

func main() {
log.Default().SetFlags(log.Lshortfile | log.Ltime)
log.Default().SetPrefix("(global) ")
checkDuplicateStreamdeckdInstance()
configPtr := flag.String("config", "", "Path to config file")
flag.Parse()
streamdeckd.SetConfigPath(*configPtr)
cleanupHook()
defer HandlePanic()
go streamdeckd.InitDBUS()
go streamdeckd.UpdateApplication()
go streamdeckd.EnableVirtualKeyboard()
examples.RegisterBaseModules()
streamdeckd.LoadConfig()
streamdeckd.Devs = make(map[string]*streamdeckd.VirtualDev)
streamdeckd.Devs = make(map[string]streamdeckd.IVirtualDev)
screensaverDbus, err := streamdeckd.ConnectScreensaver()
if err != nil {
log.Println(err)
Expand Down Expand Up @@ -62,13 +62,6 @@ func attemptConnection() {
}
}

func HandlePanic() {
if err := recover(); err != nil {
log.Println("panic occurred:", err)
shutdown()
}
}

func cleanupHook() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGSTOP, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGKILL, syscall.SIGQUIT, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGINT)
Expand All @@ -81,9 +74,9 @@ func cleanupHook() {
func shutdown() {
log.Println("Cleaning up")
isRunning = false
go streamdeckd.UnmountHandlers()
streamdeckd.UnmountHandlers()
for s := range streamdeckd.Devs {
streamdeckd.Devs[s].Stop()
streamdeckd.Devs[s].Close()
}
os.Exit(0)
}
33 changes: 33 additions & 0 deletions streamdeckd/application_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package streamdeckd

import "log"

type IApplicationManager interface {
SetApplication(application string)
AttachListener(listener func(application string))
GetApplication() string
}

type ApplicationManager struct {
listeners []func(application string)
activeApplication string
}

func (am *ApplicationManager) SetApplication(application string) {

if am.activeApplication != application {
log.Println("Application updated to: " + application)
am.activeApplication = application
for _, listener := range am.listeners {
go listener(application)
}
}
}

func (am *ApplicationManager) AttachListener(listener func(application string)) {
am.listeners = append(am.listeners, listener)
}

func (am *ApplicationManager) GetApplication() string {
return am.activeApplication
}
230 changes: 230 additions & 0 deletions streamdeckd/backgrounder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
package streamdeckd

import (
"image"
"log"

"github.com/unix-streamdeck/api/v2"
)

type IBackgrounder interface {
SetLcdBackground(backgrounder api.LcdBackgrounder)
SetKeyBackground(backgrounder api.KeyGridBackgrounder)
SetIndividualLcdBackground(backgrounder api.LcdSegmentBackgrounder, index int)
SetIndividualKeyBackground(backgrounder api.KeyBackgrounder, index int)
AttachPageChangeListener()
}

type Backgrounder struct {
vdev IVirtualDev
}

func (bg *Backgrounder) SetLcdBackground(backgrounder api.LcdBackgrounder) {
if backgrounder.GetTouchPanelBackground() == "" {
return
}

if backgrounder.GetTouchPanelBackgroundHandler() == nil {
var handler api.BackgroundHandler

for _, module := range modules {
if module.Name == backgrounder.GetTouchPanelBackground() {
handler = module.NewBackground()
}
}

backgrounder.SetTouchPanelBackgroundHandler(handler)
}

if backgrounder.GetTouchPanelBackgroundHandlerFields() != nil {
go backgrounder.GetTouchPanelBackgroundHandler().StartGrid(backgrounder.GetTouchPanelBackgroundHandlerFields(), api.LCD, *bg.vdev.SdInfo(), func(imgs []image.Image) {
if len(imgs) == bg.vdev.SdInfo().KnobCols {
backgrounder.SetTouchPanelBackgroundBuff(imgs)

for u := range imgs {
bg.vdev.SetPanelBackground(u, bg.vdev.PageManager().GetPage())
}
}
})
return
}

if backgrounder.GetTouchPanelBackgroundBuff() != nil {
return
}

img, err := LoadImage(backgrounder.GetTouchPanelBackground())
if err != nil {
bg.vdev.Logger().Println(err)
return
}

img = api.ResizeImageWH(img, bg.vdev.SdInfo().LcdBackgroundWidth, bg.vdev.SdInfo().LcdBackgroundHeight)

imgs := bg.vdev.SdInfo().SplitBackgroundImage(img, api.LCD)

backgrounder.SetTouchPanelBackgroundBuff(imgs)

for index, _ := range imgs {
bg.vdev.SetPanelBackground(index, bg.vdev.PageManager().GetPage())
}
}

func (bg *Backgrounder) SetKeyBackground(backgrounder api.KeyGridBackgrounder) {
if backgrounder.GetKeyGridBackground() == "" {
return
}

if backgrounder.GetKeyGridBackgroundHandler() == nil {
var handler api.BackgroundHandler

for _, module := range modules {
if module.Name == backgrounder.GetKeyGridBackground() {
handler = module.NewBackground()
}
}

backgrounder.SetKeyGridBackgroundHandler(handler)
}

if backgrounder.GetKeyGridBackgroundHandler() != nil {
go backgrounder.GetKeyGridBackgroundHandler().StartGrid(backgrounder.GetKeyGridBackgroundHandlerFields(), api.KEY, *bg.vdev.SdInfo(), func(imgs []image.Image) {
if len(imgs) == bg.vdev.SdInfo().Cols*bg.vdev.SdInfo().Rows {
backgrounder.SetKeyGridBackgroundBuff(imgs)

for u := range imgs {
bg.vdev.SetKeyBackground(u, bg.vdev.PageManager().GetPage())
}
}
})
return
}

if backgrounder.GetKeyGridBackgroundBuff() != nil {
return
}

img, err := LoadImage(backgrounder.GetKeyGridBackground())
if err != nil {
bg.vdev.Logger().Println(err)
return
}

img = api.ResizeImageWH(img, bg.vdev.SdInfo().KeyGridBackgroundWidth, bg.vdev.SdInfo().KeyGridBackgroundHeight)

imgs := bg.vdev.SdInfo().SplitBackgroundImage(img, api.KEY)

backgrounder.SetKeyGridBackgroundBuff(imgs)

for index, _ := range imgs {
bg.vdev.SetKeyBackground(index, bg.vdev.PageManager().GetPage())
}
}

func (bg *Backgrounder) SetIndividualLcdBackground(backgrounder api.LcdSegmentBackgrounder, index int) {
if backgrounder.GetTouchPanelBackground() == "" {
return
}

if backgrounder.GetTouchPanelBackgroundHandler() == nil {
var handler api.BackgroundHandler

for _, module := range modules {
if module.Name == backgrounder.GetTouchPanelBackground() {
handler = module.NewBackground()
}
}

backgrounder.SetTouchPanelBackgroundHandler(handler)
}

if backgrounder.GetTouchPanelBackgroundHandlerFields() != nil {
go backgrounder.GetTouchPanelBackgroundHandler().Start(backgrounder.GetTouchPanelBackgroundHandlerFields(), api.LCD, *bg.vdev.SdInfo(), func(img image.Image) {
backgrounder.SetTouchPanelBackgroundBuff(img)

bg.vdev.SetPanelBackground(index, bg.vdev.PageManager().GetPage())
})
return
}

if backgrounder.GetTouchPanelBackgroundBuff() != nil {
return
}

img, err := LoadImage(backgrounder.GetTouchPanelBackground())
if err != nil {
bg.vdev.Logger().Println(err)
return
}

img = api.ResizeImageWH(img, bg.vdev.SdInfo().LcdWidth, bg.vdev.SdInfo().LcdHeight)

backgrounder.SetTouchPanelBackgroundBuff(img)

bg.vdev.SetPanelBackground(index, bg.vdev.PageManager().GetPage())
}

func (bg *Backgrounder) SetIndividualKeyBackground(backgrounder api.KeyBackgrounder, index int) {
if backgrounder.GetKeyBackground() == "" {
return
}

if backgrounder.GetKeyBackgroundHandler() == nil {
var handler api.BackgroundHandler

for _, module := range modules {
if module.Name == backgrounder.GetKeyBackground() {
handler = module.NewBackground()
}
}

backgrounder.SetKeyBackgroundHandler(handler)
}

if backgrounder.GetKeyBackgroundHandler() != nil {
go backgrounder.GetKeyBackgroundHandler().Start(backgrounder.GetKeyBackgroundHandlerFields(), api.KEY, *bg.vdev.SdInfo(), func(img image.Image) {
backgrounder.SetKeyBackgroundBuff(img)

bg.vdev.SetKeyBackground(index, bg.vdev.PageManager().GetPage())
})
return
}

if backgrounder.GetKeyBackgroundBuff() != nil {
return
}

img, err := LoadImage(backgrounder.GetKeyBackground())
if err != nil {
log.Println(err)
return
}

img = api.ResizeImage(img, bg.vdev.SdInfo().IconSize)

bg.vdev.SetKeyBackground(index, bg.vdev.PageManager().GetPage())
}

func (bg *Backgrounder) AttachPageChangeListener() {

bg.vdev.PageManager().AttachListener(func(newPage, _ int) {

currentPage := bg.vdev.Config().Pages[newPage]

go bg.SetKeyBackground(&currentPage)

go bg.SetLcdBackground(&currentPage)

for i := range currentPage.Keys {
key := &currentPage.Keys[i]

go bg.SetIndividualKeyBackground(key, i)
}

for i := range currentPage.Knobs {
knob := &currentPage.Knobs[i]

go bg.SetIndividualLcdBackground(knob, i)
}
})
}
Loading
Loading