sway/get_tree.go

24 lines
356 B
Go
Raw Normal View History

2023-10-07 16:21:49 +02:00
package sway
import (
"context"
"encoding/json"
"os/exec"
)
func GetTree(ctx context.Context) (*Node, error) {
cmd := exec.CommandContext(ctx, "swaymsg", "-t", "get_tree")
data, err := cmd.Output()
if err != nil {
return nil, err
}
var root Node
if err := json.Unmarshal(data, &root); err != nil {
return nil, err
}
return &root, nil
}