feat: format-fullscreen and format-windowed override added

This commit is contained in:
Khiet Tam Nguyen
2024-08-24 01:25:50 +10:00
parent 1b282e67a7
commit 38ffb24c52
2 changed files with 17 additions and 8 deletions

View File

@ -22,6 +22,7 @@ class WindowCount : public waybar::AAppIconLabel, public EventHandler {
struct Workspace { struct Workspace {
int id; int id;
int windows; int windows;
bool hasfullscreen;
static auto parse(const Json::Value& value) -> Workspace; static auto parse(const Json::Value& value) -> Workspace;
}; };

View File

@ -46,20 +46,27 @@ auto WindowCount::update() -> void {
std::lock_guard<std::mutex> lg(mutex_); std::lock_guard<std::mutex> lg(mutex_);
std::string format = config_["format"].asString(); std::string format = config_["format"].asString();
std::string formatFullscreen = config_["format-fullscreen"].asString();
std::string formatWindowed = config_["format-windowed"].asString();
std::string formattedText; std::string formattedText;
if (!format.empty()) { if (workspace_.hasfullscreen && !formatFullscreen.empty()) {
formattedText = fmt::format(fmt::runtime(format), workspace_.windows);
label_.set_markup(waybar::util::rewriteString( label_.set_markup(waybar::util::rewriteString(
formattedText, fmt::format(fmt::runtime(formatFullscreen), workspace_.windows),
config_["rewrite"]));
} else if (!workspace_.hasfullscreen && !formatWindowed.empty()) {
label_.set_markup(waybar::util::rewriteString(
fmt::format(fmt::runtime(formatWindowed), workspace_.windows),
config_["rewrite"]));
} else if (!format.empty()) {
label_.set_markup(waybar::util::rewriteString(
fmt::format(fmt::runtime(format), workspace_.windows),
config_["rewrite"])); config_["rewrite"]));
label_.show();
} else { } else {
// Default display
label_.set_text(fmt::format("{}", workspace_.windows)); label_.set_text(fmt::format("{}", workspace_.windows));
label_.hide();
} }
label_.show();
AAppIconLabel::update(); AAppIconLabel::update();
} }
@ -81,7 +88,7 @@ auto WindowCount::getActiveWorkspace(const std::string& monitorName) -> Workspac
}); });
if (monitor == std::end(monitors)) { if (monitor == std::end(monitors)) {
spdlog::warn("Monitor not found: {}", monitorName); spdlog::warn("Monitor not found: {}", monitorName);
return Workspace{-1, 0}; return Workspace{-1, 0, false};
} }
const int id = (*monitor)["activeWorkspace"]["id"].asInt(); const int id = (*monitor)["activeWorkspace"]["id"].asInt();
@ -91,7 +98,7 @@ auto WindowCount::getActiveWorkspace(const std::string& monitorName) -> Workspac
[&](Json::Value workspace) { return workspace["id"] == id; }); [&](Json::Value workspace) { return workspace["id"] == id; });
if (workspace == std::end(workspaces)) { if (workspace == std::end(workspaces)) {
spdlog::warn("No workspace with id {}", id); spdlog::warn("No workspace with id {}", id);
return Workspace{-1, 0}; return Workspace{-1, 0, false};
} }
return Workspace::parse(*workspace); return Workspace::parse(*workspace);
}; };
@ -104,6 +111,7 @@ auto WindowCount::Workspace::parse(const Json::Value& value) -> WindowCount::Wor
return Workspace{ return Workspace{
value["id"].asInt(), value["id"].asInt(),
value["windows"].asInt(), value["windows"].asInt(),
value["hasfullscreen"].asBool(),
}; };
} }