feat: can disable tooltip

This commit is contained in:
Alex 2019-02-22 11:35:26 +01:00
parent 331b28393a
commit 83a6475510
9 changed files with 34 additions and 12 deletions

View File

@ -17,6 +17,8 @@ public:
virtual operator Gtk::Widget &(); virtual operator Gtk::Widget &();
protected: protected:
bool tooltipEnabled();
Gtk::EventBox event_box_; Gtk::EventBox event_box_;
Gtk::Label label_; Gtk::Label label_;
const Json::Value &config_; const Json::Value &config_;

View File

@ -86,8 +86,8 @@ bool waybar::ALabel::handleScroll(GdkEventScroll* e) {
return true; return true;
} }
std::string waybar::ALabel::getIcon(uint16_t percentage, std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt)
const std::string& alt) { {
auto format_icons = config_["format-icons"]; auto format_icons = config_["format-icons"];
if (format_icons.isObject()) { if (format_icons.isObject()) {
if (!alt.empty() && (format_icons[alt].isString() || format_icons[alt].isArray())) { if (!alt.empty() && (format_icons[alt].isString() || format_icons[alt].isArray())) {
@ -107,4 +107,10 @@ std::string waybar::ALabel::getIcon(uint16_t percentage,
return ""; return "";
} }
bool waybar::ALabel::tooltipEnabled()
{
return !config_["tooltip"].isBool() ||
(config_["tooltip"].isBool() && config_["tooltip"].asBool());
}
waybar::ALabel::operator Gtk::Widget&() { return event_box_; } waybar::ALabel::operator Gtk::Widget&() { return event_box_; }

View File

@ -148,7 +148,9 @@ auto waybar::modules::Battery::update() -> void
if (status == "Unknown") { if (status == "Unknown") {
status = getAdapterStatus(capacity); status = getAdapterStatus(capacity);
} }
label_.set_tooltip_text(status); if (tooltipEnabled()) {
label_.set_tooltip_text(status);
}
std::transform(status.begin(), status.end(), status.begin(), ::tolower); std::transform(status.begin(), status.end(), status.begin(), ::tolower);
auto format = format_; auto format = format_;
auto state = getState(capacity); auto state = getState(capacity);

View File

@ -18,7 +18,9 @@ auto waybar::modules::Cpu::update() -> void
// TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both // TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both
auto cpu_load = getCpuLoad(); auto cpu_load = getCpuLoad();
auto [cpu_usage, tooltip] = getCpuUsage(); auto [cpu_usage, tooltip] = getCpuUsage();
label_.set_tooltip_text(tooltip); if (tooltipEnabled()) {
label_.set_tooltip_text(tooltip);
}
label_.set_markup(fmt::format(format_, label_.set_markup(fmt::format(format_,
fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage))); fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage)));
} }

View File

@ -94,10 +94,12 @@ auto waybar::modules::Custom::update() -> void
fmt::arg("icon", getIcon(percentage_)), fmt::arg("icon", getIcon(percentage_)),
fmt::arg("percentage", percentage_)); fmt::arg("percentage", percentage_));
label_.set_markup(str); label_.set_markup(str);
if (text_ == tooltip_) { if (tooltipEnabled()) {
label_.set_tooltip_text(str); if (text_ == tooltip_) {
} else { label_.set_tooltip_text(str);
label_.set_tooltip_text(tooltip_); } else {
label_.set_tooltip_text(tooltip_);
}
} }
if (class_ != "") { if (class_ != "") {
if (prevclass_ != "") { if (prevclass_ != "") {

View File

@ -20,7 +20,9 @@ auto waybar::modules::Memory::update() -> void
int used_ram_percentage = 100 * (memtotal_ - memfree_) / memtotal_; int used_ram_percentage = 100 * (memtotal_ - memfree_) / memtotal_;
label_.set_markup(fmt::format(format_, used_ram_percentage)); label_.set_markup(fmt::format(format_, used_ram_percentage));
auto used_ram_gigabytes = (memtotal_ - memfree_) / std::pow(1024, 2); auto used_ram_gigabytes = (memtotal_ - memfree_) / std::pow(1024, 2);
label_.set_tooltip_text(fmt::format("{:.{}f}Gb used", used_ram_gigabytes, 1)); if (tooltipEnabled()) {
label_.set_tooltip_text(fmt::format("{:.{}f}Gb used", used_ram_gigabytes, 1));
}
event_box_.show(); event_box_.show();
} else { } else {
event_box_.hide(); event_box_.hide();

View File

@ -215,7 +215,9 @@ auto waybar::modules::Pulseaudio::update() -> void
label_.set_markup( label_.set_markup(
fmt::format(format, fmt::arg("volume", volume_), fmt::format(format, fmt::arg("volume", volume_),
fmt::arg("icon", getIcon(volume_, getPortIcon())))); fmt::arg("icon", getIcon(volume_, getPortIcon()))));
label_.set_tooltip_text(desc_); if (tooltipEnabled()) {
label_.set_tooltip_text(desc_);
}
if (scrolling_) { if (scrolling_) {
scrolling_ = false; scrolling_ = false;
} }

View File

@ -37,7 +37,9 @@ auto waybar::modules::sway::Mode::update() -> void
event_box_.hide(); event_box_.hide();
} else { } else {
label_.set_markup(fmt::format(format_, mode_)); label_.set_markup(fmt::format(format_, mode_));
label_.set_tooltip_text(mode_); if (tooltipEnabled()) {
label_.set_tooltip_text(mode_);
}
event_box_.show(); event_box_.show();
} }
} }

View File

@ -48,7 +48,9 @@ void waybar::modules::sway::Window::worker()
auto waybar::modules::sway::Window::update() -> void auto waybar::modules::sway::Window::update() -> void
{ {
label_.set_markup(fmt::format(format_, window_)); label_.set_markup(fmt::format(format_, window_));
label_.set_tooltip_text(window_); if (tooltipEnabled()) {
label_.set_tooltip_text(window_);
}
} }
std::tuple<int, std::string> waybar::modules::sway::Window::getFocusedNode( std::tuple<int, std::string> waybar::modules::sway::Window::getFocusedNode(