This commit is contained in:
Alex 2023-04-13 16:29:34 +02:00 committed by GitHub
commit 61648c55d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -50,6 +50,7 @@ class Clock final : public ALabel {
date::months cldShift_{0}; date::months cldShift_{0};
std::string cldYearCached_{}; std::string cldYearCached_{};
std::string cldMonCached_{}; std::string cldMonCached_{};
date::day cldBaseDay_{0};
/*Calendar functions*/ /*Calendar functions*/
auto get_calendar(const date::zoned_seconds& now, const date::zoned_seconds& wtime) auto get_calendar(const date::zoned_seconds& now, const date::zoned_seconds& wtime)
-> std::string; -> std::string;

View File

@ -93,9 +93,11 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
fmtMap_.insert({1, config_[kCalendarPlaceholder]["format"]["weekdays"].asString()}); fmtMap_.insert({1, config_[kCalendarPlaceholder]["format"]["weekdays"].asString()});
else else
fmtMap_.insert({1, "{}"}); fmtMap_.insert({1, "{}"});
if (config_[kCalendarPlaceholder]["format"]["today"].isString()) if (config_[kCalendarPlaceholder]["format"]["today"].isString()) {
fmtMap_.insert({3, config_[kCalendarPlaceholder]["format"]["today"].asString()}); fmtMap_.insert({3, config_[kCalendarPlaceholder]["format"]["today"].asString()});
else cldBaseDay_ =
date::year_month_day{date::floor<date::days>(std::chrono::system_clock::now())}.day();
} else
fmtMap_.insert({3, "{}"}); fmtMap_.insert({3, "{}"});
if (config_[kCalendarPlaceholder]["mode"].isString()) { if (config_[kCalendarPlaceholder]["mode"].isString()) {
const std::string cfgMode{(config_[kCalendarPlaceholder]["mode"].isString()) const std::string cfgMode{(config_[kCalendarPlaceholder]["mode"].isString())
@ -315,6 +317,7 @@ auto waybar::modules::Clock::get_calendar(const date::zoned_seconds& now,
const auto ymd{date::year_month_day{daypoint}}; const auto ymd{date::year_month_day{daypoint}};
const auto ym{ymd.year() / ymd.month()}; const auto ym{ymd.year() / ymd.month()};
const auto y{ymd.year()}; const auto y{ymd.year()};
const auto d{ymd.day()};
const auto firstdow = first_day_of_week(); const auto firstdow = first_day_of_week();
const auto maxRows{12 / cldMonCols_}; const auto maxRows{12 / cldMonCols_};
std::ostringstream os; std::ostringstream os;
@ -325,13 +328,19 @@ auto waybar::modules::Clock::get_calendar(const date::zoned_seconds& now,
if (cldMode_ == CldMode::YEAR) { if (cldMode_ == CldMode::YEAR) {
if (y / date::month{1} / 1 == cldYearShift_) if (y / date::month{1} / 1 == cldYearShift_)
if (d == cldBaseDay_ || (uint)cldBaseDay_ == 0u)
return cldYearCached_; return cldYearCached_;
else
cldBaseDay_ = d;
else else
cldYearShift_ = y / date::month{1} / 1; cldYearShift_ = y / date::month{1} / 1;
} }
if (cldMode_ == CldMode::MONTH) { if (cldMode_ == CldMode::MONTH) {
if (ym == cldMonShift_) if (ym == cldMonShift_)
if (d == cldBaseDay_ || (uint)cldBaseDay_ == 0u)
return cldMonCached_; return cldMonCached_;
else
cldBaseDay_ = d;
else else
cldMonShift_ = ym; cldMonShift_ = ym;
} }