all: retry incomplete socket reads

Fixes greetd and hyprland ipc sockets reads being incomplete and
breaking said integrations on slow machines.
This commit is contained in:
outfoxxed 2026-03-10 00:54:45 -07:00
parent cf1a2aeb2d
commit bd62179277
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
13 changed files with 221 additions and 103 deletions

View file

@ -93,6 +93,7 @@ void HyprlandIpc::eventSocketError(QLocalSocket::LocalSocketError error) const {
void HyprlandIpc::eventSocketStateChanged(QLocalSocket::LocalSocketState state) {
if (state == QLocalSocket::ConnectedState) {
this->eventReader.setDevice(&this->eventSocket);
qCInfo(logHyprlandIpc) << "Hyprland event socket connected.";
emit this->connected();
} else if (state == QLocalSocket::UnconnectedState && this->valid) {
@ -104,11 +105,11 @@ void HyprlandIpc::eventSocketStateChanged(QLocalSocket::LocalSocketState state)
void HyprlandIpc::eventSocketReady() {
while (true) {
auto rawEvent = this->eventSocket.readLine();
if (rawEvent.isEmpty()) break;
this->eventReader.startTransaction();
auto rawEvent = this->eventReader.readUntil('\n');
if (!this->eventReader.commitTransaction()) return;
// remove trailing \n
rawEvent.truncate(rawEvent.length() - 1);
rawEvent.chop(1); // remove trailing \n
auto splitIdx = rawEvent.indexOf(">>");
auto event = QByteArrayView(rawEvent.data(), splitIdx);
auto data = QByteArrayView(