Calendar scrolling opportunity
This commit is contained in:
parent
061ad13082
commit
e9e5780aae
|
@ -25,8 +25,9 @@ class Clock : public ALabel {
|
||||||
std::locale locale_;
|
std::locale locale_;
|
||||||
std::vector<const date::time_zone*> time_zones_;
|
std::vector<const date::time_zone*> time_zones_;
|
||||||
int current_time_zone_idx_;
|
int current_time_zone_idx_;
|
||||||
date::year_month_day cached_calendar_ymd_ = date::January / 1 / 0;
|
date::year_month_day calendar_cached_ymd_{date::January / 1 / 0};
|
||||||
std::string cached_calendar_text_;
|
date::months calendar_shift_{0}, calendar_shift_init_{0};
|
||||||
|
std::string calendar_cached_text_;
|
||||||
bool is_calendar_in_tooltip_;
|
bool is_calendar_in_tooltip_;
|
||||||
bool is_timezoned_list_in_tooltip_;
|
bool is_timezoned_list_in_tooltip_;
|
||||||
|
|
||||||
|
@ -39,6 +40,5 @@ class Clock : public ALabel {
|
||||||
bool is_timezone_fixed();
|
bool is_timezone_fixed();
|
||||||
auto timezones_text(std::chrono::system_clock::time_point* now) -> std::string;
|
auto timezones_text(std::chrono::system_clock::time_point* now) -> std::string;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace modules
|
} // namespace modules
|
||||||
} // namespace waybar
|
} // namespace waybar
|
||||||
|
|
|
@ -61,6 +61,13 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_calendar_in_tooltip_) {
|
||||||
|
if (config_["on-scroll"][kCalendarPlaceholder].isInt()) {
|
||||||
|
calendar_shift_init_ =
|
||||||
|
date::months{config_["on-scroll"].get(kCalendarPlaceholder, 0).asInt()};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (config_["locale"].isString()) {
|
if (config_["locale"].isString()) {
|
||||||
locale_ = std::locale(config_["locale"].asString());
|
locale_ = std::locale(config_["locale"].asString());
|
||||||
} else {
|
} else {
|
||||||
|
@ -89,8 +96,8 @@ bool waybar::modules::Clock::is_timezone_fixed() {
|
||||||
auto waybar::modules::Clock::update() -> void {
|
auto waybar::modules::Clock::update() -> void {
|
||||||
auto time_zone = current_timezone();
|
auto time_zone = current_timezone();
|
||||||
auto now = std::chrono::system_clock::now();
|
auto now = std::chrono::system_clock::now();
|
||||||
waybar_time wtime = {locale_,
|
waybar_time wtime = {locale_, date::make_zoned(time_zone, date::floor<std::chrono::seconds>(now) +
|
||||||
date::make_zoned(time_zone, date::floor<std::chrono::seconds>(now))};
|
calendar_shift_)};
|
||||||
std::string text = "";
|
std::string text = "";
|
||||||
if (!is_timezone_fixed()) {
|
if (!is_timezone_fixed()) {
|
||||||
// As date dep is not fully compatible, prefer fmt
|
// As date dep is not fully compatible, prefer fmt
|
||||||
|
@ -104,14 +111,10 @@ auto waybar::modules::Clock::update() -> void {
|
||||||
|
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
if (config_["tooltip-format"].isString()) {
|
if (config_["tooltip-format"].isString()) {
|
||||||
std::string calendar_lines = "";
|
std::string calendar_lines{""};
|
||||||
std::string timezoned_time_lines = "";
|
std::string timezoned_time_lines{""};
|
||||||
if (is_calendar_in_tooltip_) {
|
if (is_calendar_in_tooltip_) calendar_lines = calendar_text(wtime);
|
||||||
calendar_lines = calendar_text(wtime);
|
if (is_timezoned_list_in_tooltip_) timezoned_time_lines = timezones_text(&now);
|
||||||
}
|
|
||||||
if (is_timezoned_list_in_tooltip_) {
|
|
||||||
timezoned_time_lines = timezones_text(&now);
|
|
||||||
}
|
|
||||||
auto tooltip_format = config_["tooltip-format"].asString();
|
auto tooltip_format = config_["tooltip-format"].asString();
|
||||||
text =
|
text =
|
||||||
fmt::format(tooltip_format, wtime, fmt::arg(kCalendarPlaceholder.c_str(), calendar_lines),
|
fmt::format(tooltip_format, wtime, fmt::arg(kCalendarPlaceholder.c_str(), calendar_lines),
|
||||||
|
@ -131,6 +134,15 @@ bool waybar::modules::Clock::handleScroll(GdkEventScroll* e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto dir = AModule::getScrollDir(e);
|
auto dir = AModule::getScrollDir(e);
|
||||||
|
|
||||||
|
// Shift calendar date
|
||||||
|
if (calendar_shift_init_.count() > 0) {
|
||||||
|
if (dir == SCROLL_DIR::UP)
|
||||||
|
calendar_shift_ += calendar_shift_init_;
|
||||||
|
else
|
||||||
|
calendar_shift_ -= calendar_shift_init_;
|
||||||
|
} else {
|
||||||
|
// Change time zone
|
||||||
if (dir != SCROLL_DIR::UP && dir != SCROLL_DIR::DOWN) {
|
if (dir != SCROLL_DIR::UP && dir != SCROLL_DIR::DOWN) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -146,6 +158,7 @@ bool waybar::modules::Clock::handleScroll(GdkEventScroll* e) {
|
||||||
current_time_zone_idx_ =
|
current_time_zone_idx_ =
|
||||||
current_time_zone_idx_ == 0 ? nr_zones - 1 : current_time_zone_idx_ - 1;
|
current_time_zone_idx_ == 0 ? nr_zones - 1 : current_time_zone_idx_ - 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
return true;
|
return true;
|
||||||
|
@ -153,13 +166,14 @@ bool waybar::modules::Clock::handleScroll(GdkEventScroll* e) {
|
||||||
|
|
||||||
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}};
|
||||||
if (cached_calendar_ymd_ == ymd) {
|
|
||||||
return cached_calendar_text_;
|
|
||||||
}
|
|
||||||
|
|
||||||
const date::year_month ym(ymd.year(), ymd.month());
|
if (calendar_cached_ymd_ == ymd) return calendar_cached_text_;
|
||||||
const auto curr_day = ymd.day();
|
|
||||||
|
const auto curr_day{(calendar_shift_init_.count() > 0 && calendar_shift_.count() != 0)
|
||||||
|
? date::day{0}
|
||||||
|
: ymd.day()};
|
||||||
|
const date::year_month ym{ymd.year(), ymd.month()};
|
||||||
const auto week_format{config_["format-calendar-weekdays"].isString()
|
const auto week_format{config_["format-calendar-weekdays"].isString()
|
||||||
? config_["format-calendar-weekdays"].asString()
|
? config_["format-calendar-weekdays"].asString()
|
||||||
: ""};
|
: ""};
|
||||||
|
@ -243,8 +257,8 @@ auto waybar::modules::Clock::calendar_text(const waybar_time& wtime) -> std::str
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = os.str();
|
auto result = os.str();
|
||||||
cached_calendar_ymd_ = ymd;
|
calendar_cached_ymd_ = ymd;
|
||||||
cached_calendar_text_ = result;
|
calendar_cached_text_ = result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue