@@ -342,7 +342,8 @@ void HyprlandIpc::onEvent(HyprlandIpcEvent* event) {
342
342
if (this ->mFocusedMonitor != nullptr ) {
343
343
auto * workspace = this ->findWorkspaceByName (name, true , id);
344
344
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 ();
346
347
}
347
348
} else if (event->name == " moveworkspacev2" ) {
348
349
auto args = event->parseView (3 );
@@ -377,15 +378,28 @@ void HyprlandIpc::onEvent(HyprlandIpcEvent* event) {
377
378
HyprlandWorkspace*
378
379
HyprlandIpc::findWorkspaceByName (const QString& name, bool createIfMissing, qint32 id) {
379
380
const auto & mList = this ->mWorkspaces .valueList ();
381
+ HyprlandWorkspace* workspace = nullptr ;
380
382
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
+ }
383
389
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;
386
399
} else if (createIfMissing) {
387
400
qCDebug (logHyprlandIpc) << " Workspace" << name
388
- << " requested before creation, performing early init" ;
401
+ << " requested before creation, performing early init with id" << id;
402
+
389
403
auto * workspace = new HyprlandWorkspace (this );
390
404
workspace->updateInitial (id, name);
391
405
this ->mWorkspaces .insertObject (workspace);
@@ -414,9 +428,8 @@ void HyprlandIpc::refreshWorkspaces(bool canCreate) {
414
428
415
429
auto id = object.value (" id" ).toInt ();
416
430
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; });
420
433
421
434
// Only fall back to name-based filtering as a last resort, for workspaces where
422
435
// no ID has been determined yet.
0 commit comments