From 5f0fa71f3204bd2ff1b905c36e05555e11a12ccd Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Sun, 16 Jul 2023 01:43:25 +0000 Subject: [PATCH] moves createWorkspace to update() --- src/modules/hyprland/workspaces.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index b2a1d092..392f457e 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -64,10 +64,12 @@ auto Workspaces::update() -> void { workspaces_to_remove_.clear(); - for (int &workspace_to_create : workspaces_to_create_) { + for (Json::Value &workspace_to_create : workspaces_to_create_) { create_workspace(workspace_to_create); } + workspaces_to_create_.clear(); + for (auto &workspace : workspaces_) { workspace->set_active(workspace->name() == active_workspace_name); std::string &workspace_icon = icons_map_[""]; @@ -92,7 +94,7 @@ void Workspaces::onEvent(const std::string &ev) { } else if (eventName == "createworkspace") { const Json::Value workspaces_json = gIPC->getSocket1JsonReply("workspaces"); - for (auto &workspace_json : workspaces_json) { + for (Json::Value workspace_json : workspaces_json) { if (workspace_json["name"].asString() == payload && (all_outputs() || bar_.output->name == workspace_json["monitor"].asString()) && (workspace_json["name"].asString().find("special:") != 0 || show_special())) @@ -107,10 +109,10 @@ void Workspaces::onEvent(const std::string &ev) { std::string new_output = payload.substr(payload.find(",") + 1); if (bar_.output->name == new_output) { // TODO: implement this better const Json::Value workspaces_json = gIPC->getSocket1JsonReply("workspaces"); - for (auto &workspace_json : workspaces_json) { + for (Json::Value workspace_json : workspaces_json) { if (workspace_json["name"].asString() == workspace && bar_.output->name == workspace_json["monitor"].asString()) { - create_workspace(workspace_json); + workspaces_to_create_.push_back(workspace_json); break; } } @@ -122,7 +124,7 @@ void Workspaces::onEvent(const std::string &ev) { dp.emit(); } -void Workspaces::create_workspace(const Json::Value &value) { +void Workspaces::create_workspace(Json::Value &value) { workspaces_.push_back(std::make_unique(value)); Gtk::Button &new_workspace_button = workspaces_.back()->button(); box_.pack_start(new_workspace_button, false, false); @@ -146,7 +148,7 @@ void Workspaces::init() { active_workspace_name = (gIPC->getSocket1JsonReply("activeworkspace"))["name"].asString(); const Json::Value workspaces_json = gIPC->getSocket1JsonReply("workspaces"); - for (const Json::Value &workspace_json : workspaces_json) { + for (Json::Value workspace_json : workspaces_json) { if ((all_outputs() || bar_.output->name == workspace_json["monitor"].asString()) && (workspace_json["name"].asString().find("special") != 0 || show_special())) create_workspace(workspace_json);