Skip to content

Commit d328fc3

Browse files
committed
i3/sway: fix formatting, lint & avoid writing to socket if connection is not open
1 parent 48ab2bd commit d328fc3

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

src/x11/i3/ipc/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ qt_add_library(quickshell-i3-ipc STATIC
77

88
qt_add_qml_module(quickshell-i3-ipc
99
URI Quickshell.I3._Ipc
10-
VERSION 0.1
11-
DEPENDENCIES QtQml
10+
VERSION 0.1
11+
DEPENDENCIES QtQml
1212
)
1313

1414
qs_add_module_deps_light(quickshell-i3-ipc Quickshell)

src/x11/i3/ipc/connection.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <algorithm>
22
#include <array>
3+
#include <cstring>
34
#include <tuple>
45

56
#include <bit>
@@ -33,6 +34,10 @@ Q_LOGGING_CATEGORY(logI3IpcEvents, "quickshell.I3.ipc.events", QtWarningMsg);
3334
namespace qs::i3::ipc {
3435

3536
void I3Ipc::makeRequest(const QByteArray& request) {
37+
if (!this->valid) {
38+
qCWarning(logI3IpcEvents) << "IPC connection is not open, ignoring request.";
39+
return;
40+
}
3641
this->liveEventSocket.write(request);
3742
this->liveEventSocket.flush();
3843
}
@@ -85,15 +90,14 @@ void I3Ipc::subscribe() {
8590
auto payload = QByteArray(R"(["workspace","output"])");
8691
auto message = I3Ipc::buildRequestMessage(EventCode::Subscribe, payload);
8792

88-
this->liveEventSocket.write(message);
89-
this->liveEventSocket.flush();
93+
this->makeRequest(message);
9094

9195
this->refreshWorkspaces();
9296
this->refreshMonitors();
9397
}
9498

9599
void I3Ipc::eventSocketReady() {
96-
for (auto& [type, data]: I3Ipc::parseResponse()) {
100+
for (auto& [type, data]: this->parseResponse()) {
97101
this->event.mCode = type;
98102
this->event.mData = data;
99103

@@ -366,7 +370,7 @@ void I3Ipc::onEvent(I3IpcEvent* event) {
366370
case EventCode::Subscribe: qCInfo(logI3Ipc) << "Connected to IPC"; return;
367371
case EventCode::GetOutputs: this->handleGetOutputsEvent(event); return;
368372
case EventCode::GetWorkspaces: this->handleWorkspaceEvent(event); return;
369-
case EventCode::RunCommand: this->handleRunCommand(event); return;
373+
case EventCode::RunCommand: I3Ipc::handleRunCommand(event); return;
370374
case EventCode::Unknown:
371375
qCWarning(logI3Ipc) << "Unknown event:" << event->type() << event->data();
372376
return;
@@ -377,10 +381,10 @@ void I3Ipc::onEvent(I3IpcEvent* event) {
377381
void I3Ipc::handleRunCommand(I3IpcEvent* event) {
378382
for (auto r: event->mData.array()) {
379383
auto obj = r.toObject();
380-
bool success = obj["success"].toBool();
384+
const bool success = obj["success"].toBool();
381385

382386
if (!success) {
383-
QString error = obj["error"].toString();
387+
const QString error = obj["error"].toString();
384388
qCWarning(logI3Ipc) << "Error occured while running command:" << error;
385389
}
386390
}

src/x11/i3/ipc/connection.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private slots:
126126
void handleWorkspaceEvent(I3IpcEvent* event);
127127
void handleGetWorkspacesEvent(I3IpcEvent* event);
128128
void handleGetOutputsEvent(I3IpcEvent* event);
129-
void handleRunCommand(I3IpcEvent* event);
129+
static void handleRunCommand(I3IpcEvent* event);
130130

131131
void reconnectIPC();
132132

src/x11/i3/ipc/qml.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "qml.hpp"
22

3-
#include <qjsonarray.h>
43
#include <qobject.h>
54
#include <qstring.h>
65

0 commit comments

Comments
 (0)