|
12 | 12 | #include "util/rewrite_string.hpp" |
13 | 13 | #include "util/sanitize_str.hpp" |
14 | 14 |
|
| 15 | +#include <shared_mutex> |
| 16 | +#include <thread> |
| 17 | + |
15 | 18 | namespace waybar::modules::hyprland { |
16 | 19 |
|
| 20 | +std::shared_mutex windowIpcSmtx; |
| 21 | + |
17 | 22 | Window::Window(const std::string& id, const Bar& bar, const Json::Value& config) |
18 | 23 | : AAppIconLabel(config, "window", id, "{title}", 0, true), bar_(bar) { |
| 24 | + |
| 25 | + std::unique_lock<std::shared_mutex> windowIpcUniqueLock(windowIpcSmtx); |
| 26 | + |
19 | 27 | modulesReady = true; |
20 | 28 | separateOutputs_ = config["separate-outputs"].asBool(); |
21 | 29 |
|
22 | 30 | if (!gIPC) { |
23 | 31 | gIPC = std::make_unique<IPC>(); |
24 | 32 | } |
25 | 33 |
|
26 | | - queryActiveWorkspace(); |
27 | | - update(); |
28 | | - dp.emit(); |
29 | | - |
30 | 34 | // register for hyprland ipc |
31 | 35 | gIPC->registerForIPC("activewindow", this); |
32 | 36 | gIPC->registerForIPC("closewindow", this); |
33 | 37 | gIPC->registerForIPC("movewindow", this); |
34 | 38 | gIPC->registerForIPC("changefloatingmode", this); |
35 | 39 | gIPC->registerForIPC("fullscreen", this); |
| 40 | + |
| 41 | + windowIpcUniqueLock.unlock(); |
| 42 | + |
| 43 | + queryActiveWorkspace(); |
| 44 | + update(); |
| 45 | + dp.emit(); |
36 | 46 | } |
37 | 47 |
|
38 | 48 | Window::~Window() { |
| 49 | + std::unique_lock<std::shared_mutex> windowIpcUniqueLock(windowIpcSmtx); |
39 | 50 | gIPC->unregisterForIPC(this); |
40 | | - // wait for possible event handler to finish |
41 | | - std::lock_guard<std::mutex> lg(mutex_); |
42 | 51 | } |
43 | 52 |
|
44 | 53 | auto Window::update() -> void { |
45 | | - // fix ampersands |
46 | | - std::lock_guard<std::mutex> lg(mutex_); |
| 54 | + |
| 55 | + std::shared_lock<std::shared_mutex> windowIpcShareLock(windowIpcSmtx); |
47 | 56 |
|
48 | 57 | std::string windowName = waybar::util::sanitize_string(workspace_.last_window_title); |
49 | 58 | std::string windowAddress = workspace_.last_window; |
@@ -144,7 +153,8 @@ auto Window::WindowData::parse(const Json::Value& value) -> Window::WindowData { |
144 | 153 | } |
145 | 154 |
|
146 | 155 | void Window::queryActiveWorkspace() { |
147 | | - std::lock_guard<std::mutex> lg(mutex_); |
| 156 | + |
| 157 | + std::shared_lock<std::shared_mutex> windowIpcShareLock(windowIpcSmtx); |
148 | 158 |
|
149 | 159 | if (separateOutputs_) { |
150 | 160 | workspace_ = getActiveWorkspace(this->bar_.output->name); |
|
0 commit comments