image module reworked and added multiple image rendering capability

This commit is contained in:
VPavliashvili
2024-07-21 21:34:29 +04:00
parent cece04e02f
commit c7f499e372
3 changed files with 414 additions and 30 deletions
+62 -9
View File
@@ -14,9 +14,67 @@
namespace waybar::modules {
namespace image {
class IStrategy {
public:
virtual ~IStrategy() = default;
virtual void update() = 0;
};
class SingleImageStrategy : public IStrategy {
public:
SingleImageStrategy(const std::string &, const Json::Value &, const std::string &,
Gtk::EventBox &, bool);
~SingleImageStrategy() override = default;
void update() override;
private:
void parseOutputRaw();
util::command::res output_;
Json::Value config_;
Gtk::Image image_;
std::string path_;
std::string tooltip_;
int size_;
Gtk::Box box_;
bool hasTooltip_;
};
class MultipleImageStrategy : public IStrategy {
public:
MultipleImageStrategy(const std::string &, const Json::Value &, const std::string &,
Gtk::EventBox &);
~MultipleImageStrategy() override = default;
void update() override;
private:
struct ImageData {
std::string path;
std::string marker;
std::string tooltip;
std::string on_click;
std::shared_ptr<Gtk::Image> img;
std::shared_ptr<Gtk::Button> btn;
};
void setImagesData(const Json::Value &);
void setupAndDraw();
void resetBoxAndMemory();
void handleClick(const Glib::ustring &data);
Json::Value config_;
int size_;
Gtk::Box box_;
std::vector<ImageData> images_data_;
};
} // namespace image
class Image : public AModule {
public:
Image(const std::string&, const Json::Value&);
Image(const std::string &, const Json::Value &);
virtual ~Image() = default;
auto update() -> void override;
void refresh(int /*signal*/) override;
@@ -24,16 +82,11 @@ class Image : public AModule {
private:
void delayWorker();
void handleEvent();
void parseOutputRaw();
static std::unique_ptr<image::IStrategy> getStrategy(const std::string &, const Json::Value &,
const std::string &, Gtk::EventBox &, bool);
Gtk::Box box_;
Gtk::Image image_;
std::string path_;
std::string tooltip_;
int size_;
int interval_;
util::command::res output_;
std::unique_ptr<image::IStrategy> strategy_;
util::SleeperThread thread_;
};