moves createWorkspace to update()

pull/2316/head
MightyPlaza 2023-07-16 01:43:25 +00:00 committed by GitHub
parent 4f81e55e41
commit 5f0fa71f32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -64,10 +64,12 @@ auto Workspaces::update() -> void {
workspaces_to_remove_.clear(); 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); create_workspace(workspace_to_create);
} }
workspaces_to_create_.clear();
for (auto &workspace : workspaces_) { for (auto &workspace : workspaces_) {
workspace->set_active(workspace->name() == active_workspace_name); workspace->set_active(workspace->name() == active_workspace_name);
std::string &workspace_icon = icons_map_[""]; std::string &workspace_icon = icons_map_[""];
@ -92,7 +94,7 @@ void Workspaces::onEvent(const std::string &ev) {
} else if (eventName == "createworkspace") { } else if (eventName == "createworkspace") {
const Json::Value workspaces_json = gIPC->getSocket1JsonReply("workspaces"); 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 && if (workspace_json["name"].asString() == payload &&
(all_outputs() || bar_.output->name == workspace_json["monitor"].asString()) && (all_outputs() || bar_.output->name == workspace_json["monitor"].asString()) &&
(workspace_json["name"].asString().find("special:") != 0 || show_special())) (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); std::string new_output = payload.substr(payload.find(",") + 1);
if (bar_.output->name == new_output) { // TODO: implement this better if (bar_.output->name == new_output) { // TODO: implement this better
const Json::Value workspaces_json = gIPC->getSocket1JsonReply("workspaces"); 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 && if (workspace_json["name"].asString() == workspace &&
bar_.output->name == workspace_json["monitor"].asString()) { bar_.output->name == workspace_json["monitor"].asString()) {
create_workspace(workspace_json); workspaces_to_create_.push_back(workspace_json);
break; break;
} }
} }
@ -122,7 +124,7 @@ void Workspaces::onEvent(const std::string &ev) {
dp.emit(); dp.emit();
} }
void Workspaces::create_workspace(const Json::Value &value) { void Workspaces::create_workspace(Json::Value &value) {
workspaces_.push_back(std::make_unique<Workspace>(value)); workspaces_.push_back(std::make_unique<Workspace>(value));
Gtk::Button &new_workspace_button = workspaces_.back()->button(); Gtk::Button &new_workspace_button = workspaces_.back()->button();
box_.pack_start(new_workspace_button, false, false); box_.pack_start(new_workspace_button, false, false);
@ -146,7 +148,7 @@ void Workspaces::init() {
active_workspace_name = (gIPC->getSocket1JsonReply("activeworkspace"))["name"].asString(); active_workspace_name = (gIPC->getSocket1JsonReply("activeworkspace"))["name"].asString();
const Json::Value workspaces_json = gIPC->getSocket1JsonReply("workspaces"); 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()) && if ((all_outputs() || bar_.output->name == workspace_json["monitor"].asString()) &&
(workspace_json["name"].asString().find("special") != 0 || show_special())) (workspace_json["name"].asString().find("special") != 0 || show_special()))
create_workspace(workspace_json); create_workspace(workspace_json);