feat: tooltip for image module

This commit is contained in:
Alan-Kuan 2023-04-21 16:38:21 +08:00
parent a9a2223469
commit 6a17139423
No known key found for this signature in database
GPG Key ID: F55E82EE3BAA145F
2 changed files with 25 additions and 3 deletions

View File

@ -24,12 +24,15 @@ class Image : public AModule {
private: private:
void delayWorker(); void delayWorker();
void handleEvent(); void handleEvent();
void parseOutputRaw();
Gtk::Box box_; Gtk::Box box_;
Gtk::Image image_; Gtk::Image image_;
std::string path_; std::string path_;
std::string tooltip_;
int size_; int size_;
int interval_; int interval_;
util::command::res output_;
util::SleeperThread thread_; util::SleeperThread thread_;
}; };

View File

@ -41,14 +41,12 @@ void waybar::modules::Image::refresh(int sig) {
} }
auto waybar::modules::Image::update() -> void { auto waybar::modules::Image::update() -> void {
util::command::res output_;
Glib::RefPtr<Gdk::Pixbuf> pixbuf; Glib::RefPtr<Gdk::Pixbuf> pixbuf;
if (config_["path"].isString()) { if (config_["path"].isString()) {
path_ = config_["path"].asString(); path_ = config_["path"].asString();
} else if (config_["exec"].isString()) { } else if (config_["exec"].isString()) {
output_ = util::command::exec(config_["exec"].asString()); output_ = util::command::exec(config_["exec"].asString());
path_ = output_.out; parseOutputRaw();
} else { } else {
path_ = ""; path_ = "";
} }
@ -58,6 +56,11 @@ auto waybar::modules::Image::update() -> void {
pixbuf = {}; pixbuf = {};
if (pixbuf) { if (pixbuf) {
if (tooltipEnabled() && !tooltip_.empty()) {
if (box_.get_tooltip_markup() != tooltip_) {
box_.set_tooltip_markup(tooltip_);
}
}
image_.set(pixbuf); image_.set(pixbuf);
image_.show(); image_.show();
} else { } else {
@ -67,3 +70,19 @@ auto waybar::modules::Image::update() -> void {
AModule::update(); 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++;
}
}