mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat(tray): handle Status property
On the `Passive` value of `Status` tray items would be hidden unless `show-passive-items` is set to true. On the `NeedsAttention` value of `Status` tray items will have a `.needs-attention` CSS class.
This commit is contained in:
parent
245f7f4b11
commit
a5fe6f40b8
@ -35,7 +35,6 @@ class Item : public sigc::trackable {
|
|||||||
Gtk::EventBox event_box;
|
Gtk::EventBox event_box;
|
||||||
std::string category;
|
std::string category;
|
||||||
std::string id;
|
std::string id;
|
||||||
std::string status;
|
|
||||||
|
|
||||||
std::string title;
|
std::string title;
|
||||||
std::string icon_name;
|
std::string icon_name;
|
||||||
@ -59,6 +58,7 @@ class Item : public sigc::trackable {
|
|||||||
private:
|
private:
|
||||||
void proxyReady(Glib::RefPtr<Gio::AsyncResult>& result);
|
void proxyReady(Glib::RefPtr<Gio::AsyncResult>& result);
|
||||||
void setProperty(const Glib::ustring& name, Glib::VariantBase& value);
|
void setProperty(const Glib::ustring& name, Glib::VariantBase& value);
|
||||||
|
void setStatus(const Glib::ustring& value);
|
||||||
void getUpdatedProperties();
|
void getUpdatedProperties();
|
||||||
void processUpdatedProperties(Glib::RefPtr<Gio::AsyncResult>& result);
|
void processUpdatedProperties(Glib::RefPtr<Gio::AsyncResult>& result);
|
||||||
void onSignal(const Glib::ustring& sender_name, const Glib::ustring& signal_name,
|
void onSignal(const Glib::ustring& sender_name, const Glib::ustring& signal_name,
|
||||||
@ -76,6 +76,8 @@ class Item : public sigc::trackable {
|
|||||||
gdouble scroll_threshold_ = 0;
|
gdouble scroll_threshold_ = 0;
|
||||||
gdouble distance_scrolled_x_ = 0;
|
gdouble distance_scrolled_x_ = 0;
|
||||||
gdouble distance_scrolled_y_ = 0;
|
gdouble distance_scrolled_y_ = 0;
|
||||||
|
// visibility of items with Status == Passive
|
||||||
|
bool show_passive_ = false;
|
||||||
|
|
||||||
Glib::RefPtr<Gio::DBus::Proxy> proxy_;
|
Glib::RefPtr<Gio::DBus::Proxy> proxy_;
|
||||||
Glib::RefPtr<Gio::Cancellable> cancellable_;
|
Glib::RefPtr<Gio::Cancellable> cancellable_;
|
||||||
|
@ -16,6 +16,11 @@ Addressed by *tray*
|
|||||||
typeof: integer ++
|
typeof: integer ++
|
||||||
Defines the size of the tray icons.
|
Defines the size of the tray icons.
|
||||||
|
|
||||||
|
*show-passive-items*: ++
|
||||||
|
typeof: bool ++
|
||||||
|
default: false ++
|
||||||
|
Defines visibility of the tray icons with *Passive* status.
|
||||||
|
|
||||||
*smooth-scrolling-threshold*: ++
|
*smooth-scrolling-threshold*: ++
|
||||||
typeof: double ++
|
typeof: double ++
|
||||||
Threshold to be used when scrolling.
|
Threshold to be used when scrolling.
|
||||||
@ -41,3 +46,6 @@ Addressed by *tray*
|
|||||||
# STYLE
|
# STYLE
|
||||||
|
|
||||||
- *#tray*
|
- *#tray*
|
||||||
|
- *#tray > .passive*
|
||||||
|
- *#tray > .active*
|
||||||
|
- *#tray > .needs-attention*
|
||||||
|
@ -195,6 +195,15 @@ label:focus {
|
|||||||
background-color: #2980b9;
|
background-color: #2980b9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#tray > .passive {
|
||||||
|
-gtk-icon-effect: dim;
|
||||||
|
}
|
||||||
|
|
||||||
|
#tray > .needs-attention {
|
||||||
|
-gtk-icon-effect: highlight;
|
||||||
|
background-color: #eb4d4b;
|
||||||
|
}
|
||||||
|
|
||||||
#idle_inhibitor {
|
#idle_inhibitor {
|
||||||
background-color: #2d3436;
|
background-color: #2d3436;
|
||||||
}
|
}
|
||||||
|
@ -51,10 +51,15 @@ Item::Item(const std::string& bn, const std::string& op, const Json::Value& conf
|
|||||||
if (config["smooth-scrolling-threshold"].isNumeric()) {
|
if (config["smooth-scrolling-threshold"].isNumeric()) {
|
||||||
scroll_threshold_ = config["smooth-scrolling-threshold"].asDouble();
|
scroll_threshold_ = config["smooth-scrolling-threshold"].asDouble();
|
||||||
}
|
}
|
||||||
|
if (config["show-passive-items"].isBool()) {
|
||||||
|
show_passive_ = config["show-passive-items"].asBool();
|
||||||
|
}
|
||||||
event_box.add(image);
|
event_box.add(image);
|
||||||
event_box.add_events(Gdk::BUTTON_PRESS_MASK | Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
|
event_box.add_events(Gdk::BUTTON_PRESS_MASK | Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
|
||||||
event_box.signal_button_press_event().connect(sigc::mem_fun(*this, &Item::handleClick));
|
event_box.signal_button_press_event().connect(sigc::mem_fun(*this, &Item::handleClick));
|
||||||
event_box.signal_scroll_event().connect(sigc::mem_fun(*this, &Item::handleScroll));
|
event_box.signal_scroll_event().connect(sigc::mem_fun(*this, &Item::handleScroll));
|
||||||
|
// initial visibility
|
||||||
|
event_box.set_visible(show_passive_);
|
||||||
|
|
||||||
cancellable_ = Gio::Cancellable::create();
|
cancellable_ = Gio::Cancellable::create();
|
||||||
|
|
||||||
@ -81,7 +86,7 @@ void Item::proxyReady(Glib::RefPtr<Gio::AsyncResult>& result) {
|
|||||||
|
|
||||||
this->proxy_->signal_signal().connect(sigc::mem_fun(*this, &Item::onSignal));
|
this->proxy_->signal_signal().connect(sigc::mem_fun(*this, &Item::onSignal));
|
||||||
|
|
||||||
if (this->id.empty() || this->category.empty() || this->status.empty()) {
|
if (this->id.empty() || this->category.empty()) {
|
||||||
spdlog::error("Invalid Status Notifier Item: {}, {}", bus_name, object_path);
|
spdlog::error("Invalid Status Notifier Item: {}, {}", bus_name, object_path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -127,7 +132,7 @@ void Item::setProperty(const Glib::ustring& name, Glib::VariantBase& value) {
|
|||||||
event_box.set_tooltip_markup(title);
|
event_box.set_tooltip_markup(title);
|
||||||
}
|
}
|
||||||
} else if (name == "Status") {
|
} else if (name == "Status") {
|
||||||
status = get_variant<std::string>(value);
|
setStatus(get_variant<Glib::ustring>(value));
|
||||||
} else if (name == "IconName") {
|
} else if (name == "IconName") {
|
||||||
icon_name = get_variant<std::string>(value);
|
icon_name = get_variant<std::string>(value);
|
||||||
} else if (name == "IconPixmap") {
|
} else if (name == "IconPixmap") {
|
||||||
@ -173,6 +178,21 @@ void Item::setProperty(const Glib::ustring& name, Glib::VariantBase& value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Item::setStatus(const Glib::ustring& value) {
|
||||||
|
Glib::ustring lower = value.lowercase();
|
||||||
|
event_box.set_visible(show_passive_ || lower.compare("passive") != 0);
|
||||||
|
|
||||||
|
auto style = event_box.get_style_context();
|
||||||
|
for (const auto& class_name : style->list_classes()) {
|
||||||
|
style->remove_class(class_name);
|
||||||
|
}
|
||||||
|
if (lower.compare("needsattention") == 0) {
|
||||||
|
// convert status to dash-case for CSS
|
||||||
|
lower = "needs-attention";
|
||||||
|
}
|
||||||
|
style->add_class(lower);
|
||||||
|
}
|
||||||
|
|
||||||
void Item::getUpdatedProperties() {
|
void Item::getUpdatedProperties() {
|
||||||
auto params = Glib::VariantContainerBase::create_tuple(
|
auto params = Glib::VariantContainerBase::create_tuple(
|
||||||
{Glib::Variant<Glib::ustring>::create(SNI_INTERFACE_NAME)});
|
{Glib::Variant<Glib::ustring>::create(SNI_INTERFACE_NAME)});
|
||||||
|
Loading…
Reference in New Issue
Block a user