mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat(sway/window): handle floating nodes
This commit is contained in:
parent
486b5a5d38
commit
dabe2bebbb
@ -5,7 +5,6 @@
|
|||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include "ipc.hpp"
|
#include "ipc.hpp"
|
||||||
|
@ -21,7 +21,8 @@ class Window : public ALabel, public sigc::trackable {
|
|||||||
void onEvent(const struct Ipc::ipc_response&);
|
void onEvent(const struct Ipc::ipc_response&);
|
||||||
void onCmd(const struct Ipc::ipc_response&);
|
void onCmd(const struct Ipc::ipc_response&);
|
||||||
void worker();
|
void worker();
|
||||||
std::tuple<std::size_t, int, std::string, std::string> getFocusedNode(const Json::Value& nodes, std::string output);
|
std::tuple<std::size_t, int, std::string, std::string> getFocusedNode(const Json::Value& nodes,
|
||||||
|
std::string& output);
|
||||||
void getTree();
|
void getTree();
|
||||||
|
|
||||||
const Bar& bar_;
|
const Bar& bar_;
|
||||||
|
@ -24,7 +24,7 @@ void Window::onCmd(const struct Ipc::ipc_response& res) {
|
|||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
auto payload = parser_.parse(res.payload);
|
auto payload = parser_.parse(res.payload);
|
||||||
auto output = payload["ouput"].isString() ? payload["output"].asString() : "";
|
auto output = payload["ouput"].isString() ? payload["output"].asString() : "";
|
||||||
std::tie(app_nb_, windowId_, window_, app_id_) = getFocusedNode(payload, output);
|
std::tie(app_nb_, windowId_, window_, app_id_) = getFocusedNode(payload["nodes"], output);
|
||||||
dp.emit();
|
dp.emit();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
spdlog::error("Window: {}", e.what());
|
spdlog::error("Window: {}", e.what());
|
||||||
@ -70,23 +70,28 @@ auto Window::update() -> void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<std::size_t, int, std::string, std::string> Window::getFocusedNode(
|
std::tuple<std::size_t, int, std::string, std::string> Window::getFocusedNode(
|
||||||
const Json::Value& nodes, std::string output) {
|
const Json::Value& nodes, std::string& output) {
|
||||||
for (auto const& node : nodes["nodes"]) {
|
for (auto const& node : nodes) {
|
||||||
if (node["output"].isString()) {
|
if (node["output"].isString()) {
|
||||||
output = node["output"].asString();
|
output = node["output"].asString();
|
||||||
}
|
}
|
||||||
if (node["focused"].asBool() && node["type"] == "con") {
|
if (node["focused"].asBool() && (node["type"] == "con" || node["type"] == "floating_con")) {
|
||||||
if ((!config_["all-outputs"].asBool() && output == bar_.output->name) ||
|
if ((!config_["all-outputs"].asBool() && output == bar_.output->name) ||
|
||||||
config_["all-outputs"].asBool()) {
|
config_["all-outputs"].asBool()) {
|
||||||
auto app_id = node["app_id"].isString() ? node["app_id"].asString()
|
auto app_id = node["app_id"].isString() ? node["app_id"].asString()
|
||||||
: node["window_properties"]["instance"].asString();
|
: node["window_properties"]["instance"].asString();
|
||||||
return {nodes["nodes"].size(),
|
return {nodes.size(),
|
||||||
node["id"].asInt(),
|
node["id"].asInt(),
|
||||||
Glib::Markup::escape_text(node["name"].asString()),
|
Glib::Markup::escape_text(node["name"].asString()),
|
||||||
app_id};
|
app_id};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto [nb, id, name, app_id] = getFocusedNode(node, output);
|
auto [nb, id, name, app_id] = getFocusedNode(node["nodes"], output);
|
||||||
|
if (id > -1 && !name.empty()) {
|
||||||
|
return {nb, id, name, app_id};
|
||||||
|
}
|
||||||
|
// Search for floating node
|
||||||
|
std::tie(nb, id, name, app_id) = getFocusedNode(node["floating_nodes"], output);
|
||||||
if (id > -1 && !name.empty()) {
|
if (id > -1 && !name.empty()) {
|
||||||
return {nb, id, name, app_id};
|
return {nb, id, name, app_id};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user