refactor(window): gtk stuff in update method
parent
9dbf057f58
commit
1962caf144
|
@ -29,6 +29,8 @@ class Window : public ALabel, public sigc::trackable {
|
|||
std::string window_;
|
||||
int windowId_;
|
||||
std::string app_id_;
|
||||
std::string old_app_id_;
|
||||
std::size_t app_nb_;
|
||||
util::JsonParser parser_;
|
||||
|
||||
util::SleeperThread thread_;
|
||||
|
|
|
@ -23,34 +23,9 @@ void Window::onEvent(const struct Ipc::ipc_response& res) { getTree(); }
|
|||
void Window::onCmd(const struct Ipc::ipc_response& res) {
|
||||
try {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto payload = parser_.parse(res.payload);
|
||||
auto [nb, id, name, app_id] = getFocusedNode(payload);
|
||||
if (!app_id_.empty()) {
|
||||
bar_.window.get_style_context()->remove_class(app_id_);
|
||||
}
|
||||
if (nb == 0) {
|
||||
bar_.window.get_style_context()->remove_class("solo");
|
||||
if (!bar_.window.get_style_context()->has_class("empty")) {
|
||||
bar_.window.get_style_context()->add_class("empty");
|
||||
}
|
||||
} else if (nb == 1) {
|
||||
bar_.window.get_style_context()->remove_class("empty");
|
||||
if (!bar_.window.get_style_context()->has_class("solo")) {
|
||||
bar_.window.get_style_context()->add_class("solo");
|
||||
}
|
||||
if (!app_id.empty() && !bar_.window.get_style_context()->has_class(app_id)) {
|
||||
bar_.window.get_style_context()->add_class(app_id);
|
||||
}
|
||||
} else {
|
||||
bar_.window.get_style_context()->remove_class("solo");
|
||||
bar_.window.get_style_context()->remove_class("empty");
|
||||
}
|
||||
app_id_ = app_id;
|
||||
if (windowId_ != id || window_ != name) {
|
||||
windowId_ = id;
|
||||
window_ = name;
|
||||
dp.emit();
|
||||
}
|
||||
auto payload = parser_.parse(res.payload);
|
||||
std::tie(app_nb_, windowId_, window_, app_id_) = getFocusedNode(payload);
|
||||
dp.emit();
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::error("Window: {}", e.what());
|
||||
}
|
||||
|
@ -67,6 +42,27 @@ void Window::worker() {
|
|||
}
|
||||
|
||||
auto Window::update() -> void {
|
||||
if (!old_app_id_.empty()) {
|
||||
bar_.window.get_style_context()->remove_class(old_app_id_);
|
||||
}
|
||||
if (app_nb_ == 0) {
|
||||
bar_.window.get_style_context()->remove_class("solo");
|
||||
if (!bar_.window.get_style_context()->has_class("empty")) {
|
||||
bar_.window.get_style_context()->add_class("empty");
|
||||
}
|
||||
} else if (app_nb_ == 1) {
|
||||
bar_.window.get_style_context()->remove_class("empty");
|
||||
if (!bar_.window.get_style_context()->has_class("solo")) {
|
||||
bar_.window.get_style_context()->add_class("solo");
|
||||
}
|
||||
if (!app_id_.empty() && !bar_.window.get_style_context()->has_class(app_id_)) {
|
||||
bar_.window.get_style_context()->add_class(app_id_);
|
||||
old_app_id_ = app_id_;
|
||||
}
|
||||
} else {
|
||||
bar_.window.get_style_context()->remove_class("solo");
|
||||
bar_.window.get_style_context()->remove_class("empty");
|
||||
}
|
||||
label_.set_markup(fmt::format(format_, window_));
|
||||
if (tooltipEnabled()) {
|
||||
label_.set_tooltip_text(window_);
|
||||
|
|
Loading…
Reference in New Issue