go-i3/workspaces.go

36 lines
944 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package i3
import "encoding/json"
// WorkspaceID is an i3-internal ID for the node, which can be used to identify
// workspaces within the IPC interface.
type WorkspaceID int64
// Workspace describes an i3 workspace.
//
// See https://i3wm.org/docs/ipc.html#_workspaces_reply for more details.
type Workspace struct {
ID WorkspaceID `json:"id"`
Num int64 `json:"num"`
Name string `json:"name"`
Visible bool `json:"visible"`
Focused bool `json:"focused"`
Urgent bool `json:"urgent"`
Rect Rect `json:"rect"`
Output string `json:"output"`
}
// GetWorkspaces returns i3s current workspaces.
//
// GetWorkspaces is supported in i3 ≥ v4.0 (2011-07-31).
func GetWorkspaces() ([]Workspace, error) {
reply, err := roundTrip(messageTypeGetWorkspaces, nil)
if err != nil {
return nil, err
}
var ws []Workspace
err = json.Unmarshal(reply.Payload, &ws)
return ws, err
}