Merge pull request #2294 from Mr-Pine/hyprland-window-data

`hyprland/window` expose more data
This commit is contained in:
Alexis Rouillard 2023-07-09 10:18:26 +02:00 committed by GitHub
commit 91bd28d410
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 8 deletions

View File

@ -24,6 +24,17 @@ class Window : public waybar::ALabel, public EventHandler {
static auto parse(const Json::Value&) -> Workspace;
};
struct WindowData {
bool floating;
int monitor = -1;
std::string class_name;
std::string initial_class_name;
std::string title;
std::string initial_title;
static auto parse(const Json::Value&) -> WindowData;
};
auto getActiveWorkspace(const std::string&) -> Workspace;
auto getActiveWorkspace() -> Workspace;
void onEvent(const std::string&) override;
@ -34,7 +45,7 @@ class Window : public waybar::ALabel, public EventHandler {
std::mutex mutex_;
const Bar& bar_;
util::JsonParser parser_;
std::string last_title_;
WindowData window_data_;
Workspace workspace_;
std::string solo_class_;
std::string last_solo_class_;

View File

@ -14,7 +14,7 @@ Addressed by *hyprland/window*
*format*: ++
typeof: string ++
default: {} ++
default: {title} ++
The format, how information should be displayed. On {} the current window title is displayed.
*rewrite*: ++
@ -25,6 +25,17 @@ Addressed by *hyprland/window*
typeof: bool ++
Show the active window of the monitor the bar belongs to, instead of the focused window.
# FORMAT REPLACEMENTS
See the output of "hyprctl clients" for examples
*{title}*: The current title of the focused window.
*{initialTitle}*: The initial title of the focused window.
*{class}*: The current class of the focused window.
*{initialClass}*: The initial class of the focused window.
# REWRITE RULES
*rewrite* is an object where keys are regular expressions and values are

View File

@ -14,7 +14,7 @@
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) {
: ALabel(config, "window", id, "{title}", 0, true), bar_(bar) {
modulesReady = true;
separate_outputs = config["separate-outputs"].asBool();
@ -44,20 +44,25 @@ auto Window::update() -> void {
std::lock_guard<std::mutex> lg(mutex_);
std::string window_name = waybar::util::sanitize_string(workspace_.last_window_title);
std::string window_address = workspace_.last_window;
if (window_name != last_title_) {
if (window_name != window_data_.title) {
if (window_name.empty()) {
label_.get_style_context()->add_class("empty");
} else {
label_.get_style_context()->remove_class("empty");
}
last_title_ = window_name;
window_data_.title = window_name;
}
if (!format_.empty()) {
label_.show();
label_.set_markup(fmt::format(fmt::runtime(format_),
waybar::util::rewriteString(window_name, config_["rewrite"])));
label_.set_markup(waybar::util::rewriteString(
fmt::format(fmt::runtime(format_), fmt::arg("title", window_name),
fmt::arg("initialTitle", window_data_.initial_title),
fmt::arg("class", window_data_.class_name),
fmt::arg("initialClass", window_data_.initial_class_name)),
config_["rewrite"]));
} else {
label_.hide();
}
@ -117,6 +122,12 @@ auto Window::Workspace::parse(const Json::Value& value) -> Window::Workspace {
value["lastwindowtitle"].asString()};
}
auto Window::WindowData::parse(const Json::Value& value) -> Window::WindowData {
return WindowData{value["floating"].asBool(), value["monitor"].asInt(),
value["class"].asString(), value["initialClass"].asString(),
value["title"].asString(), value["initialTitle"].asString()};
}
void Window::queryActiveWorkspace() {
std::lock_guard<std::mutex> lg(mutex_);
@ -136,6 +147,7 @@ void Window::queryActiveWorkspace() {
return;
}
window_data_ = WindowData::parse(*active_window);
std::vector<Json::Value> workspace_windows;
std::copy_if(clients.begin(), clients.end(), std::back_inserter(workspace_windows),
[&](Json::Value window) {
@ -158,11 +170,12 @@ void Window::queryActiveWorkspace() {
}
if (solo_) {
solo_class_ = (*active_window)["class"].asString();
solo_class_ = window_data_.class_name;
} else {
solo_class_ = "";
}
} else {
window_data_ = WindowData{};
all_floating_ = false;
hidden_ = false;
fullscreen_ = false;