greshake / i3status-rust

Very resourcefriendly and feature-rich replacement for i3status, written in pure Rust
GNU General Public License v3.0
2.81k stars 472 forks source link

Adjust phase of time block #2005

Closed skoriop closed 4 months ago

skoriop commented 4 months ago

Closes #1991

Instead of snapping to the start (:00) of the next minute, it snaps to the nearest multiple of the interval value.

For example, if the interval value is 5 and the config is initialized at :17, the sequence shown will be :17, :20, :25 and so on.

MaxVerevkin commented 4 months ago

Thanks for the patch! Currently this does not handle suspend/resume situation. I think to fix this the timer's set_missed_tick_behavior should be set to MissedTickBehavior::Skip, at which point it's better to create a timer from duration instead of config.interval.timer() shortcut.

skoriop commented 4 months ago

Good point, I've added that change now.

MaxVerevkin commented 4 months ago

Hm, that didn't work :(

skoriop commented 4 months ago

My bad, I think I misunderstood your initial comment. Of the approaches I tried now, the only one that seems to work consistently is to move the phase adjusting logic into the loop block.

MaxVerevkin commented 4 months ago

No, no, you did exactly what I though. It's strange it didn't work, not sure why. Adjusting the phase in the loop is good too. Maybe we don't even need a timer then, and can just call sleep?

skoriop commented 4 months ago

Maybe we don't even need a timer then, and can just call sleep?

I think using interval would be better here since it measures the time since the last tick while sleep can be affected by the time spent in between calls (I couldn't tell the difference when using either, but it could become significant later if more code is added)