mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat: can disable tooltip
This commit is contained in:
parent
331b28393a
commit
83a6475510
@ -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_;
|
||||||
|
@ -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_; }
|
||||||
|
@ -148,7 +148,9 @@ auto waybar::modules::Battery::update() -> void
|
|||||||
if (status == "Unknown") {
|
if (status == "Unknown") {
|
||||||
status = getAdapterStatus(capacity);
|
status = getAdapterStatus(capacity);
|
||||||
}
|
}
|
||||||
|
if (tooltipEnabled()) {
|
||||||
label_.set_tooltip_text(status);
|
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);
|
||||||
|
@ -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();
|
||||||
|
if (tooltipEnabled()) {
|
||||||
label_.set_tooltip_text(tooltip);
|
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)));
|
||||||
}
|
}
|
||||||
|
@ -94,11 +94,13 @@ 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 (tooltipEnabled()) {
|
||||||
if (text_ == tooltip_) {
|
if (text_ == tooltip_) {
|
||||||
label_.set_tooltip_text(str);
|
label_.set_tooltip_text(str);
|
||||||
} else {
|
} else {
|
||||||
label_.set_tooltip_text(tooltip_);
|
label_.set_tooltip_text(tooltip_);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (class_ != "") {
|
if (class_ != "") {
|
||||||
if (prevclass_ != "") {
|
if (prevclass_ != "") {
|
||||||
label_.get_style_context()->remove_class(prevclass_);
|
label_.get_style_context()->remove_class(prevclass_);
|
||||||
|
@ -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);
|
||||||
|
if (tooltipEnabled()) {
|
||||||
label_.set_tooltip_text(fmt::format("{:.{}f}Gb used", used_ram_gigabytes, 1));
|
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();
|
||||||
|
@ -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()))));
|
||||||
|
if (tooltipEnabled()) {
|
||||||
label_.set_tooltip_text(desc_);
|
label_.set_tooltip_text(desc_);
|
||||||
|
}
|
||||||
if (scrolling_) {
|
if (scrolling_) {
|
||||||
scrolling_ = false;
|
scrolling_ = false;
|
||||||
}
|
}
|
||||||
|
@ -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_));
|
||||||
|
if (tooltipEnabled()) {
|
||||||
label_.set_tooltip_text(mode_);
|
label_.set_tooltip_text(mode_);
|
||||||
|
}
|
||||||
event_box_.show();
|
event_box_.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -48,8 +48,10 @@ 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_));
|
||||||
|
if (tooltipEnabled()) {
|
||||||
label_.set_tooltip_text(window_);
|
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(
|
||||||
Json::Value nodes)
|
Json::Value nodes)
|
||||||
|
Loading…
Reference in New Issue
Block a user