sway/get_workspaces.go

24 lines
388 B
Go

package sway
import (
"context"
"encoding/json"
"os/exec"
)
func GetWorkspaces(ctx context.Context) ([]Node, error) {
cmd := exec.CommandContext(ctx, "swaymsg", "-t", "get_workspaces")
data, err := cmd.Output()
if err != nil {
return nil, err
}
var workspaces []Node
if err := json.Unmarshal(data, &workspaces); err != nil {
return nil, err
}
return workspaces, nil
}