mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge branch 'master' into master
This commit is contained in:
@ -4,12 +4,14 @@
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include <xkbcommon/xkbregistry.h>
|
||||
|
||||
#include <util/sanitize_str.hpp>
|
||||
|
||||
#include "modules/hyprland/backend.hpp"
|
||||
|
||||
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) {
|
||||
: AButton(config, "language", id, "{}", 0, true), bar_(bar) {
|
||||
modulesReady = true;
|
||||
|
||||
if (!gIPC.get()) {
|
||||
@ -19,8 +21,8 @@ Language::Language(const std::string& id, const Bar& bar, const Json::Value& con
|
||||
// get the active layout when open
|
||||
initLanguage();
|
||||
|
||||
label_.hide();
|
||||
ALabel::update();
|
||||
button_.hide();
|
||||
AButton::update();
|
||||
|
||||
// register for hyprland ipc
|
||||
gIPC->registerForIPC("activelayout", [&](const std::string& ev) { this->onEvent(ev); });
|
||||
@ -30,13 +32,13 @@ auto Language::update() -> void {
|
||||
std::lock_guard<std::mutex> lg(mutex_);
|
||||
|
||||
if (!format_.empty()) {
|
||||
label_.show();
|
||||
label_.set_markup(layoutName_);
|
||||
button_.show();
|
||||
label_->set_markup(layoutName_);
|
||||
} else {
|
||||
label_.hide();
|
||||
button_.hide();
|
||||
}
|
||||
|
||||
ALabel::update();
|
||||
AButton::update();
|
||||
}
|
||||
|
||||
void Language::onEvent(const std::string& ev) {
|
||||
@ -48,16 +50,6 @@ void Language::onEvent(const std::string& ev) {
|
||||
if (config_.isMember("keyboard-name") && keebName != config_["keyboard-name"].asString())
|
||||
return; // ignore
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
const auto BRIEFNAME = getShortFrom(layoutName);
|
||||
|
||||
if (config_.isMember("format-" + BRIEFNAME)) {
|
||||
@ -67,7 +59,7 @@ void Language::onEvent(const std::string& ev) {
|
||||
layoutName = fmt::format(format_, layoutName);
|
||||
}
|
||||
|
||||
layoutName = replaceAll(layoutName, "&", "&");
|
||||
layoutName = waybar::util::sanitize_string(layoutName);
|
||||
|
||||
if (layoutName == layoutName_) return;
|
||||
|
||||
@ -128,4 +120,4 @@ std::string Language::getShortFrom(const std::string& fullName) {
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace waybar::modules::hyprland
|
||||
} // namespace waybar::modules::hyprland
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <util/sanitize_str.hpp>
|
||||
|
||||
#include "modules/hyprland/backend.hpp"
|
||||
#include "util/command.hpp"
|
||||
#include "util/json.hpp"
|
||||
@ -72,17 +74,7 @@ void Window::onEvent(const std::string& ev) {
|
||||
windowName = ev.substr(ev.find_first_of(',') + 1).substr(0, 256);
|
||||
}
|
||||
|
||||
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, "&", "&");
|
||||
windowName = waybar::util::sanitize_string(windowName);
|
||||
|
||||
if (windowName == lastView) return;
|
||||
|
||||
|
Reference in New Issue
Block a user