Files
roro9stack/lib/ui/src/toast_queue.h
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

42 lines
1.0 KiB
C++

#pragma once
#include <cstdint>
#include <deque>
#include <string>
#include "event.h"
namespace roro {
struct Toast {
std::string text;
NotificationLevel level;
uint32_t id; // unique per push, to tell two identical Toasts apart
};
// Notifications waiting to be shown as Toasts, one at a time, each for the same duration.
class ToastQueue {
public:
explicit ToastQueue(uint32_t durationMs, size_t capacity = 4) : durationMs_(durationMs), capacity_(capacity) {}
void push(const std::string& text, NotificationLevel level, uint32_t nowMs);
// The Toast to show now, or nullptr. Advances the queue as Toasts expire.
const Toast* current(uint32_t nowMs);
void dismiss(uint32_t nowMs);
// True once after the visible Toast changed (appeared, switched or disappeared).
bool takeChanged();
private:
uint32_t durationMs_;
size_t capacity_;
std::deque<Toast> queue_;
bool showing_ = false;
uint32_t shownAtMs_ = 0;
bool changed_ = false;
uint32_t nextId_ = 1;
};
} // namespace roro