Skip to content

Commit 1039ed8

Browse files
authored
Merge pull request #5248 from daher13/fix/refresh-on-changeid
fix(hyprland/workspaces): handle workspace ID changes
2 parents 9ca345e + e92f280 commit 1039ed8

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

include/modules/hyprland/workspace.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class Workspace {
6161
void setUrgent(bool value = true) { m_isUrgent = value; };
6262
void setVisible(bool value = true) { m_isVisible = value; };
6363
void setWindows(uint value) { m_windows = value; };
64+
void setId(int value) { m_id = value; };
6465
void setName(std::string const& value) { m_name = value; };
6566
void setOutput(std::string const& value) { m_output = value; };
6667
bool containsWindow(WindowAddress const& addr) const {

include/modules/hyprland/workspaces.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class Workspaces : public AModule, public EventHandler {
108108
Json::Value const& clientsData = Json::Value::nullRef);
109109
void onWorkspaceMoved(std::string const& payload);
110110
void onWorkspaceRenamed(std::string const& payload);
111+
void onWorkspaceIdChanged(std::string const& payload);
111112
static std::optional<int> parseWorkspaceId(std::string const& workspaceIdStr);
112113

113114
// monitor events
@@ -168,11 +169,12 @@ class Workspaces : public AModule, public EventHandler {
168169

169170
enum class SortMethod { ID, NAME, NUMBER, SPECIAL_CENTERED, DEFAULT };
170171
SortMethod m_sortBy = SortMethod::DEFAULT;
171-
static inline const std::map<std::string, SortMethod> m_sortMap = {{"ID", SortMethod::ID},
172-
{"NAME", SortMethod::NAME},
173-
{"NUMBER", SortMethod::NUMBER},
174-
{"SPECIAL-CENTERED", SortMethod::SPECIAL_CENTERED},
175-
{"DEFAULT", SortMethod::DEFAULT}};
172+
static inline const std::map<std::string, SortMethod> m_sortMap = {
173+
{"ID", SortMethod::ID},
174+
{"NAME", SortMethod::NAME},
175+
{"NUMBER", SortMethod::NUMBER},
176+
{"SPECIAL-CENTERED", SortMethod::SPECIAL_CENTERED},
177+
{"DEFAULT", SortMethod::DEFAULT}};
176178

177179
std::string m_formatBefore;
178180
std::string m_formatAfter;

src/modules/hyprland/workspaces.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ void Workspaces::onEvent(const std::string& ev) {
312312
onSpecialWorkspaceActivated(payload);
313313
} else if (eventName == "destroyworkspacev2") {
314314
onWorkspaceDestroyed(payload);
315+
} else if (eventName == "changeworkspaceid") {
316+
onWorkspaceIdChanged(payload);
315317
} else if (eventName == "createworkspacev2") {
316318
onWorkspaceCreated(payload);
317319
} else if (eventName == "focusedmonv2") {
@@ -449,6 +451,35 @@ void Workspaces::onWorkspaceRenamed(std::string const& payload) {
449451
sortWorkspaces();
450452
}
451453

454+
void Workspaces::onWorkspaceIdChanged(std::string const& payload) {
455+
spdlog::debug("Workspace ID changed: {}", payload);
456+
457+
const auto [oldIdStr, newIdStr] = splitDoublePayload(payload);
458+
459+
const auto oldId = parseWorkspaceId(oldIdStr);
460+
const auto newId = parseWorkspaceId(newIdStr);
461+
462+
if (!oldId.has_value() || !newId.has_value()) {
463+
spdlog::warn("Invalid workspace ID change payload: {}", payload);
464+
return;
465+
}
466+
467+
for (auto& workspace : m_workspaces) {
468+
if (workspace->id() == *oldId) {
469+
spdlog::debug("Changing workspace ID from {} to {}", *oldId, *newId);
470+
workspace->setId(*newId);
471+
break;
472+
}
473+
}
474+
475+
if (m_activeWorkspaceId == *oldId) {
476+
m_activeWorkspaceId = *newId;
477+
}
478+
479+
sortWorkspaces();
480+
updateWindowCount();
481+
}
482+
452483
void Workspaces::onMonitorFocused(std::string const& payload) {
453484
spdlog::trace("Monitor focused: {}", payload);
454485

@@ -827,6 +858,7 @@ auto Workspaces::registerIpc() -> void {
827858
m_ipc.registerForIPC("createworkspacev2", this);
828859
m_ipc.registerForIPC("destroyworkspacev2", this);
829860
m_ipc.registerForIPC("focusedmonv2", this);
861+
m_ipc.registerForIPC("changeworkspaceid", this);
830862
m_ipc.registerForIPC("moveworkspacev2", this);
831863
m_ipc.registerForIPC("renameworkspace", this);
832864
m_ipc.registerForIPC("openwindow", this);

0 commit comments

Comments
 (0)