I3_client - i3 IPC client, written in Erlang

, ,

This is an i3 IPC client implementation, written in Erlang, with zero dependencies. All the messages and events exposed by i3 and Sway are currently supported.

It’s a very early release but it’s fully featured. My next two priorities are improving the test coverage and extending the documentation with examples. Nevertheless, I’ll be happy to hear from early users.

Notable features

  • Variant negotiation - rudimentary capability checks but the fundamentals are ther
  • Automatic reconnection - opt-in but nice to have
  • Multiplexing - a single connection can handle request-response and out-of-band events.

Example

The following example shows how to start a client connection, subscribe to events and run commands. All using the same connection, all idiomatic OTP behaviour.

erl> {ok, Pid} = i3_client:start_link([]).
erl> {ok, Ref} = i3_client:subscribe(Pid, [<<"window">>]).
erl> {ok, _} = i3_client:run_command(Pid, <<"focus right">>).
erl> flush().
{i3_event, Pid, Ref, <<"window">>, <<"...">>} % Pseudocode but you get the idea

Hex: i3_client | Hex
Source:

5 Likes

I’m happy to announce that v0.2.0 was just released.

This version brings one user-facing change - first tick events, the ones received right after a subscription to tick events is made, are treated as unicast events. They used to be broadcast events, like any other type of event, but it was an incorrect behaviour. I knowingly left it that way in the initial version because it was tolerable but now it’s time for correct and predictable handling of this special kind of event.

1 Like

I’m happy to announce that v0.3.0 was just released.

This version brings a new module - i3_client_trees which includes functions for processing i3 layout trees. Currently, it holds only two functions - table/1,2. The functions return QLC handle which allows for iterator style traversal. For example, you can very easily find the focused node:

0> QH = qlc:q([Node || #{~"focused" := true} = Node <- i3_client_trees:table(Tree)]),
1> [#{~"focused" := true}] = qlc:eval(QH).