Deprecate window creation with stale event loop
Creating window when event loop is not running generally doesn't work, since a bunch of events and sync OS requests can't be processed. This is also an issue on e.g. Android, since window can't be created outside event loop easily. Thus deprecate the window creation when event loop is not running, as well as other resource creation to running event loop. Given that all the examples use the bad pattern of creating the window when event loop is not running and also most example existence is questionable, since they show single thing and the majority of their code is window/event loop initialization, they wore merged into a single example 'window.rs' example that showcases very simple application using winit. Fixes #3399.
This commit is contained in:
parent
19190a95a0
commit
3fb93b4f83
90 changed files with 1594 additions and 3495 deletions
|
|
@ -3,7 +3,7 @@ use std::sync::mpsc::{self, Receiver, Sender};
|
|||
|
||||
use crate::error::EventLoopError;
|
||||
use crate::event::Event;
|
||||
use crate::event_loop::EventLoopWindowTarget as RootEventLoopWindowTarget;
|
||||
use crate::event_loop::ActiveEventLoop as RootActiveEventLoop;
|
||||
|
||||
use super::{backend, device, window};
|
||||
|
||||
|
|
@ -13,10 +13,10 @@ mod state;
|
|||
mod window_target;
|
||||
|
||||
pub(crate) use proxy::EventLoopProxy;
|
||||
pub(crate) use window_target::{EventLoopWindowTarget, OwnedDisplayHandle};
|
||||
pub(crate) use window_target::{ActiveEventLoop, OwnedDisplayHandle};
|
||||
|
||||
pub struct EventLoop<T: 'static> {
|
||||
elw: RootEventLoopWindowTarget,
|
||||
elw: RootActiveEventLoop,
|
||||
user_event_sender: Sender<T>,
|
||||
user_event_receiver: Receiver<T>,
|
||||
}
|
||||
|
|
@ -27,8 +27,8 @@ pub(crate) struct PlatformSpecificEventLoopAttributes {}
|
|||
impl<T> EventLoop<T> {
|
||||
pub(crate) fn new(_: &PlatformSpecificEventLoopAttributes) -> Result<Self, EventLoopError> {
|
||||
let (user_event_sender, user_event_receiver) = mpsc::channel();
|
||||
let elw = RootEventLoopWindowTarget {
|
||||
p: EventLoopWindowTarget::new(),
|
||||
let elw = RootActiveEventLoop {
|
||||
p: ActiveEventLoop::new(),
|
||||
_marker: PhantomData,
|
||||
};
|
||||
Ok(EventLoop {
|
||||
|
|
@ -40,9 +40,9 @@ impl<T> EventLoop<T> {
|
|||
|
||||
pub fn run<F>(self, mut event_handler: F) -> !
|
||||
where
|
||||
F: FnMut(Event<T>, &RootEventLoopWindowTarget),
|
||||
F: FnMut(Event<T>, &RootActiveEventLoop),
|
||||
{
|
||||
let target = RootEventLoopWindowTarget {
|
||||
let target = RootActiveEventLoop {
|
||||
p: self.elw.p.clone(),
|
||||
_marker: PhantomData,
|
||||
};
|
||||
|
|
@ -77,9 +77,9 @@ impl<T> EventLoop<T> {
|
|||
|
||||
pub fn spawn<F>(self, mut event_handler: F)
|
||||
where
|
||||
F: 'static + FnMut(Event<T>, &RootEventLoopWindowTarget),
|
||||
F: 'static + FnMut(Event<T>, &RootActiveEventLoop),
|
||||
{
|
||||
let target = RootEventLoopWindowTarget {
|
||||
let target = RootActiveEventLoop {
|
||||
p: self.elw.p.clone(),
|
||||
_marker: PhantomData,
|
||||
};
|
||||
|
|
@ -105,7 +105,7 @@ impl<T> EventLoop<T> {
|
|||
EventLoopProxy::new(self.elw.p.waker(), self.user_event_sender.clone())
|
||||
}
|
||||
|
||||
pub fn window_target(&self) -> &RootEventLoopWindowTarget {
|
||||
pub fn window_target(&self) -> &RootActiveEventLoop {
|
||||
&self.elw
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue