Move PlatformSpecificWindowBuilderAttributes (#3318)
This commit is contained in:
parent
aec608f93c
commit
d7c7ba1d6c
22 changed files with 145 additions and 156 deletions
|
|
@ -788,7 +788,6 @@ impl Window {
|
|||
pub(crate) fn new(
|
||||
el: &EventLoopWindowTarget,
|
||||
_window_attrs: window::WindowAttributes,
|
||||
_: PlatformSpecificWindowBuilderAttributes,
|
||||
) -> Result<Self, error::OsError> {
|
||||
// FIXME this ignores requested window attributes
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ use crate::{
|
|||
platform::ios::ValidOrientations,
|
||||
platform_impl::platform::{
|
||||
ffi::{UIRectEdge, UIUserInterfaceIdiom},
|
||||
window::PlatformSpecificWindowBuilderAttributes,
|
||||
Fullscreen, DEVICE_ID,
|
||||
},
|
||||
window::{WindowAttributes, WindowId as RootWindowId},
|
||||
|
|
@ -264,8 +263,7 @@ extern_methods!(
|
|||
impl WinitView {
|
||||
pub(crate) fn new(
|
||||
_mtm: MainThreadMarker,
|
||||
_window_attributes: &WindowAttributes,
|
||||
platform_attributes: &PlatformSpecificWindowBuilderAttributes,
|
||||
window_attributes: &WindowAttributes,
|
||||
frame: CGRect,
|
||||
) -> Id<Self> {
|
||||
let this = Self::alloc().set_ivars(WinitViewState {
|
||||
|
|
@ -277,7 +275,7 @@ impl WinitView {
|
|||
|
||||
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 _);
|
||||
}
|
||||
|
||||
|
|
@ -515,8 +513,7 @@ impl WinitViewController {
|
|||
|
||||
pub(crate) fn new(
|
||||
mtm: MainThreadMarker,
|
||||
_window_attributes: &WindowAttributes,
|
||||
platform_attributes: &PlatformSpecificWindowBuilderAttributes,
|
||||
window_attributes: &WindowAttributes,
|
||||
view: &UIView,
|
||||
) -> Id<Self> {
|
||||
// These are set properly below, we just to set them to something in the meantime.
|
||||
|
|
@ -529,18 +526,33 @@ impl WinitViewController {
|
|||
});
|
||||
let this: Id<Self> = 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(),
|
||||
);
|
||||
|
|
@ -597,7 +609,6 @@ impl WinitUIWindow {
|
|||
pub(crate) fn new(
|
||||
mtm: MainThreadMarker,
|
||||
window_attributes: &WindowAttributes,
|
||||
_platform_attributes: &PlatformSpecificWindowBuilderAttributes,
|
||||
frame: CGRect,
|
||||
view_controller: &UIViewController,
|
||||
) -> Id<Self> {
|
||||
|
|
|
|||
|
|
@ -401,7 +401,6 @@ impl Window {
|
|||
pub(crate) fn new(
|
||||
event_loop: &EventLoopWindowTarget,
|
||||
window_attributes: WindowAttributes,
|
||||
platform_attributes: PlatformSpecificWindowBuilderAttributes,
|
||||
) -> Result<Window, RootOsError> {
|
||||
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);
|
||||
|
||||
|
|
@ -685,7 +677,7 @@ impl From<&AnyObject> for WindowId {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct PlatformSpecificWindowBuilderAttributes {
|
||||
pub scale_factor: Option<f64>,
|
||||
pub valid_orientations: ValidOrientations,
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ impl ApplicationName {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PlatformSpecificWindowBuilderAttributes {
|
||||
pub name: Option<ApplicationName>,
|
||||
pub activation_token: Option<ActivationToken>,
|
||||
|
|
@ -79,7 +79,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
|
|||
pub x11: X11WindowBuilderAttributes,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[cfg(x11_platform)]
|
||||
pub struct X11WindowBuilderAttributes {
|
||||
pub visual_id: Option<x11rb::protocol::xproto::Visualid>,
|
||||
|
|
@ -288,16 +288,15 @@ impl Window {
|
|||
pub(crate) fn new(
|
||||
window_target: &EventLoopWindowTarget,
|
||||
attribs: WindowAttributes,
|
||||
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
||||
) -> Result<Self, RootOsError> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Self, RootOsError> {
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
@ -843,9 +840,8 @@ impl Window {
|
|||
pub(crate) fn new(
|
||||
event_loop: &EventLoopWindowTarget,
|
||||
attribs: WindowAttributes,
|
||||
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
||||
) -> Result<Self, RootOsError> {
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -33,8 +33,7 @@ use crate::{
|
|||
X11Error,
|
||||
},
|
||||
Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError, PlatformCustomCursor,
|
||||
PlatformIcon, PlatformSpecificWindowBuilderAttributes,
|
||||
VideoModeHandle as PlatformVideoModeHandle,
|
||||
PlatformIcon, VideoModeHandle as PlatformVideoModeHandle,
|
||||
},
|
||||
window::{
|
||||
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes,
|
||||
|
|
@ -156,7 +155,6 @@ impl UnownedWindow {
|
|||
pub(crate) fn new(
|
||||
event_loop: &EventLoopWindowTarget,
|
||||
window_attrs: WindowAttributes,
|
||||
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
||||
) -> Result<UnownedWindow, RootOsError> {
|
||||
let xconn = &event_loop.xconn;
|
||||
let atoms = xconn.atoms();
|
||||
|
|
@ -229,7 +227,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,
|
||||
};
|
||||
|
|
@ -249,7 +247,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
|
||||
|
|
@ -291,12 +293,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,
|
||||
|
|
@ -319,7 +321,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 = {
|
||||
|
|
@ -381,7 +387,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()?;
|
||||
}
|
||||
|
||||
|
|
@ -402,7 +408,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()
|
||||
|
|
@ -435,7 +441,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
|
||||
|
|
@ -458,7 +465,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 }| {
|
||||
|
|
@ -474,7 +481,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)),
|
||||
|
|
@ -580,7 +588,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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use objc2::{declare_class, mutability, ClassType, DeclaredClass};
|
|||
|
||||
use super::event_loop::EventLoopWindowTarget;
|
||||
use super::window_delegate::WindowDelegate;
|
||||
use super::PlatformSpecificWindowBuilderAttributes;
|
||||
use crate::error::OsError as RootOsError;
|
||||
use crate::window::WindowAttributes;
|
||||
|
||||
|
|
@ -28,10 +27,9 @@ impl Window {
|
|||
pub(crate) fn new(
|
||||
window_target: &EventLoopWindowTarget,
|
||||
attributes: WindowAttributes,
|
||||
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
||||
) -> Result<Self, RootOsError> {
|
||||
let mtm = window_target.mtm;
|
||||
let delegate = autoreleasepool(|_| WindowDelegate::new(attributes, pl_attribs, mtm))?;
|
||||
let delegate = autoreleasepool(|_| WindowDelegate::new(attributes, mtm))?;
|
||||
Ok(Window {
|
||||
window: MainThreadBound::new(delegate.window().retain(), mtm),
|
||||
delegate: MainThreadBound::new(delegate, mtm),
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ use crate::window::{
|
|||
WindowAttributes, WindowButtons, WindowLevel,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PlatformSpecificWindowBuilderAttributes {
|
||||
pub movable_by_window_background: bool,
|
||||
pub titlebar_transparent: bool,
|
||||
|
|
@ -445,11 +445,7 @@ declare_class!(
|
|||
}
|
||||
);
|
||||
|
||||
fn new_window(
|
||||
attrs: &WindowAttributes,
|
||||
pl_attrs: &PlatformSpecificWindowBuilderAttributes,
|
||||
mtm: MainThreadMarker,
|
||||
) -> Option<Id<WinitWindow>> {
|
||||
fn new_window(attrs: &WindowAttributes, mtm: MainThreadMarker) -> Option<Id<WinitWindow>> {
|
||||
autoreleasepool(|_| {
|
||||
let screen = match attrs.fullscreen.clone().map(Into::into) {
|
||||
Some(Fullscreen::Borderless(Some(monitor)))
|
||||
|
|
@ -487,7 +483,9 @@ fn new_window(
|
|||
}
|
||||
};
|
||||
|
||||
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
|
||||
//
|
||||
|
|
@ -515,7 +513,7 @@ fn new_window(
|
|||
masks &= !NSWindowStyleMaskClosable;
|
||||
}
|
||||
|
||||
if pl_attrs.fullsize_content_view {
|
||||
if attrs.platform_specific.fullsize_content_view {
|
||||
masks |= NSWindowStyleMaskFullSizeContentView;
|
||||
}
|
||||
|
||||
|
|
@ -538,7 +536,7 @@ fn new_window(
|
|||
window.setTitle(&NSString::from_str(&attrs.title));
|
||||
window.setAcceptsMouseMovedEvents(true);
|
||||
|
||||
if let Some(identifier) = &pl_attrs.tabbing_identifier {
|
||||
if let Some(identifier) = &attrs.platform_specific.tabbing_identifier {
|
||||
window.setTabbingIdentifier(&NSString::from_str(identifier));
|
||||
window.setTabbingMode(NSWindowTabbingModePreferred);
|
||||
}
|
||||
|
|
@ -547,13 +545,13 @@ fn new_window(
|
|||
window.setSharingType(NSWindowSharingNone);
|
||||
}
|
||||
|
||||
if pl_attrs.titlebar_transparent {
|
||||
if attrs.platform_specific.titlebar_transparent {
|
||||
window.setTitlebarAppearsTransparent(true);
|
||||
}
|
||||
if pl_attrs.title_hidden {
|
||||
if attrs.platform_specific.title_hidden {
|
||||
window.setTitleVisibility(NSWindowTitleHidden);
|
||||
}
|
||||
if pl_attrs.titlebar_buttons_hidden {
|
||||
if attrs.platform_specific.titlebar_buttons_hidden {
|
||||
for titlebar_button in &[
|
||||
#[allow(deprecated)]
|
||||
NSWindowFullScreenButton,
|
||||
|
|
@ -566,7 +564,7 @@ fn new_window(
|
|||
}
|
||||
}
|
||||
}
|
||||
if pl_attrs.movable_by_window_background {
|
||||
if attrs.platform_specific.movable_by_window_background {
|
||||
window.setMovableByWindowBackground(true);
|
||||
}
|
||||
|
||||
|
|
@ -576,7 +574,7 @@ fn new_window(
|
|||
}
|
||||
}
|
||||
|
||||
if !pl_attrs.has_shadow {
|
||||
if !attrs.platform_specific.has_shadow {
|
||||
window.setHasShadow(false);
|
||||
}
|
||||
if attrs.position.is_none() {
|
||||
|
|
@ -585,15 +583,15 @@ fn new_window(
|
|||
|
||||
let view = WinitView::new(
|
||||
&window,
|
||||
pl_attrs.accepts_first_mouse,
|
||||
pl_attrs.option_as_alt,
|
||||
attrs.platform_specific.accepts_first_mouse,
|
||||
attrs.platform_specific.option_as_alt,
|
||||
);
|
||||
|
||||
// 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
|
||||
|
|
@ -624,12 +622,8 @@ fn new_window(
|
|||
}
|
||||
|
||||
impl WindowDelegate {
|
||||
pub fn new(
|
||||
attrs: WindowAttributes,
|
||||
pl_attrs: PlatformSpecificWindowBuilderAttributes,
|
||||
mtm: MainThreadMarker,
|
||||
) -> Result<Id<Self>, RootOsError> {
|
||||
let window = new_window(&attrs, &pl_attrs, mtm)
|
||||
pub fn new(attrs: WindowAttributes, mtm: MainThreadMarker) -> Result<Id<Self>, RootOsError> {
|
||||
let window = new_window(&attrs, mtm)
|
||||
.ok_or_else(|| os_error!(OsError::CreationError("couldn't create `NSWindow`")))?;
|
||||
|
||||
#[cfg(feature = "rwh_06")]
|
||||
|
|
|
|||
|
|
@ -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<Self, error::OsError> {
|
||||
let scale = MonitorHandle.scale_factor();
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -73,10 +73,9 @@ impl Canvas {
|
|||
id: WindowId,
|
||||
window: web_sys::Window,
|
||||
document: Document,
|
||||
attr: &WindowAttributes,
|
||||
mut platform_attr: PlatformSpecificWindowBuilderAttributes,
|
||||
attr: &mut WindowAttributes,
|
||||
) -> Result<Self, RootOE> {
|
||||
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())
|
||||
|
|
@ -88,7 +87,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")
|
||||
|
|
@ -101,7 +100,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())))?;
|
||||
|
|
@ -152,7 +151,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,
|
||||
|
|
|
|||
|
|
@ -30,8 +30,7 @@ pub struct Inner {
|
|||
impl Window {
|
||||
pub(crate) fn new(
|
||||
target: &EventLoopWindowTarget,
|
||||
attr: WindowAttributes,
|
||||
platform_attr: PlatformSpecificWindowBuilderAttributes,
|
||||
mut attr: WindowAttributes,
|
||||
) -> Result<Self, RootOE> {
|
||||
let id = target.generate_id();
|
||||
|
||||
|
|
@ -42,8 +41,7 @@ impl Window {
|
|||
id,
|
||||
window.clone(),
|
||||
document.clone(),
|
||||
&attr,
|
||||
platform_attr,
|
||||
&mut attr,
|
||||
)?;
|
||||
let canvas = Rc::new(RefCell::new(canvas));
|
||||
|
||||
|
|
@ -467,7 +465,7 @@ impl From<u64> for WindowId {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PlatformSpecificWindowBuilderAttributes {
|
||||
pub(crate) canvas: Option<Arc<MainThreadSafe<backend::RawCanvasType>>>,
|
||||
pub(crate) prevent_default: bool,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,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<HWND>,
|
||||
pub menu: Option<HMENU>,
|
||||
|
|
|
|||
|
|
@ -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<Window, RootOsError> {
|
||||
// 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> {
|
|||
// inputs
|
||||
pub event_loop: &'a EventLoopWindowTarget,
|
||||
pub attributes: WindowAttributes,
|
||||
pub pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
||||
pub window_flags: WindowFlags,
|
||||
// outputs
|
||||
pub window: Option<Window>,
|
||||
|
|
@ -1128,7 +1126,7 @@ impl<'a> InitData<'a> {
|
|||
}
|
||||
|
||||
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> InitData<'a> {
|
|||
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> InitData<'a> {
|
|||
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,19 +1269,18 @@ impl<'a> InitData<'a> {
|
|||
}
|
||||
unsafe fn init(
|
||||
attributes: WindowAttributes,
|
||||
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
||||
event_loop: &EventLoopWindowTarget,
|
||||
) -> Result<Window, RootOsError> {
|
||||
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,
|
||||
|
|
@ -1295,7 +1292,7 @@ unsafe fn init(
|
|||
);
|
||||
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);
|
||||
|
|
@ -1305,7 +1302,7 @@ unsafe fn init(
|
|||
// 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)
|
||||
|
|
@ -1320,7 +1317,7 @@ unsafe fn init(
|
|||
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)
|
||||
|
|
@ -1332,10 +1329,10 @@ unsafe fn init(
|
|||
#[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,
|
||||
};
|
||||
|
|
@ -1352,7 +1349,7 @@ unsafe fn init(
|
|||
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 _,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue