From a6c0bc5a529fa8616990792d24c6aa98408d2c12 Mon Sep 17 00:00:00 2001 From: sheenobu Date: Fri, 5 Jul 2019 20:19:50 -0700 Subject: [PATCH] Fix deadlock on workspace scrolling Make the mutex guard lifecycle finish before the send ipc command by adding scope around the code. Fixes #395 . --- src/modules/sway/workspaces.cpp | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index 3a3f0abe..27d30a94 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -218,23 +218,25 @@ bool Workspaces::handleScroll(GdkEventScroll *e) { if (dir == SCROLL_DIR::NONE) { return true; } - std::lock_guard lock(mutex_); - auto it = std::find_if(workspaces_.begin(), workspaces_.end(), [](const auto &workspace) { - return workspace["focused"].asBool(); - }); - if (it == workspaces_.end()) { - return true; - } std::string name; - if (dir == SCROLL_DIR::DOWN || dir == SCROLL_DIR::RIGHT) { - name = getCycleWorkspace(it, false); - } else if (dir == SCROLL_DIR::UP || dir == SCROLL_DIR::LEFT) { - name = getCycleWorkspace(it, true); - } else { - return true; - } - if (name == (*it)["name"].asString()) { - return true; + { + std::lock_guard lock(mutex_); + auto it = std::find_if(workspaces_.begin(), workspaces_.end(), [](const auto &workspace) { + return workspace["focused"].asBool(); + }); + if (it == workspaces_.end()) { + return true; + } + if (dir == SCROLL_DIR::DOWN || dir == SCROLL_DIR::RIGHT) { + name = getCycleWorkspace(it, false); + } else if (dir == SCROLL_DIR::UP || dir == SCROLL_DIR::LEFT) { + name = getCycleWorkspace(it, true); + } else { + return true; + } + if (name == (*it)["name"].asString()) { + return true; + } } try { ipc_.sendCmd(IPC_COMMAND, fmt::format("workspace \"{}\"", name));