Skip to content

Commit

Permalink
Merge pull request #3826 from DreamMaoMao/fix-hyprland-window-crash
Browse files Browse the repository at this point in the history
fix: hyprland/window get empty ipc json data
  • Loading branch information
Alexays authored Dec 26, 2024
2 parents dbb708c + 01ae117 commit 6ce881a
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/modules/hyprland/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,47 @@
#include "util/rewrite_string.hpp"
#include "util/sanitize_str.hpp"

#include <shared_mutex>
#include <thread>

namespace waybar::modules::hyprland {

std::shared_mutex windowIpcSmtx;

Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
: AAppIconLabel(config, "window", id, "{title}", 0, true), bar_(bar) {

std::unique_lock<std::shared_mutex> windowIpcUniqueLock(windowIpcSmtx);

modulesReady = true;
separateOutputs_ = config["separate-outputs"].asBool();

if (!gIPC) {
gIPC = std::make_unique<IPC>();
}

queryActiveWorkspace();
update();
dp.emit();

// register for hyprland ipc
gIPC->registerForIPC("activewindow", this);
gIPC->registerForIPC("closewindow", this);
gIPC->registerForIPC("movewindow", this);
gIPC->registerForIPC("changefloatingmode", this);
gIPC->registerForIPC("fullscreen", this);

windowIpcUniqueLock.unlock();

queryActiveWorkspace();
update();
dp.emit();
}

Window::~Window() {
std::unique_lock<std::shared_mutex> windowIpcUniqueLock(windowIpcSmtx);
gIPC->unregisterForIPC(this);
// wait for possible event handler to finish
std::lock_guard<std::mutex> lg(mutex_);
}

auto Window::update() -> void {
// fix ampersands
std::lock_guard<std::mutex> lg(mutex_);

std::shared_lock<std::shared_mutex> windowIpcShareLock(windowIpcSmtx);

std::string windowName = waybar::util::sanitize_string(workspace_.last_window_title);
std::string windowAddress = workspace_.last_window;
Expand Down Expand Up @@ -144,7 +153,8 @@ auto Window::WindowData::parse(const Json::Value& value) -> Window::WindowData {
}

void Window::queryActiveWorkspace() {
std::lock_guard<std::mutex> lg(mutex_);

std::shared_lock<std::shared_mutex> windowIpcShareLock(windowIpcSmtx);

if (separateOutputs_) {
workspace_ = getActiveWorkspace(this->bar_.output->name);
Expand Down

0 comments on commit 6ce881a

Please sign in to comment.