package sway import ( "encoding/json" "errors" ) type NodeID int64 type Rectangle struct { X int `json:"x"` Y int `json:"y"` Width int `json:"width"` Height int `json:"height"` } func (r Rectangle) String() string { data, _ := json.MarshalIndent(r, "", "\t") return string(data) } type Workspace struct { Num int `json:"num"` Name string `json:"name"` Visible bool `json:"visible"` Focused bool `json:"focused"` Urgent bool `json:"urgent"` Rect Rectangle `json:"rect"` Output string `json:"output"` } func (w Workspace) String() string { data, _ := json.MarshalIndent(w, "", "\t") return string(data) } type WindowProperties struct { Title string `json:"title"` Instance string `json:"instance"` Class string `json:"class"` Role string `json:"window_role"` Transient NodeID `json:"transient_for"` } func (w WindowProperties) String() string { data, _ := json.MarshalIndent(w, "", "\t") return string(data) } type Node struct { ID NodeID `json:"id"` Name string `json:"name"` Type NodeType `json:"type"` Border BorderStyle `json:"border"` CurrentBorderWidth int `json:"current_border_width"` Layout Layout `json:"layout"` Orientation Orientation `json:"orientation"` Percent float64 `json:"percent"` Rect Rectangle `json:"rect"` WindowRect Rectangle `json:"window_rect"` DecoRect Rectangle `json:"deco_rect"` Geometry Rectangle `json:"geometry"` Urgent bool `json:"urgent"` Sticky bool `json:"sticky"` Marks []interface{} `json:"marks"` // TODO type Focused bool `json:"focused"` Focus []Node `json:"focus"` Nodes []Node `json:"nodes"` FloatingNodes []Node `json:"floating_nodes"` Representation string `json:"representation"` FullscreenMode FullscreenMode `json:"fullscreen_mode"` AppID string `json:"app_id"` PID int `json:"pid"` Visible bool `json:"visible"` Shell string `json:"shell"` InhibitIdle bool `json:"inhibit_idle"` Window int `json:"window"` WindowProperties WindowProperties `json:"window_properties"` // Undocumented fields. Use with caution! Num int `json:"num"` Output string `json:"output"` } func (n Node) String() string { data, _ := json.MarshalIndent(n, "", "\t") return string(data) } type NodeType = string const ( NodeTypeRoot NodeType = "root" NodeTypeOutput NodeType = "output" NodeTypeWorkspace NodeType = "workspace" NodeTypeContainer NodeType = "con" NodeTypeFloatingContainer NodeType = "floating_con" ) type BorderStyle = string const ( BorderStyleNormal BorderStyle = "normal" BorderStyleNone BorderStyle = "none" BorderStylePixel BorderStyle = "pixel" BorderStyleCSD BorderStyle = "csd" ) type Layout = string const ( LayoutSplitH Layout = "splith" LayoutSplitV Layout = "splitv" LayoutStacked Layout = "stacked" LayoutTabbed Layout = "tabbed" LayoutOutput Layout = "output" ) type Orientation = string const ( OrientationVertical Orientation = "vertical" OrientationHorizontal Orientation = "horizontal" OrientationNone Orientation = "none" ) type FullscreenMode = uint8 const ( FullscreenModeNone FullscreenMode = iota FullscreenModeWorkspace FullscreenMode = iota FullscreenModeGlobal FullscreenMode = iota ) type WorkspaceEventChange = string const ( WorkspaceEventChangeInit WorkspaceEventChange = "init" WorkspaceEventChangeEmpty WorkspaceEventChange = "empty" WorkspaceEventChangeFocus WorkspaceEventChange = "focus" WorkspaceEventChangeMove WorkspaceEventChange = "move" WorkspaceEventChangeRename WorkspaceEventChange = "rename" WorkspaceEventChangeUrgent WorkspaceEventChange = "urgent" WorkspaceEventChangeReload WorkspaceEventChange = "reload" ) type WindowEventChange = string const ( WindowEventChangeNew WindowEventChange = "new" WindowEventChangeClose WindowEventChange = "close" WindowEventChangeFocus WindowEventChange = "focus" WindowEventChangeTitle WindowEventChange = "title" WindowEventChangeFullscreenMode WindowEventChange = "fullscreen_mode" WindowEventChangeMove WindowEventChange = "move" WindowEventChangeFloating WindowEventChange = "floating" WindowEventChangeUrgent WindowEventChange = "urgent" WindowEventChangeMark WindowEventChange = "mark" ) type InputEventChange = string const ( InputEventChangeAdded InputEventChange = "added" InputEventChangeRemoved InputEventChange = "removed" InputEventChangeXKBKeymap InputEventChange = "xkb_kemap" InputEventChangeXKBLayout InputEventChange = "xkb_layout" InputEventChangeLibInputConfig InputEventChange = "libinput_config" ) type InputType = string const ( InputTypeKeyboard InputType = "keyboard" InputTypeMouse InputType = "mouse" ) type commandResult struct { Success bool `json:"success"` ParseError bool `json:"parse_error"` Error string `json:"error"` } func (r commandResult) String() string { data, _ := json.MarshalIndent(r, "", "\t") return string(data) } func (r commandResult) GetError() error { return errors.New(r.Error) } func (r commandResult) HasError() bool { return !r.Success }