Go library for communicating with the i3 window manager
Go
Latest commit de8f6bb Feb 26, 2014 @proxypoke Merge pull request #2 from Avinash-Bhat/master
fix: check if the socket is getting opened
Permalink
Failed to load latest commit information.
README.md Updated README with usage information and license. Oct 18, 2012
bar.go Adds missing documentation and a file header. Oct 18, 2012
bar_test.go Adds missing documentation and a file header. Oct 18, 2012
command.go Adds missing documentation and a file header. Oct 18, 2012
command_test.go Adds missing documentation and a file header. Oct 18, 2012
doc.go Adds missing documentation and a file header. Oct 18, 2012
header Adds missing documentation and a file header. Oct 18, 2012
marks.go Adds missing documentation and a file header. Oct 18, 2012
marks_test.go Adds missing documentation and a file header. Oct 18, 2012
outputs.go Adds missing documentation and a file header. Oct 18, 2012
outputs_test.go Adds missing documentation and a file header. Oct 18, 2012
socket.go Makes constants MAGIC and HEADERLEN unexported. Nov 7, 2012
socket_test.go Adds missing documentation and a file header. Oct 18, 2012
subscribe.go fix: check if the socket is getting opened Feb 5, 2014
subscribe_test.go Adds missing documentation and a file header. Oct 18, 2012
tree.go Adds missing documentation and a file header. Oct 18, 2012
tree_test.go Adds missing documentation and a file header. Oct 18, 2012
version.go Adds missing documentation and a file header. Oct 18, 2012
version_test.go Adds missing documentation and a file header. Oct 18, 2012
workspaces.go Adds missing documentation and a file header. Oct 18, 2012
workspaces_test.go Adds missing documentation and a file header. Oct 18, 2012

README.md

i3ipc

Overview

i3ipc is a library for convenient access to the IPC API of the i3 window manager.

Capabilities

As of the time of writing, this library is able to access all functionality of the IPC API of i3. This includes sending commands and other message types, as well as handling subscriptions.

If you just want a quick overview of the documentation, head to go.pkgdoc.org.

Usage

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

import "github.com/proxypoke/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 subscribe to workspace events, then simple print all of them as we receive them:

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 subscribtions, then demultiplex those channels yourself - select is your friend.

License

This program is free software under the terms of the Do What The Fuck You Want To Public License. It comes without any warranty, to the extent permitted by applicable law. For a copy of the license, see COPYING or head to http://sam.zoy.org/wtfpl/COPYING.