From 84dc82e1c189b4671bc400b3e2ff511882f449af Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Mon, 21 Mar 2022 13:50:46 +0100 Subject: [PATCH] Added tooltip-padding --- include/modules/upower/upower.hpp | 1 + include/modules/upower/upower_tooltip.hpp | 3 ++- man/waybar-upower.5.scd | 5 +++++ src/modules/upower/upower.cpp | 7 ++++++- src/modules/upower/upower_tooltip.cpp | 14 ++++++++++++-- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/include/modules/upower/upower.hpp b/include/modules/upower/upower.hpp index 4ee2b1e..5b4d2f5 100644 --- a/include/modules/upower/upower.hpp +++ b/include/modules/upower/upower.hpp @@ -53,6 +53,7 @@ class UPower : public AModule { bool hideIfEmpty = true; bool tooltip_enabled = true; uint tooltip_spacing = 4; + uint tooltip_padding = 4; uint iconSize = 20; std::string format = DEFAULT_FORMAT; std::string format_alt = DEFAULT_FORMAT_ALT; diff --git a/include/modules/upower/upower_tooltip.hpp b/include/modules/upower/upower_tooltip.hpp index 9f6f16e..9d36a70 100644 --- a/include/modules/upower/upower_tooltip.hpp +++ b/include/modules/upower/upower_tooltip.hpp @@ -18,9 +18,10 @@ class UPowerTooltip : public Gtk::Window { uint iconSize; uint tooltipSpacing; + uint tooltipPadding; public: - UPowerTooltip(uint iconSize, uint tooltipSpacing); + UPowerTooltip(uint iconSize, uint tooltipSpacing, uint tooltipPadding); ~UPowerTooltip(); uint updateTooltip(Devices& devices); diff --git a/man/waybar-upower.5.scd b/man/waybar-upower.5.scd index 76af849..e6f6307 100644 --- a/man/waybar-upower.5.scd +++ b/man/waybar-upower.5.scd @@ -42,6 +42,11 @@ compatible devices in the tooltip. Defines the spacing between the tooltip device name and device battery ++ status. +*tooltip-padding*: ++ + typeof: integer ++ + default: 4 ++ + Defines the spacing between the tooltip window edge and the tooltip content. + # FORMAT REPLACEMENTS *{percentage}*: The battery capacity in percentage diff --git a/src/modules/upower/upower.cpp b/src/modules/upower/upower.cpp index 9e4b8ee..f628514 100644 --- a/src/modules/upower/upower.cpp +++ b/src/modules/upower/upower.cpp @@ -50,6 +50,11 @@ UPower::UPower(const std::string& id, const Json::Value& config) tooltip_spacing = config_["tooltip-spacing"].asUInt(); } + // Tooltip Padding + if (config_["tooltip-padding"].isUInt()) { + tooltip_padding = config_["tooltip-padding"].asUInt(); + } + // Tooltip if (config_["tooltip"].isBool()) { tooltip_enabled = config_["tooltip"].asBool(); @@ -57,7 +62,7 @@ UPower::UPower(const std::string& id, const Json::Value& config) box_.set_has_tooltip(tooltip_enabled); if (tooltip_enabled) { // Sets the window to use when showing the tooltip - upower_tooltip = new UPowerTooltip(iconSize, tooltip_spacing); + upower_tooltip = new UPowerTooltip(iconSize, tooltip_spacing, tooltip_padding); box_.set_tooltip_window(*upower_tooltip); box_.signal_query_tooltip().connect(sigc::mem_fun(*this, &UPower::show_tooltip_callback)); } diff --git a/src/modules/upower/upower_tooltip.cpp b/src/modules/upower/upower_tooltip.cpp index 7ae3e89..644b8e0 100644 --- a/src/modules/upower/upower_tooltip.cpp +++ b/src/modules/upower/upower_tooltip.cpp @@ -7,9 +7,19 @@ #include "gtkmm/label.h" namespace waybar::modules::upower { -UPowerTooltip::UPowerTooltip(uint iconSize_, uint tooltipSpacing_) - : Gtk::Window(), iconSize(iconSize_), tooltipSpacing(tooltipSpacing_) { +UPowerTooltip::UPowerTooltip(uint iconSize_, uint tooltipSpacing_, uint tooltipPadding_) + : Gtk::Window(), + iconSize(iconSize_), + tooltipSpacing(tooltipSpacing_), + tooltipPadding(tooltipPadding_) { contentBox = new Gtk::Box(Gtk::ORIENTATION_VERTICAL); + + // Sets the Tooltip Padding + contentBox->set_margin_top(tooltipPadding); + contentBox->set_margin_bottom(tooltipPadding); + contentBox->set_margin_left(tooltipPadding); + contentBox->set_margin_right(tooltipPadding); + add(*contentBox); contentBox->show(); }