mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge pull request #1911 from cdump/master
This commit is contained in:
commit
fb083f93dc
@ -66,6 +66,11 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
|
|||||||
if (config_["on-scroll"][kCalendarPlaceholder].isInt()) {
|
if (config_["on-scroll"][kCalendarPlaceholder].isInt()) {
|
||||||
calendar_shift_init_ =
|
calendar_shift_init_ =
|
||||||
date::months{config_["on-scroll"].get(kCalendarPlaceholder, 0).asInt()};
|
date::months{config_["on-scroll"].get(kCalendarPlaceholder, 0).asInt()};
|
||||||
|
event_box_.add_events(Gdk::LEAVE_NOTIFY_MASK);
|
||||||
|
event_box_.signal_leave_notify_event().connect([this](GdkEventCrossing*) {
|
||||||
|
calendar_shift_ = date::months{0};
|
||||||
|
return false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,8 +118,14 @@ 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_, date::make_zoned(time_zone, date::floor<std::chrono::seconds>(now) +
|
waybar_time wtime = {locale_,
|
||||||
calendar_shift_)};
|
date::make_zoned(time_zone, date::floor<std::chrono::seconds>(now))};
|
||||||
|
|
||||||
|
auto shifted_date = date::year_month_day{date::floor<date::days>(now)} + calendar_shift_;
|
||||||
|
auto now_shifted = date::sys_days{shifted_date} + (now - date::floor<date::days>(now));
|
||||||
|
waybar_time shifted_wtime = {
|
||||||
|
locale_, date::make_zoned(time_zone, date::floor<std::chrono::seconds>(now_shifted))};
|
||||||
|
|
||||||
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
|
||||||
@ -131,14 +142,14 @@ auto waybar::modules::Clock::update() -> void {
|
|||||||
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(shifted_wtime);
|
||||||
}
|
}
|
||||||
if (is_timezoned_list_in_tooltip_) {
|
if (is_timezoned_list_in_tooltip_) {
|
||||||
timezoned_time_lines = timezones_text(&now);
|
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, shifted_wtime,
|
||||||
fmt::format(tooltip_format, wtime, fmt::arg(kCalendarPlaceholder.c_str(), calendar_lines),
|
fmt::arg(kCalendarPlaceholder.c_str(), calendar_lines),
|
||||||
fmt::arg(KTimezonedTimeListPlaceholder.c_str(), timezoned_time_lines));
|
fmt::arg(KTimezonedTimeListPlaceholder.c_str(), timezoned_time_lines));
|
||||||
label_.set_tooltip_markup(text);
|
label_.set_tooltip_markup(text);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user