forked from quickshell/quickshell
		
	hyprland/ipc: re-request monitors and workspaces on fail
This commit is contained in:
		
							parent
							
								
									d14ca70984
								
							
						
					
					
						commit
						ef1a4134f0
					
				
					 2 changed files with 93 additions and 78 deletions
				
			
		| 
						 | 
				
			
			@ -377,13 +377,19 @@ HyprlandIpc::findWorkspaceByName(const QString& name, bool createIfMissing, qint
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void HyprlandIpc::refreshWorkspaces(bool canCreate) {
 | 
			
		||||
void HyprlandIpc::refreshWorkspaces(bool canCreate, bool tryAgain) {
 | 
			
		||||
	if (this->requestingWorkspaces) return;
 | 
			
		||||
	this->requestingWorkspaces = true;
 | 
			
		||||
 | 
			
		||||
	this->makeRequest("j/workspaces", [this, canCreate](bool success, const QByteArray& resp) {
 | 
			
		||||
	this->makeRequest(
 | 
			
		||||
	    "j/workspaces",
 | 
			
		||||
	    [this, canCreate, tryAgain](bool success, const QByteArray& resp) {
 | 
			
		||||
		    this->requestingWorkspaces = false;
 | 
			
		||||
		if (!success) return;
 | 
			
		||||
		    if (!success) {
 | 
			
		||||
			    // sometimes fails randomly, so we give it another shot.
 | 
			
		||||
			    if (tryAgain) this->refreshWorkspaces(canCreate, false);
 | 
			
		||||
			    return;
 | 
			
		||||
		    }
 | 
			
		||||
 | 
			
		||||
		    qCDebug(logHyprlandIpc) << "parsing workspaces response";
 | 
			
		||||
		    auto json = QJsonDocument::fromJson(resp).array();
 | 
			
		||||
| 
						 | 
				
			
			@ -429,7 +435,8 @@ void HyprlandIpc::refreshWorkspaces(bool canCreate) {
 | 
			
		|||
			    this->mWorkspaces.removeObject(workspace);
 | 
			
		||||
			    delete workspace;
 | 
			
		||||
		    }
 | 
			
		||||
	});
 | 
			
		||||
	    }
 | 
			
		||||
	);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
HyprlandMonitor*
 | 
			
		||||
| 
						 | 
				
			
			@ -484,13 +491,19 @@ void HyprlandIpc::onFocusedMonitorDestroyed() {
 | 
			
		|||
	emit this->focusedMonitorChanged();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void HyprlandIpc::refreshMonitors(bool canCreate) {
 | 
			
		||||
void HyprlandIpc::refreshMonitors(bool canCreate, bool tryAgain) {
 | 
			
		||||
	if (this->requestingMonitors) return;
 | 
			
		||||
	this->requestingMonitors = true;
 | 
			
		||||
 | 
			
		||||
	this->makeRequest("j/monitors", [this, canCreate](bool success, const QByteArray& resp) {
 | 
			
		||||
	this->makeRequest(
 | 
			
		||||
	    "j/monitors",
 | 
			
		||||
	    [this, canCreate, tryAgain](bool success, const QByteArray& resp) {
 | 
			
		||||
		    this->requestingMonitors = false;
 | 
			
		||||
		if (!success) return;
 | 
			
		||||
		    if (!success) {
 | 
			
		||||
			    // sometimes fails randomly, so we give it another shot.
 | 
			
		||||
			    if (tryAgain) this->refreshMonitors(canCreate, false);
 | 
			
		||||
			    return;
 | 
			
		||||
		    }
 | 
			
		||||
 | 
			
		||||
		    qCDebug(logHyprlandIpc) << "parsing monitors response";
 | 
			
		||||
		    auto json = QJsonDocument::fromJson(resp).array();
 | 
			
		||||
| 
						 | 
				
			
			@ -502,7 +515,8 @@ void HyprlandIpc::refreshMonitors(bool canCreate) {
 | 
			
		|||
			    auto object = entry.toObject().toVariantMap();
 | 
			
		||||
			    auto id = object.value("id").toInt();
 | 
			
		||||
 | 
			
		||||
			auto monitorIter = std::find_if(mList.begin(), mList.end(), [id](const HyprlandMonitor* m) {
 | 
			
		||||
			    auto monitorIter =
 | 
			
		||||
			        std::find_if(mList.begin(), mList.end(), [id](const HyprlandMonitor* m) {
 | 
			
		||||
				        return m->id() == id;
 | 
			
		||||
			        });
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -536,7 +550,8 @@ void HyprlandIpc::refreshMonitors(bool canCreate) {
 | 
			
		|||
			    // see comment in onEvent
 | 
			
		||||
			    monitor->deleteLater();
 | 
			
		||||
		    }
 | 
			
		||||
	});
 | 
			
		||||
	    }
 | 
			
		||||
	);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace qs::hyprland::ipc
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -81,8 +81,8 @@ public:
 | 
			
		|||
	HyprlandMonitor* findMonitorByName(const QString& name, bool createIfMissing, qint32 id = -1);
 | 
			
		||||
 | 
			
		||||
	// canCreate avoids making ghost workspaces when the connection races
 | 
			
		||||
	void refreshWorkspaces(bool canCreate);
 | 
			
		||||
	void refreshMonitors(bool canCreate);
 | 
			
		||||
	void refreshWorkspaces(bool canCreate, bool tryAgain = true);
 | 
			
		||||
	void refreshMonitors(bool canCreate, bool tryAgain = true);
 | 
			
		||||
 | 
			
		||||
	// The last argument may contain commas, so the count is required.
 | 
			
		||||
	[[nodiscard]] static QVector<QByteArrayView> parseEventArgs(QByteArrayView event, quint16 count);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue