modules: Set tooltip on button

Mouse-over tooltips set on the label only appear once the mouse hovers
over exactly the label. Other apps (e.g. firefox) show the tooltip once
the pointer hovers the button. Not solely its label. With this commit we
get the same behaviour.
This commit is contained in:
Simon Plakolb 2021-06-23 10:43:28 +02:00
parent 8fa5d9b838
commit 2b735f44bc
16 changed files with 27 additions and 27 deletions

View File

@ -347,7 +347,7 @@ auto waybar::modules::Battery::update() -> void {
} else if (config_["tooltip-format"].isString()) { } else if (config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
label_->set_tooltip_text(fmt::format(tooltip_format, fmt::arg("timeTo", tooltip_text_default), button_.set_tooltip_text(fmt::format(tooltip_format, fmt::arg("timeTo", tooltip_text_default),
fmt::arg("capacity", capacity), fmt::arg("capacity", capacity),
fmt::arg("time", time_remaining_formatted))); fmt::arg("time", time_remaining_formatted)));
} }

View File

@ -245,7 +245,7 @@ auto waybar::modules::Bluetooth::update() -> void {
device_enumerate_.erase(0, 1); device_enumerate_.erase(0, 1);
} }
} }
label_->set_tooltip_text(fmt::format( button_.set_tooltip_text(fmt::format(
tooltip_format, fmt::arg("status", state_), tooltip_format, fmt::arg("status", state_),
fmt::arg("num_connections", connected_devices_.size()), fmt::arg("num_connections", connected_devices_.size()),
fmt::arg("controller_address", cur_controller_.address), fmt::arg("controller_address", cur_controller_.address),

View File

@ -119,7 +119,7 @@ auto waybar::modules::Clock::update() -> void {
text = text =
fmt::format(tooltip_format, wtime, fmt::arg(kCalendarPlaceholder.c_str(), calendar_lines), fmt::format(tooltip_format, wtime, fmt::arg(kCalendarPlaceholder.c_str(), calendar_lines),
fmt::arg(KTimezonedTimeListPlaceholder.c_str(), timezoned_time_lines)); fmt::arg(KTimezonedTimeListPlaceholder.c_str(), timezoned_time_lines));
label_->set_tooltip_markup(text); button_.set_tooltip_markup(text);
} }
} }

View File

@ -23,7 +23,7 @@ auto waybar::modules::Cpu::update() -> void {
auto [cpu_usage, tooltip] = getCpuUsage(); auto [cpu_usage, tooltip] = getCpuUsage();
auto [max_frequency, min_frequency, avg_frequency] = getCpuFrequency(); auto [max_frequency, min_frequency, avg_frequency] = getCpuFrequency();
if (tooltipEnabled()) { if (tooltipEnabled()) {
label_->set_tooltip_text(tooltip); button_.set_tooltip_text(tooltip);
} }
auto format = format_; auto format = format_;
auto total_usage = cpu_usage.empty() ? 0 : cpu_usage[0]; auto total_usage = cpu_usage.empty() ? 0 : cpu_usage[0];

View File

@ -134,12 +134,12 @@ auto waybar::modules::Custom::update() -> void {
label_->set_markup(str); label_->set_markup(str);
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (text_ == tooltip_) { if (text_ == tooltip_) {
if (label_->get_tooltip_markup() != str) { if (button_.get_tooltip_markup() != str) {
label_->set_tooltip_markup(str); button_.set_tooltip_markup(str);
} }
} else { } else {
if (label_->get_tooltip_markup() != tooltip_) { if (button_.get_tooltip_markup() != tooltip_) {
label_->set_tooltip_markup(tooltip_); button_.set_tooltip_markup(tooltip_);
} }
} }
} }

View File

@ -70,7 +70,7 @@ auto waybar::modules::Disk::update() -> void {
if (config_["tooltip-format"].isString()) { if (config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
label_->set_tooltip_text( button_.set_tooltip_text(
fmt::format(tooltip_format, stats.f_bavail * 100 / stats.f_blocks, fmt::arg("free", free), fmt::format(tooltip_format, stats.f_bavail * 100 / stats.f_blocks, fmt::arg("free", free),
fmt::arg("percentage_free", stats.f_bavail * 100 / stats.f_blocks), fmt::arg("percentage_free", stats.f_bavail * 100 / stats.f_blocks),
fmt::arg("used", used), fmt::arg("percentage_used", percentage_used), fmt::arg("used", used), fmt::arg("percentage_used", percentage_used),

View File

@ -62,7 +62,7 @@ auto waybar::modules::IdleInhibitor::update() -> void {
fmt::arg("icon", getIcon(0, status_text)))); fmt::arg("icon", getIcon(0, status_text))));
button_.get_style_context()->add_class(status_text); button_.get_style_context()->add_class(status_text);
if (tooltipEnabled()) { if (tooltipEnabled()) {
label_->set_tooltip_markup( button_.set_tooltip_markup(
status ? fmt::format(config_["tooltip-format-activated"].isString() status ? fmt::format(config_["tooltip-format-activated"].isString()
? config_["tooltip-format-activated"].asString() ? config_["tooltip-format-activated"].asString()
: "{status}", : "{status}",

View File

@ -123,7 +123,7 @@ auto Inhibitor::update() -> void {
button_.get_style_context()->add_class(status_text); button_.get_style_context()->add_class(status_text);
if (tooltipEnabled()) { if (tooltipEnabled()) {
label_->set_tooltip_text(status_text); button_.set_tooltip_text(status_text);
} }
return AButton::update(); return AButton::update();

View File

@ -66,7 +66,7 @@ auto waybar::modules::Memory::update() -> void {
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (config_["tooltip-format"].isString()) { if (config_["tooltip-format"].isString()) {
auto tooltip_format = config_["tooltip-format"].asString(); auto tooltip_format = config_["tooltip-format"].asString();
label_->set_tooltip_text(fmt::format( button_.set_tooltip_text(fmt::format(
tooltip_format, used_ram_percentage, fmt::arg("total", total_ram_gigabytes), tooltip_format, used_ram_percentage, fmt::arg("total", total_ram_gigabytes),
fmt::arg("swapTotal", total_swap_gigabytes), fmt::arg("swapTotal", total_swap_gigabytes),
fmt::arg("percentage", used_ram_percentage), fmt::arg("percentage", used_ram_percentage),
@ -74,7 +74,7 @@ auto waybar::modules::Memory::update() -> void {
fmt::arg("swapUsed", used_swap_gigabytes), fmt::arg("avail", available_ram_gigabytes), fmt::arg("swapUsed", used_swap_gigabytes), fmt::arg("avail", available_ram_gigabytes),
fmt::arg("swapAvail", available_swap_gigabytes))); fmt::arg("swapAvail", available_swap_gigabytes)));
} else { } else {
label_->set_tooltip_text(fmt::format("{:.{}f}GiB used", used_ram_gigabytes, 1)); button_.set_tooltip_text(fmt::format("{:.{}f}GiB used", used_ram_gigabytes, 1));
} }
} }
} else { } else {

View File

@ -101,7 +101,7 @@ void waybar::modules::MPD::setLabel() {
? config_["tooltip-format-disconnected"].asString() ? config_["tooltip-format-disconnected"].asString()
: "MPD (disconnected)"; : "MPD (disconnected)";
// Nothing to format // Nothing to format
label_->set_tooltip_text(tooltip_format); button_.set_tooltip_text(tooltip_format);
} }
return; return;
} else { } else {
@ -195,7 +195,7 @@ void waybar::modules::MPD::setLabel() {
fmt::arg("queueLength", queue_length), fmt::arg("stateIcon", stateIcon), fmt::arg("queueLength", queue_length), fmt::arg("stateIcon", stateIcon),
fmt::arg("consumeIcon", consumeIcon), fmt::arg("randomIcon", randomIcon), fmt::arg("consumeIcon", consumeIcon), fmt::arg("randomIcon", randomIcon),
fmt::arg("repeatIcon", repeatIcon), fmt::arg("singleIcon", singleIcon)); fmt::arg("repeatIcon", repeatIcon), fmt::arg("singleIcon", singleIcon));
label_->set_tooltip_text(tooltip_text); button_.set_tooltip_text(tooltip_text);
} catch (fmt::format_error const& e) { } catch (fmt::format_error const& e) {
spdlog::warn("mpd: format error (tooltip): {}", e.what()); spdlog::warn("mpd: format error (tooltip): {}", e.what());
} }

View File

@ -382,11 +382,11 @@ auto waybar::modules::Network::update() -> void {
fmt::arg("bandwidthUpBytes", pow_format(bandwidth_up / interval_.count(), "B/s")), fmt::arg("bandwidthUpBytes", pow_format(bandwidth_up / interval_.count(), "B/s")),
fmt::arg("bandwidthTotalBytes", fmt::arg("bandwidthTotalBytes",
pow_format((bandwidth_up + bandwidth_down) / interval_.count(), "B/s"))); pow_format((bandwidth_up + bandwidth_down) / interval_.count(), "B/s")));
if (label_->get_tooltip_text() != tooltip_text) { if (button_.get_tooltip_text() != tooltip_text) {
label_->set_tooltip_markup(tooltip_text); button_.set_tooltip_markup(tooltip_text);
} }
} else if (label_->get_tooltip_text() != text) { } else if (button_.get_tooltip_text() != text) {
label_->set_tooltip_markup(text); button_.set_tooltip_markup(text);
} }
} }

View File

@ -283,13 +283,13 @@ auto waybar::modules::Pulseaudio::update() -> void {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
if (!tooltip_format.empty()) { if (!tooltip_format.empty()) {
label_->set_tooltip_text(fmt::format( button_.set_tooltip_text(fmt::format(
tooltip_format, fmt::arg("desc", desc_), fmt::arg("volume", volume_), tooltip_format, fmt::arg("desc", desc_), fmt::arg("volume", volume_),
fmt::arg("format_source", format_source), fmt::arg("source_volume", source_volume_), fmt::arg("format_source", format_source), fmt::arg("source_volume", source_volume_),
fmt::arg("source_desc", source_desc_), fmt::arg("source_desc", source_desc_),
fmt::arg("icon", getIcon(volume_, getPulseIcon())))); fmt::arg("icon", getIcon(volume_, getPulseIcon()))));
} else { } else {
label_->set_tooltip_text(desc_); button_.set_tooltip_text(desc_);
} }
} }

View File

@ -25,9 +25,9 @@ auto waybar::modules::Clock::update() -> void {
if (config_["tooltip-format"].isString()) { if (config_["tooltip-format"].isString()) {
auto tooltip_format = config_["tooltip-format"].asString(); auto tooltip_format = config_["tooltip-format"].asString();
auto tooltip_text = fmt::format(tooltip_format, localtime); auto tooltip_text = fmt::format(tooltip_format, localtime);
label_->set_tooltip_text(tooltip_text); button_.set_tooltip_text(tooltip_text);
} else { } else {
label_->set_tooltip_text(text); button_.set_tooltip_text(text);
} }
} }
// Call parent update // Call parent update

View File

@ -107,9 +107,9 @@ auto Language::update() -> void {
fmt::arg("shortDescription", layout_.short_description), fmt::arg("shortDescription", layout_.short_description),
fmt::arg("long", layout_.full_name), fmt::arg("variant", layout_.variant), fmt::arg("long", layout_.full_name), fmt::arg("variant", layout_.variant),
fmt::arg("flag", layout_.country_flag()))); fmt::arg("flag", layout_.country_flag())));
label_->set_tooltip_markup(tooltip_display_layout); button_.set_tooltip_markup(tooltip_display_layout);
} else { } else {
label_->set_tooltip_markup(display_layout); button_.set_tooltip_markup(display_layout);
} }
} }

View File

@ -44,7 +44,7 @@ auto Mode::update() -> void {
} else { } else {
label_->set_markup(fmt::format(format_, mode_)); label_->set_markup(fmt::format(format_, mode_));
if (tooltipEnabled()) { if (tooltipEnabled()) {
label_->set_tooltip_text(mode_); button_.set_tooltip_text(mode_);
} }
event_box_.show(); event_box_.show();
} }

View File

@ -67,7 +67,7 @@ auto waybar::modules::Temperature::update() -> void {
if (config_["tooltip-format"].isString()) { if (config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
label_->set_tooltip_text(fmt::format(tooltip_format, fmt::arg("temperatureC", temperature_c), button_.set_tooltip_text(fmt::format(tooltip_format, fmt::arg("temperatureC", temperature_c),
fmt::arg("temperatureF", temperature_f), fmt::arg("temperatureF", temperature_f),
fmt::arg("temperatureK", temperature_k))); fmt::arg("temperatureK", temperature_k)));
} }