Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions asan.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Suppress common address sanitizer issues in dependencies, these are often non-fixable or not an issue.
# Use it like this (when in repo root): ASAN_OPTIONS="suppressions=./asan.supp" ./build/waybar
leak:libpangoft2-1.0.so.0
leak:libgtk-3.so.0
leak:libfontconfig.so.1
13 changes: 7 additions & 6 deletions include/modules/hyprland/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ class EventHandler {
virtual ~EventHandler() = default;
};

/// If you want to use the Hyprland IPC, simply use IPC::inst() to get the singleton instance.
/// Do not create multiple instances.
class IPC {
protected:
IPC(); // use IPC::inst() instead.

public:
IPC();
~IPC();
static IPC& inst();

Expand All @@ -41,11 +45,8 @@ class IPC {
std::mutex callbackMutex_;
util::JsonParser parser_;
std::list<std::pair<std::string, EventHandler*>> callbacks_;
int socketfd_; // the hyprland socket file descriptor
int socketfd_; // the hyprland socket file descriptor
pid_t socketOwnerPid_;
bool running_ = true;
bool running_ = true; // the ipcThread will stop running when this is false
};

inline bool modulesReady = false;
inline std::unique_ptr<IPC> gIPC;
}; // namespace waybar::modules::hyprland
6 changes: 3 additions & 3 deletions include/modules/hyprland/windowcount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "AAppIconLabel.hpp"
#include "bar.hpp"
#include "modules/hyprland/backend.hpp"
#include "util/json.hpp"

namespace waybar::modules::hyprland {

Expand All @@ -26,8 +25,8 @@ class WindowCount : public waybar::AAppIconLabel, public EventHandler {
static auto parse(const Json::Value& value) -> Workspace;
};

static auto getActiveWorkspace(const std::string&) -> Workspace;
static auto getActiveWorkspace() -> Workspace;
auto getActiveWorkspace(const std::string&) -> Workspace;
auto getActiveWorkspace() -> Workspace;
void onEvent(const std::string& ev) override;
void queryActiveWorkspace();
void setClass(const std::string&, bool enable);
Expand All @@ -36,6 +35,7 @@ class WindowCount : public waybar::AAppIconLabel, public EventHandler {
std::mutex mutex_;
const Bar& bar_;
Workspace workspace_;
IPC& m_ipc;
};

} // namespace waybar::modules::hyprland
2 changes: 0 additions & 2 deletions src/modules/hyprland/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ void IPC::socketListener() {
return;
}

if (!modulesReady) return;

spdlog::info("Hyprland IPC starting");

struct sockaddr_un addr;
Expand Down
2 changes: 0 additions & 2 deletions src/modules/hyprland/language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace waybar::modules::hyprland {

Language::Language(const std::string& id, const Bar& bar, const Json::Value& config)
: ALabel(config, "language", id, "{}", 0, true), bar_(bar), m_ipc(IPC::inst()) {
modulesReady = true;

// get the active layout when open
initLanguage();

Expand Down
4 changes: 0 additions & 4 deletions src/modules/hyprland/submap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

#include <spdlog/spdlog.h>

#include "util/sanitize_str.hpp"

namespace waybar::modules::hyprland {

Submap::Submap(const std::string& id, const Bar& bar, const Json::Value& config)
: ALabel(config, "submap", id, "{}", 0, true), bar_(bar), m_ipc(IPC::inst()) {
modulesReady = true;

parseConfig(config);

label_.hide();
Expand Down
1 change: 0 additions & 1 deletion src/modules/hyprland/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
: AAppIconLabel(config, "window", id, "{title}", 0, true), bar_(bar), m_ipc(IPC::inst()) {
std::unique_lock<std::shared_mutex> windowIpcUniqueLock(windowIpcSmtx);

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

// register for hyprland ipc
Expand Down
55 changes: 28 additions & 27 deletions src/modules/hyprland/windowcount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,29 @@
#include <vector>

#include "modules/hyprland/backend.hpp"
#include "util/sanitize_str.hpp"

namespace waybar::modules::hyprland {

WindowCount::WindowCount(const std::string& id, const Bar& bar, const Json::Value& config)
: AAppIconLabel(config, "windowcount", id, "{count}", 0, true), bar_(bar) {
modulesReady = true;
: AAppIconLabel(config, "windowcount", id, "{count}", 0, true), bar_(bar), m_ipc(IPC::inst()) {
separateOutputs_ =
config.isMember("separate-outputs") ? config["separate-outputs"].asBool() : true;

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

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

// register for hyprland ipc
gIPC->registerForIPC("fullscreen", this);
gIPC->registerForIPC("workspace", this);
gIPC->registerForIPC("focusedmon", this);
gIPC->registerForIPC("openwindow", this);
gIPC->registerForIPC("closewindow", this);
gIPC->registerForIPC("movewindow", this);
m_ipc.registerForIPC("fullscreen", this);
m_ipc.registerForIPC("workspace", this);
m_ipc.registerForIPC("focusedmon", this);
m_ipc.registerForIPC("openwindow", this);
m_ipc.registerForIPC("closewindow", this);
m_ipc.registerForIPC("movewindow", this);
}

WindowCount::~WindowCount() {
gIPC->unregisterForIPC(this);
m_ipc.unregisterForIPC(this);
// wait for possible event handler to finish
std::lock_guard<std::mutex> lg(mutex_);
}
Expand Down Expand Up @@ -70,7 +64,7 @@ auto WindowCount::update() -> void {
}

auto WindowCount::getActiveWorkspace() -> Workspace {
const auto workspace = gIPC->getSocket1JsonReply("activeworkspace");
const auto workspace = m_ipc.getSocket1JsonReply("activeworkspace");

if (workspace.isObject()) {
return Workspace::parse(workspace);
Expand All @@ -80,24 +74,31 @@ auto WindowCount::getActiveWorkspace() -> Workspace {
}

auto WindowCount::getActiveWorkspace(const std::string& monitorName) -> Workspace {
const auto monitors = gIPC->getSocket1JsonReply("monitors");
const auto monitors = m_ipc.getSocket1JsonReply("monitors");
if (monitors.isArray()) {
auto monitor = std::find_if(monitors.begin(), monitors.end(), [&](Json::Value monitor) {
return monitor["name"] == monitorName;
});
auto monitor = std::ranges::find_if(
monitors, [&](Json::Value monitor) { return monitor["name"] == monitorName; });
if (monitor == std::end(monitors)) {
spdlog::warn("Monitor not found: {}", monitorName);
return Workspace{-1, 0, false};
return Workspace{
.id = -1,
.windows = 0,
.hasfullscreen = false,
};
}
const int id = (*monitor)["activeWorkspace"]["id"].asInt();

const auto workspaces = gIPC->getSocket1JsonReply("workspaces");
const auto workspaces = m_ipc.getSocket1JsonReply("workspaces");
if (workspaces.isArray()) {
auto workspace = std::find_if(workspaces.begin(), workspaces.end(),
[&](Json::Value workspace) { return workspace["id"] == id; });
auto workspace = std::ranges::find_if(
workspaces, [&](Json::Value workspace) { return workspace["id"] == id; });
if (workspace == std::end(workspaces)) {
spdlog::warn("No workspace with id {}", id);
return Workspace{-1, 0, false};
return Workspace{
.id = -1,
.windows = 0,
.hasfullscreen = false,
};
}
return Workspace::parse(*workspace);
};
Expand All @@ -108,9 +109,9 @@ auto WindowCount::getActiveWorkspace(const std::string& monitorName) -> Workspac

auto WindowCount::Workspace::parse(const Json::Value& value) -> WindowCount::Workspace {
return Workspace{
value["id"].asInt(),
value["windows"].asInt(),
value["hasfullscreen"].asBool(),
.id = value["id"].asInt(),
.windows = value["windows"].asInt(),
.hasfullscreen = value["hasfullscreen"].asBool(),
};
}

Expand Down
1 change: 0 additions & 1 deletion src/modules/hyprland/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
m_bar(bar),
m_box(bar.orientation, 0),
m_ipc(IPC::inst()) {
modulesReady = true;
parseConfig(config);

m_box.set_name("workspaces");
Expand Down
7 changes: 7 additions & 0 deletions tsan.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Suppress common thread issues in dependencies, these are often non-fixable or not an issue.
# Use it like this (when in repo root): TSAN_OPTIONS="suppressions=./tsan.supp" ./build/waybar
race:libfontconfig.so
race:libglib-2.0.so
race:libpango-1.0.so
race:libc.so.6
race:libgio-2.0.so
Loading