Skip to main content

freya_core/
user_event.rs

1use std::{
2    any::Any,
3    borrow::Cow,
4    fmt::Debug,
5};
6
7use bytes::Bytes;
8
9use crate::prelude::AccessibilityFocusStrategy;
10
11#[derive(Debug)]
12pub enum GlobalUserEvent {
13    /// Open a URL with the system's default browser.
14    OpenUrl(String),
15    /// Load a font at runtime.
16    LoadFont {
17        font_name: Cow<'static, str>,
18        font_data: Bytes,
19    },
20    Exit,
21    Erased(SingleThreadErasedEvent),
22}
23
24#[derive(Debug)]
25pub enum UserEvent {
26    RequestRedraw,
27    /// Focus with the given strategy.
28    FocusAccessibilityNode(AccessibilityFocusStrategy),
29    /// Set a custom scale factor.
30    SetCustomScaleFactor(f64),
31}
32
33pub struct SingleThreadErasedEvent(pub Box<dyn Any>);
34
35impl Debug for SingleThreadErasedEvent {
36    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37        f.write_str("SingleThreadErasedEvent")
38    }
39}
40
41/// # Safety
42/// The values are never sent, received or accessed by other threads other than the main thread.
43/// This is needed to send `Rc<T>` and other non-Send and non-Sync values from WindowConfig
44/// to the winit EventLoop
45unsafe impl Send for SingleThreadErasedEvent {}
46unsafe impl Sync for SingleThreadErasedEvent {}