2018-08-08 21:54:58 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-11-24 11:28:52 +00:00
|
|
|
#include "ALabel.hpp"
|
2023-01-23 15:42:32 +00:00
|
|
|
#include "util/date.hpp"
|
2018-12-26 10:13:36 +00:00
|
|
|
#include "util/sleeper_thread.hpp"
|
2018-08-08 21:54:58 +00:00
|
|
|
|
2023-01-23 15:42:32 +00:00
|
|
|
namespace waybar::modules {
|
2020-02-05 19:02:42 +00:00
|
|
|
|
2023-11-10 14:57:26 +00:00
|
|
|
const std::string kCldPlaceholder{"calendar"};
|
|
|
|
const std::string kTZPlaceholder{"tz_list"};
|
2024-02-04 14:41:39 +00:00
|
|
|
const std::string kOrdPlaceholder{"ordinal_date"};
|
2023-01-23 15:42:32 +00:00
|
|
|
|
2023-04-03 07:41:24 +00:00
|
|
|
enum class CldMode { MONTH, YEAR };
|
2023-11-10 14:57:26 +00:00
|
|
|
enum class WS { LEFT, RIGHT, HIDDEN };
|
2023-01-23 15:42:32 +00:00
|
|
|
|
2023-02-28 12:32:28 +00:00
|
|
|
class Clock final : public ALabel {
|
2019-04-18 15:52:00 +00:00
|
|
|
public:
|
|
|
|
Clock(const std::string&, const Json::Value&);
|
2023-03-02 13:57:07 +00:00
|
|
|
virtual ~Clock() = default;
|
|
|
|
auto update() -> void override;
|
2023-11-10 14:57:26 +00:00
|
|
|
auto doAction(const std::string&) -> void override;
|
2019-04-18 15:52:00 +00:00
|
|
|
|
|
|
|
private:
|
2024-05-17 17:17:33 +00:00
|
|
|
const std::locale m_locale_;
|
2023-11-10 14:57:26 +00:00
|
|
|
// tooltip
|
2024-05-17 17:17:33 +00:00
|
|
|
const std::string m_tlpFmt_;
|
|
|
|
std::string m_tlpText_{""}; // tooltip text to print
|
|
|
|
const Glib::RefPtr<Gtk::Label> m_tooltip_; // tooltip as a separate Gtk::Label
|
|
|
|
bool query_tlp_cb(int, int, bool, const Glib::RefPtr<Gtk::Tooltip>& tooltip);
|
2023-11-10 14:57:26 +00:00
|
|
|
// Calendar
|
|
|
|
const bool cldInTooltip_; // calendar in tooltip
|
2023-07-23 22:21:30 +00:00
|
|
|
/*
|
|
|
|
0 - calendar.format.months
|
|
|
|
1 - calendar.format.weekdays
|
|
|
|
2 - calendar.format.days
|
|
|
|
3 - calendar.format.today
|
|
|
|
4 - calendar.format.weeks
|
|
|
|
5 - tooltip-format
|
|
|
|
*/
|
2023-01-23 15:42:32 +00:00
|
|
|
std::map<int, std::string const> fmtMap_;
|
2023-11-10 14:57:26 +00:00
|
|
|
uint cldMonCols_{3}; // calendar count month columns
|
|
|
|
int cldWnLen_{3}; // calendar week number length
|
|
|
|
const int cldMonColLen_{20}; // calendar month column length
|
|
|
|
WS cldWPos_{WS::HIDDEN}; // calendar week side to print
|
|
|
|
months cldCurrShift_{0}; // calendar months shift
|
2024-03-23 13:22:19 +00:00
|
|
|
int cldShift_{1}; // calendar months shift factor
|
2023-11-10 14:57:26 +00:00
|
|
|
year_month_day cldYearShift_; // calendar Year mode. Cached ymd
|
|
|
|
std::string cldYearCached_; // calendar Year mode. Cached calendar
|
|
|
|
year_month cldMonShift_; // calendar Month mode. Cached ym
|
|
|
|
std::string cldMonCached_; // calendar Month mode. Cached calendar
|
|
|
|
day cldBaseDay_{0}; // calendar Cached day. Is used when today is changing(midnight)
|
|
|
|
std::string cldText_{""}; // calendar text to print
|
2023-01-23 15:42:32 +00:00
|
|
|
CldMode cldMode_{CldMode::MONTH};
|
2024-06-12 21:08:27 +00:00
|
|
|
auto get_calendar(const year_month_day& today, const year_month_day& ymd,
|
|
|
|
const time_zone* tz) -> const std::string;
|
2023-11-10 14:57:26 +00:00
|
|
|
|
2024-04-09 17:33:53 +00:00
|
|
|
// get local time zone
|
|
|
|
auto local_zone() -> const time_zone*;
|
|
|
|
|
2023-11-10 14:57:26 +00:00
|
|
|
// time zoned time in tooltip
|
|
|
|
const bool tzInTooltip_; // if need to print time zones text
|
|
|
|
std::vector<const time_zone*> tzList_; // time zones list
|
|
|
|
int tzCurrIdx_; // current time zone index for tzList_
|
|
|
|
std::string tzText_{""}; // time zones text to print
|
|
|
|
util::SleeperThread thread_;
|
|
|
|
|
2024-02-04 14:41:39 +00:00
|
|
|
// ordinal date in tooltip
|
|
|
|
const bool ordInTooltip_;
|
|
|
|
std::string ordText_{""};
|
|
|
|
auto get_ordinal_date(const year_month_day& today) -> std::string;
|
|
|
|
|
2023-11-10 14:57:26 +00:00
|
|
|
auto getTZtext(sys_seconds now) -> std::string;
|
|
|
|
auto first_day_of_week() -> weekday;
|
|
|
|
// Module actions
|
2023-01-23 15:42:32 +00:00
|
|
|
void cldModeSwitch();
|
2023-02-28 12:32:28 +00:00
|
|
|
void cldShift_up();
|
|
|
|
void cldShift_down();
|
2024-04-15 19:59:35 +00:00
|
|
|
void cldShift_reset();
|
2023-02-28 12:32:28 +00:00
|
|
|
void tz_up();
|
|
|
|
void tz_down();
|
2023-11-10 14:57:26 +00:00
|
|
|
// Module Action Map
|
2023-04-03 07:41:24 +00:00
|
|
|
static inline std::map<const std::string, void (waybar::modules::Clock::*const)()> actionMap_{
|
|
|
|
{"mode", &waybar::modules::Clock::cldModeSwitch},
|
|
|
|
{"shift_up", &waybar::modules::Clock::cldShift_up},
|
|
|
|
{"shift_down", &waybar::modules::Clock::cldShift_down},
|
2024-04-15 19:59:35 +00:00
|
|
|
{"shift_reset", &waybar::modules::Clock::cldShift_reset},
|
2023-04-03 07:41:24 +00:00
|
|
|
{"tz_up", &waybar::modules::Clock::tz_up},
|
|
|
|
{"tz_down", &waybar::modules::Clock::tz_down}};
|
2018-08-16 12:29:41 +00:00
|
|
|
};
|
2023-11-10 14:57:26 +00:00
|
|
|
|
2023-01-23 15:42:32 +00:00
|
|
|
} // namespace waybar::modules
|