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
This commit is contained in:
Nydragon 2024-11-02 03:52:27 +01:00
parent 84ce47b6d3
commit 31adcaac76
No known key found for this signature in database
15 changed files with 1252 additions and 1 deletions

111
src/x11/i3/ipc/monitor.cpp Normal file
View file

@ -0,0 +1,111 @@
#include "monitor.hpp"
#include <qcontainerfwd.h>
#include <qstring.h>
#include <qtmetamacros.h>
#include <qtypes.h>
#include "workspace.hpp"
namespace qs::i3::ipc {
qint32 I3Monitor::id() const { return this->mId; };
QString I3Monitor::name() const { return this->mName; };
bool I3Monitor::power() const { return this->mPower; };
I3Workspace* I3Monitor::focusedWorkspace() const { return this->mFocusedWorkspace; };
qint32 I3Monitor::x() const { return this->mX; };
qint32 I3Monitor::y() const { return this->mY; };
qint32 I3Monitor::width() const { return this->mWidth; };
qint32 I3Monitor::height() const { return this->mHeight; };
qreal I3Monitor::scale() const { return this->mScale; };
bool I3Monitor::focused() const { return this->mFocused; };
QVariantMap I3Monitor::lastIpcObject() const { return this->mLastIpcObject; };
void I3Monitor::updateFromObject(const QVariantMap& obj) {
auto id = obj.value("id").value<qint32>();
auto name = obj.value("name").value<QString>();
auto power = obj.value("power").value<bool>();
auto activeWorkspaceId = obj.value("current_workspace").value<QString>();
auto rect = obj.value("rect").toMap();
auto x = rect.value("x").value<qint32>();
auto y = rect.value("y").value<qint32>();
auto width = rect.value("width").value<qint32>();
auto height = rect.value("height").value<qint32>();
auto scale = obj.value("scale").value<qreal>();
auto focused = obj.value("focused").value<bool>();
if (id != this->mId) {
this->mId = id;
emit this->idChanged();
}
if (name != this->mName) {
this->mName = name;
emit this->nameChanged();
}
if (power != this->mPower) {
this->mPower = power;
this->powerChanged();
}
if (activeWorkspaceId != this->mFocusedWorkspaceName) {
auto* workspace = this->ipc->findWorkspaceByName(activeWorkspaceId);
if (activeWorkspaceId.isEmpty() || workspace == nullptr) { // is null when output is disabled
this->mFocusedWorkspace = nullptr;
this->mFocusedWorkspaceName = "";
} else {
this->mFocusedWorkspaceName = activeWorkspaceId;
this->mFocusedWorkspace = workspace;
}
emit this->focusedWorkspaceChanged();
};
if (x != this->mX) {
this->mX = x;
emit this->xChanged();
}
if (y != this->mY) {
this->mY = y;
emit this->yChanged();
}
if (width != this->mWidth) {
this->mWidth = width;
emit this->widthChanged();
}
if (height != this->mHeight) {
this->mHeight = height;
emit this->heightChanged();
}
if (scale != this->mScale) {
this->mScale = scale;
emit this->scaleChanged();
}
if (focused != this->mFocused) {
this->mFocused = focused;
emit this->focusedChanged();
}
if (obj != this->mLastIpcObject) {
this->mLastIpcObject = obj;
emit this->lastIpcObjectChanged();
}
}
void I3Monitor::setFocus(bool focused) {
this->mFocused = focused;
emit this->focusedChanged();
}
void I3Monitor::setFocusedWorkspace(I3Workspace* workspace) {
this->mFocusedWorkspace = workspace;
this->mFocusedWorkspaceName = workspace->name();
emit this->focusedWorkspaceChanged();
};
} // namespace qs::i3::ipc