From f6a62e258e41b0a342cf2f125cdcc7b61663101f Mon Sep 17 00:00:00 2001 From: zjeffer <4633209+zjeffer@users.noreply.github.com> Date: Sat, 1 Jul 2023 12:37:46 +0200 Subject: [PATCH] fixes for hyprland/workspaces --- src/modules/hyprland/window.cpp | 25 +++++++++++-------------- src/modules/hyprland/workspaces.cpp | 6 ++++-- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/modules/hyprland/window.cpp b/src/modules/hyprland/window.cpp index b122fc9d..cb820bcd 100644 --- a/src/modules/hyprland/window.cpp +++ b/src/modules/hyprland/window.cpp @@ -84,30 +84,27 @@ auto Window::update() -> void { } auto Window::getActiveWorkspace() -> Workspace { - const auto workspace = gIPC->getSocket1Reply("j/activeworkspace"); - Json::Value json = parser_.parse(workspace); - assert(json.isObject()); - return Workspace::parse(json); + const auto workspace = gIPC->getSocket1JsonReply("activeworkspace"); + assert(workspace.isObject()); + return Workspace::parse(workspace); } auto Window::getActiveWorkspace(const std::string& monitorName) -> Workspace { - const auto monitors = gIPC->getSocket1Reply("j/monitors"); - Json::Value json = parser_.parse(monitors); - assert(json.isArray()); - auto monitor = std::find_if(json.begin(), json.end(), + const auto monitors = gIPC->getSocket1JsonReply("monitors"); + assert(monitors.isArray()); + auto monitor = std::find_if(monitors.begin(), monitors.end(), [&](Json::Value monitor) { return monitor["name"] == monitorName; }); - if (monitor == std::end(json)) { + if (monitor == std::end(monitors)) { spdlog::warn("Monitor not found: {}", monitorName); return Workspace{-1, 0, "", ""}; } const int id = (*monitor)["activeWorkspace"]["id"].asInt(); - const auto workspaces = gIPC->getSocket1Reply("j/workspaces"); - json = parser_.parse(workspaces); - assert(json.isArray()); - auto workspace = std::find_if(json.begin(), json.end(), + const auto workspaces = gIPC->getSocket1JsonReply("workspaces"); + assert(workspaces.isArray()); + auto workspace = std::find_if(monitors.begin(), monitors.end(), [&](Json::Value workspace) { return workspace["id"] == id; }); - if (workspace == std::end(json)) { + if (workspace == std::end(monitors)) { spdlog::warn("No workspace with id {}", id); return Workspace{-1, 0, "", ""}; } diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index cdcb54e4..4321e221 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -68,8 +68,10 @@ void Workspaces::onEvent(const std::string &ev) { } else if (eventName == "destroyworkspace") { int deleted_workspace_id; std::from_chars(payload.data(), payload.data() + payload.size(), deleted_workspace_id); - workspaces_.erase(std::remove_if(workspaces_.begin(), workspaces_.end(), - [&](Workspace &x) { return x.id() == deleted_workspace_id; })); + auto workspace = std::find_if(workspaces_.begin(), workspaces_.end(), + [&](Workspace &x) { return x.id() == deleted_workspace_id; }); + box_.remove(workspace->button()); + workspaces_.erase(workspace); } else if (eventName == "createworkspace") { int new_workspace_id; std::from_chars(payload.data(), payload.data() + payload.size(), new_workspace_id);