mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge pull request #821 from danieldg/new-clock-features
New clock features
This commit is contained in:
commit
591eb2ea38
@ -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, bool ellipsize = false);
|
uint16_t interval = 0, bool ellipsize = false, bool enable_click = false, bool enable_scroll = 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);
|
||||||
|
@ -28,9 +28,12 @@ class Clock : public ALabel {
|
|||||||
std::locale locale_;
|
std::locale locale_;
|
||||||
const date::time_zone* time_zone_;
|
const date::time_zone* time_zone_;
|
||||||
bool fixed_time_zone_;
|
bool fixed_time_zone_;
|
||||||
|
int time_zone_idx_;
|
||||||
date::year_month_day cached_calendar_ymd_;
|
date::year_month_day cached_calendar_ymd_;
|
||||||
std::string cached_calendar_text_;
|
std::string cached_calendar_text_;
|
||||||
|
|
||||||
|
bool handleScroll(GdkEventScroll* e);
|
||||||
|
|
||||||
auto calendar_text(const waybar_time& wtime) -> std::string;
|
auto calendar_text(const waybar_time& wtime) -> std::string;
|
||||||
auto weekdays_header(const date::weekday& first_dow, std::ostream& os) -> void;
|
auto weekdays_header(const date::weekday& first_dow, std::ostream& os) -> void;
|
||||||
auto first_day_of_week() -> date::weekday;
|
auto first_day_of_week() -> date::weekday;
|
||||||
|
@ -26,11 +26,21 @@ The *clock* module displays the current date and time.
|
|||||||
default: inferred local timezone ++
|
default: inferred local timezone ++
|
||||||
The timezone to display the time in, e.g. America/New_York.
|
The timezone to display the time in, e.g. America/New_York.
|
||||||
|
|
||||||
|
*timezones*: ++
|
||||||
|
typeof: list of strings ++
|
||||||
|
A list of timezones to use for time display, changed using the scroll wheel. ++
|
||||||
|
Use "" to represent the system's local timezone. Using %Z in the format or tooltip format is useful to track which time zone is currently displayed.
|
||||||
|
|
||||||
*locale*: ++
|
*locale*: ++
|
||||||
typeof: string ++
|
typeof: string ++
|
||||||
default: inferred from current locale ++
|
default: inferred from current locale ++
|
||||||
A locale to be used to display the time. Intended to render times in custom timezones with the proper language and format.
|
A locale to be used to display the time. Intended to render times in custom timezones with the proper language and format.
|
||||||
|
|
||||||
|
*today-format*: ++
|
||||||
|
typeof: string ++
|
||||||
|
default: <b><u>{}</u></b> ++
|
||||||
|
The format of today's date in the calendar.
|
||||||
|
|
||||||
*max-length*: ++
|
*max-length*: ++
|
||||||
typeof: integer ++
|
typeof: integer ++
|
||||||
The maximum length in character the module should display.
|
The maximum length in character the module should display.
|
||||||
|
@ -5,8 +5,9 @@
|
|||||||
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, bool ellipsize)
|
const std::string& format, uint16_t interval, bool ellipsize, bool enable_click,
|
||||||
: AModule(config, name, id, config["format-alt"].isString()),
|
bool enable_scroll)
|
||||||
|
: AModule(config, name, id, config["format-alt"].isString() || enable_click, enable_scroll),
|
||||||
format_(config_["format"].isString() ? config_["format"].asString() : format),
|
format_(config_["format"].isString() ? config_["format"].asString() : format),
|
||||||
interval_(config_["interval"] == "once"
|
interval_(config_["interval"] == "once"
|
||||||
? std::chrono::seconds(100000000)
|
? std::chrono::seconds(100000000)
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
using waybar::modules::waybar_time;
|
using waybar::modules::waybar_time;
|
||||||
|
|
||||||
waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
|
waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
|
||||||
: ALabel(config, "clock", id, "{:%H:%M}", 60), fixed_time_zone_(false) {
|
: ALabel(config, "clock", id, "{:%H:%M}", 60, false, false, true), fixed_time_zone_(false) {
|
||||||
if (config_["timezone"].isString()) {
|
if (config_["timezone"].isString()) {
|
||||||
spdlog::warn("As using a timezone, some format args may be missing as the date library havn't got a release since 2018.");
|
spdlog::warn("As using a timezone, some format args may be missing as the date library havn't got a release since 2018.");
|
||||||
time_zone_ = date::locate_zone(config_["timezone"].asString());
|
time_zone_ = date::locate_zone(config_["timezone"].asString());
|
||||||
@ -71,6 +71,40 @@ auto waybar::modules::Clock::update() -> void {
|
|||||||
ALabel::update();
|
ALabel::update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool waybar::modules::Clock::handleScroll(GdkEventScroll *e) {
|
||||||
|
// defer to user commands if set
|
||||||
|
if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString()) {
|
||||||
|
return AModule::handleScroll(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dir = AModule::getScrollDir(e);
|
||||||
|
if (dir != SCROLL_DIR::UP && dir != SCROLL_DIR::DOWN) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!config_["timezones"].isArray() || config_["timezones"].empty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
auto nr_zones = config_["timezones"].size();
|
||||||
|
int new_idx = time_zone_idx_ + ((dir == SCROLL_DIR::UP) ? 1 : -1);
|
||||||
|
if (new_idx < 0) {
|
||||||
|
time_zone_idx_ = nr_zones - 1;
|
||||||
|
} else if (new_idx >= nr_zones) {
|
||||||
|
time_zone_idx_ = 0;
|
||||||
|
} else {
|
||||||
|
time_zone_idx_ = new_idx;
|
||||||
|
}
|
||||||
|
auto zone_name = config_["timezones"][time_zone_idx_];
|
||||||
|
if (!zone_name.isString() || zone_name.empty()) {
|
||||||
|
fixed_time_zone_ = false;
|
||||||
|
} else {
|
||||||
|
time_zone_ = date::locate_zone(zone_name.asString());
|
||||||
|
fixed_time_zone_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
auto waybar::modules::Clock::calendar_text(const waybar_time& wtime) -> std::string {
|
auto waybar::modules::Clock::calendar_text(const waybar_time& wtime) -> std::string {
|
||||||
const auto daypoint = date::floor<date::days>(wtime.ztime.get_local_time());
|
const auto daypoint = date::floor<date::days>(wtime.ztime.get_local_time());
|
||||||
const auto ymd = date::year_month_day(daypoint);
|
const auto ymd = date::year_month_day(daypoint);
|
||||||
@ -99,7 +133,12 @@ auto waybar::modules::Clock::calendar_text(const waybar_time& wtime) -> std::str
|
|||||||
os << '\n';
|
os << '\n';
|
||||||
}
|
}
|
||||||
if (d == curr_day) {
|
if (d == curr_day) {
|
||||||
|
if (config_["today-format"].isString()) {
|
||||||
|
auto today_format = config_["today-format"].asString();
|
||||||
|
os << fmt::format(today_format, date::format("%e", d));
|
||||||
|
} else {
|
||||||
os << "<b><u>" << date::format("%e", d) << "</u></b>";
|
os << "<b><u>" << date::format("%e", d) << "</u></b>";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
os << date::format("%e", d);
|
os << date::format("%e", d);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user