From e128c48573fc1cb2db3814fcdaa708e186755a59 Mon Sep 17 00:00:00 2001 From: Brent George Date: Tue, 24 Jan 2023 14:34:02 -0500 Subject: [PATCH 1/2] image module CSS fix --- include/modules/image.hpp | 4 +++- man/waybar-image.5.scd | 12 +++++------- src/factory.cpp | 5 +++-- src/modules/image.cpp | 15 ++++++++++----- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/include/modules/image.hpp b/include/modules/image.hpp index 06b61ee..b2c8946 100644 --- a/include/modules/image.hpp +++ b/include/modules/image.hpp @@ -7,6 +7,7 @@ #include #include "ALabel.hpp" +#include "gtkmm/box.h" #include "util/command.hpp" #include "util/json.hpp" #include "util/sleeper_thread.hpp" @@ -15,7 +16,7 @@ namespace waybar::modules { class Image : public AModule { public: - Image(const std::string&, const std::string&, const Json::Value&); + Image(const std::string&, const Json::Value&); auto update() -> void; void refresh(int /*signal*/); @@ -23,6 +24,7 @@ class Image : public AModule { void delayWorker(); void handleEvent(); + Gtk::Box box_; Gtk::Image image_; std::string path_; int size_; diff --git a/man/waybar-image.5.scd b/man/waybar-image.5.scd index df7086f..2d09f66 100644 --- a/man/waybar-image.5.scd +++ b/man/waybar-image.5.scd @@ -10,8 +10,6 @@ The *image* module displays an image from a path. # CONFIGURATION -Addressed by *custom/* - *path*: ++ typeof: string ++ The path to the image. @@ -58,15 +56,15 @@ Addressed by *custom/* # EXAMPLES -## Spotify: - -## mpd: - ``` -"image/album-art": { +"image#album-art": { "path": "/tmp/mpd_art", "size": 32, "interval": 5, "on-click": "mpc toggle" } ``` + +# STYLE + +- *#image* diff --git a/src/factory.cpp b/src/factory.cpp index c5b70a9..028d69e 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -97,6 +97,9 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name) const { } if (ref == "disk") { return new waybar::modules::Disk(id, config_[name]); + } + if (ref == "image") { + return new waybar::modules::Image(id, config_[name]); } #ifdef HAVE_DBUSMENU if (ref == "tray") { @@ -156,8 +159,6 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name) const { } if (ref.compare(0, 7, "custom/") == 0 && ref.size() > 7) { return new waybar::modules::Custom(ref.substr(7), id, config_[name]); - } else if (ref.compare(0, 6, "image/") == 0 && ref.size() > 6) { - return new waybar::modules::Image(ref.substr(6), id, config_[name]); } } catch (const std::exception& e) { auto err = fmt::format("Disabling module \"{}\", {}", name, e.what()); diff --git a/src/modules/image.cpp b/src/modules/image.cpp index eed19ae..769c16a 100644 --- a/src/modules/image.cpp +++ b/src/modules/image.cpp @@ -1,11 +1,16 @@ #include "modules/image.hpp" -#include - -waybar::modules::Image::Image(const std::string& name, const std::string& id, +waybar::modules::Image::Image(const std::string& id, const Json::Value& config) - : AModule(config, "image-" + name, id, "{}") { - event_box_.add(image_); + : AModule(config, "image", id), + box_(Gtk::ORIENTATION_HORIZONTAL, 0) + { + box_.pack_start(image_); + box_.set_name("image"); + if (!id.empty()) { + box_.get_style_context()->add_class(id); + } + event_box_.add(box_); dp.emit(); From c1ceb7ac42b78a2ede260e6f9ce05e536e7501a3 Mon Sep 17 00:00:00 2001 From: Brent George Date: Tue, 24 Jan 2023 14:53:49 -0500 Subject: [PATCH 2/2] fix linting issues --- src/factory.cpp | 2 +- src/modules/image.cpp | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/factory.cpp b/src/factory.cpp index 028d69e..4f196f5 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -97,7 +97,7 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name) const { } if (ref == "disk") { return new waybar::modules::Disk(id, config_[name]); - } + } if (ref == "image") { return new waybar::modules::Image(id, config_[name]); } diff --git a/src/modules/image.cpp b/src/modules/image.cpp index 769c16a..130fe79 100644 --- a/src/modules/image.cpp +++ b/src/modules/image.cpp @@ -1,10 +1,7 @@ #include "modules/image.hpp" -waybar::modules::Image::Image(const std::string& id, - const Json::Value& config) - : AModule(config, "image", id), - box_(Gtk::ORIENTATION_HORIZONTAL, 0) - { +waybar::modules::Image::Image(const std::string& id, const Json::Value& config) + : AModule(config, "image", id), box_(Gtk::ORIENTATION_HORIZONTAL, 0) { box_.pack_start(image_); box_.set_name("image"); if (!id.empty()) {