@@ -40,7 +40,7 @@ Workspaces::~Workspaces() {
40
40
}
41
41
42
42
void Workspaces::init () {
43
- m_activeWorkspaceName = (gIPC ->getSocket1JsonReply (" activeworkspace" ))[" name " ].asString ();
43
+ m_activeWorkspaceId = (gIPC ->getSocket1JsonReply (" activeworkspace" ))[" id " ].asInt ();
44
44
45
45
initializeWorkspaces ();
46
46
dp.emit ();
@@ -306,6 +306,7 @@ void Workspaces::loadPersistentWorkspacesFromWorkspaceRules(const Json::Value &c
306
306
workspaceData[" persistent-rule" ] = true ;
307
307
m_workspacesToCreate.emplace_back (workspaceData, clientsJson);
308
308
} else {
309
+ // This can be any workspace selector.
309
310
m_workspacesToRemove.emplace_back (workspace);
310
311
}
311
312
}
@@ -316,7 +317,7 @@ void Workspaces::onEvent(const std::string &ev) {
316
317
std::string eventName (begin (ev), begin (ev) + ev.find_first_of (' >' ));
317
318
std::string payload = ev.substr (eventName.size () + 2 );
318
319
319
- if (eventName == " workspace " ) {
320
+ if (eventName == " workspacev2 " ) {
320
321
onWorkspaceActivated (payload);
321
322
} else if (eventName == " activespecial" ) {
322
323
onSpecialWorkspaceActivated (payload);
@@ -348,7 +349,8 @@ void Workspaces::onEvent(const std::string &ev) {
348
349
}
349
350
350
351
void Workspaces::onWorkspaceActivated (std::string const &payload) {
351
- m_activeWorkspaceName = payload;
352
+ std::string workspaceIdStr = payload.substr (0 , payload.find (' ,' ));
353
+ m_activeWorkspaceId = std::stoi (workspaceIdStr);
352
354
}
353
355
354
356
void Workspaces::onSpecialWorkspaceActivated (std::string const &payload) {
@@ -406,7 +408,7 @@ void Workspaces::onWorkspaceMoved(std::string const &payload) {
406
408
spdlog::debug (" Workspace moved: {}" , payload);
407
409
408
410
// Update active workspace
409
- m_activeWorkspaceName = (gIPC ->getSocket1JsonReply (" activeworkspace" ))[" name " ].asString ();
411
+ m_activeWorkspaceId = (gIPC ->getSocket1JsonReply (" activeworkspace" ))[" id " ].asInt ();
410
412
411
413
if (allOutputs ()) return ;
412
414
@@ -429,9 +431,6 @@ void Workspaces::onWorkspaceRenamed(std::string const &payload) {
429
431
std::string newName = payload.substr (payload.find (' ,' ) + 1 );
430
432
for (auto &workspace : m_workspaces) {
431
433
if (workspace->id () == workspaceId) {
432
- if (workspace->name () == m_activeWorkspaceName) {
433
- m_activeWorkspaceName = newName;
434
- }
435
434
workspace->setName (newName);
436
435
break ;
437
436
}
@@ -441,7 +440,16 @@ void Workspaces::onWorkspaceRenamed(std::string const &payload) {
441
440
442
441
void Workspaces::onMonitorFocused (std::string const &payload) {
443
442
spdlog::trace (" Monitor focused: {}" , payload);
444
- m_activeWorkspaceName = payload.substr (payload.find (' ,' ) + 1 );
443
+
444
+ std::string workspaceName = payload.substr (payload.find (' ,' ) + 1 );
445
+
446
+ // TODO this will be in the payload when we upgrade to focusedmonv2
447
+ for (auto &workspace : m_workspaces) {
448
+ if (workspace->name () == workspaceName) {
449
+ m_activeWorkspaceId = workspace->id ();
450
+ break ;
451
+ }
452
+ }
445
453
446
454
for (Json::Value &monitor : gIPC ->getSocket1JsonReply (" monitors" )) {
447
455
if (monitor[" name" ].asString () == payload.substr (0 , payload.find (' ,' ))) {
@@ -669,7 +677,7 @@ void Workspaces::registerOrphanWindow(WindowCreationPayload create_window_payloa
669
677
}
670
678
671
679
auto Workspaces::registerIpc () -> void {
672
- gIPC ->registerForIPC (" workspace " , this );
680
+ gIPC ->registerForIPC (" workspacev2 " , this );
673
681
gIPC ->registerForIPC (" activespecial" , this );
674
682
gIPC ->registerForIPC (" createworkspacev2" , this );
675
683
gIPC ->registerForIPC (" destroyworkspacev2" , this );
@@ -700,14 +708,16 @@ void Workspaces::removeWorkspacesToRemove() {
700
708
void Workspaces::removeWorkspace (std::string const &workspaceString) {
701
709
spdlog::debug (" Removing workspace {}" , workspaceString);
702
710
703
- int id = - 100 ; // workspace IDs range from -99 upwards, so -100 is a good "invalid" value
711
+ int id;
704
712
std::string name;
705
713
706
- // TODO: we need to support workspace selectors here
707
- // https://wiki.hyprland.org/Configuring/Workspace-Rules/#workspace-selectors
708
714
try {
715
+ // If this succeeds, we have a workspace ID.
709
716
id = std::stoi (workspaceString);
710
717
} catch (const std::exception &e) {
718
+ // TODO: At some point we want to support all workspace selectors
719
+ // This is just a subset.
720
+ // https://wiki.hyprland.org/Configuring/Workspace-Rules/#workspace-selectors
711
721
if (workspaceString.starts_with (" special:" )) {
712
722
name = workspaceString.substr (8 );
713
723
} else if (workspaceString.starts_with (" name:" )) {
@@ -731,7 +741,7 @@ void Workspaces::removeWorkspace(std::string const &workspaceString) {
731
741
}
732
742
733
743
if ((*workspace)->isPersistentConfig ()) {
734
- spdlog::trace (" Not removing config persistent workspace {} " , (*workspace)->name ());
744
+ spdlog::trace (" Not removing config persistent workspace id={} name={} " , (*workspace)-> id () , (*workspace)->name ());
735
745
return ;
736
746
}
737
747
@@ -891,9 +901,9 @@ void Workspaces::updateWorkspaceStates() {
891
901
const std::vector<std::string> visibleWorkspaces = getVisibleWorkspaces ();
892
902
auto updatedWorkspaces = gIPC ->getSocket1JsonReply (" workspaces" );
893
903
for (auto &workspace : m_workspaces) {
894
- workspace->setActive (workspace->name () == m_activeWorkspaceName ||
904
+ workspace->setActive (workspace->id () == m_activeWorkspaceId ||
895
905
workspace->name () == m_activeSpecialWorkspaceName);
896
- if (workspace->name () == m_activeWorkspaceName && workspace->isUrgent ()) {
906
+ if (workspace->id () == m_activeWorkspaceId && workspace->isUrgent ()) {
897
907
workspace->setUrgent (false );
898
908
}
899
909
workspace->setVisible (std::find (visibleWorkspaces.begin (), visibleWorkspaces.end (),
0 commit comments