4#include "QtNetwork/qlocalsocket.h"
5#include "qi3pc_global.h"
8#include <QJsonDocument>
10#include <QLocalSocket>
11#include <QMutexLocker>
12#include <QProcessEnvironment>
24class QI3PCSHARED_EXPORT
qi3pc :
public QObject
30 static constexpr auto IpcMagicString = I3_IPC_MAGIC;
31 static constexpr auto IpcMagicLength = 6;
39 Workspace = I3_IPC_EVENT_WORKSPACE,
40 Output = I3_IPC_EVENT_OUTPUT,
41 Mode = I3_IPC_EVENT_MODE,
42 Window = I3_IPC_EVENT_WINDOW,
43 BarUpdate = I3_IPC_EVENT_BARCONFIG_UPDATE,
44 Binding = I3_IPC_EVENT_BINDING,
45 Shutdown = I3_IPC_EVENT_SHUTDOWN,
46 Tick = I3_IPC_EVENT_TICK
55 Command = I3_IPC_REPLY_TYPE_COMMAND,
56 Workspaces = I3_IPC_REPLY_TYPE_WORKSPACES,
57 Subscribe = I3_IPC_REPLY_TYPE_SUBSCRIBE,
58 Outputs = I3_IPC_REPLY_TYPE_OUTPUTS,
59 Tree = I3_IPC_REPLY_TYPE_TREE,
60 Marks = I3_IPC_REPLY_TYPE_MARKS,
61 BarConfig = I3_IPC_REPLY_TYPE_BAR_CONFIG,
62 Version = I3_IPC_REPLY_TYPE_VERSION,
63 BindingModes = I3_IPC_REPLY_TYPE_BINDING_MODES,
64 Config = I3_IPC_REPLY_TYPE_CONFIG,
65 Tick = I3_IPC_REPLY_TYPE_TICK,
66 Sync = I3_IPC_REPLY_TYPE_SYNC
157 using DataObject = std::optional<std::pair<QJsonObject, qint64>>;
162 using DataArray = std::optional<std::pair<QJsonArray, qint64>>;
163 using Error = std::optional<QString>;
164 using Message = std::optional<std::pair<QJsonDocument, quint32>>;
170 explicit qi3pc(QObject* parent =
nullptr);
216 void subscribe(
const QStringList& events);
222 QString socketPath()
const;
236 void sendMessage(
IpcType type,
const QByteArray& payload = QByteArray());
311 Message processMessage(QLocalSocket& socket);
327 void processWorkspaceEvent(
const QJsonDocument& doc);
333 void processOutputEvent(
const QJsonDocument& doc);
339 void processModeEvent(
const QJsonDocument& doc);
345 void processWindowEvent(
const QJsonDocument& doc);
351 void processBarUpdateEvent(
const QJsonDocument& doc);
357 void processBindingEvent(
const QJsonDocument& doc);
363 void processShutdownEvent(
const QJsonDocument& doc);
369 void processTickEvent(
const QJsonDocument& doc);
375 void processCommandReply(
const QJsonDocument& doc);
381 void processWorkspaceReply(
const QJsonDocument& doc);
387 void processOutputReply(
const QJsonDocument& doc);
393 void processTreeReply(
const QJsonDocument& doc);
399 void processMarkReply(
const QJsonDocument& doc);
405 void processBarConfigReply(
const QJsonDocument& doc);
411 void processVersionReply(
const QJsonDocument& doc);
417 void processModeReply(
const QJsonDocument& doc);
423 void processConfigReply(
const QJsonDocument& doc);
429 void processTickReply(
const QJsonDocument& doc);
435 void processSyncReply(
const QJsonDocument& doc);
449 WindowChange windowChangeFromString(
const QString& s)
const;
463 OutputChange outputChangeFromString(
const QString& s)
const;
470 BindingChange bindingChangeFromString(
const QString& s)
const;
533 const QJsonObject& current,
534 const QJsonObject& old);
Class mapping to the to the i3wm IPC interface.
Definition qi3pc.h:25
ShutdownChange
Enum holding the types of change a shutdown event can have.
Definition qi3pc.h:134
void configUpdated(const qi3pc::DataObject &config)
Signal emitted when the (cached) config have been updated.
DataArray m_workspaces
Definition qi3pc.h:479
void treeUpdated(const qi3pc::DataObject &tree)
Signal emitted when the layout tree cache have been updated.
WindowChange
Definition qi3pc.h:112
void barConfigUpdated(const QJsonObject &config)
Signal emitted when a specific bar's (cached) config have been updated.
void fetchConfig()
Signal to emit to trigger an update of the (cached) config.
DataArray m_modes
Definition qi3pc.h:484
void fetchBarConfigs()
Signal to emit to update the list of bar configurations.
DataObject m_version
Definition qi3pc.h:483
void bindingEvent(qi3pc::BindingChange change, const QJsonObject &binding)
Signal emitteed when a binding have been triggered to run a command.
void barUpdateEvent(const QJsonObject &doc)
Signal emitted when a bar's configuration have been updated.
QLocalSocket m_messageSocket
Definition qi3pc.h:476
void workspacesUpdated(const qi3pc::DataArray &workspaces)
Signal emitted when the (cached) list of workspaces have been updated.
void synced(bool success)
Signal emitted when a sync message have been replied to by i3.
void tickSent(bool success)
Signal emitted when a tick have been processed by i3.
DataObject m_config
Definition qi3pc.h:485
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 conne...
void subscribed(bool success)
Signal emitted when a subscribe message have been replied to.
void fetchBarConfig(const QString &id)
Signal to emit to update the (cached) configuration of a certain bar.
void outputEvent(qi3pc::OutputChange change)
Signal emitted when the output(s) change.
void fetchTree()
Signal to emit to trigger an update of the (cached) layout tree.
void modesUpdated(const qi3pc::DataArray &modes)
Signal emitted when the (cached) list of modes have been updated.
DataArray m_marks
Definition qi3pc.h:481
void fetchOutputs()
Signal to emit to trigger an update of the (cached) outputs.
void versionUpdated(const qi3pc::DataObject &version)
Signal emitted when the (cached) i3 version have been updated.
void outputsUpdated(const qi3pc::DataArray &outputs)
Signal emitted when (cached) outputs have been updated.
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.
QLocalSocket m_eventSocket
Definition qi3pc.h:475
void fetchMarks()
Signal to emit to trigger an update of the (cached) list of marks.
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 commandRan(bool success, qi3pc::Error error)
Signal emitted when a command have been ran by i3.
IpcType
Enum holding the types of messages the API expect to send and receive replies for from i3.
Definition qi3pc.h:54
DataObject m_barConfigs
Definition qi3pc.h:482
BindingChange
Definition qi3pc.h:149
void marksUpdated(const qi3pc::DataArray &marks)
Signal emitted when the (cached) list of marks have been updated.
OutputChange
Enum holding the types of change an output event can have.
Definition qi3pc.h:98
std::optional< std::pair< QJsonObject, qint64 > > DataObject
Definition qi3pc.h:157
WorkspaceChange
Enum holding the types of change a workspace event can have.
Definition qi3pc.h:77
void fetchWorkspaces()
Signal to emit to trigger an update of the list of workspace cache.
DataArray m_outputs
Definition qi3pc.h:480
void shutdownEvent(qi3pc::ShutdownChange change)
Signal emitted when the ipc socket i about to shutdown.
void workspaceEvent(qi3pc::WorkspaceChange change, const QJsonObject ¤t, const QJsonObject &old)
Signal emitted with a workspace event's data preprocessed.
void fetchModes()
Signal to emit to trigger an update of the (cached) list of modes.
std::optional< std::pair< QJsonArray, qint64 > > DataArray
Definition qi3pc.h:162
DataObject m_tree
Definition qi3pc.h:478
QString m_socketPath
Definition qi3pc.h:473
IpcEvent
Enum holding the types of events offered by the i3wm's IPC API.
Definition qi3pc.h:38