#include "toast_queue.h" namespace roro { void ToastQueue::push(const std::string& text, NotificationLevel level, uint32_t nowMs) { current(nowMs); // retire an expired Toast first, so the new one gets its full time if (queue_.size() == capacity_) { // Keep the visible one; drop the oldest waiting. queue_.erase(queue_.begin() + (showing_ && queue_.size() > 1 ? 1 : 0)); if (!showing_) changed_ = true; } queue_.push_back({text, level, nextId_++}); if (!showing_) { showing_ = true; shownAtMs_ = nowMs; changed_ = true; } } const Toast* ToastQueue::current(uint32_t nowMs) { if (!showing_) return nullptr; // Signed: a caller's clock reading may be a few ms older than the Toast's stamp. int32_t elapsed = static_cast(nowMs - shownAtMs_); if (elapsed >= static_cast(durationMs_)) dismiss(shownAtMs_ + durationMs_); return showing_ ? &queue_.front() : nullptr; } void ToastQueue::dismiss(uint32_t nowMs) { if (!showing_) return; queue_.pop_front(); changed_ = true; showing_ = !queue_.empty(); shownAtMs_ = nowMs; } bool ToastQueue::takeChanged() { bool c = changed_; changed_ = false; return c; } } // namespace roro