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 &();
protected:
bool tooltipEnabled();
Gtk::EventBox event_box_;
Gtk::Label label_;
const Json::Value &config_;

View File

@ -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_; }

View File

@ -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);

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
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)));
}

View File

@ -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_ != "") {

View File

@ -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();

View File

@ -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;
}

View File

@ -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();
}
}

View File

@ -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<int, std::string> waybar::modules::sway::Window::getFocusedNode(