From 6a1713942312a9475292e8b4dde65ccb321cb9c0 Mon Sep 17 00:00:00 2001 From: Alan-Kuan Date: Fri, 21 Apr 2023 16:38:21 +0800 Subject: [PATCH 1/2] feat: tooltip for image module --- include/modules/image.hpp | 3 +++ src/modules/image.cpp | 25 ++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/modules/image.hpp b/include/modules/image.hpp index c15270de..7c0d014f 100644 --- a/include/modules/image.hpp +++ b/include/modules/image.hpp @@ -24,12 +24,15 @@ class Image : public AModule { private: void delayWorker(); void handleEvent(); + void parseOutputRaw(); Gtk::Box box_; Gtk::Image image_; std::string path_; + std::string tooltip_; int size_; int interval_; + util::command::res output_; util::SleeperThread thread_; }; diff --git a/src/modules/image.cpp b/src/modules/image.cpp index a938617a..843cd954 100644 --- a/src/modules/image.cpp +++ b/src/modules/image.cpp @@ -41,14 +41,12 @@ void waybar::modules::Image::refresh(int sig) { } auto waybar::modules::Image::update() -> void { - util::command::res output_; - Glib::RefPtr pixbuf; if (config_["path"].isString()) { path_ = config_["path"].asString(); } else if (config_["exec"].isString()) { output_ = util::command::exec(config_["exec"].asString()); - path_ = output_.out; + parseOutputRaw(); } else { path_ = ""; } @@ -58,6 +56,11 @@ auto waybar::modules::Image::update() -> void { pixbuf = {}; if (pixbuf) { + if (tooltipEnabled() && !tooltip_.empty()) { + if (box_.get_tooltip_markup() != tooltip_) { + box_.set_tooltip_markup(tooltip_); + } + } image_.set(pixbuf); image_.show(); } else { @@ -67,3 +70,19 @@ auto waybar::modules::Image::update() -> void { AModule::update(); } + +void waybar::modules::Image::parseOutputRaw() { + std::istringstream output(output_.out); + std::string line; + int i = 0; + while (getline(output, line)) { + if (i == 0) { + path_ = line; + } else if (i == 1) { + tooltip_ = line; + } else { + break; + } + i++; + } +} From 9389c8d85495c632af76862710e7d194934d544f Mon Sep 17 00:00:00 2001 From: Alan-Kuan Date: Fri, 21 Apr 2023 16:51:04 +0800 Subject: [PATCH 2/2] chore: update manual of the image modle --- man/waybar-image.5.scd | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/man/waybar-image.5.scd b/man/waybar-image.5.scd index 09e871e3..d47dba39 100644 --- a/man/waybar-image.5.scd +++ b/man/waybar-image.5.scd @@ -57,6 +57,20 @@ The *image* module displays an image from a path. typeof: double ++ Threshold to be used when scrolling. +*tooltip*: ++ + typeof: bool ++ + default: true ++ + Option to enable tooltip on hover. + +# SCRIPT OUTPUT + +Similar to the *custom* module, output values of the script is *newline* separated. +The following is the output format: + +``` +$path\\n$tooltip +``` + # EXAMPLES ```