1package sway 2 3import "encoding/json" 4 5type Rect struct { 6 X int64 `json:"x,omitempty"` 7 Y int64 `json:"y,omitempty"` 8 Width int64 `json:"width,omitempty"` 9 Height int64 `json:"height,omitempty"` 10} 11 12type WindowProperties struct { 13 Title string `json:"title,omitempty"` 14 Instance string `json:"instance,omitempty"` 15 Class string `json:"class,omitempty"` 16 Role string `json:"window_role,omitempty"` 17 TransientFor int64 `json:"transient_for,omitempty"` 18} 19 20type Node struct { 21 ID int64 `json:"id,omitempty"` 22 Name string `json:"name,omitempty"` 23 Type string `json:"type,omitempty"` 24 Border string `json:"border,omitempty"` 25 CurrentBorderWidth int64 `json:"current_border_width,omitempty"` 26 Layout string `json:"layout,omitempty"` 27 Percent *float64 `json:"percent,omitempty"` 28 Rect Rect `json:"rect,omitempty"` 29 WindowRect Rect `json:"window_rect,omitempty"` 30 DecoRect Rect `json:"deco_rect,omitempty"` 31 Geometry Rect `json:"geometry,omitempty"` 32 Urgent *bool `json:"urgent,omitempty"` 33 Focused bool `json:"focused,omitempty"` 34 Focus []int64 `json:"focus,omitempty"` 35 Nodes []*Node `json:"nodes,omitempty"` 36 FloatingNodes []*Node `json:"floating_nodes,omitempty"` 37 Representation *string `json:"representation,omitempty"` 38 AppID *string `json:"app_id,omitempty"` 39 PID *uint32 `json:"pid,omitempty"` 40 Window *int64 `json:"window,omitempty"` 41 WindowProperties *WindowProperties `json:"window_properties,omitempty"` 42} 43 44// FocusedNode traverses the node tree and returns the focused node 45func (n *Node) FocusedNode() *Node { 46 queue := []*Node{n} 47 for len(queue) > 0 { 48 n = queue[0] 49 queue = queue[1:] 50 51 if n == nil { 52 continue 53 } 54 55 if n.Focused { 56 return n 57 } 58 59 queue = append(queue, n.Nodes...) 60 queue = append(queue, n.FloatingNodes...) 61 } 62 return nil 63} 64 65// WorkspaceEvent is sent whenever a change involving a workspace occurs 66type WorkspaceEvent struct { 67 // The type of change that occurred 68 // The following change types are currently available: 69 // init: the workspace was created 70 // empty: the workspace is empty and is being destroyed since it is not 71 // visible 72 // focus: the workspace was focused. See the old property for the previous 73 // focus 74 // move: the workspace was moved to a different output 75 // rename: the workspace was renamed 76 // urgent: a view on the workspace has had their urgency hint set or all 77 // urgency hints for views on the workspace have been cleared 78 // reload: The configuration file has been reloaded 79 Change string `json:"change,omitempty"` 80 81 // An object representing the workspace effected or null for reload changes 82 Current *Node `json:"current,omitempty"` 83 84 // For a focus change, this is will be an object representing the workspace 85 // being switched from. Otherwise, it is null 86 Old *Node `json:"old,omitempty"` 87} 88 89// WindowEvent is sent whenever a change involving a view occurs 90type WindowEvent struct { 91 // The type of change that occurred 92 // 93 // The following change types are currently available: 94 // new: The view was created 95 // close: The view was closed 96 // focus: The view was focused 97 // title: The view's title has changed 98 // fullscreen_mode: The view's fullscreen mode has changed 99 // move: The view has been reparented in the tree 100 // floating: The view has become floating or is no longer floating 101 // urgent: The view's urgency hint has changed status 102 // mark: A mark has been added or removed from the view 103 Change string `json:"change,omitempty"` 104 105 // An object representing the view effected 106 Container Node `json:"container,omitempty"` 107} 108 109// ShutdownEvent is sent whenever the IPC is shutting down 110type ShutdownEvent struct { 111 // A string containing the reason for the shutdown. Currently, the only 112 // value for change is exit, which is issued when sway is exiting. 113 Change string `json:"change,omitempty"` 114} 115 116type RunCommandReply struct { 117 Success bool `json:"success,omitempty"` 118 Error string `json:"error,omitempty"` 119} 120 121type Workspace struct { 122 ID int64 `json:"id,omitempty"` 123 Num int64 `json:"num,omitempty"` 124 Name string `json:"name,omitempty"` 125 Visible bool `json:"visible,omitempty"` 126 Focused bool `json:"focused,omitempty"` 127 Urgent bool `json:"urgent,omitempty"` 128 Rect Rect `json:"rect,omitempty"` 129 Output string `json:"output,omitempty"` 130} 131 132type Refresh float64 133 134func (r *Refresh) UnmarshalJSON(raw []byte) error { 135 var n int64 136 if err := json.Unmarshal(raw, &n); err != nil { 137 return err 138 } 139 *r = Refresh(float64(n) / 1000) 140 return nil 141} 142 143type OutputMode struct { 144 Width int64 `json:"width,omitempty"` 145 Height int64 `json:"height,omitempty"` 146 Refresh Refresh `json:"refresh,omitempty"` 147} 148 149type Output struct { 150 Name string `json:"name,omitempty"` 151 Make string `json:"make,omitempty"` 152 Model string `json:"model,omitempty"` 153 Serial string `json:"serial,omitempty"` 154 Active bool `json:"active,omitempty"` 155 Primary bool `json:"primary,omitempty"` 156 Scale float64 `json:"scale,omitempty"` 157 Transform string `json:"transform,omitempty"` 158 CurrentWorkspace string `json:"current_workspace,omitempty"` 159 Modes []OutputMode `json:"modes,omitempty"` 160 CurrentMode OutputMode `json:"current_mode,omitempty"` 161 Rect Rect `json:"rect,omitempty"` 162} 163 164type BarConfigGaps struct { 165 Top int64 `json:"top,omitempty"` 166 Right int64 `json:"right,omitempty"` 167 Bottom int64 `json:"bottom,omitempty"` 168 Left int64 `json:"left,omitempty"` 169} 170 171type BarConfigColors struct { 172 Background string `json:"background,omitempty"` 173 Statusline string `json:"statusline,omitempty"` 174 Separator string `json:"separator,omitempty"` 175 FocusedBackground string `json:"focused_background,omitempty"` 176 FocusedStatusline string `json:"focused_statusline,omitempty"` 177 FocusedSeparator string `json:"focused_separator,omitempty"` 178 FocusedWorkspaceText string `json:"focused_workspace_text,omitempty"` 179 FocusedWorkspaceBG string `json:"focused_workspace_bg,omitempty"` 180 FocusedWorkspaceBorder string `json:"focused_workspace_border,omitempty"` 181 ActiveWorkspaceText string `json:"active_workspace_text,omitempty"` 182 ActiveWorkspaceBG string `json:"active_workspace_bg,omitempty"` 183 ActiveWorkspaceBorder string `json:"active_workspace_border,omitempty"` 184 InactiveWorkspaceText string `json:"inactive_workspace_text,omitempty"` 185 InactiveWorkspaceBG string `json:"inactive_workspace_bg,omitempty"` 186 InactiveWorkspaceBorder string `json:"inactive_workspace_border,omitempty"` 187 UrgentWorkspaceText string `json:"urgent_workspace_text,omitempty"` 188 UrgentWorkspaceBG string `json:"urgent_workspace_bg,omitempty"` 189 UrgentWorkspaceBorder string `json:"urgent_workspace_border,omitempty"` 190 BindingModeText string `json:"binding_mode_text,omitempty"` 191 BindingModeBG string `json:"binding_mode_bg,omitempty"` 192 BindingModeBorder string `json:"binding_mode_border,omitempty"` 193} 194 195// BarConfigUpdateEvent is sent whenever a config for a bar changes. The event 196// is identical to that of GET_BAR_CONFIG when a bar ID is given as a payload. 197type BarConfigUpdateEvent = BarConfig 198 199type BarConfig struct { 200 ID string `json:"id,omitempty"` 201 Mode string `json:"mode,omitempty"` 202 Position string `json:"position,omitempty"` 203 StatusCommand string `json:"status_command,omitempty"` 204 Font string `json:"font,omitempty"` 205 WorkspaceButtons bool `json:"workspace_buttons,omitempty"` 206 BindingModeIndicator bool `json:"binding_mode_indicator,omitempty"` 207 Verbose bool `json:"verbose,omitempty"` 208 Colors BarConfigColors `json:"colors,omitempty"` 209 Gaps BarConfigGaps `json:"gaps,omitempty"` 210 BarHeight int64 `json:"bar_height,omitempty"` 211 StatusPadding int64 `json:"status_padding,omitempty"` 212 StatusEdgePadding int64 `json:"status_edge_padding,omitempty"` 213} 214 215type Version struct { 216 Major int64 `json:"major,omitempty"` 217 Minor int64 `json:"minor,omitempty"` 218 Patch int64 `json:"patch,omitempty"` 219 HumanReadable string `json:"human_readable,omitempty"` 220 LoadedConfigFileName string `json:"loaded_config_file_name,omitempty"` 221} 222 223type Config struct { 224 Config string `json:"config,omitempty"` 225} 226 227type TickReply struct { 228 Success bool `json:"success,omitempty"` 229} 230 231type LibInput struct { 232 SendEvents string `json:"send_events,omitempty"` 233 Tap string `json:"tap,omitempty"` 234 TapButtonMap string `json:"tap_button_map,omitempty"` 235 TapDrag string `json:"tap_drag,omitempty"` 236 TapDragLock string `json:"tap_drag_lock,omitempty"` 237 AccelSpeed float64 `json:"accel_speed,omitempty"` 238 AccelProfile string `json:"accel_profile,omitempty"` 239 NaturalScroll string `json:"natural_scroll,omitempty"` 240 LeftHanded string `json:"left_handed,omitempty"` 241 ClickMethod string `json:"click_method,omitempty"` 242 MiddleEmulation string `json:"middle_emulation,omitempty"` 243 ScrollMethod string `json:"scroll_method,omitempty"` 244 ScrollButton int64 `json:"scroll_button,omitempty"` 245 DWT string `json:"dwt,omitempty"` 246} 247 248type Input struct { 249 Identifier string `json:"identifier,omitempty"` 250 Name string `json:"name,omitempty"` 251 Vendor int64 `json:"vendor,omitempty"` 252 Product int64 `json:"product,omitempty"` 253 Type string `json:"type,omitempty"` 254 XKBActiveLayoutName *string `json:"xkb_active_layout_name,omitempty"` 255 LibInput *LibInput `json:"libinput,omitempty"` 256} 257 258type Seat struct { 259 Name string `json:"name,omitempty"` 260 Capabilities int64 `json:"capabilities,omitempty"` 261 Focus int64 `json:"focus,omitempty"` 262 Devices []Input `json:"devices,omitempty"` 263} 264 265// ModeEvent is sent whenever the binding mode changes 266type ModeEvent struct { 267 // The binding mode that became active 268 Change string `json:"change,omitempty"` 269 270 // Whether the mode should be parsed as pango markup 271 PangoMarkup bool `json:"pango_markup,omitempty"` 272} 273 274type Binding struct { 275 // The command associated with the binding 276 Command string `json:"command,omitempty"` 277 278 // An array of strings that correspond to each modifier key for the binding 279 EventStateMask []string `json:"event_state_mask,omitempty"` 280 281 // For keyboard bindcodes, this is the key code for the binding. For mouse 282 // bindings, this is the X11 button number, if there is an equivalent. In 283 // all other cases, this will be 0. 284 InputCode int64 `json:"input_code,omitempty"` 285 286 // For keyboard bindsyms, this is the bindsym for the binding. Otherwise, 287 // this will be null 288 Symbol *string `json:"symbol,omitempty"` 289 290 // The input type that triggered the binding. This is either keyboard or 291 // mouse 292 InputType string `json:"input_type,omitempty"` 293} 294 295// BindingEvent is sent whenever a binding is executed 296type BindingEvent struct { 297 // Currently this will only be run 298 Change string `json:"change,omitempty"` 299 Binding Binding `json:"binding,omitempty"` 300} 301 302// TickEvent is sent when first subscribing to tick events or by a SEND_TICK 303// message 304type TickEvent struct { 305 // Whether this event was triggered by subscribing to the tick events 306 First bool `json:"first,omitempty"` 307 308 // The payload given with a SEND_TICK message, if any. Otherwise, an empty 309 // string 310 Payload string `json:"payload,omitempty"` 311} 312 313// BarStatusUpdateEvent is sent when the visibility of a bar changes due to a 314// modifier being pressed 315type BarStatusUpdateEvent struct { 316 // The bar ID effected 317 ID string `json:"id,omitempty"` 318 319 // Whether the bar should be made visible due to a modifier being pressed 320 VisibleByModifier bool `json:"visible_by_modifier,omitempty"` 321} 322