From 99ed2bb7fa6517a0f0a06595cc6202159d1c971e Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Wed, 10 Aug 2022 10:34:51 +0200 Subject: [PATCH 1/4] Feature: sway/window can show 'shell' parameter --- include/modules/sway/window.hpp | 3 ++- src/modules/sway/window.cpp | 25 +++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/modules/sway/window.hpp b/include/modules/sway/window.hpp index d80cc25..c99ba7f 100644 --- a/include/modules/sway/window.hpp +++ b/include/modules/sway/window.hpp @@ -21,7 +21,7 @@ class Window : public AIconLabel, public sigc::trackable { private: void onEvent(const struct Ipc::ipc_response&); void onCmd(const struct Ipc::ipc_response&); - std::tuple getFocusedNode( + std::tuple getFocusedNode( const Json::Value& nodes, std::string& output); void getTree(); std::string rewriteTitle(const std::string& title); @@ -35,6 +35,7 @@ class Window : public AIconLabel, public sigc::trackable { std::string app_class_; std::string old_app_id_; std::size_t app_nb_; + std::string shell_; unsigned app_icon_size_{24}; bool update_app_icon_{true}; std::string app_icon_name_; diff --git a/src/modules/sway/window.cpp b/src/modules/sway/window.cpp index dbff90a..d39c1fe 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -44,7 +44,7 @@ void Window::onCmd(const struct Ipc::ipc_response& res) { std::lock_guard lock(mutex_); auto payload = parser_.parse(res.payload); auto output = payload["output"].isString() ? payload["output"].asString() : ""; - std::tie(app_nb_, windowId_, window_, app_id_, app_class_) = + std::tie(app_nb_, windowId_, window_, app_id_, app_class_, shell_) = getFocusedNode(payload["nodes"], output); updateAppIconName(); dp.emit(); @@ -176,7 +176,7 @@ auto Window::update() -> void { bar_.window.get_style_context()->remove_class("empty"); } label_.set_markup( - fmt::format(format_, fmt::arg("title", rewriteTitle(window_)), fmt::arg("app_id", app_id_))); + fmt::format(format_, fmt::arg("title", rewriteTitle(window_)), fmt::arg("app_id", app_id_), fmt::arg("shell", shell_))); if (tooltipEnabled()) { label_.set_tooltip_text(window_); } @@ -206,7 +206,7 @@ int leafNodesInWorkspace(const Json::Value& node) { return sum; } -std::tuple gfnWithWorkspace( +std::tuple gfnWithWorkspace( const Json::Value& nodes, std::string& output, const Json::Value& config_, const Bar& bar_, Json::Value& parentWorkspace) { for (auto const& node : nodes) { @@ -222,30 +222,35 @@ std::tuple gfnWithWorks const auto app_class = node["window_properties"]["class"].isString() ? node["window_properties"]["class"].asString() : ""; + + const auto shell = node["shell"].isString() + ? node["shell"].asString() + : ""; + int nb = node.size(); if (parentWorkspace != 0) nb = leafNodesInWorkspace(parentWorkspace); return {nb, node["id"].asInt(), Glib::Markup::escape_text(node["name"].asString()), app_id, - app_class}; + app_class, shell}; } } // iterate if (node["type"] == "workspace") parentWorkspace = node; - auto [nb, id, name, app_id, app_class] = + auto [nb, id, name, app_id, app_class, shell] = gfnWithWorkspace(node["nodes"], output, config_, bar_, parentWorkspace); if (id > -1 && !name.empty()) { - return {nb, id, name, app_id, app_class}; + return {nb, id, name, app_id, app_class, shell}; } // Search for floating node - std::tie(nb, id, name, app_id, app_class) = + std::tie(nb, id, name, app_id, app_class, shell) = gfnWithWorkspace(node["floating_nodes"], output, config_, bar_, parentWorkspace); if (id > -1 && !name.empty()) { - return {nb, id, name, app_id, app_class}; + return {nb, id, name, app_id, app_class, shell}; } } - return {0, -1, "", "", ""}; + return {0, -1, "", "", "", ""}; } -std::tuple Window::getFocusedNode( +std::tuple Window::getFocusedNode( const Json::Value& nodes, std::string& output) { Json::Value placeholder = 0; return gfnWithWorkspace(nodes, output, config_, bar_, placeholder); From 5b1cd65e2072663334802ebd811ed8a05f96fe5d Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Wed, 10 Aug 2022 10:41:18 +0200 Subject: [PATCH 2/4] Fix: better formatting --- src/modules/sway/window.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/modules/sway/window.cpp b/src/modules/sway/window.cpp index d39c1fe..ebbfa4b 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -175,8 +175,8 @@ auto Window::update() -> void { bar_.window.get_style_context()->remove_class("solo"); bar_.window.get_style_context()->remove_class("empty"); } - label_.set_markup( - fmt::format(format_, fmt::arg("title", rewriteTitle(window_)), fmt::arg("app_id", app_id_), fmt::arg("shell", shell_))); + label_.set_markup(fmt::format(format_, fmt::arg("title", rewriteTitle(window_)), + fmt::arg("app_id", app_id_), fmt::arg("shell", shell_))); if (tooltipEnabled()) { label_.set_tooltip_text(window_); } @@ -223,14 +223,12 @@ std::tuple ? node["window_properties"]["class"].asString() : ""; - const auto shell = node["shell"].isString() - ? node["shell"].asString() - : ""; + const auto shell = node["shell"].isString() ? node["shell"].asString() : ""; int nb = node.size(); if (parentWorkspace != 0) nb = leafNodesInWorkspace(parentWorkspace); - return {nb, node["id"].asInt(), Glib::Markup::escape_text(node["name"].asString()), app_id, - app_class, shell}; + return {nb, node["id"].asInt(), Glib::Markup::escape_text(node["name"].asString()), + app_id, app_class, shell}; } } // iterate @@ -250,8 +248,8 @@ std::tuple return {0, -1, "", "", "", ""}; } -std::tuple Window::getFocusedNode( - const Json::Value& nodes, std::string& output) { +std::tuple +Window::getFocusedNode(const Json::Value& nodes, std::string& output) { Json::Value placeholder = 0; return gfnWithWorkspace(nodes, output, config_, bar_, placeholder); } From c287b0c82bbeef4e97cb75b54aaf28efb6a90a64 Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Wed, 10 Aug 2022 22:24:48 +0200 Subject: [PATCH 3/4] Update manpage for sway/window --- man/waybar-sway-window.5.scd | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/man/waybar-sway-window.5.scd b/man/waybar-sway-window.5.scd index e475cea..345e779 100644 --- a/man/waybar-sway-window.5.scd +++ b/man/waybar-sway-window.5.scd @@ -14,7 +14,7 @@ Addressed by *sway/window* *format*: ++ typeof: string ++ - default: {} ++ + default: {title} ++ The format, how information should be displayed. On {} data gets inserted. *rotate*: ++ @@ -80,6 +80,15 @@ Addressed by *sway/window* default: 24 ++ Option to change the size of the application icon. +# FORMAT REPLACEMENTS + +*{title}*: The title of the focused window. + +*{app_id}*: The app_id of the focused window. + +*{shell}*: The shell of the focused window. It's 'xwayland' when the window is +running through xwayland, otherwise it's 'xdg-shell'. + # REWRITE RULES *rewrite* is an object where keys are regular expressions and values are From 6f3fe6d33963e51f7241643e331e9f467bda5ecd Mon Sep 17 00:00:00 2001 From: Lorenzo Bellina <59364991+TheRealLorenz@users.noreply.github.com> Date: Thu, 11 Aug 2022 08:41:10 +0200 Subject: [PATCH 4/4] Update waybar-sway-window.5.scd --- man/waybar-sway-window.5.scd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/waybar-sway-window.5.scd b/man/waybar-sway-window.5.scd index 345e779..6e5ebdb 100644 --- a/man/waybar-sway-window.5.scd +++ b/man/waybar-sway-window.5.scd @@ -15,7 +15,7 @@ Addressed by *sway/window* *format*: ++ typeof: string ++ default: {title} ++ - The format, how information should be displayed. On {} data gets inserted. + The format, how information should be displayed. *rotate*: ++ typeof: integer ++