quickshell/src/x11/i3/ipc/qml.hpp
Nydragon 31adcaac76
i3/sway: add support for the I3 and Sway IPC
sway: add urgent and focused dispatchers to workspaces

flake: add sway toggle

WIP sway: add monitor status

sway: handle multiple ipc events in one line

sway: reuse socket connection for dispatches & better command type handling

WIP sway: add associated monitor to a workspace

i3/sway: update to allow for i3 compatibility

i3/sway: manage setting the focused monitors

i3/sway: fix multi monitor crash

i3/sway: fix linting errors

i3/sway: update nix package flag naming to i3

i3/sway: add documentation, fix module.md and impl monitorFor

i3/sway: handle more workspace ipc events

i3/sway: fix review

i3/sway: fix crash due to newline breaking up an IPC message

i3/sway: handle broken messages by forwarding to the next magic sequence

i3/sway: break loop when buffer is empty

i3/sway: fix monitor focus & focused monitor signal not being emitted

i3/sway: use datastreams instead of qbytearrays for socket reading

i3/sway: fix lint issues

i3/sway: drop second socket connection, remove dispatch return value, recreate IPC connection on fatal error

i3/sway: handle run_command responses

i3/sway: remove reconnection on unknown event

i3/sway: fix formatting, lint & avoid writing to socket if connection is not open
2024-11-24 12:50:22 +01:00

74 lines
2.3 KiB
C++

#pragma once
#include <qjsonarray.h>
#include <qobject.h>
#include "../../../core/doc.hpp"
#include "../../../core/qmlscreen.hpp"
#include "connection.hpp"
namespace qs::i3::ipc {
///! I3/Sway IPC integration
class I3IpcQml: public QObject {
Q_OBJECT;
// clang-format off
/// Path to the I3 socket
Q_PROPERTY(QString socketPath READ socketPath CONSTANT);
Q_PROPERTY(qs::i3::ipc::I3Workspace* focusedWorkspace READ focusedWorkspace NOTIFY focusedWorkspaceChanged);
Q_PROPERTY(qs::i3::ipc::I3Monitor* focusedMonitor READ focusedMonitor NOTIFY focusedMonitorChanged);
/// All I3 monitors.
QSDOC_TYPE_OVERRIDE(ObjectModel<qs::i3::ipc::I3Monitor>*);
Q_PROPERTY(UntypedObjectModel* monitors READ monitors CONSTANT);
/// All I3 workspaces.
QSDOC_TYPE_OVERRIDE(ObjectModel<qs::i3::ipc::I3Workspace>*);
Q_PROPERTY(UntypedObjectModel* workspaces READ workspaces CONSTANT);
// clang-format on
QML_NAMED_ELEMENT(I3);
QML_SINGLETON;
public:
explicit I3IpcQml();
/// Execute an [I3/Sway command](https://i3wm.org/docs/userguide.html#list_of_commands)
Q_INVOKABLE static void dispatch(const QString& request);
/// Refresh monitor information.
Q_INVOKABLE static void refreshMonitors();
/// Refresh workspace information.
Q_INVOKABLE static void refreshWorkspaces();
/// Find an I3Workspace using its name, returns null if the workspace doesn't exist.
Q_INVOKABLE static I3Workspace* findWorkspaceByName(const QString& name);
/// Find an I3Monitor using its name, returns null if the monitor doesn't exist.
Q_INVOKABLE static I3Monitor* findMonitorByName(const QString& name);
/// Return the i3/Sway monitor associated with `screen`
Q_INVOKABLE static I3Monitor* monitorFor(QuickshellScreenInfo* screen);
/// The path to the I3 or Sway socket currently being used
[[nodiscard]] static QString socketPath();
/// All I3Monitors
[[nodiscard]] static ObjectModel<I3Monitor>* monitors();
/// All I3Workspaces
[[nodiscard]] static ObjectModel<I3Workspace>* workspaces();
/// The currently focused Workspace
[[nodiscard]] static I3Workspace* focusedWorkspace();
/// The currently focused Monitor
[[nodiscard]] static I3Monitor* focusedMonitor();
signals:
void rawEvent(I3IpcEvent* event);
void connected();
void focusedWorkspaceChanged();
void focusedMonitorChanged();
};
} // namespace qs::i3::ipc