Skip to content

Commit

Permalink
Merge pull request #2128 from Alan-Kuan/image-tooltip
Browse files Browse the repository at this point in the history
Image tooltip
  • Loading branch information
Alexays authored Jul 4, 2023
2 parents 6c196b8 + 9389c8d commit 14fa9cf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
3 changes: 3 additions & 0 deletions include/modules/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
};
Expand Down
14 changes: 14 additions & 0 deletions man/waybar-image.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
25 changes: 22 additions & 3 deletions src/modules/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ void waybar::modules::Image::refresh(int sig) {
}

auto waybar::modules::Image::update() -> void {
util::command::res output_;

Glib::RefPtr<Gdk::Pixbuf> 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_ = "";
}
Expand All @@ -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 {
Expand All @@ -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++;
}
}

0 comments on commit 14fa9cf

Please sign in to comment.