ipc

package module
v0.0.0-...-7b8fe66 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// Magic string for the IPC API.
	MAGICK string = "i3-ipc"
	// The length of the i3 message "header" is 14 bytes: 6 for the _Magic
	// string, 4 for the length of the payload (int32 in native byte order) and
	// another 4 for the message type (also int32 in NBO).
	HEADERLEN = 14

	IPC_GET_WORKSPACES    = 1
	IPC_SUBSCRIBE         = 2
	IPC_GET_OUTPUTS       = 3
	IPC_GET_TREE          = 4
	IPC_GET_MARKS         = 5
	IPC_GET_BAR_CONFIG    = 6
	IPC_GET_VERSION       = 7
	IPC_GET_BINDING_MODES = 8
	IPC_GET_CONFIG        = 9
	IPC_SEND_TICK         = 10
	IPC_SYNC              = 11

	// Sway-specific command types
	IPC_GET_INPUTS = 100
	IPC_GET_SEATS  = 101
)

Variables

This section is empty.

Functions

func ConnectToSocket

func ConnectToSocket() (net.Conn, error)

ConnectToSocket connects to the Sway socket

func FindFocusedNodes

func FindFocusedNodes(tree []Node, ch chan Node)

FindFocusedNodes finds the all focused nodes and send it to the channel

func GetLargestWindowID

func GetLargestWindowID(n []Node) int64

GetLargestWindow returns largest window ID

func GetSocketPath

func GetSocketPath() (string, error)

GetSocketPath returns socket path of the running Sway

func IsSwayAvailable

func IsSwayAvailable() bool

IsSwayAvailable exported wrapper under the checkSway()

Types

type ChangeEvent

type ChangeEvent string

type Container

type Container struct {
	ID                 int              `json:"id"`
	Name               string           `json:"name"`
	Rect               Rect             `json:"rect"`
	Focused            bool             `json:"focused"`
	Focus              []interface{}    `json:"focus"`
	Border             string           `json:"border"`
	CurrentBorderWidth int              `json:"current_border_width"`
	Layout             string           `json:"layout"`
	Orientation        string           `json:"orientation"`
	Percent            float64          `json:"percent"`
	WindowRect         WindowRect       `json:"window_rect"`
	DecoRect           DecoRect         `json:"deco_rect"`
	Geometry           Geometry         `json:"geometry"`
	Window             int              `json:"window"`
	Urgent             bool             `json:"urgent"`
	FloatingNodes      []FloatingNodes  `json:"floating_nodes"`
	Sticky             bool             `json:"sticky"`
	Type               string           `json:"type"`
	FullscreenMode     int              `json:"fullscreen_mode"`
	Pid                int              `json:"pid"`
	AppID              interface{}      `json:"app_id"`
	Visible            bool             `json:"visible"`
	Marks              []interface{}    `json:"marks"`
	WindowProperties   WindowProperties `json:"window_properties"`
	Nodes              []Node           `json:"nodes"`
}

Container represents the Sway container

type CurrentMode

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

type DecoRect

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

type Event

type Event struct {
	Change    ChangeEvent `json:"change"`
	Container Container   `json:"container"`
}

Event represents a Sway event

type FloatingNodes

type FloatingNodes struct {
	ID                 int              `json:"id"`
	Name               string           `json:"name"`
	Rect               Rect             `json:"rect"`
	Focused            bool             `json:"focused"`
	Focus              []interface{}    `json:"focus"`
	Border             string           `json:"border"`
	CurrentBorderWidth int              `json:"current_border_width"`
	Layout             string           `json:"layout"`
	Orientation        string           `json:"orientation"`
	Percent            float64          `json:"percent"`
	WindowRect         WindowRect       `json:"window_rect"`
	DecoRect           DecoRect         `json:"deco_rect"`
	Geometry           Geometry         `json:"geometry"`
	Window             int              `json:"window"`
	Urgent             bool             `json:"urgent"`
	FloatingNodes      []FloatingNodes  `json:"floating_nodes"`
	Sticky             bool             `json:"sticky"`
	Type               string           `json:"type"`
	FullscreenMode     int              `json:"fullscreen_mode"`
	Pid                int              `json:"pid"`
	AppID              interface{}      `json:"app_id"`
	Visible            bool             `json:"visible"`
	Marks              []interface{}    `json:"marks"`
	WindowProperties   WindowProperties `json:"window_properties"`
	Nodes              []Node           `json:"nodes"`
}

type Geometry

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

type Input

type Input struct {
	Identifier           string                 `json:"identifier"`
	Name                 string                 `json:"name"`
	Vendor               int64                  `json:"vendor"`
	Product              int64                  `json:"product"`
	Type                 string                 `json:"type"`
	XkbLayoutNames       []string               `json:"xkb_layout_names,omitempty"`
	XkbActiveLayoutIndex int8                   `json:"xkb_active_layout_index"`
	XkbActiveLayoutName  string                 `json:"xkb_active_layout_name"`
	LibInput             map[string]interface{} `json:"libinput"`
}

type Modes

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

type Node

type Node struct {
	ID                 int64            `json:"id"`
	Name               string           `json:"name"`
	Rect               Rect             `json:"rect"`
	Focused            bool             `json:"focused"`
	Focus              []int            `json:"focus"`
	Border             string           `json:"border"`
	CurrentBorderWidth int              `json:"current_border_width"`
	Layout             string           `json:"layout"`
	Orientation        string           `json:"orientation"`
	Percent            float64          `json:"percent"`
	WindowRect         WindowRect       `json:"window_rect"`
	DecoRect           DecoRect         `json:"deco_rect"`
	Geometry           Geometry         `json:"geometry"`
	Window             interface{}      `json:"window"`
	Urgent             bool             `json:"urgent"`
	FloatingNodes      []Node           `json:"floating_nodes"`
	Sticky             bool             `json:"sticky"`
	Type               string           `json:"type"`
	Nodes              []Node           `json:"nodes"`
	Active             bool             `json:"active,omitempty"`
	Primary            bool             `json:"primary,omitempty"`
	Make               string           `json:"make,omitempty"`
	Model              string           `json:"model,omitempty"`
	Serial             string           `json:"serial,omitempty"`
	Scale              float64          `json:"scale,omitempty"`
	Transform          string           `json:"transform,omitempty"`
	CurrentWorkspace   string           `json:"current_workspace,omitempty"`
	Modes              []Modes          `json:"modes,omitempty"`
	CurrentMode        CurrentMode      `json:"current_mode,omitempty"`
	Representation     string           `json:"representation,omitempty"`
	WindowProperties   WindowProperties `json:"window_properties"`
}

func GetAllFloatingWindows

func GetAllFloatingWindows(n []Node) []Node

GetAllFloatingWindows returns all the floating windows including scratchpads

func (Node) Command

func (n Node) Command(com string) ([]byte, error)

Command runs an sway command with the node ID: [con_id]=n.ID com

type Output

type Output struct {
	ID                 int           `json:"id,omitempty"`
	Name               string        `json:"name"`
	Rect               Rect          `json:"rect"`
	Focus              []int         `json:"focus,omitempty"`
	Border             string        `json:"border,omitempty"`
	CurrentBorderWidth int           `json:"current_border_width,omitempty"`
	Layout             string        `json:"layout,omitempty"`
	Orientation        string        `json:"orientation,omitempty"`
	Percent            float64       `json:"percent"`
	WindowRect         WindowRect    `json:"window_rect,omitempty"`
	DecoRect           DecoRect      `json:"deco_rect,omitempty"`
	Geometry           Geometry      `json:"geometry,omitempty"`
	Window             interface{}   `json:"window,omitempty"`
	Urgent             bool          `json:"urgent,omitempty"`
	FloatingNodes      []interface{} `json:"floating_nodes,omitempty"`
	Sticky             bool          `json:"sticky,omitempty"`
	Type               string        `json:"type"`
	Active             bool          `json:"active"`
	DPMS               bool          `json:"dpms"`
	Primary            bool          `json:"primary"`
	Make               string        `json:"make"`
	Model              string        `json:"model"`
	Serial             string        `json:"serial"`
	Scale              float64       `json:"scale,omitempty"`
	Transform          string        `json:"transform,omitempty"`
	CurrentWorkspace   string        `json:"current_workspace"`
	Modes              []Modes       `json:"modes"`
	CurrentMode        CurrentMode   `json:"current_mode,omitempty"`
	Focused            bool          `json:"focused,omitempty"`
}

Output represents structure that we getting from `get_outputs'

type Rect

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

type Seat

type Seat struct {
	Name         string  `json:"name"`
	Capabilities int64   `json:"capabilities"`
	Focus        int64   `json:"focus"`
	Devices      []Input `json:"devices"`
}

type SwayConnection

type SwayConnection struct {
	Conn net.Conn
}

func NewSwayConnection

func NewSwayConnection() (*SwayConnection, error)

NewSwayConnection initializes an new Sway connection through unix socket

func (*SwayConnection) FindParent

func (sc *SwayConnection) FindParent(id int64) Node

FindParent returns the parent node of the provided node ID

func (*SwayConnection) GetActiveOutput

func (sc *SwayConnection) GetActiveOutput() (*Output, error)

GetActiveOutput returns the currently active and focused output

func (*SwayConnection) GetFocusedWorkspace

func (sc *SwayConnection) GetFocusedWorkspace() (*Workspace, error)

GetFocusedWorkspace returns focused workspace name

func (*SwayConnection) GetFocusedWorkspaceWindows

func (sc *SwayConnection) GetFocusedWorkspaceWindows() ([]Node, error)

GetFocusedWorkspaceWindows returns all the windows from the focused workspace

func (*SwayConnection) GetInputs

func (sc *SwayConnection) GetInputs() ([]Input, error)

GetInputs returns all available LibInput devices

func (*SwayConnection) GetOutputs

func (sc *SwayConnection) GetOutputs() ([]*Output, error)

GetOutputs returns all outputs

func (*SwayConnection) GetSeats

func (sc *SwayConnection) GetSeats() ([]Seat, error)

GetSeats returns all available seats

func (*SwayConnection) GetTree

func (sc *SwayConnection) GetTree() (*Tree, error)

GetTree calls get_tree through a unix socket and return the Tree

func (*SwayConnection) GetWorkspaces

func (sc *SwayConnection) GetWorkspaces() ([]*Workspace, error)

GetWorkspaces returns all active workspaces

func (*SwayConnection) RunSwayCommand

func (sc *SwayConnection) RunSwayCommand(cmd string) ([]byte, error)

RunSwayCommand returns STDOUT or STDERR of the swaymsg

func (*SwayConnection) SendCommand

func (sc *SwayConnection) SendCommand(command int, s string) ([]byte, error)

SendCommand sends command to the Sway unix socket

func (*SwayConnection) Subscribe

func (sc *SwayConnection) Subscribe() *subscription

Subscribe to the sway events

func (*SwayConnection) SubscribeListener

func (sc *SwayConnection) SubscribeListener(ch chan *Event)

SubscribeListener DEPRECATED listens events from the Sway

type Tree

type Tree struct {
	ID                 int         `json:"id"`
	Name               string      `json:"name"`
	Rect               Rect        `json:"rect"`
	Focused            bool        `json:"focused"`
	Focus              []int       `json:"focus"`
	Border             string      `json:"border"`
	CurrentBorderWidth int         `json:"current_border_width"`
	Layout             string      `json:"layout"`
	Orientation        string      `json:"orientation"`
	Percent            float64     `json:"percent"`
	WindowRect         WindowRect  `json:"window_rect"`
	DecoRect           DecoRect    `json:"deco_rect"`
	Geometry           Geometry    `json:"geometry"`
	Window             interface{} `json:"window"`
	Urgent             bool        `json:"urgent"`
	FloatingNodes      []Node      `json:"floating_nodes"`
	Sticky             bool        `json:"sticky"`
	Type               string      `json:"type"`
	Nodes              []Node      `json:"nodes"`
}

Tree is a structure that we getting from `get_tree'

type WindowProperties

type WindowProperties struct {
	Class        string      `json:"class"`
	Instance     string      `json:"instance"`
	Title        string      `json:"title"`
	TransientFor interface{} `json:"transient_for"`
	WindowRole   string      `json:"window_role"`
}

type WindowRect

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

type Workspace

type Workspace struct {
	ID                 int64         `json:"id"`
	Name               string        `json:"name"`
	Rect               Rect          `json:"rect"`
	Focus              []int         `json:"focus"`
	Border             string        `json:"border"`
	CurrentBorderWidth int           `json:"current_border_width"`
	Layout             string        `json:"layout"`
	Orientation        string        `json:"orientation"`
	Percent            interface{}   `json:"percent"`
	WindowRect         WindowRect    `json:"window_rect"`
	DecoRect           DecoRect      `json:"deco_rect"`
	Geometry           Geometry      `json:"geometry"`
	Window             interface{}   `json:"window"`
	Urgent             bool          `json:"urgent"`
	FloatingNodes      []interface{} `json:"floating_nodes"`
	Sticky             bool          `json:"sticky"`
	Num                int           `json:"num"`
	Output             string        `json:"output"`
	Type               string        `json:"type"`
	Representation     string        `json:"representation"`
	Focused            bool          `json:"focused"`
	Visible            bool          `json:"visible"`
}

Workspace represents a workspace

Jump to

Keyboard shortcuts

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