mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat: ellipsize modules
This commit is contained in:
parent
bd5146fdcf
commit
a6980fca7f
@ -10,7 +10,7 @@ namespace waybar {
|
|||||||
class ALabel : public AModule {
|
class ALabel : public AModule {
|
||||||
public:
|
public:
|
||||||
ALabel(const Json::Value &, const std::string &, const std::string &, const std::string &format,
|
ALabel(const Json::Value &, const std::string &, const std::string &, const std::string &format,
|
||||||
uint16_t interval = 0);
|
uint16_t interval = 0, bool ellipsize = false);
|
||||||
virtual ~ALabel() = default;
|
virtual ~ALabel() = default;
|
||||||
virtual auto update() -> void;
|
virtual auto update() -> void;
|
||||||
virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0);
|
virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
namespace waybar {
|
namespace waybar {
|
||||||
|
|
||||||
ALabel::ALabel(const Json::Value& config, const std::string& name, const std::string& id,
|
ALabel::ALabel(const Json::Value& config, const std::string& name, const std::string& id,
|
||||||
const std::string& format, uint16_t interval)
|
const std::string& format, uint16_t interval, bool ellipsize)
|
||||||
: AModule(config, name, id, config["format-alt"].isString()),
|
: AModule(config, name, id, config["format-alt"].isString()),
|
||||||
format_(config_["format"].isString() ? config_["format"].asString() : format),
|
format_(config_["format"].isString() ? config_["format"].asString() : format),
|
||||||
interval_(config_["interval"] == "once"
|
interval_(config_["interval"] == "once"
|
||||||
@ -21,7 +21,7 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st
|
|||||||
if (config_["max-length"].isUInt()) {
|
if (config_["max-length"].isUInt()) {
|
||||||
label_.set_max_width_chars(config_["max-length"].asUInt());
|
label_.set_max_width_chars(config_["max-length"].asUInt());
|
||||||
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
|
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
|
||||||
} else if (label_.get_max_width_chars() == -1) {
|
} else if (ellipsize && label_.get_max_width_chars() == -1) {
|
||||||
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
|
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
src/bar.cpp
10
src/bar.cpp
@ -302,9 +302,9 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos) {
|
|||||||
|
|
||||||
auto waybar::Bar::setupWidgets() -> void {
|
auto waybar::Bar::setupWidgets() -> void {
|
||||||
window.add(box_);
|
window.add(box_);
|
||||||
box_.pack_start(left_, true, true);
|
box_.pack_start(left_, false, false);
|
||||||
box_.set_center_widget(center_);
|
box_.set_center_widget(center_);
|
||||||
box_.pack_end(right_, true, true);
|
box_.pack_end(right_, false, false);
|
||||||
|
|
||||||
// Convert to button code for every module that is used.
|
// Convert to button code for every module that is used.
|
||||||
setupAltFormatKeyForModuleList("modules-left");
|
setupAltFormatKeyForModuleList("modules-left");
|
||||||
@ -316,13 +316,13 @@ auto waybar::Bar::setupWidgets() -> void {
|
|||||||
getModules(factory, "modules-center");
|
getModules(factory, "modules-center");
|
||||||
getModules(factory, "modules-right");
|
getModules(factory, "modules-right");
|
||||||
for (auto const& module : modules_left_) {
|
for (auto const& module : modules_left_) {
|
||||||
left_.pack_start(*module, false, true, 0);
|
left_.pack_start(*module, false, false);
|
||||||
}
|
}
|
||||||
for (auto const& module : modules_center_) {
|
for (auto const& module : modules_center_) {
|
||||||
center_.pack_start(*module, true, true, 0);
|
center_.pack_start(*module, false, false);
|
||||||
}
|
}
|
||||||
std::reverse(modules_right_.begin(), modules_right_.end());
|
std::reverse(modules_right_.begin(), modules_right_.end());
|
||||||
for (auto const& module : modules_right_) {
|
for (auto const& module : modules_right_) {
|
||||||
right_.pack_end(*module, false, false, 0);
|
right_.pack_end(*module, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
Mode::Mode(const std::string& id, const Json::Value& config) : ALabel(config, "mode", id, "{}") {
|
Mode::Mode(const std::string& id, const Json::Value& config)
|
||||||
|
: ALabel(config, "mode", id, "{}", 0, true) {
|
||||||
ipc_.subscribe(R"(["mode"])");
|
ipc_.subscribe(R"(["mode"])");
|
||||||
ipc_.signal_event.connect(sigc::mem_fun(*this, &Mode::onEvent));
|
ipc_.signal_event.connect(sigc::mem_fun(*this, &Mode::onEvent));
|
||||||
// Launch worker
|
// Launch worker
|
||||||
@ -14,7 +15,7 @@ Mode::Mode(const std::string& id, const Json::Value& config) : ALabel(config, "m
|
|||||||
void Mode::onEvent(const struct Ipc::ipc_response& res) {
|
void Mode::onEvent(const struct Ipc::ipc_response& res) {
|
||||||
try {
|
try {
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
auto payload = parser_.parse(res.payload);
|
auto payload = parser_.parse(res.payload);
|
||||||
if (payload["change"] != "default") {
|
if (payload["change"] != "default") {
|
||||||
mode_ = Glib::Markup::escape_text(payload["change"].asString());
|
mode_ = Glib::Markup::escape_text(payload["change"].asString());
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||||
: ALabel(config, "window", id, "{}"), bar_(bar), windowId_(-1) {
|
: ALabel(config, "window", id, "{}", 0, true), bar_(bar), windowId_(-1) {
|
||||||
ipc_.subscribe(R"(["window","workspace"])");
|
ipc_.subscribe(R"(["window","workspace"])");
|
||||||
ipc_.signal_event.connect(sigc::mem_fun(*this, &Window::onEvent));
|
ipc_.signal_event.connect(sigc::mem_fun(*this, &Window::onEvent));
|
||||||
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Window::onCmd));
|
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Window::onCmd));
|
||||||
|
Loading…
Reference in New Issue
Block a user