Skip to main content

freya_core/
user_event.rs

1use std::{
2    any::Any,
3    fmt::Debug,
4};
5
6use cursor_icon::CursorIcon;
7
8use crate::prelude::AccessibilityFocusStrategy;
9
10#[derive(Debug)]
11pub enum UserEvent {
12    RequestRedraw,
13
14    /// Focus with the given strategy
15    FocusAccessibilityNode(AccessibilityFocusStrategy),
16
17    /// Set a new cursor icon.
18    SetCursorIcon(CursorIcon),
19
20    /// Set a custom scale factor.
21    SetCustomScaleFactor(f64),
22
23    Erased(SingleThreadErasedEvent),
24}
25
26pub struct SingleThreadErasedEvent(pub Box<dyn Any>);
27
28impl Debug for SingleThreadErasedEvent {
29    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30        f.write_str("SingleThreadErasedEvent")
31    }
32}
33
34/// # Safety
35/// The values are never sent, received or accessed by other threads other than the main thread.
36/// This is needed to send `Rc<T>` and other non-Send and non-Sync values from WindowConfig
37/// to the winit EventLoop
38unsafe impl Send for SingleThreadErasedEvent {}
39unsafe impl Sync for SingleThreadErasedEvent {}