feat(Bar): add class depend of window in the workspace
This commit is contained in:
parent
79a5e9ecee
commit
bb8ff5a99f
|
@ -20,14 +20,15 @@ class Window : public ALabel {
|
||||||
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<int, std::string> getFocusedNode(const Json::Value& nodes);
|
std::tuple<std::size_t, int, std::string, std::string> getFocusedNode(const Json::Value& nodes);
|
||||||
void getFocusedWindow();
|
void getTree();
|
||||||
|
|
||||||
const Bar& bar_;
|
const Bar& bar_;
|
||||||
waybar::util::SleeperThread thread_;
|
waybar::util::SleeperThread thread_;
|
||||||
Ipc ipc_;
|
Ipc ipc_;
|
||||||
std::string window_;
|
std::string window_;
|
||||||
int windowId_;
|
int windowId_;
|
||||||
|
std::string app_id_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules::sway
|
} // namespace waybar::modules::sway
|
||||||
|
|
|
@ -16,6 +16,24 @@ window#waybar.hidded {
|
||||||
opacity: 0.2;
|
opacity: 0.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
window#waybar.empty {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
window#waybar.solo {
|
||||||
|
background: #FFFFFF;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
window#waybar.termite {
|
||||||
|
background-color: #3F3F3F;
|
||||||
|
}
|
||||||
|
|
||||||
|
window#waybar.chromium {
|
||||||
|
background-color: #DEE1E6;
|
||||||
|
color: #000000;
|
||||||
|
}
|
||||||
|
|
||||||
/* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */
|
/* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */
|
||||||
#workspaces button {
|
#workspaces button {
|
||||||
padding: 0 5px;
|
padding: 0 5px;
|
||||||
|
@ -41,6 +59,7 @@ window#waybar.hidded {
|
||||||
#clock, #battery, #cpu, #memory, #temperature, #backlight, #network, #pulseaudio, #custom-media, #tray, #mode, #idle_inhibitor {
|
#clock, #battery, #cpu, #memory, #temperature, #backlight, #network, #pulseaudio, #custom-media, #tray, #mode, #idle_inhibitor {
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
margin: 0 5px;
|
margin: 0 5px;
|
||||||
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
#clock {
|
#clock {
|
||||||
|
|
|
@ -15,7 +15,8 @@ Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||||
ipc_.subscribe(R"(["window","workspace"])");
|
ipc_.subscribe(R"(["window","workspace"])");
|
||||||
ipc_.signal_event.connect(sigc::mem_fun(*this, &Window::onEvent));
|
ipc_.signal_event.connect(sigc::mem_fun(*this, &Window::onEvent));
|
||||||
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Window::onCmd));
|
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Window::onCmd));
|
||||||
getFocusedWindow();
|
// Get Initial focused window
|
||||||
|
getTree();
|
||||||
// Launch worker
|
// Launch worker
|
||||||
worker();
|
worker();
|
||||||
}
|
}
|
||||||
|
@ -28,6 +29,7 @@ void Window::onEvent(const struct Ipc::ipc_response& res) {
|
||||||
window_ = Glib::Markup::escape_text(data["container"]["name"].asString());
|
window_ = Glib::Markup::escape_text(data["container"]["name"].asString());
|
||||||
windowId_ = data["container"]["id"].asInt();
|
windowId_ = data["container"]["id"].asInt();
|
||||||
dp.emit();
|
dp.emit();
|
||||||
|
getTree();
|
||||||
} else if ((data["change"] == "close" && data["container"]["focused"].asBool() &&
|
} else if ((data["change"] == "close" && data["container"]["focused"].asBool() &&
|
||||||
windowId_ == data["container"]["id"].asInt()) ||
|
windowId_ == data["container"]["id"].asInt()) ||
|
||||||
(data["change"] == "focus" && data["current"]["focus"].isArray() &&
|
(data["change"] == "focus" && data["current"]["focus"].isArray() &&
|
||||||
|
@ -35,15 +37,35 @@ void Window::onEvent(const struct Ipc::ipc_response& res) {
|
||||||
window_.clear();
|
window_.clear();
|
||||||
windowId_ = -1;
|
windowId_ = -1;
|
||||||
dp.emit();
|
dp.emit();
|
||||||
|
getTree();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::onCmd(const struct Ipc::ipc_response& res) {
|
void Window::onCmd(const struct Ipc::ipc_response& res) {
|
||||||
auto [id, name] = getFocusedNode(res.payload["nodes"]);
|
auto [nb, id, name, app_id] = getFocusedNode(res.payload);
|
||||||
|
if (nb == 0) {
|
||||||
|
bar_.window.get_style_context()->add_class("empty");
|
||||||
|
} else {
|
||||||
|
bar_.window.get_style_context()->remove_class("empty");
|
||||||
|
}
|
||||||
|
if (!app_id_.empty()) {
|
||||||
|
bar_.window.get_style_context()->remove_class(app_id_);
|
||||||
|
}
|
||||||
|
if (nb == 1) {
|
||||||
|
bar_.window.get_style_context()->add_class("solo");
|
||||||
|
if (!app_id.empty()) {
|
||||||
|
bar_.window.get_style_context()->add_class(app_id);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bar_.window.get_style_context()->remove_class("solo");
|
||||||
|
}
|
||||||
|
app_id_ = app_id;
|
||||||
|
if (windowId_ != id || window_ != name) {
|
||||||
windowId_ = id;
|
windowId_ = id;
|
||||||
window_ = name;
|
window_ = name;
|
||||||
dp.emit();
|
dp.emit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Window::worker() {
|
void Window::worker() {
|
||||||
thread_ = [this] {
|
thread_ = [this] {
|
||||||
|
@ -62,20 +84,29 @@ auto Window::update() -> void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<int, std::string> Window::getFocusedNode(const Json::Value& nodes) {
|
std::tuple<std::size_t, int, std::string, std::string> Window::getFocusedNode(
|
||||||
for (auto const& node : nodes) {
|
const Json::Value& nodes) {
|
||||||
|
for (auto const& node : nodes["nodes"]) {
|
||||||
if (node["focused"].asBool() && node["type"] == "con") {
|
if (node["focused"].asBool() && node["type"] == "con") {
|
||||||
return {node["id"].asInt(), node["name"].asString()};
|
if ((!config_["all-outputs"].asBool() && nodes["output"] == bar_.output->name) ||
|
||||||
|
config_["all-outputs"].asBool()) {
|
||||||
|
auto app_id = node["app_id"].isString() ? node["app_id"].asString()
|
||||||
|
: node["window_properties"]["instance"].asString();
|
||||||
|
return {nodes["nodes"].size(),
|
||||||
|
node["id"].asInt(),
|
||||||
|
Glib::Markup::escape_text(node["name"].asString()),
|
||||||
|
app_id};
|
||||||
}
|
}
|
||||||
auto [id, name] = getFocusedNode(node["nodes"]);
|
}
|
||||||
|
auto [nb, id, name, app_id] = getFocusedNode(node);
|
||||||
if (id > -1 && !name.empty()) {
|
if (id > -1 && !name.empty()) {
|
||||||
return {id, name};
|
return {nb, id, name, app_id};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {-1, std::string()};
|
return {0, -1, "", ""};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::getFocusedWindow() {
|
void Window::getTree() {
|
||||||
try {
|
try {
|
||||||
ipc_.sendCmd(IPC_GET_TREE);
|
ipc_.sendCmd(IPC_GET_TREE);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
|
|
Loading…
Reference in New Issue