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
|
|
@ -24,7 +24,7 @@ use crate::{
|
|||
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
|
||||
error,
|
||||
event::{self, Force, InnerSizeWriter, StartCause},
|
||||
event_loop::{self, ControlFlow, DeviceEvents, EventLoopWindowTarget as RootELW},
|
||||
event_loop::{self, ActiveEventLoop as RootAEL, ControlFlow, DeviceEvents},
|
||||
platform::pump_events::PumpStatus,
|
||||
window::{
|
||||
self, CursorGrabMode, ImePurpose, ResizeDirection, Theme, WindowButtons, WindowLevel,
|
||||
|
|
@ -141,7 +141,7 @@ pub struct KeyEventExtra {}
|
|||
|
||||
pub struct EventLoop<T: 'static> {
|
||||
android_app: AndroidApp,
|
||||
window_target: event_loop::EventLoopWindowTarget,
|
||||
window_target: event_loop::ActiveEventLoop,
|
||||
redraw_flag: SharedFlag,
|
||||
user_events_sender: mpsc::Sender<T>,
|
||||
user_events_receiver: PeekableReceiver<T>, //must wake looper whenever something gets sent
|
||||
|
|
@ -179,8 +179,8 @@ impl<T: 'static> EventLoop<T> {
|
|||
|
||||
Ok(Self {
|
||||
android_app: android_app.clone(),
|
||||
window_target: event_loop::EventLoopWindowTarget {
|
||||
p: EventLoopWindowTarget {
|
||||
window_target: event_loop::ActiveEventLoop {
|
||||
p: ActiveEventLoop {
|
||||
app: android_app.clone(),
|
||||
control_flow: Cell::new(ControlFlow::default()),
|
||||
exit: Cell::new(false),
|
||||
|
|
@ -205,7 +205,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
|
||||
fn single_iteration<F>(&mut self, main_event: Option<MainEvent<'_>>, callback: &mut F)
|
||||
where
|
||||
F: FnMut(event::Event<T>, &RootELW),
|
||||
F: FnMut(event::Event<T>, &RootAEL),
|
||||
{
|
||||
trace!("Mainloop iteration");
|
||||
|
||||
|
|
@ -377,7 +377,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
callback: &mut F,
|
||||
) -> InputStatus
|
||||
where
|
||||
F: FnMut(event::Event<T>, &RootELW),
|
||||
F: FnMut(event::Event<T>, &RootAEL),
|
||||
{
|
||||
let mut input_status = InputStatus::Handled;
|
||||
match event {
|
||||
|
|
@ -482,14 +482,14 @@ impl<T: 'static> EventLoop<T> {
|
|||
|
||||
pub fn run<F>(mut self, event_handler: F) -> Result<(), EventLoopError>
|
||||
where
|
||||
F: FnMut(event::Event<T>, &event_loop::EventLoopWindowTarget),
|
||||
F: FnMut(event::Event<T>, &event_loop::ActiveEventLoop),
|
||||
{
|
||||
self.run_on_demand(event_handler)
|
||||
}
|
||||
|
||||
pub fn run_on_demand<F>(&mut self, mut event_handler: F) -> Result<(), EventLoopError>
|
||||
where
|
||||
F: FnMut(event::Event<T>, &event_loop::EventLoopWindowTarget),
|
||||
F: FnMut(event::Event<T>, &event_loop::ActiveEventLoop),
|
||||
{
|
||||
loop {
|
||||
match self.pump_events(None, &mut event_handler) {
|
||||
|
|
@ -508,7 +508,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
|
||||
pub fn pump_events<F>(&mut self, timeout: Option<Duration>, mut callback: F) -> PumpStatus
|
||||
where
|
||||
F: FnMut(event::Event<T>, &RootELW),
|
||||
F: FnMut(event::Event<T>, &RootAEL),
|
||||
{
|
||||
if !self.loop_running {
|
||||
self.loop_running = true;
|
||||
|
|
@ -541,7 +541,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
|
||||
fn poll_events_with_timeout<F>(&mut self, mut timeout: Option<Duration>, mut callback: F)
|
||||
where
|
||||
F: FnMut(event::Event<T>, &RootELW),
|
||||
F: FnMut(event::Event<T>, &RootAEL),
|
||||
{
|
||||
let start = Instant::now();
|
||||
|
||||
|
|
@ -617,7 +617,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn window_target(&self) -> &event_loop::EventLoopWindowTarget {
|
||||
pub fn window_target(&self) -> &event_loop::ActiveEventLoop {
|
||||
&self.window_target
|
||||
}
|
||||
|
||||
|
|
@ -661,14 +661,14 @@ impl<T> EventLoopProxy<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct EventLoopWindowTarget {
|
||||
pub struct ActiveEventLoop {
|
||||
app: AndroidApp,
|
||||
control_flow: Cell<ControlFlow>,
|
||||
exit: Cell<bool>,
|
||||
redraw_requester: RedrawRequester,
|
||||
}
|
||||
|
||||
impl EventLoopWindowTarget {
|
||||
impl ActiveEventLoop {
|
||||
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
|
||||
Some(MonitorHandle::new(self.app.clone()))
|
||||
}
|
||||
|
|
@ -773,7 +773,7 @@ impl DeviceId {
|
|||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
pub struct PlatformSpecificWindowBuilderAttributes;
|
||||
pub struct PlatformSpecificWindowAttributes;
|
||||
|
||||
pub(crate) struct Window {
|
||||
app: AndroidApp,
|
||||
|
|
@ -782,7 +782,7 @@ pub(crate) struct Window {
|
|||
|
||||
impl Window {
|
||||
pub(crate) fn new(
|
||||
el: &EventLoopWindowTarget,
|
||||
el: &ActiveEventLoop,
|
||||
_window_attrs: window::WindowAttributes,
|
||||
) -> Result<Self, error::OsError> {
|
||||
// FIXME this ignores requested window attributes
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue