i3ipc

package module
v0.0.0-...-ac599a8 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2017 License: Apache-2.0 Imports: 9 Imported by: 1

README

GoDoc Build Status Go Report Card codecov BCH compliance

i3ipc

Overview

i3ipc is a golang library for convenient access to the IPC API of the i3 window manager. If you want to take a look at the documentation then head to http://godoc.org/github.com/mdirkse/i3ipc-go/.

Compatibility

This library can be used with the i3 IPC as it is as of at least version 4.13. However, according to the i3 maintainers:

The IPC isn't versioned. It can change with every release and usually does in one way or another. We only try to avoid breaking changes to the documented values since we consider those stable, but with good enough reason even those can change.

We'll do our best to make this library track the i3 IPC as closely as possible, but if you find anything missing (or broken) please file an issue or (even better) submit a pull request.

Usage

Thanks to Go's built-in git support, you can start using i3ipc with a simple

import "github.com/mdirkse/i3ipc"

For everything except subscriptions, you will want to create an IPCSocket over which the communication will take place. This object has methods for all message types that i3 will accept, though some might be split into multiple methods (eg. Get_Bar_Config). You can create such a socket quite easily:

ipcsocket, err := i3ipc.GetIPCSocket()

As a simple example of what you could do next, let's get the version of i3 over our new socket:

version, err := ipcsocket.GetVersion()

For further commands, refer to go doc or use the aforementioned website.

Subscriptions

i3ipc handles subscriptions in a convenient way: you don't have to think about managing the socket or watch out for unordered replies. The appropriate method simply returns a channel from which you can read Event objects.

Here's a simple example - we start the event listener, we subscribe to workspace events, then simple print all of them as we receive them:

i3ipc.StartEventListener()
ws_events, err := i3ipc.Subscribe(i3ipc.I3WorkspaceEvent)
for {
    event := <-ws_events
    fmt.Printf("Received an event: %v\n", event)
}

i3ipc currently has no way of subscribing to multiple event types over a single channel. If you want this, you can simply create multiple subscriptions, then demultiplex those channels yourself - select is your friend.

Credits

Many thanks to proxypoke for originally starting this project.

Documentation

Overview

Package i3ipc implements interprocess communication facilities with the i3 window manager.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartEventListener

func StartEventListener()

StartEventListener makes the library listen to events on the i3 socket

func Subscribe

func Subscribe(eventType EventType) (subs chan Event, err error)

Subscribe to an event type. Returns a channel from which events can be read.

Types

type Colors

type Colors struct {
	Background              string
	Statusline              string
	Separator               string
	FocusedBackground       string `json:"focused_background"`
	FocusedStatusline       string `json:"focused_statusline"`
	FocusedSeparator        string `json:"focused_separator"`
	FocusedWorkspaceBg      string `json:"focused_workspace_bg"`
	FocusedWorkspaceBorder  string `json:"focused_workspace_border"`
	FocusedWorkspaceText    string `json:"focused_workspace_text"`
	ActiveWorkspaceBg       string `json:"active_workspace_bg"`
	ActiveWorkspaceBorder   string `json:"active_workspace_border"`
	ActiveWorkspaceText     string `json:"active_workspace_text"`
	InactiveWorkspaceBg     string `json:"inactive_workspace_bg"`
	InactiveWorkspaceBorder string `json:"inactive_workspace_border"`
	InactiveWorkspaceText   string `json:"inactive_workspace_text"`
	UrgentWorkspaceBg       string `json:"urgent_workspace_bg"`
	UrgentWorkspaceBorder   string `json:"urgent_workspace_border"`
	UrgentWorkspaceText     string `json:"urgent_workspace_text"`
	BindingModeBg           string `json:"binding_mode_bg"`
	BindingModeBorder       string `json:"binding_mode_border"`
	BindingModeText         string `json:"binding_mode_text"`
}

Colors represents colors as used in I3Bar.

type CommandError

type CommandError string

CommandError for replies from a command to i3.

func (CommandError) Error

func (error CommandError) Error() string

type Event

type Event struct {
	Type EventType
	// "change" is the name of the single field of the JSON map that i3 sends
	// when an event occurs, describing what happened.
	Change string
}

Event describes an event reply from i3.

type EventType

type EventType int32

EventType for subscribable events.

const (
	I3WorkspaceEvent EventType = iota
	I3OutputEvent
	I3ModeEvent
	I3WindowEvent
	I3BarConfigUpdateEvent
	I3BindingEvent
)

Enumeration of currently available event types.

func AddEventType

func AddEventType(name string) (eventType EventType)

AddEventType dynamically adds an event type by defining a name for it. Just in case i3 adds a new one and this library hasn't been updated yet. Returns the EventType which gets assigned to it.

XXX: If you use this to add more than one new event type, add them in the RIGHT ORDER. I hope this case never pops up (because that would mean that this library is severely outdated), but I thought I'd warn you anyways.

type I3Bar

type I3Bar struct {
	ID                   string
	Mode                 string
	Position             string
	StatusCommand        string `json:"status_command"`
	Font                 string
	WorkspaceButtons     bool `json:"workspace_buttons"`
	BindingModeIndicator bool `json:"binding_mode_indicator"`
	Verbose              bool
	Colors               Colors
}

I3Bar represents the configuration of a bar. For documentation of the fields, refer to http://i3wm.org/docs/ipc.html#_bar_config_reply.

type I3Node

type I3Node struct {
	//int32 isn't large enough to hold all the ids
	ID                 int64
	Name               string
	Type               string
	Border             string
	CurrentBorderWidth int32 `json:"current_border_width"`
	Layout             string
	Orientation        string
	Percent            float64
	Rect               Rect
	WindowRect         Rect
	DecoRect           Rect `json:"deco_rect"`
	Geometry           Rect
	Window             int32
	Urgent             bool
	Focused            bool
	Floating_Nodes     []I3Node
	Nodes              []I3Node
	Parent             *I3Node

	// Properties, not listed in docs:
	Window_Properties struct {
		// Transient_for ?
		Title    string
		Instance string
		Class    string
	}
	// Swallows []I3Node ?
	Sticky            bool
	Floating          string
	Last_Split_Layout string
	// Focus []I3Node ?
	Fullscreen_Mode  int32
	Scratchpad_State string
	Workspace_Layout string
}

I3Node represents a Node in the i3 tree. For documentation of the fields, refer to http://i3wm.org/docs/ipc.html#_tree_reply.

func (*I3Node) Descendents

func (self *I3Node) Descendents() []*I3Node

Returns a slice of all descendent nodes.

func (*I3Node) FindByID

func (self *I3Node) FindByID(ID int64) *I3Node

Returns a node that has given id.

func (*I3Node) FindByWindow

func (self *I3Node) FindByWindow(window int32) *I3Node

Returns a node that has given window id.

func (*I3Node) FindFocused

func (self *I3Node) FindFocused() *I3Node

Returns a node that is being focused now.

func (*I3Node) FindNamed

func (self *I3Node) FindNamed(name string) []*I3Node

Returns nodes which name matches the regexp.

func (*I3Node) Leaves

func (self *I3Node) Leaves() (leaves []*I3Node)

Returns nodes that has no children nodes (leaves).

func (*I3Node) Root

func (self *I3Node) Root() *I3Node

Returns the root node of the tree.

func (*I3Node) Workspace

func (self *I3Node) Workspace() *I3Node

Looks for a workspace up the tree.

func (*I3Node) Workspaces

func (self *I3Node) Workspaces() (workspaces []*I3Node)

Returns all nodes of workspace type.

type I3Version

type I3Version struct {
	Major                int32
	Minor                int32
	Patch                int32
	HumanReadable        string `json:"human_readable"`
	LoadedConfigFileName string `json:"loaded_config_file_name"`
}

I3Version represents the version of i3. For documentation of the fields, refer to http://i3wm.org/docs/ipc.html#_version_reply.

type IPCSocket

type IPCSocket struct {
	// contains filtered or unexported fields
}

IPCSocket represents a Unix socket to communicate with i3.

func GetIPCSocket

func GetIPCSocket() (ipc *IPCSocket, err error)

GetIPCSocket creates a new IPC socket.

func (*IPCSocket) Close

func (socket *IPCSocket) Close() error

Close the connection to the underlying Unix socket.

func (*IPCSocket) Command

func (socket *IPCSocket) Command(action string) (success bool, err error)

Command sends a command to i3. FIXME: Doesn't support chained commands yet.

func (*IPCSocket) GetBarConfig

func (socket *IPCSocket) GetBarConfig(id string) (bar I3Bar, err error)

GetBarConfig returns the configuration of the bar with the given ID.

func (*IPCSocket) GetBarIds

func (socket *IPCSocket) GetBarIds() (ids []string, err error)

GetBarIds fetches a list of IDs for all configured bars.

func (*IPCSocket) GetMarks

func (socket *IPCSocket) GetMarks() (marks []string, err error)

GetMarks returns a list of marks which are currently set.

func (*IPCSocket) GetOutputs

func (socket *IPCSocket) GetOutputs() (outputs []Output, err error)

GetOutputs fetches the list of current outputs.

func (*IPCSocket) GetTree

func (socket *IPCSocket) GetTree() (root I3Node, err error)

GetTree fetches the layout tree.

func (*IPCSocket) GetVersion

func (socket *IPCSocket) GetVersion() (version I3Version, err error)

GetVersion fetches the version of i3.

func (*IPCSocket) GetWorkspaces

func (socket *IPCSocket) GetWorkspaces() (workspaces []Workspace, err error)

GetWorkspaces fetches a list of all current workspaces.

func (*IPCSocket) Raw

func (socket *IPCSocket) Raw(messageType MessageType, args string) (jsonReply []byte, err error)

Raw sends raw messages to i3. Returns a json byte string.

type Message

type Message struct {
	Payload []byte
	IsEvent bool
	Type    int32
}

A Message from i3. Can either be a Reply or an Event.

type MessageError

type MessageError string

MessageError for communication failures.

func (MessageError) Error

func (error MessageError) Error() string

type MessageType

type MessageType int32

A MessageType that Raw() accepts.

const (
	I3Command MessageType = iota
	I3GetWorkspaces
	I3Subscribe
	I3GetOutputs
	I3GetTree
	I3GetMarks
	I3GetBarConfig
	I3GetVersion
)

type MessageTypeError

type MessageTypeError string

MessageTypeError for unknown message types.

func (MessageTypeError) Error

func (error MessageTypeError) Error() string

type Output

type Output struct {
	Name             string
	Active           bool
	CurrentWorkspace string `json:"current_workspace"`
	Rect             Rect
}

Output represents an output. For documentation of the fields, refer to http://i3wm.org/docs/ipc.html#_outputs_reply.

type Rect

type Rect struct {
	X      int32
	Y      int32
	Width  int32
	Height int32
}

Rect represents the geometry of a window, output or workspace.

type SubscribeError

type SubscribeError string

SubscribeError represents a subscription-related error.

func (SubscribeError) Error

func (subscribeError SubscribeError) Error() string

type Workspace

type Workspace struct {
	Num     int32
	Name    string
	Visible bool
	Focused bool
	Urgent  bool
	Rect    Rect
	Output  string
}

Workspace represents a workspace. For documentation of the fields, refer to http://i3wm.org/docs/ipc.html#_workspaces_reply.

Jump to

Keyboard shortcuts

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