qi3pc 0.1.2
Qt based library to communicate with i3wm via its IPC API
|
Class mapping to the to the i3wm IPC interface. More...
#include <qi3pc.h>
Public Types | |
enum class | IpcEvent : quint32 { Workspace = I3_IPC_EVENT_WORKSPACE , Output = I3_IPC_EVENT_OUTPUT , Mode = I3_IPC_EVENT_MODE , Window = I3_IPC_EVENT_WINDOW , BarUpdate = I3_IPC_EVENT_BARCONFIG_UPDATE , Binding = I3_IPC_EVENT_BINDING , Shutdown = I3_IPC_EVENT_SHUTDOWN , Tick = I3_IPC_EVENT_TICK } |
Enum holding the types of events offered by the i3wm's IPC API. | |
enum class | IpcType : quint32 { Command = I3_IPC_REPLY_TYPE_COMMAND , Workspaces = I3_IPC_REPLY_TYPE_WORKSPACES , Subscribe = I3_IPC_REPLY_TYPE_SUBSCRIBE , Outputs = I3_IPC_REPLY_TYPE_OUTPUTS , Tree = I3_IPC_REPLY_TYPE_TREE , Marks = I3_IPC_REPLY_TYPE_MARKS , BarConfig = I3_IPC_REPLY_TYPE_BAR_CONFIG , Version = I3_IPC_REPLY_TYPE_VERSION , BindingModes = I3_IPC_REPLY_TYPE_BINDING_MODES , Config = I3_IPC_REPLY_TYPE_CONFIG , Tick = I3_IPC_REPLY_TYPE_TICK , Sync = I3_IPC_REPLY_TYPE_SYNC } |
Enum holding the types of messages the API expect to send and receive replies for from i3. | |
enum class | WorkspaceChange { Focus , Init , Empty , Urgent , Reload , Rename , Restored , Move , Unknown } |
Enum holding the types of change a workspace event can have. More... | |
enum class | OutputChange { Unspecified , Unknown } |
Enum holding the types of change an output event can have. More... | |
enum class | WindowChange { New , Close , Focus , Title , Fullscreen , Move , Floating , Urgent , Mark , Unknown } |
enum class | ShutdownChange { Restart , Exit , Unknown } |
Enum holding the types of change a shutdown event can have. More... | |
enum class | BindingChange { Run , Unknown } |
using | DataObject = std::optional<std::pair<QJsonObject, qint64>> |
using | DataArray = std::optional<std::pair<QJsonArray, qint64>> |
using | Error = std::optional<QString> |
using | Message = std::optional<std::pair<QJsonDocument, quint32>> |
Signals | |
void | commandRan (bool success, qi3pc::Error error) |
Signal emitted when a command have been ran by i3. | |
void | tickSent (bool success) |
Signal emitted when a tick have been processed by i3. | |
void | synced (bool success) |
Signal emitted when a sync message have been replied to by i3. | |
void | subscribed (bool success) |
Signal emitted when a subscribe message have been replied to. | |
void | workspaceEvent (qi3pc::WorkspaceChange change, const QJsonObject ¤t, const QJsonObject &old) |
Signal emitted with a workspace event's data preprocessed. | |
void | outputEvent (qi3pc::OutputChange change) |
Signal emitted when the output(s) change. | |
void | modeEvent (QString change, bool pango) |
Signal emitted when the binding mode changes. | |
void | windowEvent (qi3pc::WindowChange change, const QJsonObject &container) |
Signal emitted when a window changes. | |
void | barUpdateEvent (const QJsonObject &doc) |
Signal emitted when a bar's configuration have been updated. | |
void | bindingEvent (qi3pc::BindingChange change, const QJsonObject &binding) |
Signal emitteed when a binding have been triggered to run a command. | |
void | shutdownEvent (qi3pc::ShutdownChange change) |
Signal emitted when the ipc socket i about to shutdown. | |
void | tickEvent (bool first, const QJsonObject &payload) |
Signal emitted when subscribing to tick events or when a tick message have been sent to the ipc connection. | |
void | fetchWorkspaces () |
Signal to emit to trigger an update of the list of workspace cache. | |
void | workspacesUpdated (const qi3pc::DataArray &workspaces) |
Signal emitted when the (cached) list of workspaces have been updated. | |
void | fetchTree () |
Signal to emit to trigger an update of the (cached) layout tree. | |
void | treeUpdated (const qi3pc::DataObject &tree) |
Signal emitted when the layout tree cache have been updated. | |
void | fetchOutputs () |
Signal to emit to trigger an update of the (cached) outputs. | |
void | outputsUpdated (const qi3pc::DataArray &outputs) |
Signal emitted when (cached) outputs have been updated. | |
void | fetchMarks () |
Signal to emit to trigger an update of the (cached) list of marks. | |
void | marksUpdated (const qi3pc::DataArray &marks) |
Signal emitted when the (cached) list of marks have been updated. | |
void | fetchBarConfig (const QString &id) |
Signal to emit to update the (cached) configuration of a certain bar. | |
void | fetchBarConfigs () |
Signal to emit to update the list of bar configurations. | |
void | barConfigUpdated (const QJsonObject &config) |
Signal emitted when a specific bar's (cached) config have been updated. | |
void | newBarConfig (const QString &id) |
Signal emitted when a new bar config have been added to the cache. | |
void | fetchVersion () |
Signal to emit to trigger a cache update for the i3wm version. | |
void | versionUpdated (const qi3pc::DataObject &version) |
Signal emitted when the (cached) i3 version have been updated. | |
void | fetchModes () |
Signal to emit to trigger an update of the (cached) list of modes. | |
void | modesUpdated (const qi3pc::DataArray &modes) |
Signal emitted when the (cached) list of modes have been updated. | |
void | fetchConfig () |
Signal to emit to trigger an update of the (cached) config. | |
void | configUpdated (const qi3pc::DataObject &config) |
Signal emitted when the (cached) config have been updated. | |
Public Member Functions | |
qi3pc (QObject *parent=nullptr) | |
Construct an qi3pc object. | |
virtual | ~qi3pc () |
Simple destructor for the qi3pc class. | |
bool | connect () |
Connect to the unix socket. | |
bool | connected () |
Check if the connection to the ipc socket is established. | |
bool | disconnect () |
Disconnect from the ipc. | |
void | subscribe (const QStringList &events) |
Subscribe to a list of events. | |
QString | socketPath () const |
Get the path to the i3 ipc local unix socket. | |
void | sendMessage (IpcType type, const QByteArray &payload=QByteArray()) |
Send a message with the specified type and payload to i3. | |
DataArray | workspaces () const |
Get the list of (cached) worksaces. | |
DataObject | tree () const |
Get the (cached) i3 layout tree. | |
DataArray | outputs () const |
Get the (cached) list of outputs. | |
DataArray | marks () const |
Get the (cached) list of set marks. | |
DataObject | barConfigs () const |
Get the (cached) list of all bar configurations. | |
DataObject | version () const |
Get the (cached) i3 version object. | |
DataArray | modes () const |
Get the (cached) list of binding modes. | |
DataObject | config () const |
Get the (cached) data read from the config file. | |
Static Public Attributes | |
static constexpr auto | IpcMagicString = I3_IPC_MAGIC |
static constexpr auto | IpcMagicLength = 6 |
Private Member Functions | |
Message | processMessage (QLocalSocket &socket) |
Read one message using the socket parameter. | |
void | processEvent () |
Read data from the event socket. | |
void | processReply () |
Read data from the message socket. | |
void | processWorkspaceEvent (const QJsonDocument &doc) |
Handle data received from a workspace event. | |
void | processOutputEvent (const QJsonDocument &doc) |
Handle data received from an output event. | |
void | processModeEvent (const QJsonDocument &doc) |
Handle data received from a mode event. | |
void | processWindowEvent (const QJsonDocument &doc) |
Handle data received from a window event. | |
void | processBarUpdateEvent (const QJsonDocument &doc) |
Handle data received from an update event. | |
void | processBindingEvent (const QJsonDocument &doc) |
Handle data received from a binding event. | |
void | processShutdownEvent (const QJsonDocument &doc) |
Handle data received from a shutdowm event. | |
void | processTickEvent (const QJsonDocument &doc) |
Handle data received from a tick event. | |
void | processCommandReply (const QJsonDocument &doc) |
Handle data received from a run command reply. | |
void | processWorkspaceReply (const QJsonDocument &doc) |
Handle data received from a workspace reply. | |
void | processOutputReply (const QJsonDocument &doc) |
Handle data received from an output reply. | |
void | processTreeReply (const QJsonDocument &doc) |
Handle data received from a tree reply. | |
void | processMarkReply (const QJsonDocument &doc) |
Handle data received from a mark reply. | |
void | processBarConfigReply (const QJsonDocument &doc) |
Handle data received from a bar config reply. | |
void | processVersionReply (const QJsonDocument &doc) |
Handle data received from a version reply. | |
void | processModeReply (const QJsonDocument &doc) |
Handle data received from a mode reply. | |
void | processConfigReply (const QJsonDocument &doc) |
Handle data received from a config reply. | |
void | processTickReply (const QJsonDocument &doc) |
Handle data received from a tick reply. | |
void | processSyncReply (const QJsonDocument &doc) |
Handle data received from a sync reply. | |
WorkspaceChange | workspaceChangeFromString (const QString &s) const |
Convert a string into a workspace change object. | |
WindowChange | windowChangeFromString (const QString &s) const |
Convert a string into a window change object. | |
ShutdownChange | shutdownChangeFromString (const QString &s) const |
Convert a string into a shutdown change object. | |
OutputChange | outputChangeFromString (const QString &s) const |
Convert a string into an output change object. | |
BindingChange | bindingChangeFromString (const QString &s) const |
Convert a string into a binding change object. | |
Private Attributes | |
QString | m_socketPath |
QLocalSocket | m_eventSocket |
QLocalSocket | m_messageSocket |
DataObject | m_tree |
DataArray | m_workspaces |
DataArray | m_outputs |
DataArray | m_marks |
DataObject | m_barConfigs |
DataObject | m_version |
DataArray | m_modes |
DataObject | m_config |
Class mapping to the to the i3wm IPC interface.
This class is an intuitive layer over the API offered by the i3wm IPC interface.
using qi3pc::DataObject = std::optional<std::pair<QJsonObject, qint64>> |
Alias used for cached JSON objects.
using qi3pc::DataArray = std::optional<std::pair<QJsonArray, qint64>> |
Alias used for cached JSON arrays.
|
strong |
Enum holding the types of change a workspace event can have.
Enum holding the types of change a binding event can have.
Enum holding the types of change a window event can have.
This information is taken from the change (a string) received with the event.
|
strong |
|
strong |
|
strong |
|
strong |
|
explicit |
Construct an qi3pc object.
parent | Parent of the qi3pc object to create |
References fetchBarConfig(), fetchBarConfigs(), fetchConfig(), fetchMarks(), fetchModes(), fetchOutputs(), fetchTree(), fetchVersion(), fetchWorkspaces(), m_eventSocket, m_messageSocket, m_socketPath, processEvent(), processReply(), sendMessage(), and socketPath().
|
virtual |
Simple destructor for the qi3pc class.
Disconnects the used sockets.
References m_eventSocket, and m_messageSocket.
bool qi3pc::connect | ( | ) |
Connect to the unix socket.
This method may wait up to 3 seconds for the connection to be established. If it takes more than 3 seconds to connect, the connection might be established later, but the returned value will not reflect that.
References m_eventSocket, m_messageSocket, and m_socketPath.
bool qi3pc::connected | ( | ) |
Check if the connection to the ipc socket is established.
References m_eventSocket, and m_messageSocket.
bool qi3pc::disconnect | ( | ) |
Disconnect from the ipc.
References m_eventSocket, and m_messageSocket.
void qi3pc::subscribe | ( | const QStringList & | events | ) |
Subscribe to a list of events.
events | A list of string with the events to subscribe to. |
References m_eventSocket.
QString qi3pc::socketPath | ( | ) | const |
Get the path to the i3 ipc local unix socket.
void qi3pc::sendMessage | ( | IpcType | type, |
const QByteArray & | payload = QByteArray() ) |
Send a message with the specified type and payload to i3.
type | The type of the message to send. |
payload | The content of the message. |
Available message types.
Do not use this method to send messages, use qi3pc::subscribe instead.
References m_messageSocket.
qi3pc::DataArray qi3pc::workspaces | ( | ) | const |
Get the list of (cached) worksaces.
References m_workspaces.
qi3pc::DataObject qi3pc::tree | ( | ) | const |
Get the (cached) i3 layout tree.
References m_tree.
qi3pc::DataArray qi3pc::outputs | ( | ) | const |
Get the (cached) list of outputs.
References m_outputs.
qi3pc::DataArray qi3pc::marks | ( | ) | const |
Get the (cached) list of set marks.
References m_marks.
qi3pc::DataObject qi3pc::barConfigs | ( | ) | const |
Get the (cached) list of all bar configurations.
References m_barConfigs.
qi3pc::DataObject qi3pc::version | ( | ) | const |
Get the (cached) i3 version object.
References m_version.
qi3pc::DataArray qi3pc::modes | ( | ) | const |
Get the (cached) list of binding modes.
References m_modes.
qi3pc::DataObject qi3pc::config | ( | ) | const |
Get the (cached) data read from the config file.
References m_config.
|
private |
Read one message using the socket parameter.
socket | Local unix socket from which the message is read |
|
private |
Handle data received from a workspace event.
doc | Document containing the data |
References workspaceChangeFromString(), and workspaceEvent().
|
private |
Handle data received from an output event.
doc | Document containing the data |
References outputChangeFromString(), outputEvent(), and Unknown.
|
private |
Handle data received from a mode event.
doc | Document containing the data |
References modeEvent().
|
private |
Handle data received from a window event.
doc | Document containing the data |
References Unknown, windowChangeFromString(), and windowEvent().
|
private |
Handle data received from an update event.
doc | Document containing the data |
References barUpdateEvent().
|
private |
Handle data received from a binding event.
doc | Document containing the data |
References bindingChangeFromString(), bindingEvent(), and Unknown.
|
private |
Handle data received from a shutdowm event.
doc | Document containing the data |
References shutdownChangeFromString(), shutdownEvent(), and Unknown.
|
private |
Handle data received from a tick event.
doc | Document containing the data |
References tickEvent().
|
private |
Handle data received from a run command reply.
doc | Document containing the data |
References commandRan().
|
private |
Handle data received from a workspace reply.
doc | Document containing the data |
References m_workspaces, and workspacesUpdated().
|
private |
Handle data received from an output reply.
doc | Document containing the data |
References m_outputs, and outputsUpdated().
|
private |
Handle data received from a tree reply.
doc | Document containing the data |
References m_tree, and treeUpdated().
|
private |
Handle data received from a mark reply.
doc | Document containing the data |
References m_marks, and marksUpdated().
|
private |
Handle data received from a bar config reply.
doc | Document containing the data |
References barConfigUpdated(), config(), m_barConfigs, and newBarConfig().
|
private |
Handle data received from a version reply.
doc | Document containing the data |
References m_version, and versionUpdated().
|
private |
Handle data received from a mode reply.
doc | Document containing the data |
References m_modes, and modesUpdated().
|
private |
Handle data received from a config reply.
doc | Document containing the data |
References configUpdated(), and m_config.
|
private |
Handle data received from a tick reply.
doc | Document containing the data |
References tickSent().
|
private |
Handle data received from a sync reply.
doc | Document containing the data |
References synced().
|
private |
Convert a string into a workspace change object.
s | The string to convert |
|
private |
Convert a string into a window change object.
s | The string to convert |
References Close, Focus, Fullscreen, Mark, Move, New, Title, Unknown, and Urgent.
|
private |
Convert a string into a shutdown change object.
s | The string to convert |
|
private |
Convert a string into an output change object.
s | The string to convert |
References Unknown, and Unspecified.
|
private |
Convert a string into a binding change object.
s | The string to convert |
|
signal |
Signal emitted when a command have been ran by i3.
success | Command exit status (??) |
error | Optional human readable string describing an error |
|
signal |
Signal emitted when a tick have been processed by i3.
success | ?? |
Use to send tick messages with the qi3pc::IpcType::Tick type.
|
signal |
Signal emitted when a sync message have been replied to by i3.
success | ?? |
|
signal |
Signal emitted when a subscribe message have been replied to.
success | ?? |
|
signal |
Signal emitted with a workspace event's data preprocessed.
change | The type of change |
current | The current workspace |
old | The old workspace |
|
signal |
Signal emitted when the output(s) change.
change | The type of change |
|
signal |
Signal emitted when the binding mode changes.
change | The name of the current mode. |
pango | Boolean telling whether to display the mode with pango markup. |
|
signal |
Signal emitted when a window changes.
change | The type of change. |
container | The parent of the changed window. |
|
signal |
Signal emitted when a bar's configuration have been updated.
doc | Json object containing the bar configuration. |
|
signal |
Signal emitteed when a binding have been triggered to run a command.
change | The type of change. |
binding | The binding that was run. |
|
signal |
Signal emitted when the ipc socket i about to shutdown.
change | The type of change. |
|
signal |
Signal emitted when subscribing to tick events or when a tick message have been sent to the ipc connection.
first | Boolean specifying whether this is a subscription |
payload | Arbitrary payload sent with the tick message. Empty for subscriptions. |
|
signal |
Signal to emit to trigger an update of the list of workspace cache.
|
signal |
Signal emitted when the (cached) list of workspaces have been updated.
workspaces | The last list of workspaces with the update time. |
|
signal |
Signal to emit to trigger an update of the (cached) layout tree.
|
signal |
Signal emitted when the layout tree cache have been updated.
tree | The most recent layout tree cached and its update time. |
|
signal |
Signal to emit to trigger an update of the (cached) outputs.
|
signal |
Signal emitted when (cached) outputs have been updated.
outputs | The latest list of outputs and their update time. |
|
signal |
Signal to emit to trigger an update of the (cached) list of marks.
|
signal |
Signal emitted when the (cached) list of marks have been updated.
marks | The most recent list of marks and the time when it was updated. |
|
signal |
Signal to emit to update the (cached) configuration of a certain bar.
id | String identifying to bar to update. |
|
signal |
Signal to emit to update the list of bar configurations.
|
signal |
Signal emitted when a specific bar's (cached) config have been updated.
config | The relevant bar's configuration. |
|
signal |
Signal emitted when a new bar config have been added to the cache.
id | The id of the new bar. |
Only the id is stored at first. Call with the appropriate id to update it.
|
signal |
Signal to emit to trigger a cache update for the i3wm version.
|
signal |
Signal emitted when the (cached) i3 version have been updated.
version | Json object with the latest cached version and the time when it was updated. |
|
signal |
Signal to emit to trigger an update of the (cached) list of modes.
|
signal |
Signal emitted when the (cached) list of modes have been updated.
modes | The most recent list of modes and the time when it was updated. |
|
signal |
Signal to emit to trigger an update of the (cached) config.
|
signal |
Signal emitted when the (cached) config have been updated.
The | most recent config and the time when it was updated. |
|
private |
Path of the local unix socket used.
|
private |
Socket used to subscribe and handle events.
|
private |
Socket used to send messages and handle replies.
|
private |
Layout tree cache.
|
private |
Workspace list cache.
|
private |
Output list cache.
|
private |
Mark list cache.
|
private |
Bar configuration list cache.
|
private |
Version cache.
|
private |
Modes list cache.
|
private |
Configuration cache.