From b4023a25e3371ce061a3a613cf133bf15c8c0afc Mon Sep 17 00:00:00 2001 From: daxpedda Date: Mon, 25 Dec 2023 09:58:04 +0100 Subject: [PATCH] Move `PlatformSpecificWindowBuilderAttributes` Move `PlatformSpecificWindowBuilderAttributes` into `WindowAttributes`. --- src/platform/ios.rs | 13 +++---- src/platform/macos.rs | 23 ++++++------ src/platform/startup_notify.rs | 2 +- src/platform/wayland.rs | 3 +- src/platform/web.rs | 8 ++--- src/platform/windows.rs | 16 ++++----- src/platform/x11.rs | 15 ++++---- src/platform_impl/android/mod.rs | 1 - src/platform_impl/ios/view.rs | 35 ++++++++++++------- src/platform_impl/ios/window.rs | 16 +++------ src/platform_impl/linux/mod.rs | 9 +++-- src/platform_impl/linux/wayland/window/mod.rs | 6 ++-- src/platform_impl/linux/x11/mod.rs | 8 ++--- src/platform_impl/linux/x11/window.rs | 35 ++++++++++++------- src/platform_impl/macos/window.rs | 30 ++++++++-------- src/platform_impl/orbital/window.rs | 4 +-- src/platform_impl/web/web_sys/canvas.rs | 13 ++++--- src/platform_impl/web/window.rs | 8 ++--- src/platform_impl/windows/mod.rs | 2 +- src/platform_impl/windows/window.rs | 29 +++++++-------- src/window.rs | 10 +++--- 21 files changed, 142 insertions(+), 144 deletions(-) diff --git a/src/platform/ios.rs b/src/platform/ios.rs index 2cb0704450..04c69405f6 100644 --- a/src/platform/ios.rs +++ b/src/platform/ios.rs @@ -187,38 +187,39 @@ pub trait WindowBuilderExtIOS { impl WindowBuilderExtIOS for WindowBuilder { #[inline] fn with_scale_factor(mut self, scale_factor: f64) -> Self { - self.platform_specific.scale_factor = Some(scale_factor); + self.window.platform_specific.scale_factor = Some(scale_factor); self } #[inline] fn with_valid_orientations(mut self, valid_orientations: ValidOrientations) -> Self { - self.platform_specific.valid_orientations = valid_orientations; + self.window.platform_specific.valid_orientations = valid_orientations; self } #[inline] fn with_prefers_home_indicator_hidden(mut self, hidden: bool) -> Self { - self.platform_specific.prefers_home_indicator_hidden = hidden; + self.window.platform_specific.prefers_home_indicator_hidden = hidden; self } #[inline] fn with_preferred_screen_edges_deferring_system_gestures(mut self, edges: ScreenEdge) -> Self { - self.platform_specific + self.window + .platform_specific .preferred_screen_edges_deferring_system_gestures = edges; self } #[inline] fn with_prefers_status_bar_hidden(mut self, hidden: bool) -> Self { - self.platform_specific.prefers_status_bar_hidden = hidden; + self.window.platform_specific.prefers_status_bar_hidden = hidden; self } #[inline] fn with_preferred_status_bar_style(mut self, status_bar_style: StatusBarStyle) -> Self { - self.platform_specific.preferred_status_bar_style = status_bar_style; + self.window.platform_specific.preferred_status_bar_style = status_bar_style; self } } diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 8a069611af..68dd2bfad2 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -214,61 +214,62 @@ pub trait WindowBuilderExtMacOS { impl WindowBuilderExtMacOS for WindowBuilder { #[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; + self.window.platform_specific.movable_by_window_background = movable_by_window_background; self } #[inline] fn with_titlebar_transparent(mut self, titlebar_transparent: bool) -> Self { - self.platform_specific.titlebar_transparent = titlebar_transparent; + self.window.platform_specific.titlebar_transparent = titlebar_transparent; self } #[inline] fn with_titlebar_hidden(mut self, titlebar_hidden: bool) -> Self { - self.platform_specific.titlebar_hidden = titlebar_hidden; + self.window.platform_specific.titlebar_hidden = titlebar_hidden; self } #[inline] fn with_titlebar_buttons_hidden(mut self, titlebar_buttons_hidden: bool) -> Self { - self.platform_specific.titlebar_buttons_hidden = titlebar_buttons_hidden; + self.window.platform_specific.titlebar_buttons_hidden = titlebar_buttons_hidden; self } #[inline] fn with_title_hidden(mut self, title_hidden: bool) -> Self { - self.platform_specific.title_hidden = title_hidden; + self.window.platform_specific.title_hidden = title_hidden; self } #[inline] fn with_fullsize_content_view(mut self, fullsize_content_view: bool) -> Self { - self.platform_specific.fullsize_content_view = fullsize_content_view; + self.window.platform_specific.fullsize_content_view = fullsize_content_view; self } #[inline] fn with_disallow_hidpi(mut self, disallow_hidpi: bool) -> Self { - self.platform_specific.disallow_hidpi = disallow_hidpi; + self.window.platform_specific.disallow_hidpi = disallow_hidpi; self } #[inline] fn with_has_shadow(mut self, has_shadow: bool) -> Self { - self.platform_specific.has_shadow = has_shadow; + self.window.platform_specific.has_shadow = has_shadow; self } #[inline] fn with_accepts_first_mouse(mut self, accepts_first_mouse: bool) -> Self { - self.platform_specific.accepts_first_mouse = accepts_first_mouse; + self.window.platform_specific.accepts_first_mouse = accepts_first_mouse; self } #[inline] fn with_tabbing_identifier(mut self, tabbing_identifier: &str) -> Self { - self.platform_specific + self.window + .platform_specific .tabbing_identifier .replace(tabbing_identifier.to_string()); self @@ -276,7 +277,7 @@ impl WindowBuilderExtMacOS for WindowBuilder { #[inline] fn with_option_as_alt(mut self, option_as_alt: OptionAsAlt) -> Self { - self.platform_specific.option_as_alt = option_as_alt; + self.window.platform_specific.option_as_alt = option_as_alt; self } } diff --git a/src/platform/startup_notify.rs b/src/platform/startup_notify.rs index 323c2fe624..a422cd7cf9 100644 --- a/src/platform/startup_notify.rs +++ b/src/platform/startup_notify.rs @@ -76,7 +76,7 @@ impl WindowExtStartupNotify for Window { impl WindowBuilderExtStartupNotify for WindowBuilder { fn with_activation_token(mut self, token: ActivationToken) -> Self { - self.platform_specific.activation_token = Some(token); + self.window.platform_specific.activation_token = Some(token); self } } diff --git a/src/platform/wayland.rs b/src/platform/wayland.rs index ba87651858..5e4fc28c13 100644 --- a/src/platform/wayland.rs +++ b/src/platform/wayland.rs @@ -67,7 +67,8 @@ pub trait WindowBuilderExtWayland { impl WindowBuilderExtWayland for WindowBuilder { #[inline] fn with_name(mut self, general: impl Into, instance: impl Into) -> Self { - self.platform_specific.name = Some(ApplicationName::new(general.into(), instance.into())); + self.window.platform_specific.name = + Some(ApplicationName::new(general.into(), instance.into())); self } } diff --git a/src/platform/web.rs b/src/platform/web.rs index baab78cfab..ab19b90421 100644 --- a/src/platform/web.rs +++ b/src/platform/web.rs @@ -104,22 +104,22 @@ pub trait WindowBuilderExtWebSys { impl WindowBuilderExtWebSys for WindowBuilder { fn with_canvas(mut self, canvas: Option) -> Self { - self.platform_specific.set_canvas(canvas); + self.window.platform_specific.set_canvas(canvas); self } fn with_prevent_default(mut self, prevent_default: bool) -> Self { - self.platform_specific.prevent_default = prevent_default; + self.window.platform_specific.prevent_default = prevent_default; self } fn with_focusable(mut self, focusable: bool) -> Self { - self.platform_specific.focusable = focusable; + self.window.platform_specific.focusable = focusable; self } fn with_append(mut self, append: bool) -> Self { - self.platform_specific.append = append; + self.window.platform_specific.append = append; self } } diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 8e10157944..9139e74a56 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -218,49 +218,49 @@ pub trait WindowBuilderExtWindows { impl WindowBuilderExtWindows for WindowBuilder { #[inline] fn with_owner_window(mut self, parent: HWND) -> Self { - self.platform_specific.owner = Some(parent); + self.window.platform_specific.owner = Some(parent); self } #[inline] fn with_menu(mut self, menu: HMENU) -> Self { - self.platform_specific.menu = Some(menu); + self.window.platform_specific.menu = Some(menu); self } #[inline] fn with_taskbar_icon(mut self, taskbar_icon: Option) -> Self { - self.platform_specific.taskbar_icon = taskbar_icon; + self.window.platform_specific.taskbar_icon = taskbar_icon; self } #[inline] fn with_no_redirection_bitmap(mut self, flag: bool) -> Self { - self.platform_specific.no_redirection_bitmap = flag; + self.window.platform_specific.no_redirection_bitmap = flag; self } #[inline] fn with_drag_and_drop(mut self, flag: bool) -> Self { - self.platform_specific.drag_and_drop = flag; + self.window.platform_specific.drag_and_drop = flag; self } #[inline] fn with_skip_taskbar(mut self, skip: bool) -> Self { - self.platform_specific.skip_taskbar = skip; + self.window.platform_specific.skip_taskbar = skip; self } #[inline] fn with_class_name>(mut self, class_name: S) -> Self { - self.platform_specific.class_name = class_name.into(); + self.window.platform_specific.class_name = class_name.into(); self } #[inline] fn with_undecorated_shadow(mut self, shadow: bool) -> Self { - self.platform_specific.decoration_shadow = shadow; + self.window.platform_specific.decoration_shadow = shadow; self } } diff --git a/src/platform/x11.rs b/src/platform/x11.rs index 5cbd2fe32a..417038f0e9 100644 --- a/src/platform/x11.rs +++ b/src/platform/x11.rs @@ -143,43 +143,44 @@ pub trait WindowBuilderExtX11 { impl WindowBuilderExtX11 for WindowBuilder { #[inline] fn with_x11_visual(mut self, visual_id: XVisualID) -> Self { - self.platform_specific.x11.visual_id = Some(visual_id); + self.window.platform_specific.x11.visual_id = Some(visual_id); self } #[inline] fn with_x11_screen(mut self, screen_id: i32) -> Self { - self.platform_specific.x11.screen_id = Some(screen_id); + self.window.platform_specific.x11.screen_id = Some(screen_id); self } #[inline] fn with_name(mut self, general: impl Into, instance: impl Into) -> Self { - self.platform_specific.name = Some(ApplicationName::new(general.into(), instance.into())); + self.window.platform_specific.name = + Some(ApplicationName::new(general.into(), instance.into())); self } #[inline] fn with_override_redirect(mut self, override_redirect: bool) -> Self { - self.platform_specific.x11.override_redirect = override_redirect; + self.window.platform_specific.x11.override_redirect = override_redirect; self } #[inline] fn with_x11_window_type(mut self, x11_window_types: Vec) -> Self { - self.platform_specific.x11.x11_window_types = x11_window_types; + self.window.platform_specific.x11.x11_window_types = x11_window_types; self } #[inline] fn with_base_size>(mut self, base_size: S) -> Self { - self.platform_specific.x11.base_size = Some(base_size.into()); + self.window.platform_specific.x11.base_size = Some(base_size.into()); self } #[inline] fn with_embed_parent_window(mut self, parent_window_id: XWindow) -> Self { - self.platform_specific.x11.embed_window = Some(parent_window_id); + self.window.platform_specific.x11.embed_window = Some(parent_window_id); self } } 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..db4e690171 100644 --- a/src/window.rs +++ b/src/window.rs @@ -121,9 +121,6 @@ impl From for WindowId { pub struct WindowBuilder { /// The attributes to use to create the window. pub(crate) window: WindowAttributes, - - // Platform-specific configuration. - pub(crate) platform_specific: platform_impl::PlatformSpecificWindowBuilderAttributes, } impl fmt::Debug for WindowBuilder { @@ -159,6 +156,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 +187,7 @@ impl Default for WindowAttributes { #[cfg(feature = "rwh_06")] parent_window: None, active: true, + platform_specific: Default::default(), } } } @@ -535,8 +536,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)?; window.maybe_queue_on_main(|w| w.request_redraw()); Ok(Window { window }) }