aio.Connection¶
- class i3ipc.aio.Connection(socket_path: str | None = None, auto_reconnect: bool = False)¶
A connection to the i3 ipc used for querying window manager state and listening to events.
The
Connection
class is the entry point into all features of the library. You must callconnect()
before using thisConnection
.- Example:
i3 = await Connection().connect() workspaces = await i3.get_workspaces() await i3.command('focus left')
- Parameters:
socket_path (str) – A path to the i3 ipc socket path to connect to. If not given, find the socket path through the default search path.
auto_reconnect (bool) – Whether to attempt to reconnect if the connection to the socket is broken when i3 restarts.
- Raises:
Exception – If the connection to i3 cannot be established.
- property auto_reconect: bool¶
Whether this
Connection
will attempt to reconnect when the connection to the socket is broken.- Return type:
bool
- coroutine command(cmd: str) List[CommandReply] ¶
Sends a command to i3.
- Parameters:
cmd (str) – The command to send to i3.
- Returns:
A list of replies that contain info for the result of each command given.
- Return type:
list(
CommandReply
)
- coroutine connect() Connection ¶
Connects to the i3 ipc socket. You must await this method to use this Connection.
- Returns:
The
Connection
.- Return type:
- coroutine get_bar_config(bar_id=None) BarConfigReply | None ¶
Gets the bar configuration specified by the id.
- Parameters:
bar_id (str) – The bar id to get the configuration for. If not given, get the configuration for the first bar id.
- Returns:
The bar configuration for the bar id.
- Return type:
BarConfigReply
orNone
if no bar configuration is found.
- coroutine get_bar_config_list() List[str] ¶
Gets the names of all bar configurations.
- Returns:
A list of all bar configurations.
- Return type:
list(str)
- coroutine get_binding_modes() List[str] ¶
Gets the names of all currently configured binding modes
- Returns:
A list of binding modes
- Return type:
list(str)
- coroutine get_config() ConfigReply ¶
Returns the last loaded i3 config.
- Returns:
A class containing the config.
- Return type:
- coroutine get_inputs() List[InputReply] ¶
(sway only) Gets the inputs connected to the compositor.
- Returns:
The reply to the inputs command
- Return type:
list(
i3ipc.InputReply
)
- coroutine get_marks() List[str] ¶
Gets the names of all currently set marks.
- Returns:
A list of currently set marks.
- Return type:
list(str)
- coroutine get_outputs() List[OutputReply] ¶
Gets the list of current outputs.
- Returns:
A list of current outputs.
- Return type:
list(
i3ipc.OutputReply
)
- coroutine get_seats() List[SeatReply] ¶
(sway only) Gets the seats configured on the compositor
- Returns:
The reply to the seats command
- Return type:
list(
i3ipc.SeatReply
)
- coroutine get_tree() Con ¶
Gets the root container of the i3 layout tree.
- Returns:
The root container of the i3 layout tree.
- Return type:
- coroutine get_version() VersionReply ¶
Gets the i3 version.
- Returns:
The i3 version.
- Return type:
- coroutine get_workspaces() List[WorkspaceReply] ¶
Gets the list of current workspaces.
- Returns:
A list of current workspaces
- Return type:
list(
i3ipc.WorkspaceReply
)
- coroutine main()¶
Starts the main loop for this connection to start handling events.
- main_quit(_error=None)¶
Quits the running main loop for this connection.
- off(handler: Callable[[Connection, IpcBaseEvent], None])¶
Unsubscribe the handler from being called on ipc events.
- Parameters:
handler (
Callable
) – The handler that was previously attached withon()
.
- on(event: Event | str, handler: Callable[[Connection, IpcBaseEvent], None])¶
Subscribe to the event and call the handler when it is emitted by the i3 ipc.
- Parameters:
event (
Event
or str) – The event to subscribe to.handler (
Callable
) – The event handler to call.
- coroutine send_tick(payload: str = '') TickReply ¶
Sends a tick with the specified payload.
- Returns:
The reply to the tick command
- Return type:
- property socket_path: str¶
The path of the socket this
Connection
is connected to.- Return type:
str
- coroutine subscribe(events: List[Event] | List[str], force: bool = False)¶
Send a
SUBSCRIBE
command to the ipc subscription connection and await the result. To attach event handlers, useConnection.on()
. Calling this is only needed if you want to be notified when events will start coming in.- Variables:
events (list(
Event
) or list(str)) – A list of events to subscribe to. Currently you cannot subscribe to detailed events.force (bool) – If
False
, the message will not be sent if this connection is already subscribed to the event.