diff --git a/examples/custom_cursors.rs b/examples/custom_cursors.rs index 4c47f362d7..e3c6ffe415 100644 --- a/examples/custom_cursors.rs +++ b/examples/custom_cursors.rs @@ -36,7 +36,7 @@ fn main() -> Result<(), impl std::error::Error> { let builder = WindowBuilder::new().with_title("A fantastic window!"); #[cfg(wasm_platform)] let builder = { - use winit::platform::web::WindowBuilderExtWebSys; + use winit::platform::web::WindowAttributesExtWebSys; builder.with_append(true) }; let window = builder.build(&event_loop).unwrap(); diff --git a/examples/startup_notification.rs b/examples/startup_notification.rs index 0cbf4d3652..9fb0c9ef2b 100644 --- a/examples/startup_notification.rs +++ b/examples/startup_notification.rs @@ -12,7 +12,7 @@ mod example { use winit::event::{ElementState, Event, KeyEvent, WindowEvent}; use winit::event_loop::EventLoop; use winit::platform::startup_notify::{ - EventLoopExtStartupNotify, WindowBuilderExtStartupNotify, WindowExtStartupNotify, + EventLoopExtStartupNotify, WindowAttributesExtStartupNotify, WindowExtStartupNotify, }; use winit::window::{Window, WindowBuilder, WindowId}; diff --git a/examples/web.rs b/examples/web.rs index febc903a38..7911f6117c 100644 --- a/examples/web.rs +++ b/examples/web.rs @@ -13,7 +13,7 @@ pub fn main() -> Result<(), impl std::error::Error> { let builder = WindowBuilder::new().with_title("A fantastic window!"); #[cfg(wasm_platform)] let builder = { - use winit::platform::web::WindowBuilderExtWebSys; + use winit::platform::web::WindowAttributesExtWebSys; builder.with_append(true) }; let window = builder.build(&event_loop).unwrap(); diff --git a/examples/web_aspect_ratio.rs b/examples/web_aspect_ratio.rs index 38bbc5550c..38bdd36d95 100644 --- a/examples/web_aspect_ratio.rs +++ b/examples/web_aspect_ratio.rs @@ -13,7 +13,7 @@ mod wasm { dpi::PhysicalSize, event::{Event, WindowEvent}, event_loop::EventLoop, - platform::web::WindowBuilderExtWebSys, + platform::web::WindowAttributesExtWebSys, window::{Window, WindowBuilder}, }; diff --git a/examples/window_tabbing.rs b/examples/window_tabbing.rs index 9413ae9a39..278771d79d 100644 --- a/examples/window_tabbing.rs +++ b/examples/window_tabbing.rs @@ -10,7 +10,7 @@ use winit::{ event::{ElementState, Event, KeyEvent, WindowEvent}, event_loop::EventLoop, keyboard::{Key, NamedKey}, - platform::macos::{WindowBuilderExtMacOS, WindowExtMacOS}, + platform::macos::{WindowAttributesExtMacOS, WindowExtMacOS}, window::{Window, WindowBuilder}, }; diff --git a/examples/x11_embed.rs b/examples/x11_embed.rs index e66482eba3..7db45a4454 100644 --- a/examples/x11_embed.rs +++ b/examples/x11_embed.rs @@ -11,7 +11,7 @@ mod imple { use winit::{ event::{Event, WindowEvent}, event_loop::EventLoop, - platform::x11::WindowBuilderExtX11, + platform::x11::WindowAttributesExtX11, window::WindowBuilder, }; diff --git a/src/platform/android.rs b/src/platform/android.rs index b5fde4ad49..06aaf468f7 100644 --- a/src/platform/android.rs +++ b/src/platform/android.rs @@ -1,6 +1,6 @@ use crate::{ event_loop::{EventLoop, EventLoopBuilder, EventLoopWindowTarget}, - window::{Window, WindowBuilder}, + window::Window, }; use android_activity::{AndroidApp, ConfigurationRef, Rect}; @@ -32,11 +32,6 @@ impl WindowExtAndroid for Window { impl EventLoopWindowTargetExtAndroid for EventLoopWindowTarget {} -/// Additional methods on [`WindowBuilder`] that are specific to Android. -pub trait WindowBuilderExtAndroid {} - -impl WindowBuilderExtAndroid for WindowBuilder {} - pub trait EventLoopBuilderExtAndroid { /// Associates the `AndroidApp` that was passed to `android_main()` with the event loop /// diff --git a/src/platform/ios.rs b/src/platform/ios.rs index 2cb0704450..6fd9076789 100644 --- a/src/platform/ios.rs +++ b/src/platform/ios.rs @@ -6,7 +6,7 @@ use objc2::rc::Id; use crate::{ event_loop::EventLoop, monitor::{MonitorHandle, VideoModeHandle}, - window::{Window, WindowBuilder}, + window::{Window, WindowAttributes}, }; /// Additional methods on [`EventLoop`] that are specific to iOS. @@ -129,8 +129,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 @@ -184,7 +184,7 @@ 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.platform_specific.scale_factor = Some(scale_factor); diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 8a069611af..fd97cbf662 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use crate::{ event_loop::{EventLoopBuilder, EventLoopWindowTarget}, monitor::MonitorHandle, - window::{Window, WindowBuilder}, + window::{Window, WindowAttributes}, }; /// Additional methods on [`Window`] that are specific to MacOS. @@ -176,15 +176,16 @@ 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. @@ -211,7 +212,7 @@ 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.platform_specific.movable_by_window_background = movable_by_window_background; diff --git a/src/platform/startup_notify.rs b/src/platform/startup_notify.rs index 323c2fe624..865baab554 100644 --- a/src/platform/startup_notify.rs +++ b/src/platform/startup_notify.rs @@ -25,7 +25,7 @@ use std::env; use crate::error::NotSupportedError; use crate::event_loop::{AsyncRequestSerial, EventLoopWindowTarget}; -use crate::window::{ActivationToken, Window, WindowBuilder}; +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; } -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 @@ -74,7 +74,7 @@ impl WindowExtStartupNotify for Window { } } -impl WindowBuilderExtStartupNotify for WindowBuilder { +impl WindowAttributesExtStartupNotify for WindowAttributes { fn with_activation_token(mut self, token: ActivationToken) -> Self { self.platform_specific.activation_token = Some(token); self diff --git a/src/platform/wayland.rs b/src/platform/wayland.rs index ba87651858..b6bf141ac2 100644 --- a/src/platform/wayland.rs +++ b/src/platform/wayland.rs @@ -1,7 +1,7 @@ use crate::{ event_loop::{EventLoopBuilder, EventLoopWindowTarget}, monitor::MonitorHandle, - window::{Window, WindowBuilder}, + window::{Window, WindowAttributes}, }; use crate::platform_impl::{ApplicationName, Backend}; @@ -52,8 +52,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` @@ -64,7 +64,7 @@ pub trait WindowBuilderExtWayland { fn with_name(self, general: impl Into, instance: impl Into) -> Self; } -impl WindowBuilderExtWayland for WindowBuilder { +impl WindowAttributesExtWayland for WindowAttributes { #[inline] fn with_name(mut self, general: impl Into, instance: impl Into) -> Self { self.platform_specific.name = Some(ApplicationName::new(general.into(), instance.into())); diff --git a/src/platform/web.rs b/src/platform/web.rs index baab78cfab..036a807c5c 100644 --- a/src/platform/web.rs +++ b/src/platform/web.rs @@ -33,7 +33,7 @@ use crate::event_loop::EventLoop; use crate::event_loop::EventLoopWindowTarget; use crate::platform_impl::PlatformCustomCursorBuilder; use crate::window::CustomCursor; -use crate::window::{Window, WindowBuilder}; +use crate::window::{Window, WindowAttributes}; use web_sys::HtmlCanvasElement; @@ -73,7 +73,7 @@ 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. /// @@ -102,7 +102,7 @@ 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) -> Self { self.platform_specific.set_canvas(canvas); self diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 8e10157944..a19d1cea00 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -8,7 +8,7 @@ use crate::{ monitor::MonitorHandle, platform::modifier_supplement::KeyEventExtModifierSupplement, platform_impl::WinIcon, - window::{BadIcon, Icon, Window, WindowBuilder}, + window::{BadIcon, Icon, Window, WindowAttributes}, }; /// Window Handle type used by Win32 API @@ -160,9 +160,9 @@ 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`. /// Can be used in combination with [`WindowExtWindows::set_enable(false)`](WindowExtWindows::set_enable) @@ -215,7 +215,7 @@ pub trait WindowBuilderExtWindows { fn with_undecorated_shadow(self, shadow: bool) -> Self; } -impl WindowBuilderExtWindows for WindowBuilder { +impl WindowAttributesExtWindows for WindowAttributes { #[inline] fn with_owner_window(mut self, parent: HWND) -> Self { self.platform_specific.owner = Some(parent); diff --git a/src/platform/x11.rs b/src/platform/x11.rs index 5cbd2fe32a..19e68b2583 100644 --- a/src/platform/x11.rs +++ b/src/platform/x11.rs @@ -1,7 +1,7 @@ use crate::{ event_loop::{EventLoopBuilder, EventLoopWindowTarget}, monitor::MonitorHandle, - window::{Window, WindowBuilder}, + window::{Window, WindowAttributes}, }; use crate::dpi::Size; @@ -86,8 +86,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; @@ -140,7 +140,7 @@ pub trait WindowBuilderExtX11 { 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.platform_specific.x11.visual_id = Some(visual_id); diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 450138f276..4463e5a2ba 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -766,7 +766,6 @@ impl Window { pub(crate) fn new( el: &EventLoopWindowTarget, _window_attrs: window::WindowAttributes, - _: PlatformSpecificWindowBuilderAttributes, ) -> Result { // FIXME this ignores requested window attributes diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 5a93ad781c..2f136a1b26 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -21,7 +21,6 @@ use crate::{ platform::ios::ValidOrientations, platform_impl::platform::{ ffi::{UIRectEdge, UIUserInterfaceIdiom}, - window::PlatformSpecificWindowBuilderAttributes, DeviceId, Fullscreen, }, window::{WindowAttributes, WindowId as RootWindowId}, @@ -182,15 +181,14 @@ extern_methods!( impl WinitView { pub(crate) fn new( _mtm: MainThreadMarker, - _window_attributes: &WindowAttributes, - platform_attributes: &PlatformSpecificWindowBuilderAttributes, + window_attributes: &WindowAttributes, frame: CGRect, ) -> Id { let this: Id = unsafe { msg_send_id![Self::alloc(), initWithFrame: frame] }; this.setMultipleTouchEnabled(true); - if let Some(scale_factor) = platform_attributes.scale_factor { + if let Some(scale_factor) = window_attributes.platform_specific.scale_factor { this.setContentScaleFactor(scale_factor as _); } @@ -385,8 +383,7 @@ impl WinitViewController { pub(crate) fn new( mtm: MainThreadMarker, - _window_attributes: &WindowAttributes, - platform_attributes: &PlatformSpecificWindowBuilderAttributes, + window_attributes: &WindowAttributes, view: &UIView, ) -> Id { // These are set properly below, we just to set them to something in the meantime. @@ -399,18 +396,33 @@ impl WinitViewController { }); let this: Id = unsafe { msg_send_id![super(this), init] }; - this.set_prefers_status_bar_hidden(platform_attributes.prefers_status_bar_hidden); + this.set_prefers_status_bar_hidden( + window_attributes + .platform_specific + .prefers_status_bar_hidden, + ); - this.set_preferred_status_bar_style(platform_attributes.preferred_status_bar_style.into()); + this.set_preferred_status_bar_style( + window_attributes + .platform_specific + .preferred_status_bar_style + .into(), + ); - this.set_supported_interface_orientations(mtm, platform_attributes.valid_orientations); + this.set_supported_interface_orientations( + mtm, + window_attributes.platform_specific.valid_orientations, + ); this.set_prefers_home_indicator_auto_hidden( - platform_attributes.prefers_home_indicator_hidden, + window_attributes + .platform_specific + .prefers_home_indicator_hidden, ); this.set_preferred_screen_edges_deferring_system_gestures( - platform_attributes + window_attributes + .platform_specific .preferred_screen_edges_deferring_system_gestures .into(), ); @@ -467,7 +479,6 @@ impl WinitUIWindow { pub(crate) fn new( mtm: MainThreadMarker, window_attributes: &WindowAttributes, - _platform_attributes: &PlatformSpecificWindowBuilderAttributes, frame: CGRect, view_controller: &UIViewController, ) -> Id { diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index 6e3f1550ea..1e763b8d7f 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -401,7 +401,6 @@ impl Window { pub(crate) fn new( event_loop: &EventLoopWindowTarget, window_attributes: WindowAttributes, - platform_attributes: PlatformSpecificWindowBuilderAttributes, ) -> Result { let mtm = event_loop.mtm; @@ -439,7 +438,7 @@ impl Window { None => screen_bounds, }; - let view = WinitView::new(mtm, &window_attributes, &platform_attributes, frame); + let view = WinitView::new(mtm, &window_attributes, frame); let gl_or_metal_backed = unsafe { let layer_class = WinitView::layerClass(); @@ -448,15 +447,8 @@ impl Window { is_metal || is_gl }; - let view_controller = - WinitViewController::new(mtm, &window_attributes, &platform_attributes, &view); - let window = WinitUIWindow::new( - mtm, - &window_attributes, - &platform_attributes, - frame, - &view_controller, - ); + let view_controller = WinitViewController::new(mtm, &window_attributes, &view); + let window = WinitUIWindow::new(mtm, &window_attributes, frame, &view_controller); app_state::set_key_window(mtm, &window); @@ -673,7 +665,7 @@ impl From<&AnyObject> for WindowId { } } -#[derive(Clone, Default)] +#[derive(Clone, Debug, Default)] pub struct PlatformSpecificWindowBuilderAttributes { pub scale_factor: Option, pub valid_orientations: ValidOrientations, diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 6a68fab08a..0ee54fc420 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -77,7 +77,7 @@ impl ApplicationName { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct PlatformSpecificWindowBuilderAttributes { pub name: Option, pub activation_token: Option, @@ -85,7 +85,7 @@ pub struct PlatformSpecificWindowBuilderAttributes { pub x11: X11WindowBuilderAttributes, } -#[derive(Clone)] +#[derive(Clone, Debug)] #[cfg(x11_platform)] pub struct X11WindowBuilderAttributes { pub visual_id: Option, @@ -294,16 +294,15 @@ impl Window { pub(crate) fn new( window_target: &EventLoopWindowTarget, attribs: WindowAttributes, - pl_attribs: PlatformSpecificWindowBuilderAttributes, ) -> Result { match *window_target { #[cfg(wayland_platform)] EventLoopWindowTarget::Wayland(ref window_target) => { - wayland::Window::new(window_target, attribs, pl_attribs).map(Window::Wayland) + wayland::Window::new(window_target, attribs).map(Window::Wayland) } #[cfg(x11_platform)] EventLoopWindowTarget::X(ref window_target) => { - x11::Window::new(window_target, attribs, pl_attribs).map(Window::X) + x11::Window::new(window_target, attribs).map(Window::X) } } } diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index 5f88b9f430..bc777f81b9 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -23,7 +23,6 @@ use crate::event::{Ime, WindowEvent}; use crate::event_loop::AsyncRequestSerial; use crate::platform_impl::{ Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError, PlatformIcon, - PlatformSpecificWindowBuilderAttributes as PlatformAttributes, }; use crate::window::{ Cursor, CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, @@ -84,7 +83,6 @@ impl Window { pub(crate) fn new( event_loop_window_target: &EventLoopWindowTarget, attributes: WindowAttributes, - platform_attributes: PlatformAttributes, ) -> Result { let queue_handle = event_loop_window_target.queue_handle.clone(); let mut state = event_loop_window_target.state.borrow_mut(); @@ -134,7 +132,7 @@ impl Window { window_state.set_decorate(attributes.decorations); // Set the app_id. - if let Some(name) = platform_attributes.name.map(|name| name.general) { + if let Some(name) = attributes.platform_specific.name.map(|name| name.general) { window.set_app_id(name); } @@ -177,7 +175,7 @@ impl Window { // Activate the window when the token is passed. if let (Some(xdg_activation), Some(token)) = ( xdg_activation.as_ref(), - platform_attributes.activation_token, + attributes.platform_specific.activation_token, ) { xdg_activation.activate(token._token, &surface); } diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 0efef5adfd..c4a31eb039 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -72,10 +72,7 @@ use crate::{ event::{Event, StartCause, WindowEvent}, event_loop::{DeviceEvents, EventLoopClosed, EventLoopWindowTarget as RootELW}, platform::pump_events::PumpStatus, - platform_impl::{ - platform::{min_timeout, WindowId}, - PlatformSpecificWindowBuilderAttributes, - }, + platform_impl::platform::{min_timeout, WindowId}, window::WindowAttributes, }; @@ -842,9 +839,8 @@ impl Window { pub(crate) fn new( event_loop: &EventLoopWindowTarget, attribs: WindowAttributes, - pl_attribs: PlatformSpecificWindowBuilderAttributes, ) -> Result { - let window = Arc::new(UnownedWindow::new(event_loop, attribs, pl_attribs)?); + let window = Arc::new(UnownedWindow::new(event_loop, attribs)?); event_loop .windows .borrow_mut() diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 11c18d0986..5986ba5f3e 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -32,7 +32,7 @@ use crate::{ X11Error, }, Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError, PlatformIcon, - PlatformSpecificWindowBuilderAttributes, VideoModeHandle as PlatformVideoModeHandle, + VideoModeHandle as PlatformVideoModeHandle, }, window::{ CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes, @@ -154,7 +154,6 @@ impl UnownedWindow { pub(crate) fn new( event_loop: &EventLoopWindowTarget, window_attrs: WindowAttributes, - pl_attribs: PlatformSpecificWindowBuilderAttributes, ) -> Result { let xconn = &event_loop.xconn; let atoms = xconn.atoms(); @@ -227,7 +226,7 @@ impl UnownedWindow { dimensions }; - let screen_id = match pl_attribs.x11.screen_id { + let screen_id = match window_attrs.platform_specific.x11.screen_id { Some(id) => id, None => xconn.default_screen_index() as c_int, }; @@ -247,7 +246,11 @@ impl UnownedWindow { }); // creating - let (visualtype, depth, require_colormap) = match pl_attribs.x11.visual_id { + let (visualtype, depth, require_colormap) = match window_attrs + .platform_specific + .x11 + .visual_id + { Some(vi) => { // Find this specific visual. let (visualtype, depth) = all_visuals @@ -289,12 +292,12 @@ impl UnownedWindow { aux = aux.event_mask(event_mask).border_pixel(0); - if pl_attribs.x11.override_redirect { + if window_attrs.platform_specific.x11.override_redirect { aux = aux.override_redirect(true as u32); } // Add a colormap if needed. - let colormap_visual = match pl_attribs.x11.visual_id { + let colormap_visual = match window_attrs.platform_specific.x11.visual_id { Some(vi) => Some(vi), None if require_colormap => Some(visual), _ => None, @@ -317,7 +320,11 @@ impl UnownedWindow { }; // Figure out the window's parent. - let parent = pl_attribs.x11.embed_window.unwrap_or(root); + let parent = window_attrs + .platform_specific + .x11 + .embed_window + .unwrap_or(root); // finally creating the window let xwindow = { @@ -379,7 +386,7 @@ impl UnownedWindow { } // Embed the window if needed. - if pl_attribs.x11.embed_window.is_some() { + if window_attrs.platform_specific.x11.embed_window.is_some() { window.embed_window()?; } @@ -400,7 +407,7 @@ impl UnownedWindow { // WM_CLASS must be set *before* mapping the window, as per ICCCM! { - let (class, instance) = if let Some(name) = pl_attribs.name { + let (class, instance) = if let Some(name) = window_attrs.platform_specific.name { (name.instance, name.general) } else { let class = env::args_os() @@ -433,7 +440,8 @@ impl UnownedWindow { flusher.ignore_error() } - leap!(window.set_window_types(pl_attribs.x11.x11_window_types)).ignore_error(); + leap!(window.set_window_types(window_attrs.platform_specific.x11.x11_window_types)) + .ignore_error(); // Set size hints. let mut min_inner_size = window_attrs @@ -456,7 +464,7 @@ impl UnownedWindow { shared_state.min_inner_size = min_inner_size.map(Into::into); shared_state.max_inner_size = max_inner_size.map(Into::into); shared_state.resize_increments = window_attrs.resize_increments; - shared_state.base_size = pl_attribs.x11.base_size; + shared_state.base_size = window_attrs.platform_specific.x11.base_size; let normal_hints = WmSizeHints { position: position.map(|PhysicalPosition { x, y }| { @@ -472,7 +480,8 @@ impl UnownedWindow { size_increment: window_attrs .resize_increments .map(|size| cast_size_to_hint(size, scale_factor)), - base_size: pl_attribs + base_size: window_attrs + .platform_specific .x11 .base_size .map(|size| cast_size_to_hint(size, scale_factor)), @@ -578,7 +587,7 @@ impl UnownedWindow { window.set_cursor(window_attrs.cursor); // Remove the startup notification if we have one. - if let Some(startup) = pl_attribs.activation_token.as_ref() { + if let Some(startup) = window_attrs.platform_specific.activation_token.as_ref() { leap!(xconn.remove_activation_token(xwindow, &startup._token)); } diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index ab890cafe5..9a09f00cb7 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -72,12 +72,10 @@ impl Window { pub(crate) fn new( _window_target: &EventLoopWindowTarget, attributes: WindowAttributes, - pl_attribs: PlatformSpecificWindowBuilderAttributes, ) -> Result { let mtm = MainThreadMarker::new() .expect("windows can only be created on the main thread on macOS"); - let (window, _delegate) = - autoreleasepool(|_| WinitWindow::new(attributes, pl_attribs, mtm))?; + let (window, _delegate) = autoreleasepool(|_| WinitWindow::new(attributes, mtm))?; Ok(Window { window: MainThreadBound::new(window, mtm), _delegate: MainThreadBound::new(_delegate, mtm), @@ -140,7 +138,7 @@ impl From for WindowId { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct PlatformSpecificWindowBuilderAttributes { pub movable_by_window_background: bool, pub titlebar_transparent: bool, @@ -286,7 +284,6 @@ impl WinitWindow { #[allow(clippy::type_complexity)] fn new( attrs: WindowAttributes, - pl_attrs: PlatformSpecificWindowBuilderAttributes, mtm: MainThreadMarker, ) -> Result<(Id, Id), RootOsError> { trace_scope!("WinitWindow::new"); @@ -328,7 +325,8 @@ impl WinitWindow { } }; - let mut masks = if (!attrs.decorations && screen.is_none()) || pl_attrs.titlebar_hidden + let mut masks = if (!attrs.decorations && screen.is_none()) + || attrs.platform_specific.titlebar_hidden { // Resizable without a titlebar or borders // if decorations is set to false, ignore pl_attrs @@ -357,7 +355,7 @@ impl WinitWindow { masks &= !NSWindowStyleMaskClosable; } - if pl_attrs.fullsize_content_view { + if attrs.platform_specific.fullsize_content_view { masks |= NSWindowStyleMaskFullSizeContentView; } @@ -400,7 +398,7 @@ impl WinitWindow { this.setTitle(&NSString::from_str(&attrs.title)); this.setAcceptsMouseMovedEvents(true); - if let Some(identifier) = pl_attrs.tabbing_identifier { + if let Some(identifier) = attrs.platform_specific.tabbing_identifier { this.setTabbingIdentifier(&NSString::from_str(&identifier)); this.setTabbingMode(NSWindowTabbingModePreferred); } @@ -409,13 +407,13 @@ impl WinitWindow { this.setSharingType(NSWindowSharingNone); } - if pl_attrs.titlebar_transparent { + if attrs.platform_specific.titlebar_transparent { this.setTitlebarAppearsTransparent(true); } - if pl_attrs.title_hidden { + if attrs.platform_specific.title_hidden { this.setTitleVisibility(NSWindowTitleHidden); } - if pl_attrs.titlebar_buttons_hidden { + if attrs.platform_specific.titlebar_buttons_hidden { for titlebar_button in &[ #[allow(deprecated)] NSWindowFullScreenButton, @@ -428,7 +426,7 @@ impl WinitWindow { } } } - if pl_attrs.movable_by_window_background { + if attrs.platform_specific.movable_by_window_background { this.setMovableByWindowBackground(true); } @@ -438,14 +436,14 @@ impl WinitWindow { } } - if !pl_attrs.has_shadow { + if !attrs.platform_specific.has_shadow { this.setHasShadow(false); } if attrs.position.is_none() { this.center(); } - this.set_option_as_alt(pl_attrs.option_as_alt); + this.set_option_as_alt(attrs.platform_specific.option_as_alt); Some(this) }) @@ -472,13 +470,13 @@ impl WinitWindow { None => (), } - let view = WinitView::new(&this, pl_attrs.accepts_first_mouse); + let view = WinitView::new(&this, attrs.platform_specific.accepts_first_mouse); // The default value of `setWantsBestResolutionOpenGLSurface:` was `false` until // macos 10.14 and `true` after 10.15, we should set it to `YES` or `NO` to avoid // always the default system value in favour of the user's code #[allow(deprecated)] - view.setWantsBestResolutionOpenGLSurface(!pl_attrs.disallow_hidpi); + view.setWantsBestResolutionOpenGLSurface(!attrs.platform_specific.disallow_hidpi); // On Mojave, views automatically become layer-backed shortly after being added to // a window. Changing the layer-backedness of a view breaks the association between diff --git a/src/platform_impl/orbital/window.rs b/src/platform_impl/orbital/window.rs index 9a15330781..7075ef14ed 100644 --- a/src/platform_impl/orbital/window.rs +++ b/src/platform_impl/orbital/window.rs @@ -13,8 +13,7 @@ use crate::{ }; use super::{ - EventLoopWindowTarget, MonitorHandle, PlatformSpecificWindowBuilderAttributes, RedoxSocket, - TimeSocket, WindowId, WindowProperties, + EventLoopWindowTarget, MonitorHandle, RedoxSocket, TimeSocket, WindowId, WindowProperties, }; // These values match the values uses in the `window_new` function in orbital: @@ -37,7 +36,6 @@ impl Window { pub(crate) fn new( el: &EventLoopWindowTarget, attrs: window::WindowAttributes, - _: PlatformSpecificWindowBuilderAttributes, ) -> Result { let scale = MonitorHandle.scale_factor(); diff --git a/src/platform_impl/web/web_sys/canvas.rs b/src/platform_impl/web/web_sys/canvas.rs index 195af6fe88..1d187328c9 100644 --- a/src/platform_impl/web/web_sys/canvas.rs +++ b/src/platform_impl/web/web_sys/canvas.rs @@ -14,7 +14,7 @@ use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize}; use crate::error::OsError as RootOE; use crate::event::{Force, InnerSizeWriter, MouseButton, MouseScrollDelta}; use crate::keyboard::{Key, KeyLocation, ModifiersState, PhysicalKey}; -use crate::platform_impl::{OsError, PlatformSpecificWindowBuilderAttributes}; +use crate::platform_impl::OsError; use crate::window::{WindowAttributes, WindowId as RootWindowId}; use super::super::cursor::CursorHandler; @@ -75,10 +75,9 @@ impl Canvas { id: WindowId, window: web_sys::Window, document: Document, - attr: &WindowAttributes, - mut platform_attr: PlatformSpecificWindowBuilderAttributes, + attr: &mut WindowAttributes, ) -> Result { - let canvas = match platform_attr.canvas.take().map(|canvas| { + let canvas = match attr.platform_specific.canvas.take().map(|canvas| { Arc::try_unwrap(canvas) .map(|canvas| canvas.into_inner(main_thread)) .unwrap_or_else(|canvas| canvas.get(main_thread).clone()) @@ -90,7 +89,7 @@ impl Canvas { .unchecked_into(), }; - if platform_attr.append && !document.contains(Some(&canvas)) { + if attr.platform_specific.append && !document.contains(Some(&canvas)) { document .body() .expect("Failed to get body from document") @@ -103,7 +102,7 @@ impl Canvas { // sequential keyboard navigation, but its order is defined by the // document's source order. // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex - if platform_attr.focusable { + if attr.platform_specific.focusable { canvas .set_attribute("tabindex", "0") .map_err(|_| os_error!(OsError("Failed to set a tabindex".to_owned())))?; @@ -154,7 +153,7 @@ impl Canvas { common, id, has_focus: Rc::new(Cell::new(false)), - prevent_default: Rc::new(Cell::new(platform_attr.prevent_default)), + prevent_default: Rc::new(Cell::new(attr.platform_specific.prevent_default)), is_intersecting: None, on_touch_start: None, on_blur: None, diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index 1e82f21f3d..847f39a24c 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -30,8 +30,7 @@ pub struct Inner { impl Window { pub(crate) fn new( target: &EventLoopWindowTarget, - attr: WindowAttributes, - platform_attr: PlatformSpecificWindowBuilderAttributes, + mut attr: WindowAttributes, ) -> Result { let id = target.generate_id(); @@ -43,8 +42,7 @@ impl Window { id, window.clone(), document.clone(), - &attr, - platform_attr, + &mut attr, )?; let canvas = Rc::new(RefCell::new(canvas)); @@ -468,7 +466,7 @@ impl From for WindowId { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct PlatformSpecificWindowBuilderAttributes { pub(crate) canvas: Option>>, pub(crate) prevent_default: bool, diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index 6978f4969b..49583c9486 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -24,7 +24,7 @@ use crate::event::DeviceId as RootDeviceId; use crate::icon::Icon; use crate::keyboard::Key; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct PlatformSpecificWindowBuilderAttributes { pub owner: Option, pub menu: Option, diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 823e6e6e7a..554fd13dce 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -75,7 +75,7 @@ use crate::{ monitor::{self, MonitorHandle}, util, window_state::{CursorFlags, SavedWindow, WindowFlags, WindowState}, - Fullscreen, PlatformSpecificWindowBuilderAttributes, SelectedCursor, WindowId, + Fullscreen, SelectedCursor, WindowId, }, window::{ CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes, @@ -99,13 +99,12 @@ impl Window { pub(crate) fn new( event_loop: &EventLoopWindowTarget, w_attr: WindowAttributes, - pl_attr: PlatformSpecificWindowBuilderAttributes, ) -> Result { // We dispatch an `init` function because of code style. // First person to remove the need for cloning here gets a cookie! // // done. you owe me -- ossi - unsafe { init(w_attr, pl_attr, event_loop) } + unsafe { init(w_attr, event_loop) } } pub(crate) fn maybe_queue_on_main(&self, f: impl FnOnce(&Self) + Send + 'static) { @@ -1078,7 +1077,6 @@ pub(super) struct InitData<'a, T: 'static> { // inputs pub event_loop: &'a EventLoopWindowTarget, pub attributes: WindowAttributes, - pub pl_attribs: PlatformSpecificWindowBuilderAttributes, pub window_flags: WindowFlags, // outputs pub window: Option, @@ -1128,7 +1126,7 @@ impl<'a, T: 'static> InitData<'a, T> { } unsafe fn create_window_data(&self, win: &Window) -> event_loop::WindowData { - let file_drop_handler = if self.pl_attribs.drag_and_drop { + let file_drop_handler = if self.attributes.platform_specific.drag_and_drop { let ole_init_result = unsafe { OleInitialize(ptr::null_mut()) }; // It is ok if the initialize result is `S_FALSE` because it might happen that // multiple windows are created on the same thread. @@ -1195,7 +1193,7 @@ impl<'a, T: 'static> InitData<'a, T> { let win = self.window.as_mut().expect("failed window creation"); // making the window transparent - if self.attributes.transparent && !self.pl_attribs.no_redirection_bitmap { + if self.attributes.transparent && !self.attributes.platform_specific.no_redirection_bitmap { // Empty region for the blur effect, so the window is fully transparent let region = unsafe { CreateRectRgn(0, 0, -1, -1) }; @@ -1215,9 +1213,9 @@ impl<'a, T: 'static> InitData<'a, T> { unsafe { DeleteObject(region) }; } - win.set_skip_taskbar(self.pl_attribs.skip_taskbar); + win.set_skip_taskbar(self.attributes.platform_specific.skip_taskbar); win.set_window_icon(self.attributes.window_icon.clone()); - win.set_taskbar_icon(self.pl_attribs.taskbar_icon.clone()); + win.set_taskbar_icon(self.attributes.platform_specific.taskbar_icon.clone()); let attributes = self.attributes.clone(); @@ -1271,7 +1269,6 @@ impl<'a, T: 'static> InitData<'a, T> { } unsafe fn init( attributes: WindowAttributes, - pl_attribs: PlatformSpecificWindowBuilderAttributes, event_loop: &EventLoopWindowTarget, ) -> Result where @@ -1279,14 +1276,14 @@ where { let title = util::encode_wide(&attributes.title); - let class_name = util::encode_wide(&pl_attribs.class_name); + let class_name = util::encode_wide(&attributes.platform_specific.class_name); unsafe { register_window_class::(&class_name) }; let mut window_flags = WindowFlags::empty(); window_flags.set(WindowFlags::MARKER_DECORATIONS, attributes.decorations); window_flags.set( WindowFlags::MARKER_UNDECORATED_SHADOW, - pl_attribs.decoration_shadow, + attributes.platform_specific.decoration_shadow, ); window_flags.set( WindowFlags::ALWAYS_ON_TOP, @@ -1298,7 +1295,7 @@ where ); window_flags.set( WindowFlags::NO_BACK_BUFFER, - pl_attribs.no_redirection_bitmap, + attributes.platform_specific.no_redirection_bitmap, ); window_flags.set(WindowFlags::MARKER_ACTIVATE, attributes.active); window_flags.set(WindowFlags::TRANSPARENT, attributes.transparent); @@ -1308,7 +1305,7 @@ where // so the diffing later can work. window_flags.set(WindowFlags::CLOSABLE, true); - let mut fallback_parent = || match pl_attribs.owner { + let mut fallback_parent = || match attributes.platform_specific.owner { Some(parent) => { window_flags.set(WindowFlags::POPUP, true); Some(parent) @@ -1323,7 +1320,7 @@ where let parent = match attributes.parent_window.as_ref().map(|handle| handle.0) { Some(rwh_06::RawWindowHandle::Win32(handle)) => { window_flags.set(WindowFlags::CHILD, true); - if pl_attribs.menu.is_some() { + if attributes.platform_specific.menu.is_some() { warn!("Setting a menu on a child window is unsupported"); } Some(handle.hwnd.get() as HWND) @@ -1335,10 +1332,10 @@ where #[cfg(not(feature = "rwh_06"))] let parent = fallback_parent(); + let menu = attributes.platform_specific.menu; let mut initdata = InitData { event_loop, attributes, - pl_attribs: pl_attribs.clone(), window_flags, window: None, }; @@ -1355,7 +1352,7 @@ where CW_USEDEFAULT, CW_USEDEFAULT, parent.unwrap_or(0), - pl_attribs.menu.unwrap_or(0), + menu.unwrap_or(0), util::get_instance_handle(), &mut initdata as *mut _ as *mut _, ) diff --git a/src/window.rs b/src/window.rs index 7257e16b23..7e38e56c57 100644 --- a/src/window.rs +++ b/src/window.rs @@ -115,27 +115,12 @@ impl From for WindowId { } } -/// Object that allows building windows. -#[derive(Clone, Default)] -#[must_use] -pub struct WindowBuilder { - /// The attributes to use to create the window. - pub(crate) window: WindowAttributes, +#[deprecated = "use `WindowAttributes` directly"] +pub type WindowBuilder = WindowAttributes; - // Platform-specific configuration. - pub(crate) platform_specific: platform_impl::PlatformSpecificWindowBuilderAttributes, -} - -impl fmt::Debug for WindowBuilder { - fn fmt(&self, fmtr: &mut fmt::Formatter<'_>) -> fmt::Result { - fmtr.debug_struct("WindowBuilder") - .field("window", &self.window) - .finish() - } -} - -/// Attributes to use when creating a window. +/// Attributes to use when creating a new window. #[derive(Debug, Clone)] +#[non_exhaustive] pub struct WindowAttributes { pub inner_size: Option, pub min_inner_size: Option, @@ -159,6 +144,9 @@ pub struct WindowAttributes { #[cfg(feature = "rwh_06")] pub(crate) parent_window: Option, pub fullscreen: Option, + // Platform-specific configuration. + #[allow(dead_code)] + pub(crate) platform_specific: platform_impl::PlatformSpecificWindowBuilderAttributes, } impl Default for WindowAttributes { @@ -187,6 +175,7 @@ impl Default for WindowAttributes { #[cfg(feature = "rwh_06")] parent_window: None, active: true, + platform_specific: Default::default(), } } } @@ -195,7 +184,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")] @@ -214,20 +203,15 @@ impl WindowAttributes { } } -impl WindowBuilder { - /// Initializes a new builder with default values. +impl WindowAttributes { + /// Initializes new attributes with default values. #[inline] pub fn new() -> Self { Default::default() } } -impl WindowBuilder { - /// Get the current window attributes. - pub fn window_attributes(&self) -> &WindowAttributes { - &self.window - } - +impl WindowAttributes { /// Requests the window to be of specific dimensions. /// /// If this is not set, some platform-specific dimensions will be used. @@ -235,7 +219,7 @@ impl WindowBuilder { /// See [`Window::request_inner_size`] for details. #[inline] pub fn with_inner_size>(mut self, size: S) -> Self { - self.window.inner_size = Some(size.into()); + self.inner_size = Some(size.into()); self } @@ -247,7 +231,7 @@ impl WindowBuilder { /// See [`Window::set_min_inner_size`] for details. #[inline] pub fn with_min_inner_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 } @@ -259,7 +243,7 @@ impl WindowBuilder { /// See [`Window::set_max_inner_size`] for details. #[inline] pub fn with_max_inner_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 } @@ -287,7 +271,7 @@ impl WindowBuilder { /// - **Others:** Ignored. #[inline] pub fn with_position>(mut self, position: P) -> Self { - self.window.position = Some(position.into()); + self.position = Some(position.into()); self } @@ -298,7 +282,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 } @@ -309,7 +293,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 } @@ -320,7 +304,7 @@ impl WindowBuilder { /// See [`Window::set_title`] for details. #[inline] pub fn with_title>(mut self, title: T) -> Self { - self.window.title = title.into(); + self.title = title.into(); self } @@ -331,7 +315,7 @@ impl WindowBuilder { /// See [`Window::set_fullscreen`] for details. #[inline] pub fn with_fullscreen(mut self, fullscreen: Option) -> Self { - self.window.fullscreen = fullscreen; + self.fullscreen = fullscreen; self } @@ -342,7 +326,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 } @@ -353,7 +337,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 } @@ -367,7 +351,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 } @@ -378,14 +362,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. @@ -395,7 +379,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 } @@ -408,7 +392,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 } @@ -419,7 +403,7 @@ impl WindowBuilder { /// See [`Window::set_window_icon`] for details. #[inline] pub fn with_window_icon(mut self, window_icon: Option) -> Self { - self.window.window_icon = window_icon; + self.window_icon = window_icon; self } @@ -438,7 +422,7 @@ impl WindowBuilder { /// - **iOS / Android / Web / x11 / Orbital:** Ignored. #[inline] pub fn with_theme(mut self, theme: Option) -> Self { - self.window.preferred_theme = theme; + self.preferred_theme = theme; self } @@ -449,7 +433,7 @@ impl WindowBuilder { /// See [`Window::set_resize_increments`] for details. #[inline] pub fn with_resize_increments>(mut self, resize_increments: S) -> Self { - self.window.resize_increments = Some(resize_increments.into()); + self.resize_increments = Some(resize_increments.into()); self } @@ -466,7 +450,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 } @@ -482,7 +466,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 } @@ -493,7 +477,7 @@ impl WindowBuilder { /// See [`Window::set_cursor()`] for more details. #[inline] pub fn with_cursor(mut self, cursor: impl Into) -> Self { - self.window.cursor = cursor.into(); + self.cursor = cursor.into(); self } @@ -518,7 +502,7 @@ impl WindowBuilder { mut self, parent_window: Option, ) -> Self { - self.window.parent_window = parent_window.map(SendSyncRawWindowHandle); + self.parent_window = parent_window.map(SendSyncRawWindowHandle); self } @@ -535,8 +519,7 @@ impl WindowBuilder { self, window_target: &EventLoopWindowTarget, ) -> Result { - let window = - platform_impl::Window::new(&window_target.p, self.window, self.platform_specific)?; + let window = platform_impl::Window::new(&window_target.p, self)?; window.maybe_queue_on_main(|w| w.request_redraw()); Ok(Window { window }) } @@ -546,7 +529,7 @@ impl WindowBuilder { impl Window { /// Creates a new Window for platforms where this is appropriate. /// - /// This function is equivalent to [`WindowBuilder::new().build(event_loop)`]. + /// This function is equivalent to [`WindowAttributes::new().build(event_loop)`]. /// /// Error should be very rare and only occur in case of permission denied, incompatible system, /// out of memory, etc. @@ -556,10 +539,10 @@ impl Window { /// - **Web:** The window is created but not inserted into the web page automatically. Please /// see the web platform module for more information. /// - /// [`WindowBuilder::new().build(event_loop)`]: WindowBuilder::build + /// [`WindowAttributes::new().build(event_loop)`]: WindowAttributes::build #[inline] pub fn new(event_loop: &EventLoopWindowTarget) -> Result { - let builder = WindowBuilder::new(); + let builder = WindowAttributes::new(); builder.build(event_loop) } @@ -929,12 +912,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 / Orbital:** Unsupported. - /// - **X11:** Can only be set while building the window, with [`WindowBuilder::with_transparent`]. + /// - **X11:** Can only be set while creating the window, with [`WindowAttributes::with_transparent`]. #[inline] pub fn set_transparent(&self, transparent: bool) { self.window diff --git a/tests/send_objects.rs b/tests/send_objects.rs index 0a5d1a9eb3..f23be03628 100644 --- a/tests/send_objects.rs +++ b/tests/send_objects.rs @@ -17,8 +17,8 @@ fn window_send() { } #[test] -fn window_builder_send() { - needs_send::(); +fn window_attributes_send() { + needs_send::(); } #[test]