sway/types.go

245 lines
7.1 KiB
Go
Raw Normal View History

2024-02-14 15:12:39 +01:00
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)
}
2024-02-14 15:26:04 +01:00
type Output struct {
Name string `json:"name"`
Make string `json:"make"`
Model string `json:"model"`
Serial string `json:"serial"`
Active bool `json:"active"`
DPMS bool `json:"dpms"`
Power bool `json:"power"`
Scale float64 `json:"scale"`
SubPixelHinting SubPixelHinting `json:"subpixel_hinting"`
Transform Transform `json:"transform"`
CurrentWorkspace string `json:"current_workspace"`
Modes []Mode `json:"modes"`
CurrentMode Mode `json:"current_mode"`
Rect Rectangle `json:"rect"`
}
func (o Output) String() string {
data, _ := json.MarshalIndent(o, "", "\t")
return string(data)
}
2024-02-14 15:12:39 +01:00
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"
)
2024-02-14 15:26:04 +01:00
type SubPixelHinting = string
const (
SubPixelHintingRGB SubPixelHinting = "rgb"
SubPixelHintingBGR SubPixelHinting = "bgr"
SubPixelHintingVRGB SubPixelHinting = "vrgb"
SubPixelHintingVBGR SubPixelHinting = "vbgr"
SubPixelHintingNone SubPixelHinting = "none"
)
type Transform = string
const (
Transform90 Transform = "90"
Transform180 Transform = "180"
Transform270 Transform = "270"
TransformFlipped90 Transform = "flipped-90"
TransformFlipped180 Transform = "flipped-180"
TransformFlipped270 Transform = "flipped-270"
)
2024-02-14 15:12:39 +01:00
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
}
2024-02-14 15:26:04 +01:00
type Mode struct {
Width int `json:"width"`
Height int `json:"height"`
Refresh int `json:"refresh"`
}