forked from quickshell/quickshell
		
	hyprland/ipc: ensure requests are flushed
This commit is contained in:
		
							parent
							
								
									e89035b18c
								
							
						
					
					
						commit
						ae762f5c6e
					
				
					 2 changed files with 12 additions and 24 deletions
				
			
		| 
						 | 
					@ -15,7 +15,6 @@
 | 
				
			||||||
#include <qloggingcategory.h>
 | 
					#include <qloggingcategory.h>
 | 
				
			||||||
#include <qobject.h>
 | 
					#include <qobject.h>
 | 
				
			||||||
#include <qtenvironmentvariables.h>
 | 
					#include <qtenvironmentvariables.h>
 | 
				
			||||||
#include <qtimer.h>
 | 
					 | 
				
			||||||
#include <qtmetamacros.h>
 | 
					#include <qtmetamacros.h>
 | 
				
			||||||
#include <qtypes.h>
 | 
					#include <qtypes.h>
 | 
				
			||||||
#include <qvariant.h>
 | 
					#include <qvariant.h>
 | 
				
			||||||
| 
						 | 
					@ -58,13 +57,9 @@ HyprlandIpc::HyprlandIpc() {
 | 
				
			||||||
	QObject::connect(&this->eventSocket, &QLocalSocket::readyRead, this, &HyprlandIpc::eventSocketReady);
 | 
						QObject::connect(&this->eventSocket, &QLocalSocket::readyRead, this, &HyprlandIpc::eventSocketReady);
 | 
				
			||||||
	// clang-format on
 | 
						// clang-format on
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Sockets don't appear to be able to send data in the first event loop
 | 
						this->eventSocket.connectToServer(this->mEventSocketPath, QLocalSocket::ReadOnly);
 | 
				
			||||||
	// cycle of the program, so delay it by one. No idea why this is the case.
 | 
						this->refreshMonitors(true);
 | 
				
			||||||
	QTimer::singleShot(0, [this]() {
 | 
						this->refreshWorkspaces(true);
 | 
				
			||||||
		this->eventSocket.connectToServer(this->mEventSocketPath, QLocalSocket::ReadOnly);
 | 
					 | 
				
			||||||
		this->refreshMonitors(true);
 | 
					 | 
				
			||||||
		this->refreshWorkspaces(true);
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QString HyprlandIpc::requestSocketPath() const { return this->mRequestSocketPath; }
 | 
					QString HyprlandIpc::requestSocketPath() const { return this->mRequestSocketPath; }
 | 
				
			||||||
| 
						 | 
					@ -128,6 +123,7 @@ void HyprlandIpc::makeRequest(
 | 
				
			||||||
		QObject::connect(requestSocket, &QLocalSocket::readyRead, this, responseCallback);
 | 
							QObject::connect(requestSocket, &QLocalSocket::readyRead, this, responseCallback);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		requestSocket->write(request);
 | 
							requestSocket->write(request);
 | 
				
			||||||
 | 
							requestSocket->flush();
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	auto errorCallback = [=](QLocalSocket::LocalSocketError error) {
 | 
						auto errorCallback = [=](QLocalSocket::LocalSocketError error) {
 | 
				
			||||||
| 
						 | 
					@ -377,19 +373,15 @@ HyprlandIpc::findWorkspaceByName(const QString& name, bool createIfMissing, qint
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void HyprlandIpc::refreshWorkspaces(bool canCreate, bool tryAgain) {
 | 
					void HyprlandIpc::refreshWorkspaces(bool canCreate) {
 | 
				
			||||||
	if (this->requestingWorkspaces) return;
 | 
						if (this->requestingWorkspaces) return;
 | 
				
			||||||
	this->requestingWorkspaces = true;
 | 
						this->requestingWorkspaces = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	this->makeRequest(
 | 
						this->makeRequest(
 | 
				
			||||||
	    "j/workspaces",
 | 
						    "j/workspaces",
 | 
				
			||||||
	    [this, canCreate, tryAgain](bool success, const QByteArray& resp) {
 | 
						    [this, canCreate](bool success, const QByteArray& resp) {
 | 
				
			||||||
		    this->requestingWorkspaces = false;
 | 
							    this->requestingWorkspaces = false;
 | 
				
			||||||
		    if (!success) {
 | 
							    if (!success) return;
 | 
				
			||||||
			    // sometimes fails randomly, so we give it another shot.
 | 
					 | 
				
			||||||
			    if (tryAgain) this->refreshWorkspaces(canCreate, false);
 | 
					 | 
				
			||||||
			    return;
 | 
					 | 
				
			||||||
		    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		    qCDebug(logHyprlandIpc) << "parsing workspaces response";
 | 
							    qCDebug(logHyprlandIpc) << "parsing workspaces response";
 | 
				
			||||||
		    auto json = QJsonDocument::fromJson(resp).array();
 | 
							    auto json = QJsonDocument::fromJson(resp).array();
 | 
				
			||||||
| 
						 | 
					@ -493,19 +485,15 @@ void HyprlandIpc::onFocusedMonitorDestroyed() {
 | 
				
			||||||
	emit this->focusedMonitorChanged();
 | 
						emit this->focusedMonitorChanged();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void HyprlandIpc::refreshMonitors(bool canCreate, bool tryAgain) {
 | 
					void HyprlandIpc::refreshMonitors(bool canCreate) {
 | 
				
			||||||
	if (this->requestingMonitors) return;
 | 
						if (this->requestingMonitors) return;
 | 
				
			||||||
	this->requestingMonitors = true;
 | 
						this->requestingMonitors = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	this->makeRequest(
 | 
						this->makeRequest(
 | 
				
			||||||
	    "j/monitors",
 | 
						    "j/monitors",
 | 
				
			||||||
	    [this, canCreate, tryAgain](bool success, const QByteArray& resp) {
 | 
						    [this, canCreate](bool success, const QByteArray& resp) {
 | 
				
			||||||
		    this->requestingMonitors = false;
 | 
							    this->requestingMonitors = false;
 | 
				
			||||||
		    if (!success) {
 | 
							    if (!success) return;
 | 
				
			||||||
			    // sometimes fails randomly, so we give it another shot.
 | 
					 | 
				
			||||||
			    if (tryAgain) this->refreshMonitors(canCreate, false);
 | 
					 | 
				
			||||||
			    return;
 | 
					 | 
				
			||||||
		    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		    this->monitorsRequested = true;
 | 
							    this->monitorsRequested = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -81,8 +81,8 @@ public:
 | 
				
			||||||
	HyprlandMonitor* findMonitorByName(const QString& name, bool createIfMissing, qint32 id = -1);
 | 
						HyprlandMonitor* findMonitorByName(const QString& name, bool createIfMissing, qint32 id = -1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// canCreate avoids making ghost workspaces when the connection races
 | 
						// canCreate avoids making ghost workspaces when the connection races
 | 
				
			||||||
	void refreshWorkspaces(bool canCreate, bool tryAgain = true);
 | 
						void refreshWorkspaces(bool canCreate);
 | 
				
			||||||
	void refreshMonitors(bool canCreate, bool tryAgain = true);
 | 
						void refreshMonitors(bool canCreate);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// The last argument may contain commas, so the count is required.
 | 
						// The last argument may contain commas, so the count is required.
 | 
				
			||||||
	[[nodiscard]] static QVector<QByteArrayView> parseEventArgs(QByteArrayView event, quint16 count);
 | 
						[[nodiscard]] static QVector<QByteArrayView> parseEventArgs(QByteArrayView event, quint16 count);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue