mirror of
https://github.com/polybar/polybar.git
synced 2026-03-04 15:29:32 +00:00
fix(date): Do not trigger updates when unchanged
This commit is contained in:
@ -23,11 +23,18 @@ DateModule::DateModule(std::string name_)
|
||||
|
||||
bool DateModule::update()
|
||||
{
|
||||
if (!this->formatter->has(TAG_DATE))
|
||||
return false;
|
||||
|
||||
auto date_format = this->detailed ? this->date_detailed : this->date;
|
||||
auto time = std::time(nullptr);
|
||||
char new_str[256] = {0,};
|
||||
std::strftime(new_str, sizeof(this->date_str), date_format.c_str(), std::localtime(&time));
|
||||
|
||||
if (this->formatter->has(TAG_DATE))
|
||||
std::strftime(this->date_str, sizeof(this->date_str), date_format.c_str(), std::localtime(&time));
|
||||
if (std::strncmp(new_str, this->date_str, sizeof(new_str)) == 0)
|
||||
return false;
|
||||
else
|
||||
std::memmove(this->date_str, new_str, sizeof(new_str));
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -36,9 +43,7 @@ std::string DateModule::get_output()
|
||||
{
|
||||
if (!this->date_detailed.empty())
|
||||
this->builder->cmd(Cmd::LEFT_CLICK, EVENT_TOGGLE);
|
||||
|
||||
this->builder->node(this->Module::get_output());
|
||||
|
||||
return this->builder->flush();
|
||||
}
|
||||
|
||||
@ -53,8 +58,7 @@ bool DateModule::handle_command(std::string cmd)
|
||||
{
|
||||
if (cmd == EVENT_TOGGLE) {
|
||||
this->detailed = !this->detailed;
|
||||
this->broadcast();
|
||||
this->wakeup();
|
||||
}
|
||||
|
||||
return cmd == EVENT_TOGGLE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user