The examples below assume some familiarity with Qt development as well as i3wm's IPC idioms.
Below is an example that monitors window events from i3wm.
There are no free functions. All functionality is through the qi3pc class. So first, an object of that class has to be constructed.
Events from the window manager are available as Qt signals. To monitor those events, simply subscribe to them as to any other Qt signal. Window events include creation of new window, focus change, window move, etc.
Next, connect to the i3wm's IPC server.
Multiple qi3pc objects can be instantiated in the same application. Each object is only notified of the event it cares about. These events have to be explicitly subscribed to. Without this, the qi3pc::windowEvent signal will never fire on this object, and the lambda in the connection above will never run.
Below is an example showing how to automatically move to a newly created workspace.
When a new workspace is created, a command is sent to switch to it. As simple as that!
In the example above, after sending the workspace change request to i3wm, the response is not monitored, simply because the interesting side effect is the wokspace change itself (and also because it was just a simple example). However, sometimes we are interested in the reply from the wm. For those cases, message replies are also published with Qt signals.
To actively fetch information from i3wm, the fetch methods can be used (e.g. qi3pc::fetchWorkspaces). When called, a message is sent to i3wm, and the reply is published through a reply signal. In the case of workspaces, through qi3pc::workspacesUpdated.
Additionally, the reply is cached along with its last update time. This cached data is available through another member function, in this case qi3pc::workspaces.
The following is an example of using that workflow.
Note that in this case there was no need to subscribe to workspace events with qi3pc::subscribe.
Other examples can be found in the repository.