2018-08-15 18:17:17 +00:00
|
|
|
#include "modules/sway/window.hpp"
|
2021-10-17 18:08:16 +00:00
|
|
|
|
|
|
|
#include <gdkmm/pixbuf.h>
|
|
|
|
#include <glibmm/fileutils.h>
|
|
|
|
#include <glibmm/keyfile.h>
|
|
|
|
#include <glibmm/miscutils.h>
|
|
|
|
#include <gtkmm/enums.h>
|
2019-05-18 23:44:45 +00:00
|
|
|
#include <spdlog/spdlog.h>
|
2021-10-17 18:08:16 +00:00
|
|
|
|
|
|
|
#include <filesystem>
|
2021-03-21 10:42:25 +00:00
|
|
|
#include <regex>
|
2021-10-17 18:08:16 +00:00
|
|
|
#include <string>
|
2018-08-15 18:17:17 +00:00
|
|
|
|
2023-06-28 22:28:38 +00:00
|
|
|
#include "util/gtk_icon.hpp"
|
2023-07-04 17:48:04 +00:00
|
|
|
#include "util/rewrite_string.hpp"
|
2022-10-19 11:29:05 +00:00
|
|
|
|
2019-04-19 09:09:06 +00:00
|
|
|
namespace waybar::modules::sway {
|
|
|
|
|
|
|
|
Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
2023-07-10 20:55:46 +00:00
|
|
|
: AAppIconLabel(config, "window", id, "{}", 0, true), bar_(bar), windowId_(-1) {
|
2019-06-11 12:01:55 +00:00
|
|
|
ipc_.subscribe(R"(["window","workspace"])");
|
2019-04-19 09:09:06 +00:00
|
|
|
ipc_.signal_event.connect(sigc::mem_fun(*this, &Window::onEvent));
|
|
|
|
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Window::onCmd));
|
2019-04-25 14:47:51 +00:00
|
|
|
// Get Initial focused window
|
|
|
|
getTree();
|
2018-08-20 12:50:45 +00:00
|
|
|
// Launch worker
|
2019-08-28 02:43:03 +00:00
|
|
|
ipc_.setWorker([this] {
|
|
|
|
try {
|
|
|
|
ipc_.handleEvent();
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
spdlog::error("Window: {}", e.what());
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
spdlog::trace("Window::Window exception");
|
2019-08-28 02:43:03 +00:00
|
|
|
}
|
|
|
|
});
|
2018-08-20 12:50:45 +00:00
|
|
|
}
|
|
|
|
|
2019-05-07 11:43:48 +00:00
|
|
|
void Window::onEvent(const struct Ipc::ipc_response& res) { getTree(); }
|
2019-04-19 09:09:06 +00:00
|
|
|
|
2019-04-24 10:37:24 +00:00
|
|
|
void Window::onCmd(const struct Ipc::ipc_response& res) {
|
2019-05-09 08:30:54 +00:00
|
|
|
try {
|
2019-06-17 09:39:45 +00:00
|
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
2019-06-15 12:57:52 +00:00
|
|
|
auto payload = parser_.parse(res.payload);
|
2019-08-31 17:50:56 +00:00
|
|
|
auto output = payload["output"].isString() ? payload["output"].asString() : "";
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
std::tie(app_nb_, floating_count_, windowId_, window_, app_id_, app_class_, shell_, layout_) =
|
2022-04-18 01:09:25 +00:00
|
|
|
getFocusedNode(payload["nodes"], output);
|
2023-07-10 21:48:18 +00:00
|
|
|
updateAppIconName(app_id_, app_class_);
|
2019-06-04 15:34:00 +00:00
|
|
|
dp.emit();
|
2019-05-09 08:30:54 +00:00
|
|
|
} catch (const std::exception& e) {
|
2019-05-18 23:44:45 +00:00
|
|
|
spdlog::error("Window: {}", e.what());
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
spdlog::trace("Window::onCmd exception");
|
2019-04-25 14:47:51 +00:00
|
|
|
}
|
2019-04-19 09:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto Window::update() -> void {
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
spdlog::trace("workspace layout {}, tiled count {}, floating count {}", layout_, app_nb_,
|
|
|
|
floating_count_);
|
|
|
|
|
|
|
|
int mode = 0;
|
2019-06-04 15:34:00 +00:00
|
|
|
if (app_nb_ == 0) {
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
if (floating_count_ == 0) {
|
|
|
|
mode += 1;
|
|
|
|
} else {
|
|
|
|
mode += 4;
|
2019-06-04 15:34:00 +00:00
|
|
|
}
|
|
|
|
} else if (app_nb_ == 1) {
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
mode += 2;
|
|
|
|
} else {
|
|
|
|
if (layout_ == "tabbed") {
|
|
|
|
mode += 8;
|
|
|
|
} else if (layout_ == "stacked") {
|
|
|
|
mode += 16;
|
|
|
|
} else {
|
|
|
|
mode += 32;
|
2019-06-04 15:34:00 +00:00
|
|
|
}
|
|
|
|
}
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
|
|
|
|
if (!old_app_id_.empty() && ((mode & 2) == 0 || old_app_id_ != app_id_) &&
|
|
|
|
bar_.window.get_style_context()->has_class(old_app_id_)) {
|
|
|
|
spdlog::trace("Removing app_id class: {}", old_app_id_);
|
|
|
|
bar_.window.get_style_context()->remove_class(old_app_id_);
|
|
|
|
old_app_id_ = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
setClass("empty", ((mode & 1) > 0));
|
|
|
|
setClass("solo", ((mode & 2) > 0));
|
|
|
|
setClass("floating", ((mode & 4) > 0));
|
|
|
|
setClass("tabbed", ((mode & 8) > 0));
|
|
|
|
setClass("stacked", ((mode & 16) > 0));
|
|
|
|
setClass("tiled", ((mode & 32) > 0));
|
|
|
|
|
|
|
|
if ((mode & 2) > 0 && !app_id_.empty() && !bar_.window.get_style_context()->has_class(app_id_)) {
|
|
|
|
spdlog::trace("Adding app_id class: {}", app_id_);
|
|
|
|
bar_.window.get_style_context()->add_class(app_id_);
|
|
|
|
old_app_id_ = app_id_;
|
|
|
|
}
|
|
|
|
|
2023-03-25 16:36:00 +00:00
|
|
|
label_.set_markup(waybar::util::rewriteString(
|
|
|
|
fmt::format(fmt::runtime(format_), fmt::arg("title", window_), fmt::arg("app_id", app_id_),
|
|
|
|
fmt::arg("shell", shell_)),
|
|
|
|
config_["rewrite"]));
|
2019-02-22 10:35:26 +00:00
|
|
|
if (tooltipEnabled()) {
|
|
|
|
label_.set_tooltip_text(window_);
|
|
|
|
}
|
2022-04-17 20:55:58 +00:00
|
|
|
|
|
|
|
updateAppIcon();
|
|
|
|
|
2020-04-12 16:30:21 +00:00
|
|
|
// Call parent update
|
2023-07-10 20:55:46 +00:00
|
|
|
AAppIconLabel::update();
|
2018-08-15 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
void Window::setClass(std::string classname, bool enable) {
|
|
|
|
if (enable) {
|
|
|
|
if (!bar_.window.get_style_context()->has_class(classname)) {
|
|
|
|
bar_.window.get_style_context()->add_class(classname);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bar_.window.get_style_context()->remove_class(classname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<int, int> leafNodesInWorkspace(const Json::Value& node) {
|
2020-12-18 23:14:14 +00:00
|
|
|
auto const& nodes = node["nodes"];
|
2021-10-02 16:35:38 +00:00
|
|
|
auto const& floating_nodes = node["floating_nodes"];
|
2022-04-06 06:37:19 +00:00
|
|
|
if (nodes.empty() && floating_nodes.empty()) {
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
if (node["type"].asString() == "workspace")
|
|
|
|
return {0, 0};
|
|
|
|
else if (node["type"].asString() == "floating_con") {
|
|
|
|
return {0, 1};
|
|
|
|
} else {
|
|
|
|
return {1, 0};
|
|
|
|
}
|
2020-12-18 23:14:14 +00:00
|
|
|
}
|
|
|
|
int sum = 0;
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
int floating_sum = 0;
|
|
|
|
for (auto const& node : nodes) {
|
|
|
|
std::pair all_leaf_nodes = leafNodesInWorkspace(node);
|
|
|
|
sum += all_leaf_nodes.first;
|
|
|
|
floating_sum += all_leaf_nodes.second;
|
2021-10-02 16:35:38 +00:00
|
|
|
}
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
for (auto const& node : floating_nodes) {
|
|
|
|
std::pair all_leaf_nodes = leafNodesInWorkspace(node);
|
|
|
|
sum += all_leaf_nodes.first;
|
|
|
|
floating_sum += all_leaf_nodes.second;
|
2021-10-02 16:35:38 +00:00
|
|
|
}
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
return {sum, floating_sum};
|
2020-12-18 23:14:14 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 06:35:46 +00:00
|
|
|
std::optional<std::reference_wrapper<const Json::Value>> getSingleChildNode(
|
|
|
|
const Json::Value& node) {
|
2023-06-12 23:37:45 +00:00
|
|
|
auto const& nodes = node["nodes"];
|
|
|
|
if (nodes.empty()) {
|
|
|
|
if (node["type"].asString() == "workspace")
|
|
|
|
return {};
|
|
|
|
else if (node["type"].asString() == "floating_con") {
|
|
|
|
return {};
|
|
|
|
} else {
|
|
|
|
return {std::cref(node)};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto it = std::cbegin(nodes);
|
|
|
|
if (it == std::cend(nodes)) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
auto const& child = *it;
|
|
|
|
++it;
|
|
|
|
if (it != std::cend(nodes)) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
return {getSingleChildNode(child)};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::tuple<std::string, std::string, std::string> getWindowInfo(const Json::Value& node) {
|
|
|
|
const auto app_id = node["app_id"].isString() ? node["app_id"].asString()
|
|
|
|
: node["window_properties"]["instance"].asString();
|
|
|
|
const auto app_class = node["window_properties"]["class"].isString()
|
|
|
|
? node["window_properties"]["class"].asString()
|
|
|
|
: "";
|
|
|
|
const auto shell = node["shell"].isString() ? node["shell"].asString() : "";
|
|
|
|
return {app_id, app_class, shell};
|
|
|
|
}
|
|
|
|
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
std::tuple<std::size_t, int, int, std::string, std::string, std::string, std::string, std::string>
|
|
|
|
gfnWithWorkspace(const Json::Value& nodes, std::string& output, const Json::Value& config_,
|
|
|
|
const Bar& bar_, Json::Value& parentWorkspace,
|
|
|
|
const Json::Value& immediateParent) {
|
2022-04-06 06:37:19 +00:00
|
|
|
for (auto const& node : nodes) {
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
if (node["type"].asString() == "output") {
|
|
|
|
if ((!config_["all-outputs"].asBool() || config_["offscreen-css"].asBool()) &&
|
|
|
|
(node["name"].asString() != bar_.output->name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
output = node["name"].asString();
|
|
|
|
} else if (node["type"].asString() == "workspace") {
|
|
|
|
// needs to be a string comparison, because filterWorkspace is the current_workspace
|
|
|
|
if (node["name"].asString() != immediateParent["current_workspace"].asString()) {
|
|
|
|
continue;
|
2019-04-25 14:47:51 +00:00
|
|
|
}
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
if (node["focused"].asBool()) {
|
|
|
|
std::pair all_leaf_nodes = leafNodesInWorkspace(node);
|
|
|
|
return {all_leaf_nodes.first,
|
|
|
|
all_leaf_nodes.second,
|
|
|
|
node["id"].asInt(),
|
|
|
|
(((all_leaf_nodes.first > 0) || (all_leaf_nodes.second > 0)) &&
|
|
|
|
(config_["show-focused-workspace-name"].asBool()))
|
|
|
|
? node["name"].asString()
|
|
|
|
: "",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
node["layout"].asString()};
|
|
|
|
}
|
|
|
|
parentWorkspace = node;
|
|
|
|
} else if ((node["type"].asString() == "con" || node["type"].asString() == "floating_con") &&
|
|
|
|
(node["focused"].asBool())) {
|
|
|
|
// found node
|
|
|
|
spdlog::trace("actual output {}, output found {}, node (focused) found {}", bar_.output->name,
|
|
|
|
output, node["name"].asString());
|
2023-06-12 23:37:45 +00:00
|
|
|
const auto [app_id, app_class, shell] = getWindowInfo(node);
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
int nb = node.size();
|
|
|
|
int floating_count = 0;
|
|
|
|
std::string workspace_layout = "";
|
|
|
|
if (!parentWorkspace.isNull()) {
|
|
|
|
std::pair all_leaf_nodes = leafNodesInWorkspace(parentWorkspace);
|
|
|
|
nb = all_leaf_nodes.first;
|
|
|
|
floating_count = all_leaf_nodes.second;
|
|
|
|
workspace_layout = parentWorkspace["layout"].asString();
|
|
|
|
}
|
|
|
|
return {nb,
|
|
|
|
floating_count,
|
|
|
|
node["id"].asInt(),
|
|
|
|
Glib::Markup::escape_text(node["name"].asString()),
|
|
|
|
app_id,
|
|
|
|
app_class,
|
|
|
|
shell,
|
|
|
|
workspace_layout};
|
2018-08-16 12:29:41 +00:00
|
|
|
}
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
|
2020-12-18 23:14:14 +00:00
|
|
|
// iterate
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
auto [nb, f, id, name, app_id, app_class, shell, workspace_layout] =
|
|
|
|
gfnWithWorkspace(node["nodes"], output, config_, bar_, parentWorkspace, node);
|
|
|
|
auto [nb2, f2, id2, name2, app_id2, app_class2, shell2, workspace_layout2] =
|
|
|
|
gfnWithWorkspace(node["floating_nodes"], output, config_, bar_, parentWorkspace, node);
|
|
|
|
|
|
|
|
// if ((id > 0 || ((id2 < 0 || name2.empty()) && id > -1)) && !name.empty()) {
|
|
|
|
if ((id > 0) || (id2 < 0 && id > -1)) {
|
|
|
|
return {nb, f, id, name, app_id, app_class, shell, workspace_layout};
|
|
|
|
} else if (id2 > 0 && !name2.empty()) {
|
|
|
|
return {nb2, f2, id2, name2, app_id2, app_class, shell2, workspace_layout2};
|
2018-08-16 12:29:41 +00:00
|
|
|
}
|
2018-08-15 18:17:17 +00:00
|
|
|
}
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
|
|
|
|
// this only comes into effect when no focused children are present
|
|
|
|
if (config_["all-outputs"].asBool() && config_["offscreen-css"].asBool() &&
|
|
|
|
immediateParent["type"].asString() == "workspace") {
|
|
|
|
std::pair all_leaf_nodes = leafNodesInWorkspace(immediateParent);
|
|
|
|
// using an empty string as default ensures that no window depending styles are set due to the
|
|
|
|
// checks above for !name.empty()
|
2023-06-12 23:37:45 +00:00
|
|
|
std::string app_id = "";
|
|
|
|
std::string app_class = "";
|
|
|
|
std::string workspace_layout = "";
|
|
|
|
if (all_leaf_nodes.first == 1) {
|
|
|
|
const auto single_child = getSingleChildNode(immediateParent);
|
|
|
|
if (single_child.has_value()) {
|
|
|
|
std::tie(app_id, app_class, workspace_layout) = getWindowInfo(single_child.value());
|
|
|
|
}
|
|
|
|
}
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
return {all_leaf_nodes.first,
|
|
|
|
all_leaf_nodes.second,
|
|
|
|
0,
|
|
|
|
(all_leaf_nodes.first > 0 || all_leaf_nodes.second > 0)
|
|
|
|
? config_["offscreen-css-text"].asString()
|
|
|
|
: "",
|
2023-06-12 23:37:45 +00:00
|
|
|
app_id,
|
|
|
|
app_class,
|
|
|
|
workspace_layout,
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
immediateParent["layout"].asString()};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {0, 0, -1, "", "", "", "", ""};
|
2018-08-15 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
std::tuple<std::size_t, int, int, std::string, std::string, std::string, std::string, std::string>
|
2022-08-10 08:41:18 +00:00
|
|
|
Window::getFocusedNode(const Json::Value& nodes, std::string& output) {
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
Json::Value placeholder = Json::Value::null;
|
|
|
|
return gfnWithWorkspace(nodes, output, config_, bar_, placeholder, placeholder);
|
2020-12-18 23:14:14 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 14:47:51 +00:00
|
|
|
void Window::getTree() {
|
2018-08-15 18:17:17 +00:00
|
|
|
try {
|
2019-04-19 09:09:06 +00:00
|
|
|
ipc_.sendCmd(IPC_GET_TREE);
|
2019-04-18 15:52:00 +00:00
|
|
|
} catch (const std::exception& e) {
|
2019-05-18 23:44:45 +00:00
|
|
|
spdlog::error("Window: {}", e.what());
|
sway-window, Issue 1399: new style classes
Provides CSS classes empty, floating, tabbed, tiled, solo, stacked and
app_id.
Adds offscreen-css bool option (default false), only effective when
"all-outputs" is true. This adds styles on outputs without focused
node, according to its focused workspaces window situation.
Adds an "offscreen-css-text" string option (default empty), only
effective when "all-outputs" and "offscreen-style" are set. This
is shown as a text on outputs without a focused node.
Adds a "show-focused-workspace" bool option (default false) to indicate
the workspace name if the whole workspace is focused when nodes are
also present. If not set, empty text is shown, but css classes
according to nodes in the workspace are still applied.
Limitation:
When the top level layout changes, there is no sway event so the
module cannot react. Perhaps in the future recurring polling can
be added to go around this limitation.
2022-04-17 05:13:35 +00:00
|
|
|
spdlog::trace("Window::getTree exception");
|
2018-08-15 18:17:17 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-19 09:09:06 +00:00
|
|
|
|
2019-05-11 18:36:10 +00:00
|
|
|
} // namespace waybar::modules::sway
|