@@ -342,7 +342,8 @@ void HyprlandIpc::onEvent(HyprlandIpcEvent* event) {
342342 if (this ->mFocusedMonitor != nullptr ) {
343343 auto * workspace = this ->findWorkspaceByName (name, true , id);
344344 this ->mFocusedMonitor ->setActiveWorkspace (workspace);
345- qCDebug (logHyprlandIpc) << " Workspace" << id << " activated on" << this ->mFocusedMonitor ->name ();
345+ qCDebug (logHyprlandIpc) << " Workspace" << id << " activated on"
346+ << this ->mFocusedMonitor ->name ();
346347 }
347348 } else if (event->name == " moveworkspacev2" ) {
348349 auto args = event->parseView (3 );
@@ -377,15 +378,28 @@ void HyprlandIpc::onEvent(HyprlandIpcEvent* event) {
377378HyprlandWorkspace*
378379HyprlandIpc::findWorkspaceByName (const QString& name, bool createIfMissing, qint32 id) {
379380 const auto & mList = this ->mWorkspaces .valueList ();
381+ HyprlandWorkspace* workspace = nullptr ;
380382
381- auto workspaceIter =
382- std::ranges::find_if (mList , [name](const HyprlandWorkspace* m) { return m->name () == name; });
383+ if (id != -1 ) {
384+ auto workspaceIter =
385+ std::ranges::find_if (mList , [&](const HyprlandWorkspace* m) { return m->id () == id; });
386+
387+ workspace = workspaceIter == mList .end () ? nullptr : *workspaceIter;
388+ }
383389
384- if (workspaceIter != mList .end ()) {
385- return *workspaceIter;
390+ if (!workspace) {
391+ auto workspaceIter =
392+ std::ranges::find_if (mList , [&](const HyprlandWorkspace* m) { return m->name () == name; });
393+
394+ workspace = workspaceIter == mList .end () ? nullptr : *workspaceIter;
395+ }
396+
397+ if (workspace) {
398+ return workspace;
386399 } else if (createIfMissing) {
387400 qCDebug (logHyprlandIpc) << " Workspace" << name
388- << " requested before creation, performing early init" ;
401+ << " requested before creation, performing early init with id" << id;
402+
389403 auto * workspace = new HyprlandWorkspace (this );
390404 workspace->updateInitial (id, name);
391405 this ->mWorkspaces .insertObject (workspace);
@@ -414,9 +428,8 @@ void HyprlandIpc::refreshWorkspaces(bool canCreate) {
414428
415429 auto id = object.value (" id" ).toInt ();
416430
417- auto workspaceIter = std::ranges::find_if (mList , [&](const HyprlandWorkspace* m) {
418- return m->id () == id;
419- });
431+ auto workspaceIter =
432+ std::ranges::find_if (mList , [&](const HyprlandWorkspace* m) { return m->id () == id; });
420433
421434 // Only fall back to name-based filtering as a last resort, for workspaces where
422435 // no ID has been determined yet.
0 commit comments