fix format

This commit is contained in:
dmitry 2023-06-27 00:18:49 +03:00
parent ce4da59f34
commit afc489869a

View File

@ -4,12 +4,12 @@
#include <algorithm> #include <algorithm>
#include <regex> #include <regex>
#include <util/sanitize_str.hpp>
#include <vector> #include <vector>
#include "modules/hyprland/backend.hpp" #include "modules/hyprland/backend.hpp"
#include "util/json.hpp" #include "util/json.hpp"
#include "util/rewrite_string.hpp" #include "util/rewrite_string.hpp"
#include <util/sanitize_str.hpp>
namespace waybar::modules::hyprland { namespace waybar::modules::hyprland {
@ -54,7 +54,6 @@ auto Window::update() -> void {
last_title_ = window_name; last_title_ = window_name;
} }
if (!format_.empty()) { if (!format_.empty()) {
label_.show(); label_.show();
label_.set_markup(fmt::format(fmt::runtime(format_), label_.set_markup(fmt::format(fmt::runtime(format_),
@ -63,7 +62,6 @@ auto Window::update() -> void {
label_.hide(); label_.hide();
} }
setClass("empty", workspace_.windows == 0); setClass("empty", workspace_.windows == 0);
setClass("solo", solo_); setClass("solo", solo_);
setClass("fullscreen", fullscreen_); setClass("fullscreen", fullscreen_);
@ -117,12 +115,8 @@ auto Window::getActiveWorkspace(const std::string& monitorName) -> Workspace {
} }
auto Window::Workspace::parse(const Json::Value& value) -> Window::Workspace { auto Window::Workspace::parse(const Json::Value& value) -> Window::Workspace {
return Workspace{ return Workspace{value["id"].asInt(), value["windows"].asInt(), value["lastwindow"].asString(),
value["id"].asInt(), value["lastwindowtitle"].asString()};
value["windows"].asInt(),
value["lastwindow"].asString(),
value["lastwindowtitle"].asString()
};
} }
void Window::queryActiveWorkspace() { void Window::queryActiveWorkspace() {
@ -134,13 +128,13 @@ void Window::queryActiveWorkspace() {
workspace_ = getActiveWorkspace(); workspace_ = getActiveWorkspace();
} }
if (workspace_.windows > 0) { if (workspace_.windows > 0) {
const auto clients = gIPC->getSocket1Reply("j/clients"); const auto clients = gIPC->getSocket1Reply("j/clients");
Json::Value json = parser_.parse(clients); Json::Value json = parser_.parse(clients);
assert(json.isArray()); assert(json.isArray());
auto active_window = std::find_if(json.begin(), json.end(), auto active_window = std::find_if(json.begin(), json.end(), [&](Json::Value window) {
[&](Json::Value window) { return window["address"] == workspace_.last_window; }); return window["address"] == workspace_.last_window;
});
if (active_window == std::end(json)) { if (active_window == std::end(json)) {
return; return;
} }
@ -152,8 +146,9 @@ void Window::queryActiveWorkspace() {
} }
std::vector<Json::Value> workspace_windows; std::vector<Json::Value> workspace_windows;
std::copy_if(json.begin(), json.end(), std::back_inserter(workspace_windows), std::copy_if(json.begin(), json.end(), std::back_inserter(workspace_windows),
[&](Json::Value window) { return window["workspace"]["id"] == workspace_.id && [&](Json::Value window) {
window["mapped"].asBool(); }); return window["workspace"]["id"] == workspace_.id && window["mapped"].asBool();
});
solo_ = 1 == std::count_if(workspace_windows.begin(), workspace_windows.end(), solo_ = 1 == std::count_if(workspace_windows.begin(), workspace_windows.end(),
[&](Json::Value window) { return !window["floating"].asBool(); }); [&](Json::Value window) { return !window["floating"].asBool(); });
all_floating_ = std::all_of(workspace_windows.begin(), workspace_windows.end(), all_floating_ = std::all_of(workspace_windows.begin(), workspace_windows.end(),
@ -173,7 +168,6 @@ void Window::onEvent(const std::string& ev) {
dp.emit(); dp.emit();
} }
void Window::setClass(const std::string& classname, bool enable) { void Window::setClass(const std::string& classname, bool enable) {
if (enable) { if (enable) {
if (!bar_.window.get_style_context()->has_class(classname)) { if (!bar_.window.get_style_context()->has_class(classname)) {