mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
added backend and hyprland/window
This commit is contained in:
54
src/modules/hyprland/window.cpp
Normal file
54
src/modules/hyprland/window.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include "modules/hyprland/backend.hpp"
|
||||
#include "modules/hyprland/window.hpp"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace waybar::modules::hyprland {
|
||||
|
||||
Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
: ALabel(config, "window", id, "{}", 0, true), bar_(bar) {
|
||||
modulesReady = true;
|
||||
|
||||
if (!gIPC.get()) {
|
||||
gIPC = std::make_unique<IPC>();
|
||||
}
|
||||
|
||||
label_.hide();
|
||||
ALabel::update();
|
||||
|
||||
// register for hyprland ipc
|
||||
gIPC->registerForIPC("activewindow", [&](const std::string& ev) { this->onEvent(ev); });
|
||||
}
|
||||
|
||||
void Window::onEvent(const std::string& ev) {
|
||||
auto windowName = ev.substr(ev.find_first_of(',') + 1).substr(0, 256);
|
||||
|
||||
// fix ampersands
|
||||
auto replaceAll = [](std::string str, const std::string& from,
|
||||
const std::string& to) -> std::string {
|
||||
size_t start_pos = 0;
|
||||
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
|
||||
str.replace(start_pos, from.length(), to);
|
||||
start_pos += to.length();
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
windowName = replaceAll(windowName, "&", "&");
|
||||
|
||||
if (windowName == lastView) return;
|
||||
|
||||
lastView = windowName;
|
||||
|
||||
spdlog::debug("hyprland window onevent with {}", windowName);
|
||||
|
||||
if (!format_.empty()) {
|
||||
label_.show();
|
||||
label_.set_markup(fmt::format(format_, windowName));
|
||||
} else {
|
||||
label_.hide();
|
||||
}
|
||||
|
||||
ALabel::update();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user