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);
3334namespace qs ::i3::ipc {
3435
3536void 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
9599void 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) {
377381void 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 }
0 commit comments