Files
roro9stack/lib/ui/src/toast_queue.cpp
T
twislaandClaude Opus 5.5 a053b1a5de Fix Toast timing and alert once per shown Toast
- ToastQueue compared times unsigned: a Toast stamped a few ms after the
  main loop read the clock looked expired, so Toasts were skipped or
  shown late and bursts chained wrongly
- Notifier now beeps and flashes when each Toast appears instead of when
  the Notification arrives, so a burst alerts once per Toast

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
2026-10-02 11:09:46 +02:00

43 lines
1.2 KiB
C++

#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<int32_t>(nowMs - shownAtMs_);
if (elapsed >= static_cast<int32_t>(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