From 83a6475510df2c3db325c6ba24b377858b487ca5 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 22 Feb 2019 11:35:26 +0100 Subject: [PATCH] feat: can disable tooltip --- include/ALabel.hpp | 2 ++ src/ALabel.cpp | 10 ++++++++-- src/modules/battery.cpp | 4 +++- src/modules/cpu.cpp | 4 +++- src/modules/custom.cpp | 10 ++++++---- src/modules/memory.cpp | 4 +++- src/modules/pulseaudio.cpp | 4 +++- src/modules/sway/mode.cpp | 4 +++- src/modules/sway/window.cpp | 4 +++- 9 files changed, 34 insertions(+), 12 deletions(-) diff --git a/include/ALabel.hpp b/include/ALabel.hpp index b4d79bec..f389da5f 100644 --- a/include/ALabel.hpp +++ b/include/ALabel.hpp @@ -17,6 +17,8 @@ public: virtual operator Gtk::Widget &(); protected: + bool tooltipEnabled(); + Gtk::EventBox event_box_; Gtk::Label label_; const Json::Value &config_; diff --git a/src/ALabel.cpp b/src/ALabel.cpp index de755978..223b942b 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -86,8 +86,8 @@ bool waybar::ALabel::handleScroll(GdkEventScroll* e) { return true; } -std::string waybar::ALabel::getIcon(uint16_t percentage, - const std::string& alt) { +std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt) +{ auto format_icons = config_["format-icons"]; if (format_icons.isObject()) { if (!alt.empty() && (format_icons[alt].isString() || format_icons[alt].isArray())) { @@ -107,4 +107,10 @@ std::string waybar::ALabel::getIcon(uint16_t percentage, return ""; } +bool waybar::ALabel::tooltipEnabled() +{ + return !config_["tooltip"].isBool() || + (config_["tooltip"].isBool() && config_["tooltip"].asBool()); +} + waybar::ALabel::operator Gtk::Widget&() { return event_box_; } diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 1d6c42a0..27d8baaf 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -148,7 +148,9 @@ auto waybar::modules::Battery::update() -> void if (status == "Unknown") { status = getAdapterStatus(capacity); } - label_.set_tooltip_text(status); + if (tooltipEnabled()) { + label_.set_tooltip_text(status); + } std::transform(status.begin(), status.end(), status.begin(), ::tolower); auto format = format_; auto state = getState(capacity); diff --git a/src/modules/cpu.cpp b/src/modules/cpu.cpp index 3e01aff1..e800dbf7 100644 --- a/src/modules/cpu.cpp +++ b/src/modules/cpu.cpp @@ -18,7 +18,9 @@ auto waybar::modules::Cpu::update() -> void // TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both auto cpu_load = getCpuLoad(); auto [cpu_usage, tooltip] = getCpuUsage(); - label_.set_tooltip_text(tooltip); + if (tooltipEnabled()) { + label_.set_tooltip_text(tooltip); + } label_.set_markup(fmt::format(format_, fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage))); } diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 3c037773..978602c8 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -94,10 +94,12 @@ auto waybar::modules::Custom::update() -> void fmt::arg("icon", getIcon(percentage_)), fmt::arg("percentage", percentage_)); label_.set_markup(str); - if (text_ == tooltip_) { - label_.set_tooltip_text(str); - } else { - label_.set_tooltip_text(tooltip_); + if (tooltipEnabled()) { + if (text_ == tooltip_) { + label_.set_tooltip_text(str); + } else { + label_.set_tooltip_text(tooltip_); + } } if (class_ != "") { if (prevclass_ != "") { diff --git a/src/modules/memory.cpp b/src/modules/memory.cpp index 9ddace76..649cdf6a 100644 --- a/src/modules/memory.cpp +++ b/src/modules/memory.cpp @@ -20,7 +20,9 @@ auto waybar::modules::Memory::update() -> void int used_ram_percentage = 100 * (memtotal_ - memfree_) / memtotal_; label_.set_markup(fmt::format(format_, used_ram_percentage)); 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(); } else { event_box_.hide(); diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index 4f7f8c2a..c3a67b8d 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -215,7 +215,9 @@ auto waybar::modules::Pulseaudio::update() -> void label_.set_markup( fmt::format(format, fmt::arg("volume", volume_), fmt::arg("icon", getIcon(volume_, getPortIcon())))); - label_.set_tooltip_text(desc_); + if (tooltipEnabled()) { + label_.set_tooltip_text(desc_); + } if (scrolling_) { scrolling_ = false; } diff --git a/src/modules/sway/mode.cpp b/src/modules/sway/mode.cpp index 83ab43bf..c4b47350 100644 --- a/src/modules/sway/mode.cpp +++ b/src/modules/sway/mode.cpp @@ -37,7 +37,9 @@ auto waybar::modules::sway::Mode::update() -> void event_box_.hide(); } else { label_.set_markup(fmt::format(format_, mode_)); - label_.set_tooltip_text(mode_); + if (tooltipEnabled()) { + label_.set_tooltip_text(mode_); + } event_box_.show(); } } \ No newline at end of file diff --git a/src/modules/sway/window.cpp b/src/modules/sway/window.cpp index 9c569ff2..aa54978d 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -48,7 +48,9 @@ void waybar::modules::sway::Window::worker() auto waybar::modules::sway::Window::update() -> void { label_.set_markup(fmt::format(format_, window_)); - label_.set_tooltip_text(window_); + if (tooltipEnabled()) { + label_.set_tooltip_text(window_); + } } std::tuple waybar::modules::sway::Window::getFocusedNode(