From e64d66ab243fc7c5b9614d0310a8b858f67fed5b Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sat, 23 Dec 2023 21:38:19 +0800 Subject: [PATCH] fix:the workspace data is null in a small probability update fix clang-format warn no manual unlock --- src/modules/hyprland/workspaces.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 7ad87bab..e0e00eec 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -6,7 +6,9 @@ #include #include #include +#include #include +#include #include #include @@ -14,6 +16,8 @@ namespace waybar::modules::hyprland { +std::shared_mutex workspaceCreateSmtx; + int Workspaces::windowRewritePriorityFunction(std::string const &window_rule) { // Rules that match against title are prioritized // Rules that don't specify if they're matching against either title or class are deprioritized @@ -161,6 +165,7 @@ auto Workspaces::update() -> void { } // add workspaces that wait to be created + std::shared_lock workspaceCreateShareLock(workspaceCreateSmtx); unsigned int currentCreateWorkspaceNum = 0; for (Json::Value const &workspaceToCreate : m_workspacesToCreate) { createWorkspace(workspaceToCreate); @@ -300,6 +305,7 @@ void Workspaces::onWorkspaceCreated(std::string const &payload) { if (name == payload && (allOutputs() || m_bar.output->name == workspaceJson["monitor"].asString()) && (showSpecial() || !name.starts_with("special")) && !isDoubleSpecial(payload)) { + std::unique_lock workspaceCreateUniqueLock(workspaceCreateSmtx); m_workspacesToCreate.push_back(workspaceJson); break; }