@@ -5,14 +5,14 @@
|
|||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "ALabel.hpp"
|
#include "AIconLabel.hpp"
|
||||||
#include "util/command.hpp"
|
#include "util/command.hpp"
|
||||||
#include "util/json.hpp"
|
#include "util/json.hpp"
|
||||||
#include "util/sleeper_thread.hpp"
|
#include "util/sleeper_thread.hpp"
|
||||||
|
|
||||||
namespace waybar::modules {
|
namespace waybar::modules {
|
||||||
|
|
||||||
class Custom : public ALabel {
|
class Custom : public AIconLabel {
|
||||||
public:
|
public:
|
||||||
Custom(const std::string&, const std::string&, const Json::Value&, const std::string&);
|
Custom(const std::string&, const std::string&, const Json::Value&, const std::string&);
|
||||||
virtual ~Custom();
|
virtual ~Custom();
|
||||||
@@ -36,6 +36,9 @@ class Custom : public ALabel {
|
|||||||
std::string alt_;
|
std::string alt_;
|
||||||
std::string tooltip_;
|
std::string tooltip_;
|
||||||
std::string last_tooltip_markup_;
|
std::string last_tooltip_markup_;
|
||||||
|
std::string image_path_;
|
||||||
|
std::string image_name_;
|
||||||
|
unsigned app_icon_size_{24};
|
||||||
const bool tooltip_format_enabled_;
|
const bool tooltip_format_enabled_;
|
||||||
std::vector<std::string> class_;
|
std::vector<std::string> class_;
|
||||||
int percentage_;
|
int percentage_;
|
||||||
|
|||||||
+26
-3
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
|
waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
|
||||||
const Json::Value& config, const std::string& output_name)
|
const Json::Value& config, const std::string& output_name)
|
||||||
: ALabel(config, "custom-" + name, id, "{}"),
|
: AIconLabel(config, "custom-" + name, id, "{}"),
|
||||||
name_(name),
|
name_(name),
|
||||||
output_name_(output_name),
|
output_name_(output_name),
|
||||||
id_(id),
|
id_(id),
|
||||||
@@ -28,6 +28,15 @@ waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
|
|||||||
} else if (config_["exec"].isString()) {
|
} else if (config_["exec"].isString()) {
|
||||||
continuousWorker();
|
continuousWorker();
|
||||||
}
|
}
|
||||||
|
if (config_["image-path"].isString()) {
|
||||||
|
image_path_ = config_["image-path"].asString();
|
||||||
|
}
|
||||||
|
if (config_["image-name"].isString()) {
|
||||||
|
image_name_ = config_["image-name"].asString();
|
||||||
|
}
|
||||||
|
if (config["icon-size"].isUInt()) {
|
||||||
|
app_icon_size_ = config["icon-size"].asUInt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
waybar::modules::Custom::~Custom() {
|
waybar::modules::Custom::~Custom() {
|
||||||
@@ -184,7 +193,8 @@ auto waybar::modules::Custom::update() -> void {
|
|||||||
auto str = fmt::format(fmt::runtime(format_), fmt::arg("text", text_), fmt::arg("alt", alt_),
|
auto str = fmt::format(fmt::runtime(format_), fmt::arg("text", text_), fmt::arg("alt", alt_),
|
||||||
fmt::arg("icon", getIcon(percentage_, alt_)),
|
fmt::arg("icon", getIcon(percentage_, alt_)),
|
||||||
fmt::arg("percentage", percentage_));
|
fmt::arg("percentage", percentage_));
|
||||||
if ((config_["hide-empty-text"].asBool() && text_.empty()) || str.empty()) {
|
if ((config_["hide-empty-text"].asBool() && text_.empty()) ||
|
||||||
|
(str.empty() && image_path_.empty() && image_name_.empty())) {
|
||||||
event_box_.hide();
|
event_box_.hide();
|
||||||
} else {
|
} else {
|
||||||
label_.set_markup(str);
|
label_.set_markup(str);
|
||||||
@@ -219,7 +229,19 @@ auto waybar::modules::Custom::update() -> void {
|
|||||||
style->add_class("flat");
|
style->add_class("flat");
|
||||||
style->add_class("text-button");
|
style->add_class("text-button");
|
||||||
style->add_class(MODULE_CLASS);
|
style->add_class(MODULE_CLASS);
|
||||||
|
auto image_style = image_.get_style_context();
|
||||||
|
image_style->add_class("image-button");
|
||||||
event_box_.show();
|
event_box_.show();
|
||||||
|
if (!image_path_.empty()) {
|
||||||
|
auto pixbuf = Gdk::Pixbuf::create_from_file(image_path_, app_icon_size_, app_icon_size_);
|
||||||
|
image_.set(pixbuf);
|
||||||
|
} else if (!image_name_.empty()) {
|
||||||
|
image_.set_from_icon_name(image_name_, Gtk::ICON_SIZE_INVALID);
|
||||||
|
image_.set_pixel_size(app_icon_size_);
|
||||||
|
}
|
||||||
|
|
||||||
|
image_.set_visible(!image_name_.empty() || !image_path_.empty());
|
||||||
|
label_.set_visible(!str.empty());
|
||||||
}
|
}
|
||||||
} catch (const fmt::format_error& e) {
|
} catch (const fmt::format_error& e) {
|
||||||
if (std::strcmp(e.what(), "cannot switch from manual to automatic argument indexing") != 0)
|
if (std::strcmp(e.what(), "cannot switch from manual to automatic argument indexing") != 0)
|
||||||
@@ -231,7 +253,7 @@ auto waybar::modules::Custom::update() -> void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Call parent update
|
// Call parent update
|
||||||
ALabel::update();
|
AIconLabel::update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::modules::Custom::parseOutputRaw() {
|
void waybar::modules::Custom::parseOutputRaw() {
|
||||||
@@ -297,6 +319,7 @@ void waybar::modules::Custom::parseOutputJson() {
|
|||||||
class_.push_back(c.asString());
|
class_.push_back(c.asString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parsed["percentage"].asString().empty() && parsed["percentage"].isNumeric()) {
|
if (!parsed["percentage"].asString().empty() && parsed["percentage"].isNumeric()) {
|
||||||
percentage_ = (int)lround(parsed["percentage"].asFloat());
|
percentage_ = (int)lround(parsed["percentage"].asFloat());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user