sway/get_tree.go
2023-10-07 16:21:49 +02:00

24 lines
356 B
Go

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
}