394 lines
12 KiB
Go
394 lines
12 KiB
Go
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 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)
|
|
}
|
|
|
|
type BarConfig struct {
|
|
ID string `json:"id"`
|
|
Mode BarMode `json:"mode"`
|
|
Position BarPosition `json:"position"`
|
|
StatusCommand string `json:"status_command"`
|
|
Font string `json:"font"`
|
|
WorkspaceButtons bool `json:"workspace_buttons"`
|
|
WorkspaceMinWidth int `json:"workspace_min_width"`
|
|
BindingModeIndicator bool `json:"binding_mode_indicator"`
|
|
Colors BarColors `json:"colors"`
|
|
Gaps BarGaps `json:"gaps"`
|
|
BarHeight int `json:"bar_height"`
|
|
StatusPadding int `json:"status_padding"`
|
|
StatusEdgePadding int `json:"status_edge_padding"`
|
|
}
|
|
|
|
func (bc BarConfig) String() string {
|
|
data, _ := json.MarshalIndent(bc, "", "\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 []string `json:"marks"`
|
|
Focused bool `json:"focused"`
|
|
Focus []NodeID `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"`
|
|
|
|
// The following fields are undocumented. Use with caution!
|
|
// They are included in sway as well as in i3 for years though
|
|
Num int `json:"num"` // workspace number
|
|
Output string `json:"output"` // output port name
|
|
}
|
|
|
|
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 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"
|
|
)
|
|
|
|
type BarMode = string
|
|
|
|
const (
|
|
BarModeDock BarMode = "dock"
|
|
BarModeHide BarMode = "hide"
|
|
barModeInvisible BarMode = "invisible"
|
|
)
|
|
|
|
type BarPosition = string
|
|
|
|
const (
|
|
BarPositionTop BarPosition = "top"
|
|
BarPositionBottom BarPosition = "bottom"
|
|
)
|
|
|
|
type InputDeviceType = string
|
|
|
|
const (
|
|
InputDeviceTypeKeyboard InputDeviceType = "keyboard"
|
|
InputDeviceTypePointer InputDeviceType = "pointer"
|
|
InputDeviceTypeTouch InputDeviceType = "touch"
|
|
InputDeviceTypeTabletTool InputDeviceType = "tablet_tool"
|
|
InputDeviceTypeTabletPad InputDeviceType = "tablet_pad"
|
|
InputDeviceTypeSwitch InputDeviceType = "switch"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
type Mode struct {
|
|
Width int `json:"width"`
|
|
Height int `json:"height"`
|
|
Refresh int `json:"refresh"`
|
|
}
|
|
|
|
type BarColors struct {
|
|
Background string `json:"background"`
|
|
Statusline string `json:"statusline"`
|
|
Separator string `json:"separator"`
|
|
FocusedBackground string `json:"focused_background"`
|
|
FocusedStatusline string `json:"focused_statusline"`
|
|
FocusedSeparator string `json:"focused_separator"`
|
|
FocusedWorkspaceText string `json:"focused_workspace_text"`
|
|
FocusedWorkspaceBackground string `json:"focused_workspace_bg"`
|
|
FocusedWorkspaceBorder string `json:"focused_workspace_border"`
|
|
ActiveWorkspaceText string `json:"active_workspace_text"`
|
|
ActiveWorkspaceBackground string `json:"active_workspace_bg"`
|
|
ActiveWorkspaceBorder string `json:"active_workspace_border"`
|
|
InactiveWorkspaceText string `json:"inactive_workspace_text"`
|
|
InactiveWorkspaceBackground string `json:"inactive_workspace_bg"`
|
|
InactiveWorkspaceBorder string `json:"inactive_workspace_border"`
|
|
UrgentWorkspaceText string `json:"urgent_workspace_text"`
|
|
UrgentWorkspaceBackground string `json:"urgent_workspace_bg"`
|
|
UrgentWorkspaceBorder string `json:"urgent_workspace_border"`
|
|
BindingModeText string `json:"binding_mode_text"`
|
|
BindingModeBackground string `json:"binding_mode_bg"`
|
|
BindingModeBorder string `json:"binding_mode_border"`
|
|
}
|
|
|
|
type BarGaps struct {
|
|
Top int `json:"top"`
|
|
Right int `json:"right"`
|
|
Bottom int `json:"bottom"`
|
|
Left int `json:"left"`
|
|
}
|
|
|
|
type Version struct {
|
|
Major int `json:"major"`
|
|
Minor int `json:"minor"`
|
|
Patch int `json:"patch"`
|
|
HumanReadable string `json:"human_readable"`
|
|
LoadedConfigFileName string `json:"loaded_config_file_name"`
|
|
}
|
|
|
|
func (v Version) String() string {
|
|
data, _ := json.MarshalIndent(v, "", "\t")
|
|
return string(data)
|
|
}
|
|
|
|
type config struct {
|
|
Config string `json:"config"`
|
|
}
|
|
|
|
type name struct {
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type InputDevice struct {
|
|
Identifier string `json:"identifier"`
|
|
Name string `json:"name"`
|
|
Vendor int `json:"vendor"`
|
|
Product int `json:"product"`
|
|
Type InputDeviceType `json:"type"`
|
|
XKBActiveLayoutName string `json:"xkb_active_layout_name"`
|
|
XKBLayoutNames []string `json:"xkb_layout_names"`
|
|
XKBActiveLayoutIndex int `json:"xkb_active_layout_index"`
|
|
ScrollFactor float64 `json:"scroll_factor"`
|
|
LibInput LibInput `json:"libinput"`
|
|
}
|
|
|
|
func (id InputDevice) String() string {
|
|
data, _ := json.MarshalIndent(id, "", "\t")
|
|
return string(data)
|
|
}
|
|
|
|
type LibInput struct {
|
|
SendEvents string `json:"send_events"`
|
|
Tap string `json:"tap"`
|
|
TapButtonMap string `json:"tap_button_map"`
|
|
TapDrag string `json:"tap_drag"`
|
|
TapDragLock string `json:"tap_drag_lock"`
|
|
AccelSpeed float64 `json:"accel_speed"`
|
|
AccelProfile string `json:"accel_profile"`
|
|
NaturalScroll string `json:"natural_scroll"`
|
|
LeftHanded string `json:"left_handed"`
|
|
ClickMethod string `json:"click_method"`
|
|
MiddleEmulation string `json:"middle_emulation"`
|
|
ScrollMethod string `json:"scroll_method"`
|
|
ScrollButton int `json:"scroll_button"`
|
|
Dwt string `json:"dwt"`
|
|
Dwtp string `json:"dwtp"`
|
|
CalibrationMatrix [6]float64 `json:"calibration_matrix"`
|
|
}
|
|
|
|
type Seat struct {
|
|
Name string `json:"name"`
|
|
Capabilities int `json:"capabilities"`
|
|
Focus NodeID `json:"focus"`
|
|
Devices []InputDevice `json:"devices"`
|
|
}
|
|
|
|
func (s Seat) String() string {
|
|
data, _ := json.MarshalIndent(s, "", "\t")
|
|
return string(data)
|
|
}
|