GetWorkspaces implemented
This commit is contained in:
parent
489f32e0c3
commit
5a556ec6c9
23
get_workspaces.go
Normal file
23
get_workspaces.go
Normal file
@ -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
|
||||
}
|
18
get_workspaces_test.go
Normal file
18
get_workspaces_test.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
7
node.go
7
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
|
||||
|
Loading…
Reference in New Issue
Block a user