diff --git a/get_workspaces.go b/get_workspaces.go new file mode 100644 index 0000000..764e5b5 --- /dev/null +++ b/get_workspaces.go @@ -0,0 +1,23 @@ +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 +} diff --git a/get_workspaces_test.go b/get_workspaces_test.go new file mode 100644 index 0000000..776f1ab --- /dev/null +++ b/get_workspaces_test.go @@ -0,0 +1,18 @@ +package sway + +import ( + "context" + "fmt" + "testing" +) + +func TestGetWorkspaces(t *testing.T) { + workspaces, err := GetWorkspaces(context.Background()) + if err != nil { + t.Fatal(err) + } + + for _, workspace := range workspaces { + fmt.Println(workspace.Type, workspace.Output, workspace.Name) + } +} diff --git a/node.go b/node.go index 6c6ad44..7ff503f 100644 --- a/node.go +++ b/node.go @@ -4,7 +4,7 @@ type Node struct { ID NodeID `json:"id"` Type NodeType `json:"type"` Orientation Orientation `json:"orientation"` - Percentage float64 `json:"percent"` + Percentage *float64 `json:"percent"` Urgent bool `json:"urgent"` Marks []string `json:"marks"` Focused bool `json:"focused"` @@ -47,6 +47,11 @@ type Node struct { LayerShellSurfaces []LayerShellSurface `json:"layer_shell_surfaces"` CurrentWorkspace string `json:"current_workspace"` CurrentMode OutputMode `json:"current_mode"` + + // NodeTypeWorkspace only + WorkspaceNumber int `json:"num"` + Output string `json:"output"` + Representation string `json:"representation"` } type NodeID int64