mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
fix(Window): avoid concurrency
This commit is contained in:
parent
b54160e02f
commit
0c3c548bc0
@ -6,8 +6,8 @@
|
|||||||
#include "bar.hpp"
|
#include "bar.hpp"
|
||||||
#include "client.hpp"
|
#include "client.hpp"
|
||||||
#include "modules/sway/ipc/client.hpp"
|
#include "modules/sway/ipc/client.hpp"
|
||||||
#include "util/sleeper_thread.hpp"
|
|
||||||
#include "util/json.hpp"
|
#include "util/json.hpp"
|
||||||
|
#include "util/sleeper_thread.hpp"
|
||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
@ -27,6 +27,7 @@ class Window : public ALabel {
|
|||||||
const Bar& bar_;
|
const Bar& bar_;
|
||||||
waybar::util::SleeperThread thread_;
|
waybar::util::SleeperThread thread_;
|
||||||
Ipc ipc_;
|
Ipc ipc_;
|
||||||
|
std::mutex mutex_;
|
||||||
std::string window_;
|
std::string window_;
|
||||||
int windowId_;
|
int windowId_;
|
||||||
std::string app_id_;
|
std::string app_id_;
|
||||||
|
@ -65,7 +65,7 @@ std::thread waybar::modules::MPD::event_listener() {
|
|||||||
try {
|
try {
|
||||||
if (connection_ == nullptr) {
|
if (connection_ == nullptr) {
|
||||||
// Retry periodically if no connection
|
// Retry periodically if no connection
|
||||||
update();
|
dp.emit();
|
||||||
std::this_thread::sleep_for(interval_);
|
std::this_thread::sleep_for(interval_);
|
||||||
} else {
|
} else {
|
||||||
waitForEvent();
|
waitForEvent();
|
||||||
|
@ -25,6 +25,7 @@ void Window::onEvent(const struct Ipc::ipc_response& res) { getTree(); }
|
|||||||
|
|
||||||
void Window::onCmd(const struct Ipc::ipc_response& res) {
|
void Window::onCmd(const struct Ipc::ipc_response& res) {
|
||||||
try {
|
try {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
auto payload = parser_.parse(res.payload);
|
auto payload = parser_.parse(res.payload);
|
||||||
auto [nb, id, name, app_id] = getFocusedNode(payload);
|
auto [nb, id, name, app_id] = getFocusedNode(payload);
|
||||||
if (!app_id_.empty()) {
|
if (!app_id_.empty()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user