Documentation ¶
Overview ¶
Package ipc provides a Client for connecting to the Sway window manager ipc socket. The Client supports sending messages and subscribing to events.
Subsciption wraps Client to add support for typed event callbacks.
swager/ipc aims to be a fully featured library that supports all features exposed over the sway ipc socket.
Notable missing pieces include everything related to Bars and Inputs, though the primitives provided by the library should be able to get raw json representations.
Example usage can be seen in the swager/internal/* packages and the swager/blocks package.
Index ¶
- Variables
- func ValidMagic(test [6]byte) bool
- type BindingChange
- type BindingChangeType
- type BindingState
- type BorderType
- type Client
- func (c *Client) BindingModes() ([]string, error)
- func (c *Client) BindingModesRaw() (string, error)
- func (c *Client) BindingState() (*BindingState, error)
- func (c *Client) BindingStateRaw() (string, error)
- func (c *Client) Command(cmd string) ([]Command, error)
- func (c *Client) CommandRaw(cmd string) (string, error)
- func (c *Client) Marks() ([]string, error)
- func (c *Client) MarksRaw() (string, error)
- func (c *Client) Outputs() ([]Output, error)
- func (c *Client) OutputsRaw() (string, error)
- func (c *Client) Subscribe(evts ...EventPayloadType) (*Result, error)
- func (c *Client) Tick(payload string) (*Result, error)
- func (c *Client) TickRaw(payload string) (string, error)
- func (c *Client) Tree() (*Node, error)
- func (c *Client) TreeRaw() (string, error)
- func (c *Client) Version() (*Version, error)
- func (c *Client) VersionRaw() (string, error)
- func (c *Client) Workspaces() ([]Workspace, error)
- func (c *Client) WorkspacesRaw() (string, error)
- type Command
- type Cookie
- type EventArgs
- type EventPayloadType
- type FullscreenModeType
- type Header
- type InputType
- type LayoutType
- type Mode
- type ModeChange
- type MonitoringError
- type Node
- type NodeType
- type OrientationType
- type Output
- type PayloadType
- type Rect
- type Result
- type ShutdownChange
- type ShutdownChangeType
- type Subscription
- func (s *Subscription) BindingChanges(h func(BindingChange)) (Cookie, error)
- func (s *Subscription) Close() error
- func (s *Subscription) Errors(ch chan<- error)
- func (s *Subscription) ModeChanges(h func(ModeChange)) (Cookie, error)
- func (s *Subscription) RemoveHandler(c Cookie)
- func (s *Subscription) Run()
- func (s *Subscription) ShutdownChanges(h func(ShutdownChange)) (Cookie, error)
- func (s *Subscription) Ticks(h func(Tick)) (Cookie, error)
- func (s *Subscription) WindowChanges(h func(WindowChange)) (Cookie, error)
- func (s *Subscription) WorkspaceChanges(h func(WorkspaceChange)) (Cookie, error)
- type Tick
- type Version
- type WindowChange
- type WindowChangeType
- type WindowProperties
- type Workspace
- type WorkspaceChange
- type WorkspaceChangeType
Constants ¶
This section is empty.
Variables ¶
var EmptyCookie = Cookie(0)
Functions ¶
func ValidMagic ¶
ValidMagic tests whether the byte array represents the ipc payload magic string
Types ¶
type BindingChange ¶
type BindingChangeType ¶
type BindingChangeType string
const (
RunBinding BindingChangeType = "run"
)
type BindingState ¶
type BindingState struct {
Name string `json:"name"`
}
type BorderType ¶
type BorderType string
const ( NormalBorder BorderType = "normal" NoneBorder BorderType = "none" PixelBorder BorderType = "pixel" CSDBorder BorderType = "csd" )
type Client ¶
type Client struct { io.ReadWriteCloser // contains filtered or unexported fields }
Client is a sway-ipc compatible rpc client. Client is also an io.ReadWriteCloser.
func Connect ¶
Connect returns a Client connected to the UDS exported to the environment variable SWAYSOCK, using LittleEndian byte order.
func ConnectCustom ¶
ConnectCustom returns a Client connected to the UDS path specified by the uds parameter, with your choice of byte order.
func (*Client) BindingModes ¶
BindingModes implements the sway-ipc GET_BINDING_MODES message.
func (*Client) BindingModesRaw ¶
BindingModes implements the sway-ipc GET_BINDING_MODES message and returns a json string.
func (*Client) BindingState ¶
func (c *Client) BindingState() (*BindingState, error)
BindingState implements the sway-ipc GET_BINDING_STATE message.
func (*Client) BindingStateRaw ¶
BindingState implements the sway-ipc GET_BINDING_STATE message and returns a json string.
func (*Client) CommandRaw ¶
CommandRaw implements the sway-ipc RUN_COMMAND message and returns a json string.
func (*Client) MarksRaw ¶
Marks implements the sway-ipc GET_MARKS message and returns a json string.
func (*Client) OutputsRaw ¶
Outputs implements the sway-ipc GET_OUTPUTS message and returns a json string.
func (*Client) Subscribe ¶
func (c *Client) Subscribe(evts ...EventPayloadType) (*Result, error)
Subscribe implements the sway-ipc SUBSCRIBE message.
func (*Client) Tree ¶
Tree implements the sway-ipc GET_TREE message. Returns a *Node representing the root of the tree.
func (*Client) VersionRaw ¶
Version implements the sway-ipc GET_VERSION message and returns a json string.
func (*Client) Workspaces ¶
Workspaces implements the sway-ipc GET_WORKSPACES message.
func (*Client) WorkspacesRaw ¶
Workspaces implements the sway-ipc GET_WORKSPACES message and returns a json string.
type EventArgs ¶
type EventArgs interface { WorkspaceChange | ModeChange | WindowChange | BindingChange | ShutdownChange | Tick }
type EventPayloadType ¶
type EventPayloadType PayloadType
const ( WorkspaceEvent EventPayloadType = 0x80000000 ModeEvent EventPayloadType = 0x80000002 WindowEvent EventPayloadType = 0x80000003 BarconfigUpdateEvent EventPayloadType = 0x80000004 BindingEvent EventPayloadType = 0x80000005 ShutdownEvent EventPayloadType = 0x80000006 TickEvent EventPayloadType = 0x80000007 BarStateUpdateEvent EventPayloadType = 0x80000014 InputEvent EventPayloadType = 0x80000015 )
func (EventPayloadType) String ¶
func (i EventPayloadType) String() string
type FullscreenModeType ¶
type FullscreenModeType uint8
const ( NoneFullscreenMode FullscreenModeType = 0 WorkspaceFullscreenMode FullscreenModeType = 1 GlobalFullscreenMode FullscreenModeType = 2 )
func (FullscreenModeType) String ¶
func (i FullscreenModeType) String() string
type Header ¶
type Header struct { Magic [6]byte PayloadLength uint32 PayloadType PayloadType }
func NewHeader ¶
func NewHeader(pt PayloadType, plen int) *Header
type LayoutType ¶
type LayoutType string
const ( SplitHLayout LayoutType = "splith" SplitVLayout LayoutType = "splitv" StackedLayout LayoutType = "stacked" TabbedLayout LayoutType = "tabbed" OutputLayout LayoutType = "output" )
type ModeChange ¶
type MonitoringError ¶
type MonitoringError struct {
// contains filtered or unexported fields
}
func NewMonitoringError ¶
func NewMonitoringError(err error) *MonitoringError
func (*MonitoringError) Error ¶
func (e *MonitoringError) Error() string
func (*MonitoringError) Unwrap ¶
func (e *MonitoringError) Unwrap() error
type Node ¶
type Node struct { ID int `json:"id"` Name string `json:"name"` Type NodeType `json:"type"` Border BorderType `json:"border"` CurrentBorderWidth int `json:"current_border_width"` Layout LayoutType `json:"layout"` Orientation OrientationType `json:"orientation"` Percent *float64 `json:"percent"` Rect Rect `json:"rect"` WindowRect Rect `json:"window_rect"` DecoRect Rect `json:"deco_rect"` Geometry Rect `json:"geometry"` Urgent *bool `json:"urgent"` Sticky bool `json:"sticky"` Marks []string `json:"marks"` Focused bool `json:"focused"` Focus []int `json:"focus"` Nodes []*Node `json:"nodes"` FloatingNodes []*Node `json:"floating_nodes"` Representation *string `json:"representation"` FullscreenMode *FullscreenModeType `json:"fullscreen_mode"` AppID *string `json:"app_id"` Pid *int `json:"pid"` Visible *bool `json:"visible"` Shell *string `json:"shell"` Window *int `json:"window"` WindowProperties *WindowProperties `json:"window_properties"` }
type OrientationType ¶
type OrientationType string
const ( VerticalOrientation OrientationType = "vertical" HorizontalOrientation OrientationType = "horizontal" NoneOrientation OrientationType = "none" )
type Output ¶
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"` Primary bool `json:"primary"` Scale float64 `json:"scale"` SubpixelHinting string `json:"subpixel_hinting"` Transform string `json:"transform"` CurrentWorkspace string `json:"current_workspace"` Modes []Mode `json:"modes"` CurrentMode Mode `json:"current_mode"` Rect Rect `json:"rect"` }
type PayloadType ¶
type PayloadType uint32
const ( RunCommandMessage PayloadType = 0 GetWorkspacesMessage PayloadType = 1 SubscribeMessage PayloadType = 2 GetOutputsMessage PayloadType = 3 GetTreeMessage PayloadType = 4 GetMarksMessage PayloadType = 5 GetBarConfigMessage PayloadType = 6 GetVersionMessage PayloadType = 7 GetBindingModesMessage PayloadType = 8 GetConfigMessage PayloadType = 9 SendTickMessage PayloadType = 10 SyncMessage PayloadType = 11 GetBindingStateMessage PayloadType = 12 GetInputsMessage PayloadType = 100 GetSeatsMessage PayloadType = 101 )
func (PayloadType) String ¶
func (i PayloadType) String() string
type ShutdownChange ¶
type ShutdownChange struct {
Change ShutdownChangeType `json:"change"`
}
type ShutdownChangeType ¶
type ShutdownChangeType string
const (
ExitShutdown ShutdownChangeType = "exit"
)
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription wraps a Client. It registers event handlers for the supported sway-ipc events.
func Subscribe ¶
func Subscribe() (*Subscription, error)
Subscribe to sway-ipc events, creating a new Client. A single Subscription can listen for multiple event types. After all event handlers have been added, call Run to start listening for events.
func SubscribeCustom ¶
func SubscribeCustom(client *Client) *Subscription
SubscribeCustom uses a custom Client instance to listen for events. The Client should be used only for this Subcription. Multiple events can be subscribed to. After all event handlers have been added, call Run to start listening for events.
func (*Subscription) BindingChanges ¶
func (s *Subscription) BindingChanges(h func(BindingChange)) (Cookie, error)
BindingChanges registers a new event handler.
func (*Subscription) Close ¶
func (s *Subscription) Close() error
Close removes all registered event handlers and closes the underlying Client.
func (*Subscription) Errors ¶
func (s *Subscription) Errors(ch chan<- error)
Errors returns the channel that subscription errors are yielded on. All errors from this channel are of type MonitoringError.
func (*Subscription) ModeChanges ¶
func (s *Subscription) ModeChanges(h func(ModeChange)) (Cookie, error)
ModeChanges registers a new event handler.
func (*Subscription) RemoveHandler ¶
func (s *Subscription) RemoveHandler(c Cookie)
RemoveHandler removes a registered event handler.
func (*Subscription) Run ¶
func (s *Subscription) Run()
Run starts listening for events, calling the registered handlers as events come in.
func (*Subscription) ShutdownChanges ¶
func (s *Subscription) ShutdownChanges(h func(ShutdownChange)) (Cookie, error)
ShutdownChanges registers a new event handler.
func (*Subscription) Ticks ¶
func (s *Subscription) Ticks(h func(Tick)) (Cookie, error)
Ticks registers a new event handler.
func (*Subscription) WindowChanges ¶
func (s *Subscription) WindowChanges(h func(WindowChange)) (Cookie, error)
WindowChanges registers a new event handler.
func (*Subscription) WorkspaceChanges ¶
func (s *Subscription) WorkspaceChanges(h func(WorkspaceChange)) (Cookie, error)
WorkspaceChanges registers a new event handler.
type WindowChange ¶
type WindowChange struct { Change WindowChangeType `json:"change"` Container Node `json:"container"` }
type WindowChangeType ¶
type WindowChangeType string
const ( NewWindow WindowChangeType = "new" CloseWindow WindowChangeType = "close" FocusWindow WindowChangeType = "focus" TitleWindow WindowChangeType = "title" FullscreenModeWindow WindowChangeType = "fullscreen_mode" MoveWindow WindowChangeType = "move" FloatingWindow WindowChangeType = "floating" UrgentWindow WindowChangeType = "urgent" MarkWindow WindowChangeType = "mark" )
type WindowProperties ¶
type WorkspaceChange ¶
type WorkspaceChange struct { Change WorkspaceChangeType `json:"change"` Current *Node `json:"current"` Old *Node `json:"old"` }
type WorkspaceChangeType ¶
type WorkspaceChangeType string
const ( InitWorkspace WorkspaceChangeType = "init" EmptyWorkspace WorkspaceChangeType = "empty" FocusWorkspace WorkspaceChangeType = "focus" MoveWorkspace WorkspaceChangeType = "move" RenameWorkspace WorkspaceChangeType = "rename" UrgentWorkspace WorkspaceChangeType = "urgent" ReloadWorkspace WorkspaceChangeType = "reload" )