@@ -333,6 +333,7 @@ void HyprlandIpc::onEvent(HyprlandIpcEvent* event) {
333333 auto * monitor = this ->findMonitorByName (name, true );
334334 this ->setFocusedMonitor (monitor);
335335 monitor->setActiveWorkspace (workspace);
336+ qCDebug (logHyprlandIpc) << " Monitor" << name << " focused with workspace" << workspace->id ();
336337 } else if (event->name == " workspacev2" ) {
337338 auto args = event->parseView (2 );
338339 auto id = args.at (0 ).toInt ();
@@ -341,6 +342,7 @@ void HyprlandIpc::onEvent(HyprlandIpcEvent* event) {
341342 if (this ->mFocusedMonitor != nullptr ) {
342343 auto * workspace = this ->findWorkspaceByName (name, true , id);
343344 this ->mFocusedMonitor ->setActiveWorkspace (workspace);
345+ qCDebug (logHyprlandIpc) << " Workspace" << id << " activated on" << this ->mFocusedMonitor ->name ();
344346 }
345347 } else if (event->name == " moveworkspacev2" ) {
346348 auto args = event->parseView (3 );
@@ -351,6 +353,7 @@ void HyprlandIpc::onEvent(HyprlandIpcEvent* event) {
351353 auto * workspace = this ->findWorkspaceByName (name, true , id);
352354 auto * monitor = this ->findMonitorByName (monitorName, true );
353355
356+ qCDebug (logHyprlandIpc) << " Workspace" << id << " moved to monitor" << monitorName;
354357 workspace->setMonitor (monitor);
355358 } else if (event->name == " renameworkspace" ) {
356359 auto args = event->parseView (2 );
@@ -400,24 +403,35 @@ void HyprlandIpc::refreshWorkspaces(bool canCreate) {
400403 this ->requestingWorkspaces = false ;
401404 if (!success) return ;
402405
403- qCDebug (logHyprlandIpc) << " parsing workspaces response" ;
406+ qCDebug (logHyprlandIpc) << " Parsing workspaces response" ;
404407 auto json = QJsonDocument::fromJson (resp).array ();
405408
406409 const auto & mList = this ->mWorkspaces .valueList ();
407- auto names = QVector<QString >();
410+ auto ids = QVector<quint32 >();
408411
409412 for (auto entry: json) {
410413 auto object = entry.toObject ().toVariantMap ();
411- auto name = object.value (" name" ).toString ();
412414
413- auto workspaceIter = std::ranges::find_if (mList , [name](const HyprlandWorkspace* m) {
414- return m->name () == name;
415+ auto id = object.value (" id" ).toInt ();
416+
417+ auto workspaceIter = std::ranges::find_if (mList , [&](const HyprlandWorkspace* m) {
418+ return m->id () == id;
415419 });
416420
421+ // Only fall back to name-based filtering as a last resort, for workspaces where
422+ // no ID has been determined yet.
423+ if (workspaceIter == mList .end ()) {
424+ auto name = object.value (" name" ).toString ();
425+
426+ workspaceIter = std::ranges::find_if (mList , [&](const HyprlandWorkspace* m) {
427+ return m->id () == -1 && m->name () == name;
428+ });
429+ }
430+
417431 auto * workspace = workspaceIter == mList .end () ? nullptr : *workspaceIter;
418432 auto existed = workspace != nullptr ;
419433
420- if (workspace == nullptr ) {
434+ if (!existed ) {
421435 if (!canCreate) continue ;
422436 workspace = new HyprlandWorkspace (this );
423437 }
@@ -428,20 +442,22 @@ void HyprlandIpc::refreshWorkspaces(bool canCreate) {
428442 this ->mWorkspaces .insertObject (workspace);
429443 }
430444
431- names .push_back (name );
445+ ids .push_back (id );
432446 }
433447
434- auto removedWorkspaces = QVector<HyprlandWorkspace*>();
448+ if (canCreate) {
449+ auto removedWorkspaces = QVector<HyprlandWorkspace*>();
435450
436- for (auto * workspace: mList ) {
437- if (!names.contains (workspace->name ())) {
438- removedWorkspaces.push_back (workspace);
451+ for (auto * workspace: mList ) {
452+ if (!ids.contains (workspace->id ())) {
453+ removedWorkspaces.push_back (workspace);
454+ }
439455 }
440- }
441456
442- for (auto * workspace: removedWorkspaces) {
443- this ->mWorkspaces .removeObject (workspace);
444- delete workspace;
457+ for (auto * workspace: removedWorkspaces) {
458+ this ->mWorkspaces .removeObject (workspace);
459+ delete workspace;
460+ }
445461 }
446462 });
447463}
0 commit comments