-
-
Notifications
You must be signed in to change notification settings - Fork 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
74 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,51 @@ | ||
#include "ALabel.hpp" | ||
|
||
waybar::ALabel::ALabel(const Json::Value& config) | ||
: config_(config) | ||
#include <iostream> | ||
|
||
waybar::ALabel::ALabel(const Json::Value& config, const std::string format) | ||
: config_(config), | ||
format_(config_["format"] ? config_["format"].asString() : format), | ||
default_format_(format_) | ||
{ | ||
event_box_.add(label_); | ||
if (config_["max-length"]) { | ||
label_.set_max_width_chars(config_["max-length"].asUInt()); | ||
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END); | ||
} | ||
if (config_["format-alt"]) { | ||
event_box_.add_events(Gdk::BUTTON_PRESS_MASK); | ||
event_box_.signal_button_press_event() | ||
.connect(sigc::mem_fun(*this, &ALabel::handleToggle)); | ||
} | ||
} | ||
|
||
auto waybar::ALabel::update() -> void | ||
{ | ||
// Nothing here | ||
} | ||
|
||
bool waybar::ALabel::handleToggle(GdkEventButton* const& ev) | ||
{ | ||
alt = !alt; | ||
if (alt) { | ||
format_ = config_["format-alt"].asString(); | ||
} else { | ||
format_ = default_format_; | ||
} | ||
dp.emit(); | ||
return true; | ||
} | ||
|
||
std::string waybar::ALabel::getIcon(uint16_t percentage) | ||
{ | ||
if (!config_["format-icons"] || !config_["format-icons"].isArray()) { | ||
return ""; | ||
} | ||
auto size = config_["format-icons"].size(); | ||
auto idx = std::clamp(percentage / (100 / size), 0U, size - 1); | ||
return config_["format-icons"][idx].asString(); | ||
} | ||
|
||
waybar::ALabel::operator Gtk::Widget &() { | ||
return label_; | ||
return event_box_; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters