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:
Kirill Chibisov 2024-01-31 17:29:59 +04:00
parent 19190a95a0
commit 3fb93b4f83
90 changed files with 1594 additions and 3495 deletions

View file

@ -5,7 +5,7 @@ use std::{error::Error, hash::Hash};
use cursor_icon::CursorIcon;
use crate::event_loop::EventLoopWindowTarget;
use crate::event_loop::ActiveEventLoop;
use crate::platform_impl::{self, PlatformCustomCursor, PlatformCustomCursorBuilder};
/// The maximum width and height for a cursor when using [`CustomCursor::from_rgba`].
@ -49,13 +49,10 @@ impl From<CustomCursor> for Cursor {
/// # Example
///
/// ```no_run
/// use winit::{
/// event::{Event, WindowEvent},
/// event_loop::{ControlFlow, EventLoop},
/// window::{CustomCursor, Window},
/// };
///
/// let mut event_loop = EventLoop::new().unwrap();
/// # use winit::event_loop::ActiveEventLoop;
/// # use winit::window::Window;
/// # fn scope(event_loop: &ActiveEventLoop, window: &Window) {
/// use winit::window::CustomCursor;
///
/// let w = 10;
/// let h = 10;
@ -72,8 +69,8 @@ impl From<CustomCursor> for Cursor {
///
/// let custom_cursor = builder.build(&event_loop);
///
/// let window = Window::new(&event_loop).unwrap();
/// window.set_cursor(custom_cursor.clone());
/// # }
/// ```
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct CustomCursor {
@ -113,7 +110,7 @@ pub struct CustomCursorBuilder {
}
impl CustomCursorBuilder {
pub fn build(self, window_target: &EventLoopWindowTarget) -> CustomCursor {
pub fn build(self, window_target: &ActiveEventLoop) -> CustomCursor {
CustomCursor {
inner: PlatformCustomCursor::build(self.inner, &window_target.p),
}
@ -217,7 +214,7 @@ impl Eq for OnlyCursorImage {}
impl OnlyCursorImage {
pub(crate) fn build(
builder: OnlyCursorImageBuilder,
_: &platform_impl::EventLoopWindowTarget,
_: &platform_impl::ActiveEventLoop,
) -> Self {
Self(Arc::new(builder.0))
}
@ -298,7 +295,7 @@ impl NoCustomCursor {
Ok(Self)
}
fn build(self, _: &platform_impl::EventLoopWindowTarget) -> NoCustomCursor {
fn build(self, _: &platform_impl::ActiveEventLoop) -> NoCustomCursor {
self
}
}

View file

@ -8,7 +8,6 @@
//! See the root-level documentation for information on how to create and use an event loop to
//! handle events.
use std::marker::PhantomData;
use std::ops::Deref;
#[cfg(any(x11_platform, wayland_platform))]
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
@ -19,7 +18,8 @@ use std::time::{Duration, Instant};
#[cfg(web_platform)]
use web_time::{Duration, Instant};
use crate::error::EventLoopError;
use crate::error::{EventLoopError, OsError};
use crate::window::{Window, WindowAttributes};
use crate::{event::Event, monitor::MonitorHandle, platform_impl};
/// Provides a way to retrieve events from the system and from the windows that were registered to
@ -45,11 +45,9 @@ pub struct EventLoop<T: 'static> {
/// Target that associates windows with an [`EventLoop`].
///
/// This type exists to allow you to create new windows while Winit executes
/// your callback. [`EventLoop`] will coerce into this type (`impl<T> Deref for
/// EventLoop<T>`), so functions that take this as a parameter can also take
/// `&EventLoop`.
pub struct EventLoopWindowTarget {
pub(crate) p: platform_impl::EventLoopWindowTarget,
/// your callback.
pub struct ActiveEventLoop {
pub(crate) p: platform_impl::ActiveEventLoop,
pub(crate) _marker: PhantomData<*mut ()>, // Not Send nor Sync
}
@ -135,13 +133,13 @@ impl<T> fmt::Debug for EventLoop<T> {
}
}
impl fmt::Debug for EventLoopWindowTarget {
impl fmt::Debug for ActiveEventLoop {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("EventLoopWindowTarget { .. }")
f.pad("ActiveEventLoop { .. }")
}
}
/// Set through [`EventLoopWindowTarget::set_control_flow()`].
/// Set through [`ActiveEventLoop::set_control_flow()`].
///
/// Indicates the desired behavior of the event loop after [`Event::AboutToWait`] is emitted.
///
@ -241,14 +239,14 @@ impl<T> EventLoop<T> {
///
/// This function won't be available with `target_feature = "exception-handling"`.
///
/// [`set_control_flow()`]: EventLoopWindowTarget::set_control_flow()
/// [`set_control_flow()`]: ActiveEventLoop::set_control_flow()
/// [`run()`]: Self::run()
/// [^1]: `EventLoopExtWebSys::spawn()` is only available on Web.
#[inline]
#[cfg(not(all(web_platform, target_feature = "exception-handling")))]
pub fn run<F>(self, event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<T>, &EventLoopWindowTarget),
F: FnMut(Event<T>, &ActiveEventLoop),
{
self.event_loop.run(event_handler)
}
@ -260,12 +258,53 @@ impl<T> EventLoop<T> {
event_loop_proxy: self.event_loop.create_proxy(),
}
}
/// Gets a persistent reference to the underlying platform display.
///
/// See the [`OwnedDisplayHandle`] type for more information.
pub fn owned_display_handle(&self) -> OwnedDisplayHandle {
OwnedDisplayHandle {
platform: self.event_loop.window_target().p.owned_display_handle(),
}
}
/// Change if or when [`DeviceEvent`]s are captured.
///
/// See [`ActiveEventLoop::listen_device_events`] for details.
///
/// [`DeviceEvent`]: crate::event::DeviceEvent
pub fn listen_device_events(&self, allowed: DeviceEvents) {
self.event_loop
.window_target()
.p
.listen_device_events(allowed);
}
/// Sets the [`ControlFlow`].
pub fn set_control_flow(&self, control_flow: ControlFlow) {
self.event_loop
.window_target()
.p
.set_control_flow(control_flow)
}
/// Create a window.
///
/// Creating window without event loop running often leads to improper window creation;
/// use [`ActiveEventLoop::create_window`] instead.
#[deprecated = "use `ActiveEventLoop::create_window` instead"]
#[inline]
pub fn create_window(&self, window_attributes: WindowAttributes) -> Result<Window, OsError> {
let window =
platform_impl::Window::new(&self.event_loop.window_target().p, window_attributes)?;
Ok(Window { window })
}
}
#[cfg(feature = "rwh_06")]
impl<T> rwh_06::HasDisplayHandle for EventLoop<T> {
fn display_handle(&self) -> Result<rwh_06::DisplayHandle<'_>, rwh_06::HandleError> {
rwh_06::HasDisplayHandle::display_handle(&**self)
rwh_06::HasDisplayHandle::display_handle(self.event_loop.window_target())
}
}
@ -273,7 +312,7 @@ impl<T> rwh_06::HasDisplayHandle for EventLoop<T> {
unsafe impl<T> rwh_05::HasRawDisplayHandle for EventLoop<T> {
/// Returns a [`rwh_05::RawDisplayHandle`] for the event loop.
fn raw_display_handle(&self) -> rwh_05::RawDisplayHandle {
rwh_05::HasRawDisplayHandle::raw_display_handle(&**self)
rwh_05::HasRawDisplayHandle::raw_display_handle(self.event_loop.window_target())
}
}
@ -305,14 +344,21 @@ impl<T> AsRawFd for EventLoop<T> {
}
}
impl<T> Deref for EventLoop<T> {
type Target = EventLoopWindowTarget;
fn deref(&self) -> &EventLoopWindowTarget {
self.event_loop.window_target()
impl ActiveEventLoop {
/// Create the window.
///
/// Possible causes of error include denied permission, incompatible system, and lack of memory.
///
/// ## Platform-specific
///
/// - **Web:** The window is created but not inserted into the web page automatically. Please
/// see the web platform module for more information.
#[inline]
pub fn create_window(&self, window_attributes: WindowAttributes) -> Result<Window, OsError> {
let window = platform_impl::Window::new(&self.p, window_attributes)?;
Ok(Window { window })
}
}
impl EventLoopWindowTarget {
/// Returns the list of all the monitors available on the system.
#[inline]
pub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle> {
@ -387,7 +433,7 @@ impl EventLoopWindowTarget {
}
#[cfg(feature = "rwh_06")]
impl rwh_06::HasDisplayHandle for EventLoopWindowTarget {
impl rwh_06::HasDisplayHandle for ActiveEventLoop {
fn display_handle(&self) -> Result<rwh_06::DisplayHandle<'_>, rwh_06::HandleError> {
let raw = self.p.raw_display_handle_rwh_06()?;
// SAFETY: The display will never be deallocated while the event loop is alive.
@ -396,7 +442,7 @@ impl rwh_06::HasDisplayHandle for EventLoopWindowTarget {
}
#[cfg(feature = "rwh_05")]
unsafe impl rwh_05::HasRawDisplayHandle for EventLoopWindowTarget {
unsafe impl rwh_05::HasRawDisplayHandle for ActiveEventLoop {
/// Returns a [`rwh_05::RawDisplayHandle`] for the event loop.
fn raw_display_handle(&self) -> rwh_05::RawDisplayHandle {
self.p.raw_display_handle_rwh_05()
@ -407,7 +453,7 @@ unsafe impl rwh_05::HasRawDisplayHandle for EventLoopWindowTarget {
///
/// The purpose of this type is to provide a cheaply clonable handle to the underlying
/// display handle. This is often used by graphics APIs to connect to the underlying APIs.
/// It is difficult to keep a handle to the [`EventLoop`] type or the [`EventLoopWindowTarget`]
/// It is difficult to keep a handle to the [`EventLoop`] type or the [`ActiveEventLoop`]
/// type. In contrast, this type involves no lifetimes and can be persisted for as long as
/// needed.
///

View file

@ -2,22 +2,15 @@
//!
//! # Building windows
//!
//! Before you can build a [`Window`], you first need to build an [`EventLoop`]. This is done with the
//! [`EventLoop::new()`] function.
//! Before you can create a [`Window`], you first need to build an [`EventLoop`]. This is done with
//! the [`EventLoop::new()`] function.
//!
//! ```no_run
//! use winit::event_loop::EventLoop;
//! let event_loop = EventLoop::new().unwrap();
//! ```
//!
//! Once this is done, there are two ways to create a [`Window`]:
//!
//! - Calling [`Window::new(&event_loop)`][window_new].
//! - Calling [`let builder = Window::builder()`][window_builder_new] then [`builder.build(&event_loop)`][window_builder_build].
//!
//! The first method is the simplest and will give you default values for everything. The second
//! method allows you to customize the way your [`Window`] will look and behave by modifying the
//! fields of the [`WindowBuilder`] object before you create the [`Window`].
//! Then you create a [`Window`] with [`create_window`].
//!
//! # Event handling
//!
@ -67,7 +60,6 @@
//! };
//!
//! let event_loop = EventLoop::new().unwrap();
//! let window = Window::builder().build(&event_loop).unwrap();
//!
//! // ControlFlow::Poll continuously runs the event loop, even if the OS hasn't
//! // dispatched any events. This is ideal for games and similar applications.
@ -78,14 +70,19 @@
//! // input, and uses significantly less power/CPU time than ControlFlow::Poll.
//! event_loop.set_control_flow(ControlFlow::Wait);
//!
//! event_loop.run(move |event, elwt| {
//! let mut window = None;
//!
//! event_loop.run(move |event, event_loop| {
//! match event {
//! Event::Resumed => {
//! window = Some(event_loop.create_window(Window::default_attributes()).unwrap());
//! }
//! Event::WindowEvent {
//! event: WindowEvent::CloseRequested,
//! ..
//! } => {
//! println!("The close button was pressed; stopping");
//! elwt.exit();
//! event_loop.exit();
//! },
//! Event::AboutToWait => {
//! // Application update code.
@ -95,7 +92,7 @@
//! // You only need to call this if you've determined that you need to redraw in
//! // applications which do not always need to. Applications that redraw continuously
//! // can render here instead.
//! window.request_redraw();
//! window.as_ref().unwrap().request_redraw();
//! },
//! Event::WindowEvent {
//! event: WindowEvent::RedrawRequested,
@ -126,19 +123,18 @@
//! Note that many platforms will display garbage data in the window's client area if the
//! application doesn't render anything to the window by the time the desktop compositor is ready to
//! display the window to the user. If you notice this happening, you should create the window with
//! [`visible` set to `false`](crate::window::WindowBuilder::with_visible) and explicitly make the
//! [`visible` set to `false`](crate::window::WindowAttributes::with_visible) and explicitly make the
//! window visible only once you're ready to render into it.
//!
//! [`EventLoop`]: event_loop::EventLoop
//! [`EventLoop::new()`]: event_loop::EventLoop::new
//! [`EventLoop::run()`]: event_loop::EventLoop::run
//! [`exit()`]: event_loop::EventLoopWindowTarget::exit
//! [`exit()`]: event_loop::ActiveEventLoop::exit
//! [`Window`]: window::Window
//! [`WindowId`]: window::WindowId
//! [`WindowBuilder`]: window::WindowBuilder
//! [`WindowAttributes`]: window::WindowAttributes
//! [window_new]: window::Window::new
//! [window_builder_new]: window::Window::builder
//! [window_builder_build]: window::WindowBuilder::build
//! [`create_window`]: event_loop::ActiveEventLoop::create_window
//! [`Window::id()`]: window::Window::id
//! [`WindowEvent`]: event::WindowEvent
//! [`DeviceEvent`]: event::DeviceEvent

View file

@ -3,7 +3,7 @@
//! If you want to get basic information about a monitor, you can use the
//! [`MonitorHandle`] type. This is retrieved from one of the following
//! methods, which return an iterator of [`MonitorHandle`]:
//! - [`EventLoopWindowTarget::available_monitors`](crate::event_loop::EventLoopWindowTarget::available_monitors).
//! - [`ActiveEventLoop::available_monitors`](crate::event_loop::ActiveEventLoop::available_monitors).
//! - [`Window::available_monitors`](crate::window::Window::available_monitors).
use crate::{
dpi::{PhysicalPosition, PhysicalSize},

View file

@ -1,6 +1,6 @@
use crate::{
event_loop::{EventLoop, EventLoopBuilder, EventLoopWindowTarget},
window::{Window, WindowBuilder},
event_loop::{ActiveEventLoop, EventLoop, EventLoopBuilder},
window::{Window, WindowAttributes},
};
use self::activity::{AndroidApp, ConfigurationRef, Rect};
@ -10,8 +10,8 @@ pub trait EventLoopExtAndroid {}
impl<T> EventLoopExtAndroid for EventLoop<T> {}
/// Additional methods on [`EventLoopWindowTarget`] that are specific to Android.
pub trait EventLoopWindowTargetExtAndroid {}
/// Additional methods on [`ActiveEventLoop`] that are specific to Android.
pub trait ActiveEventLoopExtAndroid {}
/// Additional methods on [`Window`] that are specific to Android.
pub trait WindowExtAndroid {
@ -30,12 +30,12 @@ impl WindowExtAndroid for Window {
}
}
impl EventLoopWindowTargetExtAndroid for EventLoopWindowTarget {}
impl ActiveEventLoopExtAndroid for ActiveEventLoop {}
/// Additional methods on [`WindowBuilder`] that are specific to Android.
pub trait WindowBuilderExtAndroid {}
/// Additional methods on [`WindowAttributes`] that are specific to Android.
pub trait WindowAttributesExtAndroid {}
impl WindowBuilderExtAndroid for WindowBuilder {}
impl WindowAttributesExtAndroid for WindowAttributes {}
pub trait EventLoopBuilderExtAndroid {
/// Associates the `AndroidApp` that was passed to `android_main()` with the event loop

View file

@ -3,7 +3,7 @@ use std::os::raw::c_void;
use crate::{
event_loop::EventLoop,
monitor::{MonitorHandle, VideoModeHandle},
window::{Window, WindowBuilder},
window::{Window, WindowAttributes},
};
/// Additional methods on [`EventLoop`] that are specific to iOS.
@ -159,8 +159,8 @@ impl WindowExtIOS for Window {
}
}
/// Additional methods on [`WindowBuilder`] that are specific to iOS.
pub trait WindowBuilderExtIOS {
/// Additional methods on [`WindowAttributes`] that are specific to iOS.
pub trait WindowAttributesExtIOS {
/// Sets the [`contentScaleFactor`] of the underlying [`UIWindow`] to `scale_factor`.
///
/// The default value is device dependent, and it's recommended GLES or Metal applications set
@ -214,42 +214,41 @@ pub trait WindowBuilderExtIOS {
fn with_preferred_status_bar_style(self, status_bar_style: StatusBarStyle) -> Self;
}
impl WindowBuilderExtIOS for WindowBuilder {
impl WindowAttributesExtIOS for WindowAttributes {
#[inline]
fn with_scale_factor(mut self, scale_factor: f64) -> Self {
self.window.platform_specific.scale_factor = Some(scale_factor);
self.platform_specific.scale_factor = Some(scale_factor);
self
}
#[inline]
fn with_valid_orientations(mut self, valid_orientations: ValidOrientations) -> Self {
self.window.platform_specific.valid_orientations = valid_orientations;
self.platform_specific.valid_orientations = valid_orientations;
self
}
#[inline]
fn with_prefers_home_indicator_hidden(mut self, hidden: bool) -> Self {
self.window.platform_specific.prefers_home_indicator_hidden = hidden;
self.platform_specific.prefers_home_indicator_hidden = hidden;
self
}
#[inline]
fn with_preferred_screen_edges_deferring_system_gestures(mut self, edges: ScreenEdge) -> Self {
self.window
.platform_specific
self.platform_specific
.preferred_screen_edges_deferring_system_gestures = edges;
self
}
#[inline]
fn with_prefers_status_bar_hidden(mut self, hidden: bool) -> Self {
self.window.platform_specific.prefers_status_bar_hidden = hidden;
self.platform_specific.prefers_status_bar_hidden = hidden;
self
}
#[inline]
fn with_preferred_status_bar_style(mut self, status_bar_style: StatusBarStyle) -> Self {
self.window.platform_specific.preferred_status_bar_style = status_bar_style;
self.platform_specific.preferred_status_bar_style = status_bar_style;
self
}
}

View file

@ -4,9 +4,9 @@ use std::os::raw::c_void;
use serde::{Deserialize, Serialize};
use crate::{
event_loop::{EventLoopBuilder, EventLoopWindowTarget},
event_loop::{ActiveEventLoop, EventLoopBuilder},
monitor::MonitorHandle,
window::{Window, WindowBuilder},
window::{Window, WindowAttributes},
};
/// Additional methods on [`Window`] that are specific to MacOS.
@ -174,15 +174,15 @@ pub enum ActivationPolicy {
Prohibited,
}
/// Additional methods on [`WindowBuilder`] that are specific to MacOS.
/// Additional methods on [`WindowAttributes`] that are specific to MacOS.
///
/// **Note:** Properties dealing with the titlebar will be overwritten by the [`WindowBuilder::with_decorations`] method:
/// **Note:** Properties dealing with the titlebar will be overwritten by the [`WindowAttributes::with_decorations`] method:
/// - `with_titlebar_transparent`
/// - `with_title_hidden`
/// - `with_titlebar_hidden`
/// - `with_titlebar_buttons_hidden`
/// - `with_fullsize_content_view`
pub trait WindowBuilderExtMacOS {
pub trait WindowAttributesExtMacOS {
/// Enables click-and-drag behavior for the entire window, not just the titlebar.
fn with_movable_by_window_background(self, movable_by_window_background: bool) -> Self;
/// Makes the titlebar transparent and allows the content to appear behind it.
@ -209,65 +209,64 @@ pub trait WindowBuilderExtMacOS {
fn with_option_as_alt(self, option_as_alt: OptionAsAlt) -> Self;
}
impl WindowBuilderExtMacOS for WindowBuilder {
impl WindowAttributesExtMacOS for WindowAttributes {
#[inline]
fn with_movable_by_window_background(mut self, movable_by_window_background: bool) -> Self {
self.window.platform_specific.movable_by_window_background = movable_by_window_background;
self.platform_specific.movable_by_window_background = movable_by_window_background;
self
}
#[inline]
fn with_titlebar_transparent(mut self, titlebar_transparent: bool) -> Self {
self.window.platform_specific.titlebar_transparent = titlebar_transparent;
self.platform_specific.titlebar_transparent = titlebar_transparent;
self
}
#[inline]
fn with_titlebar_hidden(mut self, titlebar_hidden: bool) -> Self {
self.window.platform_specific.titlebar_hidden = titlebar_hidden;
self.platform_specific.titlebar_hidden = titlebar_hidden;
self
}
#[inline]
fn with_titlebar_buttons_hidden(mut self, titlebar_buttons_hidden: bool) -> Self {
self.window.platform_specific.titlebar_buttons_hidden = titlebar_buttons_hidden;
self.platform_specific.titlebar_buttons_hidden = titlebar_buttons_hidden;
self
}
#[inline]
fn with_title_hidden(mut self, title_hidden: bool) -> Self {
self.window.platform_specific.title_hidden = title_hidden;
self.platform_specific.title_hidden = title_hidden;
self
}
#[inline]
fn with_fullsize_content_view(mut self, fullsize_content_view: bool) -> Self {
self.window.platform_specific.fullsize_content_view = fullsize_content_view;
self.platform_specific.fullsize_content_view = fullsize_content_view;
self
}
#[inline]
fn with_disallow_hidpi(mut self, disallow_hidpi: bool) -> Self {
self.window.platform_specific.disallow_hidpi = disallow_hidpi;
self.platform_specific.disallow_hidpi = disallow_hidpi;
self
}
#[inline]
fn with_has_shadow(mut self, has_shadow: bool) -> Self {
self.window.platform_specific.has_shadow = has_shadow;
self.platform_specific.has_shadow = has_shadow;
self
}
#[inline]
fn with_accepts_first_mouse(mut self, accepts_first_mouse: bool) -> Self {
self.window.platform_specific.accepts_first_mouse = accepts_first_mouse;
self.platform_specific.accepts_first_mouse = accepts_first_mouse;
self
}
#[inline]
fn with_tabbing_identifier(mut self, tabbing_identifier: &str) -> Self {
self.window
.platform_specific
self.platform_specific
.tabbing_identifier
.replace(tabbing_identifier.to_string());
self
@ -275,7 +274,7 @@ impl WindowBuilderExtMacOS for WindowBuilder {
#[inline]
fn with_option_as_alt(mut self, option_as_alt: OptionAsAlt) -> Self {
self.window.platform_specific.option_as_alt = option_as_alt;
self.platform_specific.option_as_alt = option_as_alt;
self
}
}
@ -375,8 +374,8 @@ impl MonitorHandleExtMacOS for MonitorHandle {
}
}
/// Additional methods on [`EventLoopWindowTarget`] that are specific to macOS.
pub trait EventLoopWindowTargetExtMacOS {
/// Additional methods on [`ActiveEventLoop`] that are specific to macOS.
pub trait ActiveEventLoopExtMacOS {
/// Hide the entire application. In most applications this is typically triggered with Command-H.
fn hide_application(&self);
/// Hide the other applications. In most applications this is typically triggered with Command+Option-H.
@ -389,7 +388,7 @@ pub trait EventLoopWindowTargetExtMacOS {
fn allows_automatic_window_tabbing(&self) -> bool;
}
impl EventLoopWindowTargetExtMacOS for EventLoopWindowTarget {
impl ActiveEventLoopExtMacOS for ActiveEventLoop {
fn hide_application(&self) {
self.p.hide_application()
}

View file

@ -2,7 +2,7 @@ use std::time::Duration;
use crate::{
event::Event,
event_loop::{EventLoop, EventLoopWindowTarget},
event_loop::{ActiveEventLoop, EventLoop},
};
/// The return status for `pump_events`
@ -32,68 +32,6 @@ pub trait EventLoopExtPumpEvents {
/// Passing a `timeout` of `None` means that it may wait indefinitely for new
/// events before returning control back to the external loop.
///
/// ## Example
///
/// ```rust,no_run
/// # // Copied from examples/window_pump_events.rs
/// # #[cfg(any(
/// # windows_platform,
/// # macos_platform,
/// # x11_platform,
/// # wayland_platform,
/// # android_platform,
/// # ))]
/// fn main() -> std::process::ExitCode {
/// # use std::{process::ExitCode, thread::sleep, time::Duration};
/// #
/// # use simple_logger::SimpleLogger;
/// # use winit::{
/// # event::{Event, WindowEvent},
/// # event_loop::EventLoop,
/// # platform::pump_events::{EventLoopExtPumpEvents, PumpStatus},
/// # window::Window,
/// # };
/// let mut event_loop = EventLoop::new().unwrap();
/// #
/// # SimpleLogger::new().init().unwrap();
/// let window = Window::builder()
/// .with_title("A fantastic window!")
/// .build(&event_loop)
/// .unwrap();
///
/// 'main: loop {
/// let timeout = Some(Duration::ZERO);
/// let status = event_loop.pump_events(timeout, |event, elwt| {
/// # if let Event::WindowEvent { event, .. } = &event {
/// # // Print only Window events to reduce noise
/// # println!("{event:?}");
/// # }
/// #
/// match event {
/// Event::WindowEvent {
/// event: WindowEvent::CloseRequested,
/// window_id,
/// } if window_id == window.id() => elwt.exit(),
/// Event::AboutToWait => {
/// window.request_redraw();
/// }
/// _ => (),
/// }
/// });
/// if let PumpStatus::Exit(exit_code) = status {
/// break 'main ExitCode::from(exit_code as u8);
/// }
///
/// // Sleep for 1/60 second to simulate application work
/// //
/// // Since `pump_events` doesn't block it will be important to
/// // throttle the loop in the app somehow.
/// println!("Update()");
/// sleep(Duration::from_millis(16));
/// }
/// }
/// ```
///
/// **Note:** This is not a portable API, and its usage involves a number of
/// caveats and trade offs that should be considered before using this API!
///
@ -137,12 +75,14 @@ pub trait EventLoopExtPumpEvents {
/// other lifecycle events occur while the event is buffered.
///
/// ## Supported Platforms
///
/// - Windows
/// - Linux
/// - MacOS
/// - Android
///
/// ## Unsupported Platforms
///
/// - **Web:** This API is fundamentally incompatible with the event-based way in which
/// Web browsers work because it's not possible to have a long-running external
/// loop that would block the browser and there is nothing that can be
@ -152,6 +92,7 @@ pub trait EventLoopExtPumpEvents {
/// there's no way to support the same approach to polling as on MacOS.
///
/// ## Platform-specific
///
/// - **Windows**: The implementation will use `PeekMessage` when checking for
/// window messages to avoid blocking your external event loop.
///
@ -174,7 +115,7 @@ pub trait EventLoopExtPumpEvents {
/// callback.
fn pump_events<F>(&mut self, timeout: Option<Duration>, event_handler: F) -> PumpStatus
where
F: FnMut(Event<Self::UserEvent>, &EventLoopWindowTarget);
F: FnMut(Event<Self::UserEvent>, &ActiveEventLoop);
}
impl<T> EventLoopExtPumpEvents for EventLoop<T> {
@ -182,7 +123,7 @@ impl<T> EventLoopExtPumpEvents for EventLoop<T> {
fn pump_events<F>(&mut self, timeout: Option<Duration>, event_handler: F) -> PumpStatus
where
F: FnMut(Event<Self::UserEvent>, &EventLoopWindowTarget),
F: FnMut(Event<Self::UserEvent>, &ActiveEventLoop),
{
self.event_loop.pump_events(timeout, event_handler)
}

View file

@ -1,7 +1,7 @@
use crate::{
error::EventLoopError,
event::Event,
event_loop::{EventLoop, EventLoopWindowTarget},
event_loop::{ActiveEventLoop, EventLoop},
};
#[cfg(doc)]
@ -62,11 +62,11 @@ pub trait EventLoopExtRunOnDemand {
doc = "[^1]: `spawn()` is only available on `wasm` platforms."
)]
///
/// [`exit()`]: EventLoopWindowTarget::exit()
/// [`set_control_flow()`]: EventLoopWindowTarget::set_control_flow()
/// [`exit()`]: ActiveEventLoop::exit()
/// [`set_control_flow()`]: ActiveEventLoop::set_control_flow()
fn run_on_demand<F>(&mut self, event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<Self::UserEvent>, &EventLoopWindowTarget);
F: FnMut(Event<Self::UserEvent>, &ActiveEventLoop);
}
impl<T> EventLoopExtRunOnDemand for EventLoop<T> {
@ -74,14 +74,14 @@ impl<T> EventLoopExtRunOnDemand for EventLoop<T> {
fn run_on_demand<F>(&mut self, event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<Self::UserEvent>, &EventLoopWindowTarget),
F: FnMut(Event<Self::UserEvent>, &ActiveEventLoop),
{
self.event_loop.window_target().clear_exit();
self.event_loop.run_on_demand(event_handler)
}
}
impl EventLoopWindowTarget {
impl ActiveEventLoop {
/// Clear exit status.
pub(crate) fn clear_exit(&self) {
self.p.clear_exit()

View file

@ -24,8 +24,8 @@
use std::env;
use crate::error::NotSupportedError;
use crate::event_loop::{AsyncRequestSerial, EventLoopWindowTarget};
use crate::window::{ActivationToken, Window, WindowBuilder};
use crate::event_loop::{ActiveEventLoop, AsyncRequestSerial};
use crate::window::{ActivationToken, Window, WindowAttributes};
/// The variable which is used mostly on X11.
const X11_VAR: &str = "DESKTOP_STARTUP_ID";
@ -47,7 +47,7 @@ pub trait WindowExtStartupNotify {
fn request_activation_token(&self) -> Result<AsyncRequestSerial, NotSupportedError>;
}
pub trait WindowBuilderExtStartupNotify {
pub trait WindowAttributesExtStartupNotify {
/// Use this [`ActivationToken`] during window creation.
///
/// Not using such a token upon a window could make your window not gaining
@ -55,13 +55,13 @@ pub trait WindowBuilderExtStartupNotify {
fn with_activation_token(self, token: ActivationToken) -> Self;
}
impl EventLoopExtStartupNotify for EventLoopWindowTarget {
impl EventLoopExtStartupNotify for ActiveEventLoop {
fn read_token_from_env(&self) -> Option<ActivationToken> {
match self.p {
#[cfg(wayland_platform)]
crate::platform_impl::EventLoopWindowTarget::Wayland(_) => env::var(WAYLAND_VAR),
crate::platform_impl::ActiveEventLoop::Wayland(_) => env::var(WAYLAND_VAR),
#[cfg(x11_platform)]
crate::platform_impl::EventLoopWindowTarget::X(_) => env::var(X11_VAR),
crate::platform_impl::ActiveEventLoop::X(_) => env::var(X11_VAR),
}
.ok()
.map(ActivationToken::_new)
@ -74,9 +74,9 @@ impl WindowExtStartupNotify for Window {
}
}
impl WindowBuilderExtStartupNotify for WindowBuilder {
impl WindowAttributesExtStartupNotify for WindowAttributes {
fn with_activation_token(mut self, token: ActivationToken) -> Self {
self.window.platform_specific.activation_token = Some(token);
self.platform_specific.activation_token = Some(token);
self
}
}

View file

@ -1,18 +1,18 @@
use crate::{
event_loop::{EventLoopBuilder, EventLoopWindowTarget},
event_loop::{ActiveEventLoop, EventLoopBuilder},
monitor::MonitorHandle,
window::{Window, WindowBuilder},
window::{Window, WindowAttributes},
};
pub use crate::window::Theme;
/// Additional methods on [`EventLoopWindowTarget`] that are specific to Wayland.
pub trait EventLoopWindowTargetExtWayland {
/// True if the [`EventLoopWindowTarget`] uses Wayland.
/// Additional methods on [`ActiveEventLoop`] that are specific to Wayland.
pub trait ActiveEventLoopExtWayland {
/// True if the [`ActiveEventLoop`] uses Wayland.
fn is_wayland(&self) -> bool;
}
impl EventLoopWindowTargetExtWayland for EventLoopWindowTarget {
impl ActiveEventLoopExtWayland for ActiveEventLoop {
#[inline]
fn is_wayland(&self) -> bool {
self.p.is_wayland()
@ -50,8 +50,8 @@ pub trait WindowExtWayland {}
impl WindowExtWayland for Window {}
/// Additional methods on [`WindowBuilder`] that are specific to Wayland.
pub trait WindowBuilderExtWayland {
/// Additional methods on [`WindowAttributes`] that are specific to Wayland.
pub trait WindowAttributesExtWayland {
/// Build window with the given name.
///
/// The `general` name sets an application ID, which should match the `.desktop`
@ -62,10 +62,10 @@ pub trait WindowBuilderExtWayland {
fn with_name(self, general: impl Into<String>, instance: impl Into<String>) -> Self;
}
impl WindowBuilderExtWayland for WindowBuilder {
impl WindowAttributesExtWayland for WindowAttributes {
#[inline]
fn with_name(mut self, general: impl Into<String>, instance: impl Into<String>) -> Self {
self.window.platform_specific.name = Some(crate::platform_impl::ApplicationName::new(
self.platform_specific.name = Some(crate::platform_impl::ApplicationName::new(
general.into(),
instance.into(),
));

View file

@ -1,6 +1,6 @@
//! The web target does not automatically insert the canvas element object into the web page, to
//! allow end users to determine how the page should be laid out. Use the [`WindowExtWebSys`] trait
//! to retrieve the canvas from the Window. Alternatively, use the [`WindowBuilderExtWebSys`] trait
//! to retrieve the canvas from the Window. Alternatively, use the [`WindowAttributesExtWebSys`] trait
//! to provide your own canvas.
//!
//! It is recommended **not** to apply certain CSS properties to the canvas:
@ -39,11 +39,11 @@ use web_sys::HtmlCanvasElement;
use crate::cursor::CustomCursorBuilder;
use crate::event::Event;
use crate::event_loop::{EventLoop, EventLoopWindowTarget};
use crate::event_loop::{ActiveEventLoop, EventLoop};
#[cfg(web_platform)]
use crate::platform_impl::CustomCursorFuture as PlatformCustomCursorFuture;
use crate::platform_impl::{PlatformCustomCursor, PlatformCustomCursorBuilder};
use crate::window::{CustomCursor, Window, WindowBuilder};
use crate::window::{CustomCursor, Window, WindowAttributes};
#[cfg(not(web_platform))]
#[doc(hidden)]
@ -85,9 +85,9 @@ impl WindowExtWebSys for Window {
}
}
pub trait WindowBuilderExtWebSys {
pub trait WindowAttributesExtWebSys {
/// Pass an [`HtmlCanvasElement`] to be used for this [`Window`]. If [`None`],
/// [`WindowBuilder::build()`] will create one.
/// [`WindowAttributes::default()`] will create one.
///
/// In any case, the canvas won't be automatically inserted into the web page.
///
@ -119,24 +119,24 @@ pub trait WindowBuilderExtWebSys {
fn with_append(self, append: bool) -> Self;
}
impl WindowBuilderExtWebSys for WindowBuilder {
impl WindowAttributesExtWebSys for WindowAttributes {
fn with_canvas(mut self, canvas: Option<HtmlCanvasElement>) -> Self {
self.window.platform_specific.set_canvas(canvas);
self.platform_specific.set_canvas(canvas);
self
}
fn with_prevent_default(mut self, prevent_default: bool) -> Self {
self.window.platform_specific.prevent_default = prevent_default;
self.platform_specific.prevent_default = prevent_default;
self
}
fn with_focusable(mut self, focusable: bool) -> Self {
self.window.platform_specific.focusable = focusable;
self.platform_specific.focusable = focusable;
self
}
fn with_append(mut self, append: bool) -> Self {
self.window.platform_specific.append = append;
self.platform_specific.append = append;
self
}
}
@ -172,7 +172,7 @@ pub trait EventLoopExtWebSys {
/// [^1]: `run()` is _not_ available on WASM when the target supports `exception-handling`.
fn spawn<F>(self, event_handler: F)
where
F: 'static + FnMut(Event<Self::UserEvent>, &EventLoopWindowTarget);
F: 'static + FnMut(Event<Self::UserEvent>, &ActiveEventLoop);
}
impl<T> EventLoopExtWebSys for EventLoop<T> {
@ -180,13 +180,13 @@ impl<T> EventLoopExtWebSys for EventLoop<T> {
fn spawn<F>(self, event_handler: F)
where
F: 'static + FnMut(Event<Self::UserEvent>, &EventLoopWindowTarget),
F: 'static + FnMut(Event<Self::UserEvent>, &ActiveEventLoop),
{
self.event_loop.spawn(event_handler)
}
}
pub trait EventLoopWindowTargetExtWebSys {
pub trait ActiveEventLoopExtWebSys {
/// Sets the strategy for [`ControlFlow::Poll`].
///
/// See [`PollStrategy`].
@ -202,7 +202,7 @@ pub trait EventLoopWindowTargetExtWebSys {
fn poll_strategy(&self) -> PollStrategy;
}
impl EventLoopWindowTargetExtWebSys for EventLoopWindowTarget {
impl ActiveEventLoopExtWebSys for ActiveEventLoop {
#[inline]
fn set_poll_strategy(&self, strategy: PollStrategy) {
self.p.set_poll_strategy(strategy);
@ -315,11 +315,11 @@ impl Error for BadAnimation {}
pub trait CustomCursorBuilderExtWebSys {
/// Async version of [`CustomCursorBuilder::build()`] which waits until the
/// cursor has completely finished loading.
fn build_async(self, window_target: &EventLoopWindowTarget) -> CustomCursorFuture;
fn build_async(self, window_target: &ActiveEventLoop) -> CustomCursorFuture;
}
impl CustomCursorBuilderExtWebSys for CustomCursorBuilder {
fn build_async(self, window_target: &EventLoopWindowTarget) -> CustomCursorFuture {
fn build_async(self, window_target: &ActiveEventLoop) -> CustomCursorFuture {
CustomCursorFuture(PlatformCustomCursor::build_async(
self.inner,
&window_target.p,

View file

@ -5,7 +5,7 @@ use crate::{
event::DeviceId,
event_loop::EventLoopBuilder,
monitor::MonitorHandle,
window::{BadIcon, Icon, Window, WindowBuilder},
window::{BadIcon, Icon, Window, WindowAttributes},
};
/// Window Handle type used by Win32 API
@ -198,7 +198,7 @@ pub trait WindowExtWindows {
///
/// A window must be enabled before it can be activated.
/// If an application has create a modal dialog box by disabling its owner window
/// (as described in [`WindowBuilderExtWindows::with_owner_window`]), the application must enable
/// (as described in [`WindowAttributesExtWindows::with_owner_window`]), the application must enable
/// the owner window before destroying the dialog box.
/// Otherwise, another window will receive the keyboard focus and be activated.
///
@ -296,11 +296,11 @@ impl WindowExtWindows for Window {
}
}
/// Additional methods on `WindowBuilder` that are specific to Windows.
/// Additional methods on `WindowAttributes` that are specific to Windows.
#[allow(rustdoc::broken_intra_doc_links)]
pub trait WindowBuilderExtWindows {
pub trait WindowAttributesExtWindows {
/// Set an owner to the window to be created. Can be used to create a dialog box, for example.
/// This only works when [`WindowBuilder::with_parent_window`] isn't called or set to `None`.
/// This only works when [`WindowAttributes::with_parent_window`] isn't called or set to `None`.
/// Can be used in combination with [`WindowExtWindows::set_enable(false)`](WindowExtWindows::set_enable)
/// on the owner window to create a modal dialog box.
///
@ -386,88 +386,88 @@ pub trait WindowBuilderExtWindows {
fn with_corner_preference(self, corners: CornerPreference) -> Self;
}
impl WindowBuilderExtWindows for WindowBuilder {
impl WindowAttributesExtWindows for WindowAttributes {
#[inline]
fn with_owner_window(mut self, parent: HWND) -> Self {
self.window.platform_specific.owner = Some(parent);
self.platform_specific.owner = Some(parent);
self
}
#[inline]
fn with_menu(mut self, menu: HMENU) -> Self {
self.window.platform_specific.menu = Some(menu);
self.platform_specific.menu = Some(menu);
self
}
#[inline]
fn with_taskbar_icon(mut self, taskbar_icon: Option<Icon>) -> Self {
self.window.platform_specific.taskbar_icon = taskbar_icon;
self.platform_specific.taskbar_icon = taskbar_icon;
self
}
#[inline]
fn with_no_redirection_bitmap(mut self, flag: bool) -> Self {
self.window.platform_specific.no_redirection_bitmap = flag;
self.platform_specific.no_redirection_bitmap = flag;
self
}
#[inline]
fn with_drag_and_drop(mut self, flag: bool) -> Self {
self.window.platform_specific.drag_and_drop = flag;
self.platform_specific.drag_and_drop = flag;
self
}
#[inline]
fn with_skip_taskbar(mut self, skip: bool) -> Self {
self.window.platform_specific.skip_taskbar = skip;
self.platform_specific.skip_taskbar = skip;
self
}
#[inline]
fn with_class_name<S: Into<String>>(mut self, class_name: S) -> Self {
self.window.platform_specific.class_name = class_name.into();
self.platform_specific.class_name = class_name.into();
self
}
#[inline]
fn with_undecorated_shadow(mut self, shadow: bool) -> Self {
self.window.platform_specific.decoration_shadow = shadow;
self.platform_specific.decoration_shadow = shadow;
self
}
#[inline]
fn with_system_backdrop(mut self, backdrop_type: BackdropType) -> Self {
self.window.platform_specific.backdrop_type = backdrop_type;
self.platform_specific.backdrop_type = backdrop_type;
self
}
#[inline]
fn with_clip_children(mut self, flag: bool) -> Self {
self.window.platform_specific.clip_children = flag;
self.platform_specific.clip_children = flag;
self
}
#[inline]
fn with_border_color(mut self, color: Option<Color>) -> Self {
self.window.platform_specific.border_color = Some(color.unwrap_or(Color::NONE));
self.platform_specific.border_color = Some(color.unwrap_or(Color::NONE));
self
}
#[inline]
fn with_title_background_color(mut self, color: Option<Color>) -> Self {
self.window.platform_specific.title_background_color = Some(color.unwrap_or(Color::NONE));
self.platform_specific.title_background_color = Some(color.unwrap_or(Color::NONE));
self
}
#[inline]
fn with_title_text_color(mut self, color: Color) -> Self {
self.window.platform_specific.title_text_color = Some(color);
self.platform_specific.title_text_color = Some(color);
self
}
#[inline]
fn with_corner_preference(mut self, corners: CornerPreference) -> Self {
self.window.platform_specific.corner_preference = Some(corners);
self.platform_specific.corner_preference = Some(corners);
self
}
}

View file

@ -2,9 +2,9 @@
use serde::{Deserialize, Serialize};
use crate::{
event_loop::{EventLoopBuilder, EventLoopWindowTarget},
event_loop::{ActiveEventLoop, EventLoopBuilder},
monitor::MonitorHandle,
window::{Window, WindowBuilder},
window::{Window, WindowAttributes},
};
use crate::dpi::Size;
@ -89,13 +89,13 @@ pub fn register_xlib_error_hook(hook: XlibErrorHook) {
}
}
/// Additional methods on [`EventLoopWindowTarget`] that are specific to X11.
pub trait EventLoopWindowTargetExtX11 {
/// True if the [`EventLoopWindowTarget`] uses X11.
/// Additional methods on [`ActiveEventLoop`] that are specific to X11.
pub trait ActiveEventLoopExtX11 {
/// True if the [`ActiveEventLoop`] uses X11.
fn is_x11(&self) -> bool;
}
impl EventLoopWindowTargetExtX11 for EventLoopWindowTarget {
impl ActiveEventLoopExtX11 for ActiveEventLoop {
#[inline]
fn is_x11(&self) -> bool {
!self.p.is_wayland()
@ -133,8 +133,8 @@ pub trait WindowExtX11 {}
impl WindowExtX11 for Window {}
/// Additional methods on [`WindowBuilder`] that are specific to X11.
pub trait WindowBuilderExtX11 {
/// Additional methods on [`WindowAttributes`] that are specific to X11.
pub trait WindowAttributesExtX11 {
/// Create this window with a specific X11 visual.
fn with_x11_visual(self, visual_id: XVisualID) -> Self;
@ -160,12 +160,12 @@ pub trait WindowBuilderExtX11 {
/// ```
/// # use winit::dpi::{LogicalSize, PhysicalSize};
/// # use winit::window::Window;
/// # use winit::platform::x11::WindowBuilderExtX11;
/// # use winit::platform::x11::WindowAttributesExtX11;
/// // Specify the size in logical dimensions like this:
/// Window::builder().with_base_size(LogicalSize::new(400.0, 200.0));
/// Window::default_attributes().with_base_size(LogicalSize::new(400.0, 200.0));
///
/// // Or specify the size in physical dimensions like this:
/// Window::builder().with_base_size(PhysicalSize::new(400, 200));
/// Window::default_attributes().with_base_size(PhysicalSize::new(400, 200));
/// ```
fn with_base_size<S: Into<Size>>(self, base_size: S) -> Self;
@ -175,34 +175,33 @@ pub trait WindowBuilderExtX11 {
///
/// ```no_run
/// use winit::window::Window;
/// use winit::platform::x11::{XWindow, WindowBuilderExtX11};
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let event_loop = winit::event_loop::EventLoop::new().unwrap();
/// use winit::event_loop::ActiveEventLoop;
/// use winit::platform::x11::{XWindow, WindowAttributesExtX11};
/// # fn create_window(event_loop: &ActiveEventLoop) -> Result<(), Box<dyn std::error::Error>> {
/// let parent_window_id = std::env::args().nth(1).unwrap().parse::<XWindow>()?;
/// let window = Window::builder()
/// .with_embed_parent_window(parent_window_id)
/// .build(&event_loop)?;
/// let window_attributes = Window::default_attributes().with_embed_parent_window(parent_window_id);
/// let window = event_loop.create_window(window_attributes)?;
/// # Ok(()) }
/// ```
fn with_embed_parent_window(self, parent_window_id: XWindow) -> Self;
}
impl WindowBuilderExtX11 for WindowBuilder {
impl WindowAttributesExtX11 for WindowAttributes {
#[inline]
fn with_x11_visual(mut self, visual_id: XVisualID) -> Self {
self.window.platform_specific.x11.visual_id = Some(visual_id);
self.platform_specific.x11.visual_id = Some(visual_id);
self
}
#[inline]
fn with_x11_screen(mut self, screen_id: i32) -> Self {
self.window.platform_specific.x11.screen_id = Some(screen_id);
self.platform_specific.x11.screen_id = Some(screen_id);
self
}
#[inline]
fn with_name(mut self, general: impl Into<String>, instance: impl Into<String>) -> Self {
self.window.platform_specific.name = Some(crate::platform_impl::ApplicationName::new(
self.platform_specific.name = Some(crate::platform_impl::ApplicationName::new(
general.into(),
instance.into(),
));
@ -211,25 +210,25 @@ impl WindowBuilderExtX11 for WindowBuilder {
#[inline]
fn with_override_redirect(mut self, override_redirect: bool) -> Self {
self.window.platform_specific.x11.override_redirect = override_redirect;
self.platform_specific.x11.override_redirect = override_redirect;
self
}
#[inline]
fn with_x11_window_type(mut self, x11_window_types: Vec<WindowType>) -> Self {
self.window.platform_specific.x11.x11_window_types = x11_window_types;
self.platform_specific.x11.x11_window_types = x11_window_types;
self
}
#[inline]
fn with_base_size<S: Into<Size>>(mut self, base_size: S) -> Self {
self.window.platform_specific.x11.base_size = Some(base_size.into());
self.platform_specific.x11.base_size = Some(base_size.into());
self
}
#[inline]
fn with_embed_parent_window(mut self, parent_window_id: XWindow) -> Self {
self.window.platform_specific.x11.embed_window = Some(parent_window_id);
self.platform_specific.x11.embed_window = Some(parent_window_id);
self
}
}

View file

@ -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

View file

@ -29,7 +29,7 @@ use super::view::WinitUIWindow;
use crate::{
dpi::PhysicalSize,
event::{Event, InnerSizeWriter, StartCause, WindowEvent},
event_loop::{ControlFlow, EventLoopWindowTarget as RootEventLoopWindowTarget},
event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow},
window::WindowId as RootWindowId,
};
@ -50,8 +50,8 @@ pub(crate) struct HandlePendingUserEvents;
pub(crate) struct EventLoopHandler {
#[allow(clippy::type_complexity)]
pub(crate) handler: Box<dyn FnMut(Event<HandlePendingUserEvents>, &RootEventLoopWindowTarget)>,
pub(crate) event_loop: RootEventLoopWindowTarget,
pub(crate) handler: Box<dyn FnMut(Event<HandlePendingUserEvents>, &RootActiveEventLoop)>,
pub(crate) event_loop: RootActiveEventLoop,
}
impl fmt::Debug for EventLoopHandler {

View file

@ -20,8 +20,7 @@ use crate::{
error::EventLoopError,
event::Event,
event_loop::{
ControlFlow, DeviceEvents, EventLoopClosed,
EventLoopWindowTarget as RootEventLoopWindowTarget,
ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, EventLoopClosed,
},
platform::ios::Idiom,
platform_impl::platform::app_state::{EventLoopHandler, HandlePendingUserEvents},
@ -34,11 +33,11 @@ use super::{
};
#[derive(Debug)]
pub struct EventLoopWindowTarget {
pub struct ActiveEventLoop {
pub(super) mtm: MainThreadMarker,
}
impl EventLoopWindowTarget {
impl ActiveEventLoop {
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
monitor::uiscreens(self.mtm)
}
@ -109,9 +108,9 @@ impl OwnedDisplayHandle {
}
fn map_user_event<T: 'static>(
mut handler: impl FnMut(Event<T>, &RootEventLoopWindowTarget),
mut handler: impl FnMut(Event<T>, &RootActiveEventLoop),
receiver: mpsc::Receiver<T>,
) -> impl FnMut(Event<HandlePendingUserEvents>, &RootEventLoopWindowTarget) {
) -> impl FnMut(Event<HandlePendingUserEvents>, &RootActiveEventLoop) {
move |event, window_target| match event.map_nonuser_event() {
Ok(event) => (handler)(event, window_target),
Err(_) => {
@ -126,7 +125,7 @@ pub struct EventLoop<T: 'static> {
mtm: MainThreadMarker,
sender: Sender<T>,
receiver: Receiver<T>,
window_target: RootEventLoopWindowTarget,
window_target: RootActiveEventLoop,
}
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
@ -158,8 +157,8 @@ impl<T: 'static> EventLoop<T> {
mtm,
sender,
receiver,
window_target: RootEventLoopWindowTarget {
p: EventLoopWindowTarget { mtm },
window_target: RootActiveEventLoop {
p: ActiveEventLoop { mtm },
_marker: PhantomData,
},
})
@ -167,7 +166,7 @@ impl<T: 'static> EventLoop<T> {
pub fn run<F>(self, handler: F) -> !
where
F: FnMut(Event<T>, &RootEventLoopWindowTarget),
F: FnMut(Event<T>, &RootActiveEventLoop),
{
let application = UIApplication::shared(self.mtm);
assert!(
@ -181,8 +180,8 @@ impl<T: 'static> EventLoop<T> {
let handler = unsafe {
std::mem::transmute::<
Box<dyn FnMut(Event<HandlePendingUserEvents>, &RootEventLoopWindowTarget)>,
Box<dyn FnMut(Event<HandlePendingUserEvents>, &RootEventLoopWindowTarget)>,
Box<dyn FnMut(Event<HandlePendingUserEvents>, &RootActiveEventLoop)>,
Box<dyn FnMut(Event<HandlePendingUserEvents>, &RootActiveEventLoop)>,
>(Box::new(handler))
};
@ -211,7 +210,7 @@ impl<T: 'static> EventLoop<T> {
EventLoopProxy::new(self.sender.clone())
}
pub fn window_target(&self) -> &RootEventLoopWindowTarget {
pub fn window_target(&self) -> &RootActiveEventLoop {
&self.window_target
}
}

View file

@ -72,11 +72,11 @@ use crate::event::DeviceId as RootDeviceId;
pub(crate) use self::{
event_loop::{
EventLoop, EventLoopProxy, EventLoopWindowTarget, OwnedDisplayHandle,
ActiveEventLoop, EventLoop, EventLoopProxy, OwnedDisplayHandle,
PlatformSpecificEventLoopAttributes,
},
monitor::{MonitorHandle, VideoModeHandle},
window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId},
window::{PlatformSpecificWindowAttributes, Window, WindowId},
};
pub(crate) use crate::cursor::NoCustomCursor as PlatformCustomCursor;
pub(crate) use crate::cursor::NoCustomCursor as PlatformCustomCursorBuilder;

View file

@ -18,9 +18,7 @@ use crate::{
event::{Event, WindowEvent},
icon::Icon,
platform::ios::{ScreenEdge, StatusBarStyle, ValidOrientations},
platform_impl::platform::{
app_state, monitor, EventLoopWindowTarget, Fullscreen, MonitorHandle,
},
platform_impl::platform::{app_state, monitor, ActiveEventLoop, Fullscreen, MonitorHandle},
window::{
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes,
WindowButtons, WindowId as RootWindowId, WindowLevel,
@ -399,7 +397,7 @@ pub struct Window {
impl Window {
pub(crate) fn new(
event_loop: &EventLoopWindowTarget,
event_loop: &ActiveEventLoop,
window_attributes: WindowAttributes,
) -> Result<Window, RootOsError> {
let mtm = event_loop.mtm;
@ -678,7 +676,7 @@ impl From<&AnyObject> for WindowId {
}
#[derive(Clone, Debug, Default)]
pub struct PlatformSpecificWindowBuilderAttributes {
pub struct PlatformSpecificWindowAttributes {
pub scale_factor: Option<f64>,
pub valid_orientations: ValidOrientations,
pub prefers_home_indicator_hidden: bool,

View file

@ -22,8 +22,7 @@ use crate::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
error::{EventLoopError, ExternalError, NotSupportedError, OsError as RootOsError},
event_loop::{
AsyncRequestSerial, ControlFlow, DeviceEvents, EventLoopClosed,
EventLoopWindowTarget as RootELW,
ActiveEventLoop as RootELW, AsyncRequestSerial, ControlFlow, DeviceEvents, EventLoopClosed,
},
icon::Icon,
keyboard::Key,
@ -72,16 +71,16 @@ impl ApplicationName {
}
#[derive(Clone, Debug)]
pub struct PlatformSpecificWindowBuilderAttributes {
pub struct PlatformSpecificWindowAttributes {
pub name: Option<ApplicationName>,
pub activation_token: Option<ActivationToken>,
#[cfg(x11_platform)]
pub x11: X11WindowBuilderAttributes,
pub x11: X11WindowAttributes,
}
#[derive(Clone, Debug)]
#[cfg(x11_platform)]
pub struct X11WindowBuilderAttributes {
pub struct X11WindowAttributes {
pub visual_id: Option<x11rb::protocol::xproto::Visualid>,
pub screen_id: Option<i32>,
pub base_size: Option<Size>,
@ -92,13 +91,13 @@ pub struct X11WindowBuilderAttributes {
pub embed_window: Option<x11rb::protocol::xproto::Window>,
}
impl Default for PlatformSpecificWindowBuilderAttributes {
impl Default for PlatformSpecificWindowAttributes {
fn default() -> Self {
Self {
name: None,
activation_token: None,
#[cfg(x11_platform)]
x11: X11WindowBuilderAttributes {
x11: X11WindowAttributes {
visual_id: None,
screen_id: None,
base_size: None,
@ -286,16 +285,16 @@ impl VideoModeHandle {
impl Window {
#[inline]
pub(crate) fn new(
window_target: &EventLoopWindowTarget,
window_target: &ActiveEventLoop,
attribs: WindowAttributes,
) -> Result<Self, RootOsError> {
match *window_target {
#[cfg(wayland_platform)]
EventLoopWindowTarget::Wayland(ref window_target) => {
ActiveEventLoop::Wayland(ref window_target) => {
wayland::Window::new(window_target, attribs).map(Window::Wayland)
}
#[cfg(x11_platform)]
EventLoopWindowTarget::X(ref window_target) => {
ActiveEventLoop::X(ref window_target) => {
x11::Window::new(window_target, attribs).map(Window::X)
}
}
@ -647,15 +646,13 @@ pub(crate) enum PlatformCustomCursor {
impl PlatformCustomCursor {
pub(crate) fn build(
builder: PlatformCustomCursorBuilder,
p: &EventLoopWindowTarget,
p: &ActiveEventLoop,
) -> PlatformCustomCursor {
match p {
#[cfg(wayland_platform)]
EventLoopWindowTarget::Wayland(_) => {
Self::Wayland(wayland::CustomCursor::build(builder, p))
}
ActiveEventLoop::Wayland(_) => Self::Wayland(wayland::CustomCursor::build(builder, p)),
#[cfg(x11_platform)]
EventLoopWindowTarget::X(p) => Self::X(x11::CustomCursor::build(builder, p)),
ActiveEventLoop::X(p) => Self::X(x11::CustomCursor::build(builder, p)),
}
}
}
@ -829,7 +826,7 @@ impl<T: 'static> EventLoop<T> {
x11_or_wayland!(match self; EventLoop(evlp) => evlp.pump_events(timeout, callback))
}
pub fn window_target(&self) -> &crate::event_loop::EventLoopWindowTarget {
pub fn window_target(&self) -> &crate::event_loop::ActiveEventLoop {
x11_or_wayland!(match self; EventLoop(evlp) => evlp.window_target())
}
}
@ -852,19 +849,19 @@ impl<T: 'static> EventLoopProxy<T> {
}
}
pub enum EventLoopWindowTarget {
pub enum ActiveEventLoop {
#[cfg(wayland_platform)]
Wayland(wayland::EventLoopWindowTarget),
Wayland(wayland::ActiveEventLoop),
#[cfg(x11_platform)]
X(x11::EventLoopWindowTarget),
X(x11::ActiveEventLoop),
}
impl EventLoopWindowTarget {
impl ActiveEventLoop {
#[inline]
pub fn is_wayland(&self) -> bool {
match *self {
#[cfg(wayland_platform)]
EventLoopWindowTarget::Wayland(_) => true,
ActiveEventLoop::Wayland(_) => true,
#[cfg(x11_platform)]
_ => false,
}
@ -874,12 +871,12 @@ impl EventLoopWindowTarget {
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
match *self {
#[cfg(wayland_platform)]
EventLoopWindowTarget::Wayland(ref evlp) => evlp
ActiveEventLoop::Wayland(ref evlp) => evlp
.available_monitors()
.map(MonitorHandle::Wayland)
.collect(),
#[cfg(x11_platform)]
EventLoopWindowTarget::X(ref evlp) => {
ActiveEventLoop::X(ref evlp) => {
evlp.available_monitors().map(MonitorHandle::X).collect()
}
}
@ -888,7 +885,7 @@ impl EventLoopWindowTarget {
#[inline]
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(
x11_or_wayland!(match self; EventLoopWindowTarget(evlp) => evlp.primary_monitor()?; as MonitorHandle),
x11_or_wayland!(match self; ActiveEventLoop(evlp) => evlp.primary_monitor()?; as MonitorHandle),
)
}

View file

@ -18,12 +18,10 @@ use sctk::reexports::client::{Connection, QueueHandle};
use crate::dpi::LogicalSize;
use crate::error::{EventLoopError, OsError as RootOsError};
use crate::event::{Event, InnerSizeWriter, StartCause, WindowEvent};
use crate::event_loop::{
ControlFlow, DeviceEvents, EventLoopWindowTarget as RootEventLoopWindowTarget,
};
use crate::event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents};
use crate::platform::pump_events::PumpStatus;
use crate::platform_impl::platform::min_timeout;
use crate::platform_impl::{EventLoopWindowTarget as PlatformEventLoopWindowTarget, OsError};
use crate::platform_impl::{ActiveEventLoop as PlatformActiveEventLoop, OsError};
mod proxy;
pub mod sink;
@ -62,7 +60,7 @@ pub struct EventLoop<T: 'static> {
connection: Connection,
/// Event loop window target.
window_target: RootEventLoopWindowTarget,
window_target: RootActiveEventLoop,
// XXX drop after everything else, just to be safe.
/// Calloop's event loop.
@ -158,7 +156,7 @@ impl<T: 'static> EventLoop<T> {
.map_err(|error| error.error);
map_err!(result, WaylandError::Calloop)?;
let window_target = EventLoopWindowTarget {
let window_target = ActiveEventLoop {
connection: connection.clone(),
wayland_dispatcher: wayland_dispatcher.clone(),
event_loop_awakener,
@ -178,8 +176,8 @@ impl<T: 'static> EventLoop<T> {
user_events_sender,
pending_user_events,
event_loop,
window_target: RootEventLoopWindowTarget {
p: PlatformEventLoopWindowTarget::Wayland(window_target),
window_target: RootActiveEventLoop {
p: PlatformActiveEventLoop::Wayland(window_target),
_marker: PhantomData,
},
};
@ -189,7 +187,7 @@ impl<T: 'static> EventLoop<T> {
pub fn run_on_demand<F>(&mut self, mut event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<T>, &RootEventLoopWindowTarget),
F: FnMut(Event<T>, &RootActiveEventLoop),
{
let exit = loop {
match self.pump_events(None, &mut event_handler) {
@ -216,7 +214,7 @@ impl<T: 'static> EventLoop<T> {
pub fn pump_events<F>(&mut self, timeout: Option<Duration>, mut callback: F) -> PumpStatus
where
F: FnMut(Event<T>, &RootEventLoopWindowTarget),
F: FnMut(Event<T>, &RootActiveEventLoop),
{
if !self.loop_running {
self.loop_running = true;
@ -243,7 +241,7 @@ impl<T: 'static> EventLoop<T> {
pub fn poll_events_with_timeout<F>(&mut self, mut timeout: Option<Duration>, mut callback: F)
where
F: FnMut(Event<T>, &RootEventLoopWindowTarget),
F: FnMut(Event<T>, &RootActiveEventLoop),
{
let cause = loop {
let start = Instant::now();
@ -319,7 +317,7 @@ impl<T: 'static> EventLoop<T> {
fn single_iteration<F>(&mut self, callback: &mut F, cause: StartCause)
where
F: FnMut(Event<T>, &RootEventLoopWindowTarget),
F: FnMut(Event<T>, &RootActiveEventLoop),
{
// NOTE currently just indented to simplify the diff
@ -541,11 +539,11 @@ impl<T: 'static> EventLoop<T> {
// we can't do much about it.
if wake_up {
match &self.window_target.p {
PlatformEventLoopWindowTarget::Wayland(window_target) => {
PlatformActiveEventLoop::Wayland(window_target) => {
window_target.event_loop_awakener.ping();
}
#[cfg(x11_platform)]
PlatformEventLoopWindowTarget::X(_) => unreachable!(),
PlatformActiveEventLoop::X(_) => unreachable!(),
}
}
@ -560,13 +558,13 @@ impl<T: 'static> EventLoop<T> {
}
#[inline]
pub fn window_target(&self) -> &RootEventLoopWindowTarget {
pub fn window_target(&self) -> &RootActiveEventLoop {
&self.window_target
}
fn with_state<'a, U: 'a, F: FnOnce(&'a mut WinitState) -> U>(&'a mut self, callback: F) -> U {
let state = match &mut self.window_target.p {
PlatformEventLoopWindowTarget::Wayland(window_target) => window_target.state.get_mut(),
PlatformActiveEventLoop::Wayland(window_target) => window_target.state.get_mut(),
#[cfg(x11_platform)]
_ => unreachable!(),
};
@ -576,7 +574,7 @@ impl<T: 'static> EventLoop<T> {
fn loop_dispatch<D: Into<Option<std::time::Duration>>>(&mut self, timeout: D) -> IOResult<()> {
let state = match &mut self.window_target.p {
PlatformEventLoopWindowTarget::Wayland(window_target) => window_target.state.get_mut(),
PlatformActiveEventLoop::Wayland(window_target) => window_target.state.get_mut(),
#[cfg(feature = "x11")]
_ => unreachable!(),
};
@ -589,7 +587,7 @@ impl<T: 'static> EventLoop<T> {
fn roundtrip(&mut self) -> Result<usize, RootOsError> {
let state = match &mut self.window_target.p {
PlatformEventLoopWindowTarget::Wayland(window_target) => window_target.state.get_mut(),
PlatformActiveEventLoop::Wayland(window_target) => window_target.state.get_mut(),
#[cfg(feature = "x11")]
_ => unreachable!(),
};
@ -632,7 +630,7 @@ impl<T> AsRawFd for EventLoop<T> {
}
}
pub struct EventLoopWindowTarget {
pub struct ActiveEventLoop {
/// The event loop wakeup source.
pub event_loop_awakener: calloop::ping::Ping,
@ -656,7 +654,7 @@ pub struct EventLoopWindowTarget {
pub connection: Connection,
}
impl EventLoopWindowTarget {
impl ActiveEventLoop {
pub(crate) fn set_control_flow(&self, control_flow: ControlFlow) {
self.control_flow.set(control_flow)
}

View file

@ -12,7 +12,7 @@ use sctk::reexports::client::{self, ConnectError, DispatchError, Proxy};
pub(super) use crate::cursor::OnlyCursorImage as CustomCursor;
use crate::dpi::{LogicalSize, PhysicalSize};
pub use crate::platform_impl::platform::{OsError, WindowId};
pub use event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget};
pub use event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy};
pub use output::{MonitorHandle, VideoModeHandle};
pub use window::Window;

View file

@ -6,9 +6,9 @@ use sctk::output::OutputData;
use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
use crate::platform_impl::platform::VideoModeHandle as PlatformVideoModeHandle;
use super::event_loop::EventLoopWindowTarget;
use super::event_loop::ActiveEventLoop;
impl EventLoopWindowTarget {
impl ActiveEventLoop {
#[inline]
pub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle> {
self.state

View file

@ -32,7 +32,7 @@ use super::event_loop::sink::EventSink;
use super::output::MonitorHandle;
use super::state::WinitState;
use super::types::xdg_activation::XdgActivationTokenData;
use super::{EventLoopWindowTarget, WaylandError, WindowId};
use super::{ActiveEventLoop, WaylandError, WindowId};
pub(crate) mod state;
@ -80,7 +80,7 @@ pub struct Window {
impl Window {
pub(crate) fn new(
event_loop_window_target: &EventLoopWindowTarget,
event_loop_window_target: &ActiveEventLoop,
attributes: WindowAttributes,
) -> Result<Self, RootOsError> {
let queue_handle = event_loop_window_target.queue_handle.clone();

View file

@ -25,13 +25,13 @@ use crate::event::{
WindowEvent,
};
use crate::event::{InnerSizeWriter, MouseButton};
use crate::event_loop::EventLoopWindowTarget as RootELW;
use crate::event_loop::ActiveEventLoop as RootAEL;
use crate::keyboard::ModifiersState;
use crate::platform_impl::common::xkb::{self, XkbState};
use crate::platform_impl::platform::common::xkb::Context;
use crate::platform_impl::platform::x11::ime::{ImeEvent, ImeEventReceiver, ImeRequest};
use crate::platform_impl::platform::x11::EventLoopWindowTarget;
use crate::platform_impl::platform::EventLoopWindowTarget as PlatformEventLoopWindowTarget;
use crate::platform_impl::platform::x11::ActiveEventLoop;
use crate::platform_impl::platform::ActiveEventLoop as PlatformActiveEventLoop;
use crate::platform_impl::x11::{
atoms::*, mkdid, mkwid, util, CookieResultExt, Device, DeviceId, DeviceInfo, Dnd, DndState,
GenericEventCookie, ImeReceiver, ScrollOrientation, UnownedWindow, WindowId,
@ -48,7 +48,7 @@ pub struct EventProcessor {
pub devices: RefCell<HashMap<DeviceId, Device>>,
pub xi2ext: ExtensionInformation,
pub xkbext: ExtensionInformation,
pub target: RootELW,
pub target: RootAEL,
pub xkb_context: Context,
// Number of touch events currently in progress
pub num_touch: u32,
@ -68,7 +68,7 @@ pub struct EventProcessor {
impl EventProcessor {
pub fn process_event<T: 'static, F>(&mut self, xev: &mut XEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
self.process_xevent(xev, &mut callback);
@ -135,7 +135,7 @@ impl EventProcessor {
fn process_xevent<T: 'static, F>(&mut self, xev: &mut XEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
if self.filter_event(xev) {
return;
@ -334,18 +334,18 @@ impl EventProcessor {
// NOTE: we avoid `self` to not borrow the entire `self` as not mut.
/// Get the platform window target.
pub fn window_target(window_target: &RootELW) -> &EventLoopWindowTarget {
pub fn window_target(window_target: &RootAEL) -> &ActiveEventLoop {
match &window_target.p {
PlatformEventLoopWindowTarget::X(target) => target,
PlatformActiveEventLoop::X(target) => target,
#[cfg(wayland_platform)]
_ => unreachable!(),
}
}
/// Get the platform window target.
pub fn window_target_mut(window_target: &mut RootELW) -> &mut EventLoopWindowTarget {
pub fn window_target_mut(window_target: &mut RootAEL) -> &mut ActiveEventLoop {
match &mut window_target.p {
PlatformEventLoopWindowTarget::X(target) => target,
PlatformActiveEventLoop::X(target) => target,
#[cfg(wayland_platform)]
_ => unreachable!(),
}
@ -353,7 +353,7 @@ impl EventProcessor {
fn client_message<T: 'static, F>(&mut self, xev: &XClientMessageEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
let atoms = wt.xconn.atoms();
@ -524,7 +524,7 @@ impl EventProcessor {
fn selection_notify<T: 'static, F>(&mut self, xev: &XSelectionEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
let atoms = wt.xconn.atoms();
@ -558,7 +558,7 @@ impl EventProcessor {
fn configure_notify<T: 'static, F>(&self, xev: &XConfigureEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
@ -765,7 +765,7 @@ impl EventProcessor {
fn map_notify<T: 'static, F>(&self, xev: &XMapEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let window = xev.window as xproto::Window;
let window_id = mkwid(window);
@ -788,7 +788,7 @@ impl EventProcessor {
fn destroy_notify<T: 'static, F>(&self, xev: &XDestroyWindowEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
@ -818,7 +818,7 @@ impl EventProcessor {
fn property_notify<T: 'static, F>(&mut self, xev: &XPropertyEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
let atoms = wt.x_connection().atoms();
@ -833,7 +833,7 @@ impl EventProcessor {
fn visibility_notify<T: 'static, F>(&self, xev: &XVisibilityEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let xwindow = xev.window as xproto::Window;
@ -850,7 +850,7 @@ impl EventProcessor {
fn expose<T: 'static, F>(&self, xev: &XExposeEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
// Multiple Expose events may be received for subareas of a window.
// We issue `RedrawRequested` only for the last event of such a series.
@ -873,7 +873,7 @@ impl EventProcessor {
state: ElementState,
mut callback: F,
) where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
@ -976,7 +976,7 @@ impl EventProcessor {
state: ElementState,
mut callback: F,
) where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
let window_id = mkwid(event.event as xproto::Window);
@ -1046,7 +1046,7 @@ impl EventProcessor {
fn xinput2_mouse_motion<T: 'static, F>(&self, event: &XIDeviceEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
@ -1137,7 +1137,7 @@ impl EventProcessor {
fn xinput2_mouse_enter<T: 'static, F>(&self, event: &XIEnterEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
@ -1188,7 +1188,7 @@ impl EventProcessor {
fn xinput2_mouse_left<T: 'static, F>(&self, event: &XILeaveEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
let window = event.event as xproto::Window;
@ -1211,7 +1211,7 @@ impl EventProcessor {
fn xinput2_focused<T: 'static, F>(&mut self, xev: &XIFocusInEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
let window = xev.event as xproto::Window;
@ -1281,7 +1281,7 @@ impl EventProcessor {
fn xinput2_unfocused<T: 'static, F>(&mut self, xev: &XIFocusOutEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
let window = xev.event as xproto::Window;
@ -1337,7 +1337,7 @@ impl EventProcessor {
phase: TouchPhase,
mut callback: F,
) where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
@ -1383,7 +1383,7 @@ impl EventProcessor {
state: ElementState,
mut callback: F,
) where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
@ -1404,7 +1404,7 @@ impl EventProcessor {
fn xinput2_raw_mouse_motion<T: 'static, F>(&self, xev: &XIRawEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
@ -1471,7 +1471,7 @@ impl EventProcessor {
state: ElementState,
mut callback: F,
) where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
@ -1499,7 +1499,7 @@ impl EventProcessor {
fn xinput2_hierarchy_changed<T: 'static, F>(&mut self, xev: &XIHierarchyEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
@ -1532,7 +1532,7 @@ impl EventProcessor {
fn xkb_event<T: 'static, F>(&mut self, xev: &XkbAnyEvent, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
match xev.xkb_type {
@ -1597,7 +1597,7 @@ impl EventProcessor {
group: &XIModifierState,
mut callback: F,
) where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
if let Some(state) = self.xkb_context.state_mut() {
state.update_modifiers(
@ -1616,7 +1616,7 @@ impl EventProcessor {
pub fn udpate_mods_from_core_event<T: 'static, F>(&mut self, state: u16, mut callback: F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let xkb_mask = self.xkb_mod_mask_from_core(state);
let xkb_state = match self.xkb_context.state_mut() {
@ -1693,7 +1693,7 @@ impl EventProcessor {
/// Send modifiers for the active window.
///
/// The event won't be sent when the `modifiers` match the previously `sent` modifiers value.
fn send_modifiers<T: 'static, F: FnMut(&RootELW, Event<T>)>(
fn send_modifiers<T: 'static, F: FnMut(&RootAEL, Event<T>)>(
&self,
modifiers: ModifiersState,
callback: &mut F,
@ -1715,13 +1715,13 @@ impl EventProcessor {
}
fn handle_pressed_keys<T: 'static, F>(
target: &RootELW,
target: &RootAEL,
window_id: crate::window::WindowId,
state: ElementState,
xkb_context: &mut Context,
callback: &mut F,
) where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let device_id = mkdid(util::VIRTUAL_CORE_KEYBOARD);
@ -1768,7 +1768,7 @@ impl EventProcessor {
fn process_dpi_change<T: 'static, F>(&self, callback: &mut F)
where
F: FnMut(&RootELW, Event<T>),
F: FnMut(&RootAEL, Event<T>),
{
let wt = Self::window_target(&self.target);
wt.xconn

View file

@ -32,7 +32,7 @@ use super::{ControlFlow, OsError};
use crate::{
error::{EventLoopError, OsError as RootOsError},
event::{Event, StartCause, WindowEvent},
event_loop::{DeviceEvents, EventLoopClosed, EventLoopWindowTarget as RootELW},
event_loop::{ActiveEventLoop as RootAEL, DeviceEvents, EventLoopClosed},
platform::pump_events::PumpStatus,
platform_impl::common::xkb::Context,
platform_impl::platform::{min_timeout, WindowId},
@ -126,7 +126,7 @@ impl<T> PeekableReceiver<T> {
}
}
pub struct EventLoopWindowTarget {
pub struct ActiveEventLoop {
xconn: Arc<XConnection>,
wm_delete_window: xproto::Atom,
net_wm_ping: xproto::Atom,
@ -285,7 +285,7 @@ impl<T: 'static> EventLoop<T> {
let xkb_context =
Context::from_x11_xkb(xconn.xcb_connection().get_raw_xcb_connection()).unwrap();
let window_target = EventLoopWindowTarget {
let window_target = ActiveEventLoop {
ime,
root,
control_flow: Cell::new(ControlFlow::default()),
@ -309,8 +309,8 @@ impl<T: 'static> EventLoop<T> {
// Set initial device event filter.
window_target.update_listen_device_events(true);
let root_window_target = RootELW {
p: super::EventLoopWindowTarget::X(window_target),
let root_window_target = RootAEL {
p: super::ActiveEventLoop::X(window_target),
_marker: PhantomData,
};
@ -379,13 +379,13 @@ impl<T: 'static> EventLoop<T> {
}
}
pub(crate) fn window_target(&self) -> &RootELW {
pub(crate) fn window_target(&self) -> &RootAEL {
&self.event_processor.target
}
pub fn run_on_demand<F>(&mut self, mut event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<T>, &RootELW),
F: FnMut(Event<T>, &RootAEL),
{
let exit = loop {
match self.pump_events(None, &mut event_handler) {
@ -415,7 +415,7 @@ impl<T: 'static> EventLoop<T> {
pub fn pump_events<F>(&mut self, timeout: Option<Duration>, mut callback: F) -> PumpStatus
where
F: FnMut(Event<T>, &RootELW),
F: FnMut(Event<T>, &RootAEL),
{
if !self.loop_running {
self.loop_running = true;
@ -448,7 +448,7 @@ impl<T: 'static> EventLoop<T> {
pub fn poll_events_with_timeout<F>(&mut self, mut timeout: Option<Duration>, mut callback: F)
where
F: FnMut(Event<T>, &RootELW),
F: FnMut(Event<T>, &RootAEL),
{
let start = Instant::now();
@ -526,7 +526,7 @@ impl<T: 'static> EventLoop<T> {
fn single_iteration<F>(&mut self, callback: &mut F, cause: StartCause)
where
F: FnMut(Event<T>, &RootELW),
F: FnMut(Event<T>, &RootAEL),
{
callback(Event::NewEvents(cause), &self.event_processor.target);
@ -600,7 +600,7 @@ impl<T: 'static> EventLoop<T> {
fn drain_events<F>(&mut self, callback: &mut F)
where
F: FnMut(Event<T>, &RootELW),
F: FnMut(Event<T>, &RootAEL),
{
let mut xev = MaybeUninit::uninit();
@ -655,7 +655,7 @@ impl<T> AsRawFd for EventLoop<T> {
}
}
impl EventLoopWindowTarget {
impl ActiveEventLoop {
/// Returns the `XConnection` of this events loop.
#[inline]
pub(crate) fn x_connection(&self) -> &Arc<XConnection> {
@ -815,7 +815,7 @@ impl Deref for Window {
impl Window {
pub(crate) fn new(
event_loop: &EventLoopWindowTarget,
event_loop: &ActiveEventLoop,
attribs: WindowAttributes,
) -> Result<Self, RootOsError> {
let window = Arc::new(UnownedWindow::new(event_loop, attribs)?);

View file

@ -9,7 +9,7 @@ use x11rb::connection::Connection;
use crate::{platform_impl::PlatformCustomCursorBuilder, window::CursorIcon};
use super::super::EventLoopWindowTarget;
use super::super::ActiveEventLoop;
use super::*;
impl XConnection {
@ -124,10 +124,7 @@ impl PartialEq for CustomCursor {
impl Eq for CustomCursor {}
impl CustomCursor {
pub(crate) fn build(
builder: PlatformCustomCursorBuilder,
p: &EventLoopWindowTarget,
) -> CustomCursor {
pub(crate) fn build(builder: PlatformCustomCursorBuilder, p: &ActiveEventLoop) -> CustomCursor {
unsafe {
let ximage = (p.xconn.xcursor.XcursorImageCreate)(
builder.0.width as i32,

View file

@ -44,8 +44,7 @@ use crate::{
use super::{
ffi,
util::{self, SelectedCursor},
CookieResultExt, EventLoopWindowTarget, ImeRequest, ImeSender, VoidCookie, WindowId,
XConnection,
ActiveEventLoop, CookieResultExt, ImeRequest, ImeSender, VoidCookie, WindowId, XConnection,
};
#[derive(Debug)]
@ -153,7 +152,7 @@ macro_rules! leap {
impl UnownedWindow {
#[allow(clippy::unnecessary_cast)]
pub(crate) fn new(
event_loop: &EventLoopWindowTarget,
event_loop: &ActiveEventLoop,
window_attrs: WindowAttributes,
) -> Result<UnownedWindow, RootOsError> {
let xconn = &event_loop.xconn;

View file

@ -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)]

View file

@ -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))
}
}

View file

@ -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,

View file

@ -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;

View file

@ -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;

View file

@ -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
}

View file

@ -308,7 +308,7 @@ impl EventState {
pub struct EventLoop<T> {
windows: Vec<(Arc<RedoxSocket>, EventState)>,
window_target: event_loop::EventLoopWindowTarget,
window_target: event_loop::ActiveEventLoop,
user_events_sender: mpsc::Sender<T>,
user_events_receiver: mpsc::Receiver<T>,
}
@ -340,8 +340,8 @@ impl<T: 'static> EventLoop<T> {
Ok(Self {
windows: Vec::new(),
window_target: event_loop::EventLoopWindowTarget {
p: EventLoopWindowTarget {
window_target: event_loop::ActiveEventLoop {
p: ActiveEventLoop {
control_flow: Cell::new(ControlFlow::default()),
exit: Cell::new(false),
creates: Mutex::new(VecDeque::new()),
@ -544,10 +544,10 @@ impl<T: 'static> EventLoop<T> {
pub fn run<F>(mut self, mut event_handler_inner: F) -> Result<(), EventLoopError>
where
F: FnMut(event::Event<T>, &event_loop::EventLoopWindowTarget),
F: FnMut(event::Event<T>, &event_loop::ActiveEventLoop),
{
let mut event_handler =
move |event: event::Event<T>, window_target: &event_loop::EventLoopWindowTarget| {
move |event: event::Event<T>, window_target: &event_loop::ActiveEventLoop| {
event_handler_inner(event, window_target);
};
@ -754,7 +754,7 @@ impl<T: 'static> EventLoop<T> {
Ok(())
}
pub fn window_target(&self) -> &event_loop::EventLoopWindowTarget {
pub fn window_target(&self) -> &event_loop::ActiveEventLoop {
&self.window_target
}
@ -794,7 +794,7 @@ impl<T> Clone for EventLoopProxy<T> {
impl<T> Unpin for EventLoopProxy<T> {}
pub struct EventLoopWindowTarget {
pub struct ActiveEventLoop {
control_flow: Cell<ControlFlow>,
exit: Cell<bool>,
pub(super) creates: Mutex<VecDeque<Arc<RedoxSocket>>>,
@ -804,7 +804,7 @@ pub struct EventLoopWindowTarget {
pub(super) wake_socket: Arc<TimeSocket>,
}
impl EventLoopWindowTarget {
impl ActiveEventLoop {
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle)
}

View file

@ -11,9 +11,7 @@ use crate::{
keyboard::Key,
};
pub(crate) use self::event_loop::{
EventLoop, EventLoopProxy, EventLoopWindowTarget, OwnedDisplayHandle,
};
pub(crate) use self::event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy, OwnedDisplayHandle};
mod event_loop;
pub use self::window::Window;
@ -135,7 +133,7 @@ impl DeviceId {
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct PlatformSpecificWindowBuilderAttributes;
pub struct PlatformSpecificWindowAttributes;
struct WindowProperties<'a> {
flags: &'a str,

View file

@ -13,8 +13,7 @@ use crate::{
};
use super::{
EventLoopWindowTarget, MonitorHandle, OsError, RedoxSocket, TimeSocket, WindowId,
WindowProperties,
ActiveEventLoop, MonitorHandle, OsError, RedoxSocket, TimeSocket, WindowId, WindowProperties,
};
// These values match the values uses in the `window_new` function in orbital:
@ -37,7 +36,7 @@ pub struct Window {
impl Window {
pub(crate) fn new(
el: &EventLoopWindowTarget,
el: &ActiveEventLoop,
attrs: window::WindowAttributes,
) -> Result<Self, error::OsError> {
let scale = MonitorHandle.scale_factor();

View file

@ -22,7 +22,7 @@ use web_sys::{
use super::backend::Style;
use super::main_thread::{MainThreadMarker, MainThreadSafe};
use super::r#async::{AbortHandle, Abortable, DropAbortHandle, Notified, Notifier};
use super::EventLoopWindowTarget;
use super::ActiveEventLoop;
use crate::cursor::{BadImage, Cursor, CursorImage, CustomCursor as RootCustomCursor};
use crate::platform::web::CustomCursorError;
@ -75,10 +75,7 @@ impl PartialEq for CustomCursor {
impl Eq for CustomCursor {}
impl CustomCursor {
pub(crate) fn build(
builder: CustomCursorBuilder,
window_target: &EventLoopWindowTarget,
) -> Self {
pub(crate) fn build(builder: CustomCursorBuilder, window_target: &ActiveEventLoop) -> Self {
match builder {
CustomCursorBuilder::Image(image) => Self::build_spawn(
window_target,
@ -110,11 +107,7 @@ impl CustomCursor {
}
}
fn build_spawn<F, S>(
window_target: &EventLoopWindowTarget,
task: F,
animation: bool,
) -> CustomCursor
fn build_spawn<F, S>(window_target: &ActiveEventLoop, task: F, animation: bool) -> CustomCursor
where
F: 'static + Future<Output = Result<S, CustomCursorError>>,
S: Into<ImageState>,
@ -172,7 +165,7 @@ impl CustomCursor {
pub(crate) fn build_async(
builder: CustomCursorBuilder,
window_target: &EventLoopWindowTarget,
window_target: &ActiveEventLoop,
) -> CustomCursorFuture {
let CustomCursor { animation, state } = Self::build(builder, window_target);
let binding = state.get(window_target.runner.main_thread()).borrow();

View file

@ -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
}
}

View file

@ -214,7 +214,7 @@ impl Shared {
// Set the event callback to use for the event loop runner
// This the event callback is a fairly thin layer over the user-provided callback that closes
// over a RootEventLoopWindowTarget reference
// over a RootActiveEventLoop reference
pub fn set_listener(&self, event_handler: Box<EventHandler>) {
{
let mut runner = self.0.runner.borrow_mut();
@ -735,7 +735,7 @@ impl Shared {
// * `self`, i.e. the item which triggered this event loop wakeup, which
// is usually a `wasm-bindgen` `Closure`, which will be dropped after
// returning to the JS glue code.
// * The `EventLoopWindowTarget` leaked inside `EventLoop::run` due to the
// * The `ActiveEventLoop` leaked inside `EventLoop::run` due to the
// JS exception thrown at the end.
// * For each undropped `Window`:
// * The `register_redraw_request` closure.

View file

@ -43,12 +43,12 @@ impl Clone for ModifiersShared {
}
#[derive(Clone)]
pub struct EventLoopWindowTarget {
pub struct ActiveEventLoop {
pub(crate) runner: runner::Shared,
modifiers: ModifiersShared,
}
impl EventLoopWindowTarget {
impl ActiveEventLoop {
pub fn new() -> Self {
Self {
runner: runner::Shared::new(),

View file

@ -12,7 +12,7 @@
// for winit's cross-platform structures. They are all relatively simple translations.
//
// The event_loop module handles listening for and processing events. 'Proxy' implements
// EventLoopProxy and 'WindowTarget' implements EventLoopWindowTarget. WindowTarget also handles
// EventLoopProxy and 'WindowTarget' implements ActiveEventLoop. WindowTarget also handles
// registering the event handlers. The 'Execution' struct in the 'runner' module handles taking
// incoming events (from the registered handlers) and ensuring they are passed to the user in a
// compliant way.
@ -33,11 +33,11 @@ mod backend;
pub use self::device::DeviceId;
pub use self::error::OsError;
pub(crate) use self::event_loop::{
EventLoop, EventLoopProxy, EventLoopWindowTarget, OwnedDisplayHandle,
ActiveEventLoop, EventLoop, EventLoopProxy, OwnedDisplayHandle,
PlatformSpecificEventLoopAttributes,
};
pub use self::monitor::{MonitorHandle, VideoModeHandle};
pub use self::window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId};
pub use self::window::{PlatformSpecificWindowAttributes, Window, WindowId};
pub(crate) use self::keyboard::KeyEventExtra;
pub(crate) use crate::icon::NoIcon as PlatformIcon;

View file

@ -8,7 +8,7 @@ use crate::window::{
use super::main_thread::{MainThreadMarker, MainThreadSafe};
use super::r#async::Dispatcher;
use super::{backend, monitor::MonitorHandle, EventLoopWindowTarget, Fullscreen};
use super::{backend, monitor::MonitorHandle, ActiveEventLoop, Fullscreen};
use web_sys::HtmlCanvasElement;
use std::cell::RefCell;
@ -29,7 +29,7 @@ pub struct Inner {
impl Window {
pub(crate) fn new(
target: &EventLoopWindowTarget,
target: &ActiveEventLoop,
mut attr: WindowAttributes,
) -> Result<Self, RootOE> {
let id = target.generate_id();
@ -466,14 +466,14 @@ impl From<u64> for WindowId {
}
#[derive(Clone, Debug)]
pub struct PlatformSpecificWindowBuilderAttributes {
pub struct PlatformSpecificWindowAttributes {
pub(crate) canvas: Option<Arc<MainThreadSafe<backend::RawCanvasType>>>,
pub(crate) prevent_default: bool,
pub(crate) focusable: bool,
pub(crate) append: bool,
}
impl PlatformSpecificWindowBuilderAttributes {
impl PlatformSpecificWindowAttributes {
pub(crate) fn set_canvas(&mut self, canvas: Option<backend::RawCanvasType>) {
let Some(canvas) = canvas else {
self.canvas = None;
@ -487,7 +487,7 @@ impl PlatformSpecificWindowBuilderAttributes {
}
}
impl Default for PlatformSpecificWindowBuilderAttributes {
impl Default for PlatformSpecificWindowAttributes {
fn default() -> Self {
Self {
canvas: None,

View file

@ -74,7 +74,7 @@ use crate::{
DeviceEvent, Event, Force, Ime, InnerSizeWriter, RawKeyEvent, Touch, TouchPhase,
WindowEvent,
},
event_loop::{ControlFlow, DeviceEvents, EventLoopClosed, EventLoopWindowTarget as RootELW},
event_loop::{ActiveEventLoop as RootAEL, ControlFlow, DeviceEvents, EventLoopClosed},
keyboard::ModifiersState,
platform::pump_events::PumpStatus,
platform_impl::platform::{
@ -156,7 +156,7 @@ pub(crate) enum ProcResult {
pub struct EventLoop<T: 'static> {
user_event_sender: Sender<T>,
user_event_receiver: Receiver<T>,
window_target: RootELW,
window_target: RootAEL,
msg_hook: Option<Box<dyn FnMut(*const c_void) -> bool + 'static>>,
}
@ -176,7 +176,7 @@ impl Default for PlatformSpecificEventLoopAttributes {
}
}
pub struct EventLoopWindowTarget {
pub struct ActiveEventLoop {
thread_id: u32,
thread_msg_target: HWND,
pub(crate) runner_shared: EventLoopRunnerShared<UserEventPlaceholder>,
@ -215,8 +215,8 @@ impl<T: 'static> EventLoop<T> {
Ok(EventLoop {
user_event_sender,
user_event_receiver,
window_target: RootELW {
p: EventLoopWindowTarget {
window_target: RootAEL {
p: ActiveEventLoop {
thread_id,
thread_msg_target,
runner_shared,
@ -227,20 +227,20 @@ impl<T: 'static> EventLoop<T> {
})
}
pub fn window_target(&self) -> &RootELW {
pub fn window_target(&self) -> &RootAEL {
&self.window_target
}
pub fn run<F>(mut self, event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<T>, &RootELW),
F: FnMut(Event<T>, &RootAEL),
{
self.run_on_demand(event_handler)
}
pub fn run_on_demand<F>(&mut self, mut event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<T>, &RootELW),
F: FnMut(Event<T>, &RootAEL),
{
{
let runner = &self.window_target.p.runner_shared;
@ -302,7 +302,7 @@ impl<T: 'static> EventLoop<T> {
pub fn pump_events<F>(&mut self, timeout: Option<Duration>, mut event_handler: F) -> PumpStatus
where
F: FnMut(Event<T>, &RootELW),
F: FnMut(Event<T>, &RootAEL),
{
{
let runner = &self.window_target.p.runner_shared;
@ -522,7 +522,7 @@ impl<T: 'static> EventLoop<T> {
}
}
impl EventLoopWindowTarget {
impl ActiveEventLoop {
#[inline(always)]
pub(crate) fn create_thread_executor(&self) -> EventLoopThreadExecutor {
EventLoopThreadExecutor {

View file

@ -22,7 +22,7 @@ use crate::{
dpi::PhysicalSize,
};
use super::{util, EventLoopWindowTarget};
use super::{util, ActiveEventLoop};
impl Pixel {
fn convert_to_bgra(&mut self) {
@ -237,7 +237,7 @@ impl WinCursor {
}
}
pub(crate) fn build(cursor: OnlyCursorImageBuilder, _: &EventLoopWindowTarget) -> Self {
pub(crate) fn build(cursor: OnlyCursorImageBuilder, _: &ActiveEventLoop) -> Self {
match Self::new(&cursor.0) {
Ok(cursor) => cursor,
Err(err) => {

View file

@ -8,7 +8,7 @@ use windows_sys::Win32::{
pub(crate) use self::{
event_loop::{
EventLoop, EventLoopProxy, EventLoopWindowTarget, OwnedDisplayHandle,
ActiveEventLoop, EventLoop, EventLoopProxy, OwnedDisplayHandle,
PlatformSpecificEventLoopAttributes,
},
icon::{SelectedCursor, WinIcon},
@ -28,7 +28,7 @@ use crate::keyboard::Key;
use crate::platform::windows::{BackdropType, Color, CornerPreference};
#[derive(Clone, Debug)]
pub struct PlatformSpecificWindowBuilderAttributes {
pub struct PlatformSpecificWindowAttributes {
pub owner: Option<HWND>,
pub menu: Option<HMENU>,
pub taskbar_icon: Option<Icon>,
@ -45,7 +45,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
pub corner_preference: Option<CornerPreference>,
}
impl Default for PlatformSpecificWindowBuilderAttributes {
impl Default for PlatformSpecificWindowAttributes {
fn default() -> Self {
Self {
owner: None,
@ -66,8 +66,8 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
}
}
unsafe impl Send for PlatformSpecificWindowBuilderAttributes {}
unsafe impl Sync for PlatformSpecificWindowBuilderAttributes {}
unsafe impl Send for PlatformSpecificWindowAttributes {}
unsafe impl Sync for PlatformSpecificWindowAttributes {}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId(u32);

View file

@ -74,7 +74,7 @@ use crate::{
},
dpi::{dpi_to_scale_factor, enable_non_client_dpi_scaling, hwnd_dpi},
drop_handler::FileDropHandler,
event_loop::{self, EventLoopWindowTarget, DESTROY_MSG_ID},
event_loop::{self, ActiveEventLoop, DESTROY_MSG_ID},
icon::{self, IconType, WinCursor},
ime::ImeContext,
keyboard::KeyEventBuilder,
@ -103,7 +103,7 @@ pub(crate) struct Window {
impl Window {
pub(crate) fn new(
event_loop: &EventLoopWindowTarget,
event_loop: &ActiveEventLoop,
w_attr: WindowAttributes,
) -> Result<Window, RootOsError> {
// We dispatch an `init` function because of code style.
@ -1141,7 +1141,7 @@ impl Drop for Window {
pub(super) struct InitData<'a> {
// inputs
pub event_loop: &'a EventLoopWindowTarget,
pub event_loop: &'a ActiveEventLoop,
pub attributes: WindowAttributes,
pub window_flags: WindowFlags,
// outputs
@ -1339,7 +1339,7 @@ impl<'a> InitData<'a> {
}
unsafe fn init(
attributes: WindowAttributes,
event_loop: &EventLoopWindowTarget,
event_loop: &ActiveEventLoop,
) -> Result<Window, RootOsError> {
let title = util::encode_wide(&attributes.title);

View file

@ -3,10 +3,9 @@ use std::fmt;
use crate::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
error::{ExternalError, NotSupportedError, OsError},
event_loop::EventLoopWindowTarget,
error::{ExternalError, NotSupportedError},
monitor::{MonitorHandle, VideoModeHandle},
platform_impl::{self, PlatformSpecificWindowBuilderAttributes},
platform_impl::{self, PlatformSpecificWindowAttributes},
};
pub use crate::cursor::{BadImage, Cursor, CustomCursor, CustomCursorBuilder, MAX_CURSOR_SIZE};
@ -42,14 +41,21 @@ use serde::{Deserialize, Serialize};
///
/// let mut event_loop = EventLoop::new().unwrap();
/// event_loop.set_control_flow(ControlFlow::Wait);
/// let window = Window::new(&event_loop).unwrap();
/// let mut windows = Vec::new();
///
/// event_loop.run(move |event, elwt| {
/// event_loop.run(move |event, event_loop| {
/// match event {
/// Event::Resumed => {
/// let window = event_loop.create_window(Window::default_attributes()).unwrap();
/// windows.push(window);
/// }
/// Event::WindowEvent {
/// event: WindowEvent::CloseRequested,
/// ..
/// } => elwt.exit(),
/// } => {
/// windows.clear();
/// event_loop.exit();
/// }
/// _ => (),
/// }
/// });
@ -123,24 +129,6 @@ impl From<u64> for WindowId {
}
}
/// Configure windows before creation.
///
/// You can access this from [`Window::builder`].
#[derive(Clone, Default)]
#[must_use]
pub struct WindowBuilder {
/// The attributes to use to create the window.
pub(crate) window: WindowAttributes,
}
impl fmt::Debug for WindowBuilder {
fn fmt(&self, fmtr: &mut fmt::Formatter<'_>) -> fmt::Result {
fmtr.debug_struct("WindowBuilder")
.field("window", &self.window)
.finish()
}
}
/// Attributes used when creating a window.
#[derive(Debug, Clone)]
pub struct WindowAttributes {
@ -168,7 +156,7 @@ pub struct WindowAttributes {
pub fullscreen: Option<Fullscreen>,
// Platform-specific configuration.
#[allow(dead_code)]
pub(crate) platform_specific: PlatformSpecificWindowBuilderAttributes,
pub(crate) platform_specific: PlatformSpecificWindowAttributes,
}
impl Default for WindowAttributes {
@ -206,7 +194,7 @@ impl Default for WindowAttributes {
///
/// # Safety
///
/// The user has to account for that when using [`WindowBuilder::with_parent_window()`],
/// The user has to account for that when using [`WindowAttributes::with_parent_window()`],
/// which is `unsafe`.
#[derive(Debug, Clone)]
#[cfg(feature = "rwh_06")]
@ -218,26 +206,19 @@ unsafe impl Send for SendSyncRawWindowHandle {}
unsafe impl Sync for SendSyncRawWindowHandle {}
impl WindowAttributes {
/// Get the parent window stored on the attributes.
#[cfg(feature = "rwh_06")]
pub fn parent_window(&self) -> Option<&rwh_06::RawWindowHandle> {
self.parent_window.as_ref().map(|handle| &handle.0)
}
}
impl WindowBuilder {
/// Initializes a new builder with default values.
/// Initializes new attributes with default values.
#[inline]
#[deprecated = "use `Window::builder` instead"]
#[deprecated = "use `Window::default_attributes` instead"]
pub fn new() -> Self {
Default::default()
}
}
impl WindowBuilder {
/// Get the current window attributes.
pub fn window_attributes(&self) -> &WindowAttributes {
&self.window
impl WindowAttributes {
/// Get the parent window stored on the attributes.
#[cfg(feature = "rwh_06")]
pub fn parent_window(&self) -> Option<&rwh_06::RawWindowHandle> {
self.parent_window.as_ref().map(|handle| &handle.0)
}
/// Requests the window to be of specific dimensions.
@ -247,7 +228,7 @@ impl WindowBuilder {
/// See [`Window::request_inner_size`] for details.
#[inline]
pub fn with_inner_size<S: Into<Size>>(mut self, size: S) -> Self {
self.window.inner_size = Some(size.into());
self.inner_size = Some(size.into());
self
}
@ -259,7 +240,7 @@ impl WindowBuilder {
/// See [`Window::set_min_inner_size`] for details.
#[inline]
pub fn with_min_inner_size<S: Into<Size>>(mut self, min_size: S) -> Self {
self.window.min_inner_size = Some(min_size.into());
self.min_inner_size = Some(min_size.into());
self
}
@ -271,7 +252,7 @@ impl WindowBuilder {
/// See [`Window::set_max_inner_size`] for details.
#[inline]
pub fn with_max_inner_size<S: Into<Size>>(mut self, max_size: S) -> Self {
self.window.max_inner_size = Some(max_size.into());
self.max_inner_size = Some(max_size.into());
self
}
@ -299,7 +280,7 @@ impl WindowBuilder {
/// - **Others:** Ignored.
#[inline]
pub fn with_position<P: Into<Position>>(mut self, position: P) -> Self {
self.window.position = Some(position.into());
self.position = Some(position.into());
self
}
@ -310,7 +291,7 @@ impl WindowBuilder {
/// See [`Window::set_resizable`] for details.
#[inline]
pub fn with_resizable(mut self, resizable: bool) -> Self {
self.window.resizable = resizable;
self.resizable = resizable;
self
}
@ -321,7 +302,7 @@ impl WindowBuilder {
/// See [`Window::set_enabled_buttons`] for details.
#[inline]
pub fn with_enabled_buttons(mut self, buttons: WindowButtons) -> Self {
self.window.enabled_buttons = buttons;
self.enabled_buttons = buttons;
self
}
@ -332,7 +313,7 @@ impl WindowBuilder {
/// See [`Window::set_title`] for details.
#[inline]
pub fn with_title<T: Into<String>>(mut self, title: T) -> Self {
self.window.title = title.into();
self.title = title.into();
self
}
@ -343,7 +324,7 @@ impl WindowBuilder {
/// See [`Window::set_fullscreen`] for details.
#[inline]
pub fn with_fullscreen(mut self, fullscreen: Option<Fullscreen>) -> Self {
self.window.fullscreen = fullscreen;
self.fullscreen = fullscreen;
self
}
@ -354,7 +335,7 @@ impl WindowBuilder {
/// See [`Window::set_maximized`] for details.
#[inline]
pub fn with_maximized(mut self, maximized: bool) -> Self {
self.window.maximized = maximized;
self.maximized = maximized;
self
}
@ -365,7 +346,7 @@ impl WindowBuilder {
/// See [`Window::set_visible`] for details.
#[inline]
pub fn with_visible(mut self, visible: bool) -> Self {
self.window.visible = visible;
self.visible = visible;
self
}
@ -379,7 +360,7 @@ impl WindowBuilder {
/// The default is `false`.
#[inline]
pub fn with_transparent(mut self, transparent: bool) -> Self {
self.window.transparent = transparent;
self.transparent = transparent;
self
}
@ -390,14 +371,14 @@ impl WindowBuilder {
/// See [`Window::set_blur`] for details.
#[inline]
pub fn with_blur(mut self, blur: bool) -> Self {
self.window.blur = blur;
self.blur = blur;
self
}
/// Get whether the window will support transparency.
#[inline]
pub fn transparent(&self) -> bool {
self.window.transparent
self.transparent
}
/// Sets whether the window should have a border, a title bar, etc.
@ -407,7 +388,7 @@ impl WindowBuilder {
/// See [`Window::set_decorations`] for details.
#[inline]
pub fn with_decorations(mut self, decorations: bool) -> Self {
self.window.decorations = decorations;
self.decorations = decorations;
self
}
@ -420,7 +401,7 @@ impl WindowBuilder {
/// See [`WindowLevel`] for details.
#[inline]
pub fn with_window_level(mut self, level: WindowLevel) -> Self {
self.window.window_level = level;
self.window_level = level;
self
}
@ -431,7 +412,7 @@ impl WindowBuilder {
/// See [`Window::set_window_icon`] for details.
#[inline]
pub fn with_window_icon(mut self, window_icon: Option<Icon>) -> Self {
self.window.window_icon = window_icon;
self.window_icon = window_icon;
self
}
@ -450,7 +431,7 @@ impl WindowBuilder {
/// - **iOS / Android / Web / x11 / Orbital:** Ignored.
#[inline]
pub fn with_theme(mut self, theme: Option<Theme>) -> Self {
self.window.preferred_theme = theme;
self.preferred_theme = theme;
self
}
@ -461,7 +442,7 @@ impl WindowBuilder {
/// See [`Window::set_resize_increments`] for details.
#[inline]
pub fn with_resize_increments<S: Into<Size>>(mut self, resize_increments: S) -> Self {
self.window.resize_increments = Some(resize_increments.into());
self.resize_increments = Some(resize_increments.into());
self
}
@ -478,7 +459,7 @@ impl WindowBuilder {
/// [`NSWindowSharingNone`]: https://developer.apple.com/documentation/appkit/nswindowsharingtype/nswindowsharingnone
#[inline]
pub fn with_content_protected(mut self, protected: bool) -> Self {
self.window.content_protected = protected;
self.content_protected = protected;
self
}
@ -494,7 +475,7 @@ impl WindowBuilder {
/// [`WindowEvent::Focused`]: crate::event::WindowEvent::Focused.
#[inline]
pub fn with_active(mut self, active: bool) -> Self {
self.window.active = active;
self.active = active;
self
}
@ -505,7 +486,7 @@ impl WindowBuilder {
/// See [`Window::set_cursor()`] for more details.
#[inline]
pub fn with_cursor(mut self, cursor: impl Into<Cursor>) -> Self {
self.window.cursor = cursor.into();
self.cursor = cursor.into();
self
}
@ -530,50 +511,18 @@ impl WindowBuilder {
mut self,
parent_window: Option<rwh_06::RawWindowHandle>,
) -> Self {
self.window.parent_window = parent_window.map(SendSyncRawWindowHandle);
self.parent_window = parent_window.map(SendSyncRawWindowHandle);
self
}
/// Builds the window.
///
/// Possible causes of error include denied permission, incompatible system, and lack of memory.
///
/// ## Platform-specific
///
/// - **Web:** The window is created but not inserted into the web page automatically. Please
/// see the web platform module for more information.
#[inline]
pub fn build(self, window_target: &EventLoopWindowTarget) -> Result<Window, OsError> {
let window = platform_impl::Window::new(&window_target.p, self.window)?;
window.maybe_queue_on_main(|w| w.request_redraw());
Ok(Window { window })
}
}
/// Base Window functions.
impl Window {
/// Creates a new Window for platforms where this is appropriate.
///
/// This function is equivalent to [`Window::builder().build(event_loop)`].
///
/// Error should be very rare and only occur in case of permission denied, incompatible system,
/// out of memory, etc.
///
/// ## Platform-specific
///
/// - **Web:** The window is created but not inserted into the web page automatically. Please
/// see the web platform module for more information.
///
/// [`Window::builder().build(event_loop)`]: WindowBuilder::build
/// Create a new [`WindowAttributes`] which allows modifying the window's attributes before
/// creation.
#[inline]
pub fn new(event_loop: &EventLoopWindowTarget) -> Result<Window, OsError> {
Window::builder().build(event_loop)
}
/// Create a new [`WindowBuilder`] which allows modifying the window's attributes before creation.
#[inline]
pub fn builder() -> WindowBuilder {
WindowBuilder::default()
pub fn default_attributes() -> WindowAttributes {
WindowAttributes::default()
}
/// Returns an identifier unique to the window.
@ -652,11 +601,9 @@ impl Window {
/// APIs and software rendering.
///
/// ```no_run
/// # use winit::event_loop::EventLoop;
/// # use winit::window::Window;
/// # let mut event_loop = EventLoop::new().unwrap();
/// # let window = Window::new(&event_loop).unwrap();
/// # fn swap_buffers() {}
/// # fn scope(window: &Window) {
/// // Do the actual drawing with OpenGL.
///
/// // Notify winit that we're about to submit buffer to the windowing system.
@ -664,6 +611,7 @@ impl Window {
///
/// // Submit buffer to the windowing system.
/// swap_buffers();
/// # }
/// ```
///
/// ## Platform-specific
@ -742,15 +690,14 @@ impl Window {
///
/// ```no_run
/// # use winit::dpi::{LogicalPosition, PhysicalPosition};
/// # use winit::event_loop::EventLoop;
/// # use winit::window::Window;
/// # let mut event_loop = EventLoop::new().unwrap();
/// # let window = Window::new(&event_loop).unwrap();
/// # fn scope(window: &Window) {
/// // Specify the position in logical dimensions like this:
/// window.set_outer_position(LogicalPosition::new(400.0, 200.0));
///
/// // Or specify the position in physical dimensions like this:
/// window.set_outer_position(PhysicalPosition::new(400, 200));
/// # }
/// ```
///
/// ## Platform-specific
@ -804,15 +751,14 @@ impl Window {
///
/// ```no_run
/// # use winit::dpi::{LogicalSize, PhysicalSize};
/// # use winit::event_loop::EventLoop;
/// # use winit::window::Window;
/// # let mut event_loop = EventLoop::new().unwrap();
/// # let window = Window::new(&event_loop).unwrap();
/// # fn scope(window: &Window) {
/// // Specify the size in logical dimensions like this:
/// let _ = window.request_inner_size(LogicalSize::new(400.0, 200.0));
///
/// // Or specify the size in physical dimensions like this:
/// let _ = window.request_inner_size(PhysicalSize::new(400, 200));
/// # }
/// ```
///
/// ## Platform-specific
@ -849,15 +795,14 @@ impl Window {
///
/// ```no_run
/// # use winit::dpi::{LogicalSize, PhysicalSize};
/// # use winit::event_loop::EventLoop;
/// # use winit::window::Window;
/// # let mut event_loop = EventLoop::new().unwrap();
/// # let window = Window::new(&event_loop).unwrap();
/// # fn scope(window: &Window) {
/// // Specify the size in logical dimensions like this:
/// window.set_min_inner_size(Some(LogicalSize::new(400.0, 200.0)));
///
/// // Or specify the size in physical dimensions like this:
/// window.set_min_inner_size(Some(PhysicalSize::new(400, 200)));
/// # }
/// ```
///
/// ## Platform-specific
@ -874,15 +819,14 @@ impl Window {
///
/// ```no_run
/// # use winit::dpi::{LogicalSize, PhysicalSize};
/// # use winit::event_loop::EventLoop;
/// # use winit::window::Window;
/// # let mut event_loop = EventLoop::new().unwrap();
/// # let window = Window::new(&event_loop).unwrap();
/// # fn scope(window: &Window) {
/// // Specify the size in logical dimensions like this:
/// window.set_max_inner_size(Some(LogicalSize::new(400.0, 200.0)));
///
/// // Or specify the size in physical dimensions like this:
/// window.set_max_inner_size(Some(PhysicalSize::new(400, 200)));
/// # }
/// ```
///
/// ## Platform-specific
@ -942,12 +886,12 @@ impl Window {
/// the content of your window and this hint may result in
/// visual artifacts.
///
/// The default value follows the [`WindowBuilder::with_transparent`].
/// The default value follows the [`WindowAttributes::with_transparent`].
///
/// ## Platform-specific
///
/// - **Web / iOS / Android:** Unsupported.
/// - **X11:** Can only be set while building the window, with [`WindowBuilder::with_transparent`].
/// - **X11:** Can only be set while building the window, with [`WindowAttributes::with_transparent`].
#[inline]
pub fn set_transparent(&self, transparent: bool) {
self.window
@ -1214,15 +1158,14 @@ impl Window {
///
/// ```no_run
/// # use winit::dpi::{LogicalPosition, PhysicalPosition, LogicalSize, PhysicalSize};
/// # use winit::event_loop::EventLoop;
/// # use winit::window::Window;
/// # let mut event_loop = EventLoop::new().unwrap();
/// # let window = Window::new(&event_loop).unwrap();
/// # fn scope(window: &Window) {
/// // Specify the position in logical dimensions like this:
/// window.set_ime_cursor_area(LogicalPosition::new(400.0, 200.0), LogicalSize::new(100, 100));
///
/// // Or specify the position in physical dimensions like this:
/// window.set_ime_cursor_area(PhysicalPosition::new(400, 200), PhysicalSize::new(100, 100));
/// # }
/// ```
///
/// ## Platform-specific
@ -1398,15 +1341,14 @@ impl Window {
///
/// ```no_run
/// # use winit::dpi::{LogicalPosition, PhysicalPosition};
/// # use winit::event_loop::EventLoop;
/// # use winit::window::Window;
/// # let mut event_loop = EventLoop::new().unwrap();
/// # let window = Window::new(&event_loop).unwrap();
/// # fn scope(window: &Window) {
/// // Specify the position in logical dimensions like this:
/// window.set_cursor_position(LogicalPosition::new(400.0, 200.0));
///
/// // Or specify the position in physical dimensions like this:
/// window.set_cursor_position(PhysicalPosition::new(400, 200));
/// # }
/// ```
///
/// ## Platform-specific
@ -1426,13 +1368,12 @@ impl Window {
/// First try confining the cursor, and if that fails, try locking it instead.
///
/// ```no_run
/// # use winit::event_loop::EventLoop;
/// # use winit::window::{CursorGrabMode, Window};
/// # let mut event_loop = EventLoop::new().unwrap();
/// # let window = Window::new(&event_loop).unwrap();
/// # fn scope(window: &Window) {
/// window.set_cursor_grab(CursorGrabMode::Confined)
/// .or_else(|_e| window.set_cursor_grab(CursorGrabMode::Locked))
/// .unwrap();
/// # }
/// ```
#[inline]
pub fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), ExternalError> {
@ -1531,9 +1472,9 @@ impl Window {
/// Returns the list of all the monitors available on the system.
///
/// This is the same as [`EventLoopWindowTarget::available_monitors`], and is provided for convenience.
/// This is the same as [`ActiveEventLoop::available_monitors`], and is provided for convenience.
///
/// [`EventLoopWindowTarget::available_monitors`]: crate::event_loop::EventLoopWindowTarget::available_monitors
/// [`ActiveEventLoop::available_monitors`]: crate::event_loop::ActiveEventLoop::available_monitors
#[inline]
pub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle> {
self.window.maybe_wait_on_main(|w| {
@ -1547,13 +1488,13 @@ impl Window {
///
/// Returns `None` if it can't identify any monitor as a primary one.
///
/// This is the same as [`EventLoopWindowTarget::primary_monitor`], and is provided for convenience.
/// This is the same as [`ActiveEventLoop::primary_monitor`], and is provided for convenience.
///
/// ## Platform-specific
///
/// **Wayland / Web:** Always returns `None`.
///
/// [`EventLoopWindowTarget::primary_monitor`]: crate::event_loop::EventLoopWindowTarget::primary_monitor
/// [`ActiveEventLoop::primary_monitor`]: crate::event_loop::ActiveEventLoop::primary_monitor
#[inline]
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
self.window