9 if (
auto* kd = std::get_if<Core::WindowEvent::KeyData>(&event.
data)) {
17 if (
auto* bd = std::get_if<Core::WindowEvent::MouseButtonData>(&event.
data)) {
25 if (
auto* pd = std::get_if<Core::WindowEvent::MousePosData>(&event.
data)) {
47 std::vector<std::function<void()>> deferred_actions;
49 for (
auto& action : deferred_actions)
88 std::deque<Core::WindowEvent> tmp;
89 std::optional<Core::WindowEvent> result;
101 if (
auto* kd = std::get_if<Core::WindowEvent::KeyData>(&ev.data)) {
102 matches = kd->key ==
static_cast<int16_t
>(*filter.
key_code);
108 if (matches && filter.
button) {
109 if (
auto* bd = std::get_if<Core::WindowEvent::MouseButtonData>(&ev.data)) {
110 matches = bd->button ==
static_cast<int>(*filter.
button);
116 if (matches && !result) {
vk::PhysicalDeviceType type
Awaiter for suspending on window input events with optional filtering.
void dispatch(const void *event)
Iterates the waiter list, passing the type-erased signal to each.
bool is_key_pressed(IO::Keys key) const
Returns true if the given key is currently held.
bool is_mouse_pressed(int button) const
Returns true if the given mouse button is currently held.
Kriya::WindowEventAwaiter await_event(Core::WindowEventType type)
Creates an awaiter that resumes on the next event matching a type.
void defer(std::function< void()> action)
Run an action after the active outermost window-event dispatch.
std::unordered_map< int16_t, bool > m_key_states
void signal(Core::WindowEvent event)
Enqueue a window event and resume matching waiters.
std::vector< std::function< void()> > m_deferred_actions
std::deque< Core::WindowEvent > m_pending_events
std::pair< double, double > get_mouse_position() const
Returns the last known cursor position in screen coordinates.
std::optional< Core::WindowEvent > pop_event(const WindowEventFilter &filter)
Removes and returns the first pending event matching the filter.
Kriya::WindowEventAwaiter next_event()
Creates an awaiter that resumes on the next event of any type.
std::unordered_map< int, bool > m_button_states
std::array< size_t, 256 > m_pending_counts
static constexpr size_t k_max_pending_events
Most events of one type held for a later awaiter before the oldest of that type is dropped.
WindowEventType
Types of window and input events.
Event data for window and input events.
std::optional< IO::Keys > key_code
std::optional< Core::WindowEventType > event_type
std::optional< IO::MouseButtons > button
Filter criteria for window input events.