ipc

package
v0.0.1-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2022 License: MIT Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var EmptyCookie = Cookie(0)

Functions

func ValidMagic

func ValidMagic(test [6]byte) bool

ValidMagic tests whether the byte array represents the ipc payload magic string

Types

type BindingChange

type BindingChange struct {
	Change         BindingChangeType `json:"change"`
	Command        string            `json:"command"`
	EventStateMask []string          `json:"event_state_mask"`
	InputCode      int               `json:"input_code"`
	Symbol         *string           `json:"symbol"`
	InputType      InputType         `json:"input_type"`
}

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

func Connect() (*Client, error)

Connect returns a Client connected to the UDS exported to the environment variable SWAYSOCK, using LittleEndian byte order.

func ConnectCustom

func ConnectCustom(uds string, yo binary.ByteOrder) (*Client, error)

ConnectCustom returns a Client connected to the UDS path specified by the uds parameter, with your choice of byte order.

func NewClient

func NewClient(conn io.ReadWriteCloser, yo binary.ByteOrder) *Client

func (*Client) BindingModes

func (c *Client) BindingModes() ([]string, error)

BindingModes implements the sway-ipc GET_BINDING_MODES message.

func (*Client) BindingModesRaw

func (c *Client) BindingModesRaw() (string, error)

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

func (c *Client) BindingStateRaw() (string, error)

BindingState implements the sway-ipc GET_BINDING_STATE message and returns a json string.

func (*Client) Command

func (c *Client) Command(cmd string) ([]Command, error)

Command implements the sway-ipc RUN_COMMAND message.

func (*Client) CommandRaw

func (c *Client) CommandRaw(cmd string) (string, error)

CommandRaw implements the sway-ipc RUN_COMMAND message and returns a json string.

func (*Client) Marks

func (c *Client) Marks() ([]string, error)

Marks implements the sway-ipc GET_MARKS message.

func (*Client) MarksRaw

func (c *Client) MarksRaw() (string, error)

Marks implements the sway-ipc GET_MARKS message and returns a json string.

func (*Client) Outputs

func (c *Client) Outputs() ([]Output, error)

Outputs implements the sway-ipc GET_OUTPUTS message.

func (*Client) OutputsRaw

func (c *Client) OutputsRaw() (string, error)

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) Tick

func (c *Client) Tick(payload string) (*Result, error)

Tick implements the sway-ipc SEND_TICK message.

func (*Client) TickRaw

func (c *Client) TickRaw(payload string) (string, error)

Tick implements the sway-ipc SEND_TICK message and returns a json string.

func (*Client) Tree

func (c *Client) Tree() (*Node, error)

Tree implements the sway-ipc GET_TREE message. Returns a *Node representing the root of the tree.

func (*Client) TreeRaw

func (c *Client) TreeRaw() (string, error)

Tree implements the sway-ipc GET_TREE message and returns a json string.

func (*Client) Version

func (c *Client) Version() (*Version, error)

Version implements the sway-ipc GET_VERSION message.

func (*Client) VersionRaw

func (c *Client) VersionRaw() (string, error)

Version implements the sway-ipc GET_VERSION message and returns a json string.

func (*Client) Workspaces

func (c *Client) Workspaces() ([]Workspace, error)

Workspaces implements the sway-ipc GET_WORKSPACES message.

func (*Client) WorkspacesRaw

func (c *Client) WorkspacesRaw() (string, error)

Workspaces implements the sway-ipc GET_WORKSPACES message and returns a json string.

type Command

type Command struct {
	Result
	ParseError bool   `json:"parse_error"`
	Error      string `json:"error,omitempty"`
}
type Cookie uint32

Cookie represents a single registered event handler.

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 struct {
	Magic         [6]byte
	PayloadLength uint32
	PayloadType   PayloadType
}

func NewHeader

func NewHeader(pt PayloadType, plen int) *Header

type InputType

type InputType string
const (
	KeyboardInput InputType = "keyboard"
	MouseInput    InputType = "mouse"
)

type LayoutType

type LayoutType string
const (
	SplitHLayout  LayoutType = "splith"
	SplitVLayout  LayoutType = "splitv"
	StackedLayout LayoutType = "stacked"
	TabbedLayout  LayoutType = "tabbed"
	OutputLayout  LayoutType = "output"
)

type Mode

type Mode struct {
	Width   int `json:"width"`
	Height  int `json:"height"`
	Refresh int `json:"refresh"`
}

type ModeChange

type ModeChange struct {
	// Change is the custom name of the activated mode
	Change      string `json:"change"`
	PangoMarkup bool   `json:"pango_markup"`
}

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 NodeType

type NodeType string
const (
	RootNode        NodeType = "root"
	OutputNode      NodeType = "output"
	WorkspaceNode   NodeType = "workspace"
	ConNode         NodeType = "con"
	FloatingConNode NodeType = "floating_con"
)

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 Rect

type Rect struct {
	X      int `json:"x"`
	Y      int `json:"y"`
	Width  int `json:"width"`
	Height int `json:"height"`
}

type Result

type Result struct {
	Success bool `json:"success"`
}

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 Tick

type Tick struct {
	First   bool   `json:"first"`
	Payload string `json:"payload"`
}

type Version

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"`
}

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 WindowProperties struct {
	Class        string      `json:"class"`
	Instance     string      `json:"instance"`
	TransientFor interface{} `json:"transient_for"`
}

type Workspace

type Workspace struct {
	Num     int    `json:"num"`
	Name    string `json:"name"`
	Visible bool   `json:"visible"`
	Focused bool   `json:"focused"`
	Urgent  bool   `json:"urgent"`
	Rect    Rect   `json:"rect"`
	Output  string `json:"output"`
}

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"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL