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
|
|
@ -17,7 +17,7 @@ use super::window::WinitWindow;
|
|||
use super::{menu, WindowId, DEVICE_ID};
|
||||
use crate::dpi::PhysicalSize;
|
||||
use crate::event::{DeviceEvent, Event, InnerSizeWriter, StartCause, WindowEvent};
|
||||
use crate::event_loop::{ControlFlow, EventLoopWindowTarget as RootWindowTarget};
|
||||
use crate::event_loop::{ActiveEventLoop as RootWindowTarget, ControlFlow};
|
||||
use crate::window::WindowId as RootWindowId;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use once_cell::sync::Lazy;
|
|||
use std::ffi::c_uchar;
|
||||
use std::slice;
|
||||
|
||||
use super::EventLoopWindowTarget;
|
||||
use super::ActiveEventLoop;
|
||||
use crate::cursor::CursorImage;
|
||||
use crate::cursor::OnlyCursorImageBuilder;
|
||||
use crate::window::CursorIcon;
|
||||
|
|
@ -24,7 +24,7 @@ unsafe impl Send for CustomCursor {}
|
|||
unsafe impl Sync for CustomCursor {}
|
||||
|
||||
impl CustomCursor {
|
||||
pub(crate) fn build(cursor: OnlyCursorImageBuilder, _: &EventLoopWindowTarget) -> CustomCursor {
|
||||
pub(crate) fn build(cursor: OnlyCursorImageBuilder, _: &ActiveEventLoop) -> CustomCursor {
|
||||
Self(cursor_from_image(&cursor.0))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,9 +38,7 @@ use super::{
|
|||
use crate::{
|
||||
error::EventLoopError,
|
||||
event::Event,
|
||||
event_loop::{
|
||||
ControlFlow, DeviceEvents, EventLoopClosed, EventLoopWindowTarget as RootWindowTarget,
|
||||
},
|
||||
event_loop::{ActiveEventLoop as RootWindowTarget, ControlFlow, DeviceEvents, EventLoopClosed},
|
||||
platform::{macos::ActivationPolicy, pump_events::PumpStatus},
|
||||
};
|
||||
|
||||
|
|
@ -73,12 +71,12 @@ impl PanicInfo {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EventLoopWindowTarget {
|
||||
pub struct ActiveEventLoop {
|
||||
delegate: Id<ApplicationDelegate>,
|
||||
pub(super) mtm: MainThreadMarker,
|
||||
}
|
||||
|
||||
impl EventLoopWindowTarget {
|
||||
impl ActiveEventLoop {
|
||||
#[inline]
|
||||
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
|
||||
monitor::available_monitors()
|
||||
|
|
@ -134,7 +132,7 @@ impl EventLoopWindowTarget {
|
|||
}
|
||||
}
|
||||
|
||||
impl EventLoopWindowTarget {
|
||||
impl ActiveEventLoop {
|
||||
pub(crate) fn hide_application(&self) {
|
||||
NSApplication::sharedApplication(self.mtm).hide(None)
|
||||
}
|
||||
|
|
@ -252,7 +250,7 @@ impl<T> EventLoop<T> {
|
|||
sender,
|
||||
receiver: Rc::new(receiver),
|
||||
window_target: Rc::new(RootWindowTarget {
|
||||
p: EventLoopWindowTarget { delegate, mtm },
|
||||
p: ActiveEventLoop { delegate, mtm },
|
||||
_marker: PhantomData,
|
||||
}),
|
||||
panic_info,
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ use std::fmt;
|
|||
pub(crate) use self::{
|
||||
event::{physicalkey_to_scancode, scancode_to_physicalkey, KeyEventExtra},
|
||||
event_loop::{
|
||||
EventLoop, EventLoopProxy, EventLoopWindowTarget, OwnedDisplayHandle,
|
||||
ActiveEventLoop, EventLoop, EventLoopProxy, OwnedDisplayHandle,
|
||||
PlatformSpecificEventLoopAttributes,
|
||||
},
|
||||
monitor::{MonitorHandle, VideoModeHandle},
|
||||
window::WindowId,
|
||||
window_delegate::PlatformSpecificWindowBuilderAttributes,
|
||||
window_delegate::PlatformSpecificWindowAttributes,
|
||||
};
|
||||
use crate::event::DeviceId as RootDeviceId;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use icrate::Foundation::{MainThreadBound, MainThreadMarker, NSObject};
|
|||
use objc2::rc::{autoreleasepool, Id};
|
||||
use objc2::{declare_class, mutability, ClassType, DeclaredClass};
|
||||
|
||||
use super::event_loop::EventLoopWindowTarget;
|
||||
use super::event_loop::ActiveEventLoop;
|
||||
use super::window_delegate::WindowDelegate;
|
||||
use crate::error::OsError as RootOsError;
|
||||
use crate::window::WindowAttributes;
|
||||
|
|
@ -25,7 +25,7 @@ impl Drop for Window {
|
|||
|
||||
impl Window {
|
||||
pub(crate) fn new(
|
||||
window_target: &EventLoopWindowTarget,
|
||||
window_target: &ActiveEventLoop,
|
||||
attributes: WindowAttributes,
|
||||
) -> Result<Self, RootOsError> {
|
||||
let mtm = window_target.mtm;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ use crate::window::{
|
|||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PlatformSpecificWindowBuilderAttributes {
|
||||
pub struct PlatformSpecificWindowAttributes {
|
||||
pub movable_by_window_background: bool,
|
||||
pub titlebar_transparent: bool,
|
||||
pub title_hidden: bool,
|
||||
|
|
@ -58,7 +58,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
|
|||
pub option_as_alt: OptionAsAlt,
|
||||
}
|
||||
|
||||
impl Default for PlatformSpecificWindowBuilderAttributes {
|
||||
impl Default for PlatformSpecificWindowAttributes {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
@ -104,7 +104,7 @@ pub(crate) struct State {
|
|||
/// bar in exclusive fullscreen but want to restore the original options when
|
||||
/// transitioning back to borderless fullscreen.
|
||||
save_presentation_opts: Cell<Option<NSApplicationPresentationOptions>>,
|
||||
// This is set when WindowBuilder::with_fullscreen was set,
|
||||
// This is set when WindowAttributes::with_fullscreen was set,
|
||||
// see comments of `window_did_fail_to_enter_fullscreen`
|
||||
initial_fullscreen: Cell<bool>,
|
||||
/// This field tracks the current fullscreen state of the window
|
||||
|
|
@ -1492,7 +1492,7 @@ impl WindowDelegate {
|
|||
// only be used when the window is in some way representing a specific
|
||||
// file/directory. For instance, Terminal.app uses this for the CWD.
|
||||
// Anyway, that should eventually be implemented as
|
||||
// `WindowBuilderExt::with_represented_file` or something, and doesn't
|
||||
// `WindowAttributesExt::with_represented_file` or something, and doesn't
|
||||
// have anything to do with `set_window_icon`.
|
||||
// https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/WinPanel/Tasks/SettingWindowTitle.html
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue