Rename "inner size" to "surface size" (#3889)

* Rename `WindowEvent::Resized` to `SurfaceResized`
* Rename `InnerSizeWriter` to `SurfaceSizeWriter`
* Replace `inner_size` with `surface_size`
* Rename `resize_increments` to `surface_resize_increments`
This commit is contained in:
Mads Marquart 2024-09-04 15:04:48 +02:00 committed by GitHub
parent d37c591378
commit 8db3e0e043
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 466 additions and 436 deletions

View file

@ -24,7 +24,7 @@ fn main() -> Result<(), impl std::error::Error> {
let attributes = WindowAttributes::default() let attributes = WindowAttributes::default()
.with_title("parent window") .with_title("parent window")
.with_position(Position::Logical(LogicalPosition::new(0.0, 0.0))) .with_position(Position::Logical(LogicalPosition::new(0.0, 0.0)))
.with_inner_size(LogicalSize::new(640.0f32, 480.0f32)); .with_surface_size(LogicalSize::new(640.0f32, 480.0f32));
let window = event_loop.create_window(attributes).unwrap(); let window = event_loop.create_window(attributes).unwrap();
println!("Parent window id: {:?})", window.id()); println!("Parent window id: {:?})", window.id());
@ -79,7 +79,7 @@ fn main() -> Result<(), impl std::error::Error> {
let parent = parent.raw_window_handle().unwrap(); let parent = parent.raw_window_handle().unwrap();
let mut window_attributes = WindowAttributes::default() let mut window_attributes = WindowAttributes::default()
.with_title("child window") .with_title("child window")
.with_inner_size(LogicalSize::new(200.0f32, 200.0f32)) .with_surface_size(LogicalSize::new(200.0f32, 200.0f32))
.with_position(Position::Logical(LogicalPosition::new(0.0, 0.0))) .with_position(Position::Logical(LogicalPosition::new(0.0, 0.0)))
.with_visible(true); .with_visible(true);
// `with_parent_window` is unsafe. Parent window must be a valid window. // `with_parent_window` is unsafe. Parent window must be a valid window.

View file

@ -31,7 +31,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) { fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) {
let window_attributes = WindowAttributes::default() let window_attributes = WindowAttributes::default()
.with_title("Fantastic window number one!") .with_title("Fantastic window number one!")
.with_inner_size(winit::dpi::LogicalSize::new(128.0, 128.0)); .with_surface_size(winit::dpi::LogicalSize::new(128.0, 128.0));
let window = event_loop.create_window(window_attributes).unwrap(); let window = event_loop.create_window(window_attributes).unwrap();
self.window_id = Some(window.id()); self.window_id = Some(window.id());
self.window = Some(window); self.window = Some(window);

View file

@ -72,7 +72,7 @@ mod platform {
pub fn fill_window(window: &dyn Window) { pub fn fill_window(window: &dyn Window) {
GC.with(|gc| { GC.with(|gc| {
let size = window.inner_size(); let size = window.surface_size();
let (Some(width), Some(height)) = let (Some(width), Some(height)) =
(NonZeroU32::new(size.width), NonZeroU32::new(size.height)) (NonZeroU32::new(size.width), NonZeroU32::new(size.height))
else { else {

View file

@ -389,7 +389,7 @@ impl ApplicationHandler for Application {
}; };
match event { match event {
WindowEvent::Resized(size) => { WindowEvent::SurfaceResized(size) => {
window.resize(size); window.resize(size);
}, },
WindowEvent::Focused(focused) => { WindowEvent::Focused(focused) => {
@ -607,7 +607,7 @@ impl WindowState {
let ime = true; let ime = true;
window.set_ime_allowed(ime); window.set_ime_allowed(ime);
let size = window.inner_size(); let size = window.surface_size();
let mut state = Self { let mut state = Self {
#[cfg(macos_platform)] #[cfg(macos_platform)]
option_as_alt: window.option_as_alt(), option_as_alt: window.option_as_alt(),
@ -681,12 +681,12 @@ impl WindowState {
/// Toggle resize increments on a window. /// Toggle resize increments on a window.
fn toggle_resize_increments(&mut self) { fn toggle_resize_increments(&mut self) {
let new_increments = match self.window.resize_increments() { let new_increments = match self.window.surface_resize_increments() {
Some(_) => None, Some(_) => None,
None => Some(LogicalSize::new(25.0, 25.0).into()), None => Some(LogicalSize::new(25.0, 25.0).into()),
}; };
info!("Had increments: {}", new_increments.is_none()); info!("Had increments: {}", new_increments.is_none());
self.window.set_resize_increments(new_increments); self.window.set_surface_resize_increments(new_increments);
} }
/// Toggle fullscreen. /// Toggle fullscreen.
@ -725,22 +725,22 @@ impl WindowState {
self.window.set_option_as_alt(self.option_as_alt); self.window.set_option_as_alt(self.option_as_alt);
} }
/// Swap the window dimensions with `request_inner_size`. /// Swap the window dimensions with `request_surface_size`.
fn swap_dimensions(&mut self) { fn swap_dimensions(&mut self) {
let old_inner_size = self.window.inner_size(); let old_surface_size = self.window.surface_size();
let mut inner_size = old_inner_size; let mut surface_size = old_surface_size;
mem::swap(&mut inner_size.width, &mut inner_size.height); mem::swap(&mut surface_size.width, &mut surface_size.height);
info!("Requesting resize from {old_inner_size:?} to {inner_size:?}"); info!("Requesting resize from {old_surface_size:?} to {surface_size:?}");
if let Some(new_inner_size) = self.window.request_inner_size(inner_size.into()) { if let Some(new_surface_size) = self.window.request_surface_size(surface_size.into()) {
if old_inner_size == new_inner_size { if old_surface_size == new_surface_size {
info!("Inner size change got ignored"); info!("Inner size change got ignored");
} else { } else {
self.resize(new_inner_size); self.resize(new_surface_size);
} }
} else { } else {
info!("Request inner size is asynchronous"); info!("Requesting surface size is asynchronous");
} }
} }
@ -793,9 +793,9 @@ impl WindowState {
Ok(()) Ok(())
} }
/// Resize the window to the new size. /// Resize the surface to the new size.
fn resize(&mut self, size: PhysicalSize<u32>) { fn resize(&mut self, size: PhysicalSize<u32>) {
info!("Resized to {size:?}"); info!("Surface resized to {size:?}");
#[cfg(not(any(android_platform, ios_platform)))] #[cfg(not(any(android_platform, ios_platform)))]
{ {
let (width, height) = match (NonZeroU32::new(size.width), NonZeroU32::new(size.height)) let (width, height) = match (NonZeroU32::new(size.width), NonZeroU32::new(size.height))
@ -840,7 +840,7 @@ impl WindowState {
}, },
}; };
let win_size = self.window.inner_size(); let win_size = self.window.surface_size();
let border_size = BORDER_SIZE * self.window.scale_factor(); let border_size = BORDER_SIZE * self.window.scale_factor();
let x_direction = if position.x < border_size { let x_direction = if position.x < border_size {

View file

@ -21,7 +21,7 @@ fn main() -> Result<(), Box<dyn Error>> {
fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) { fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) {
let window_attributes = WindowAttributes::default() let window_attributes = WindowAttributes::default()
.with_title("An embedded window!") .with_title("An embedded window!")
.with_inner_size(winit::dpi::LogicalSize::new(128.0, 128.0)) .with_surface_size(winit::dpi::LogicalSize::new(128.0, 128.0))
.with_embed_parent_window(self.parent_window_id); .with_embed_parent_window(self.parent_window_id);
self.window = Some(event_loop.create_window(window_attributes).unwrap()); self.window = Some(event_loop.create_window(window_attributes).unwrap());

View file

@ -107,6 +107,23 @@ changelog entry.
- On iOS, no longer act as-if the application successfully open all URLs. Override - On iOS, no longer act as-if the application successfully open all URLs. Override
`application:didFinishLaunchingWithOptions:` and provide the desired behaviour yourself. `application:didFinishLaunchingWithOptions:` and provide the desired behaviour yourself.
- On X11, remove our dependency on libXcursor. (#3749) - On X11, remove our dependency on libXcursor. (#3749)
- Renamed the following APIs to make it clearer that the sizes apply to the underlying surface:
- `WindowEvent::Resized` to `SurfaceResized`.
- `InnerSizeWriter` to `SurfaceSizeWriter`.
- `WindowAttributes.inner_size` to `surface_size`.
- `WindowAttributes.min_inner_size` to `min_surface_size`.
- `WindowAttributes.max_inner_size` to `max_surface_size`.
- `WindowAttributes.resize_increments` to `surface_resize_increments`.
- `WindowAttributes::with_inner_size` to `with_surface_size`.
- `WindowAttributes::with_min_inner_size` to `with_min_surface_size`.
- `WindowAttributes::with_max_inner_size` to `with_max_surface_size`.
- `WindowAttributes::with_resize_increments` to `with_surface_resize_increments`.
- `Window::inner_size` to `surface_size`.
- `Window::request_inner_size` to `request_surface_size`.
- `Window::set_min_inner_size` to `set_min_surface_size`.
- `Window::set_max_inner_size` to `set_max_surface_size`.
To migrate, you can probably just replace all instances of `inner_size` with `surface_size` in your codebase.
### Removed ### Removed

View file

@ -148,8 +148,13 @@ pub enum WindowEvent {
/// [`request_activation_token`]: crate::platform::startup_notify::WindowExtStartupNotify::request_activation_token /// [`request_activation_token`]: crate::platform::startup_notify::WindowExtStartupNotify::request_activation_token
ActivationTokenDone { serial: AsyncRequestSerial, token: ActivationToken }, ActivationTokenDone { serial: AsyncRequestSerial, token: ActivationToken },
/// The size of the window has changed. Contains the client area's new dimensions. /// The size of the window's surface has changed.
Resized(PhysicalSize<u32>), ///
/// Contains the new dimensions of the surface (can also be retrieved with
/// [`Window::surface_size`]).
///
/// [`Window::surface_size`]: crate::window::Window::surface_size
SurfaceResized(PhysicalSize<u32>),
/// The position of the window has changed. Contains the window's new position. /// The position of the window has changed. Contains the window's new position.
/// ///
@ -360,16 +365,16 @@ pub enum WindowEvent {
/// * Changing the display's scale factor (e.g. in Control Panel on Windows). /// * Changing the display's scale factor (e.g. in Control Panel on Windows).
/// * Moving the window to a display with a different scale factor. /// * Moving the window to a display with a different scale factor.
/// ///
/// To update the window size, use the provided [`InnerSizeWriter`] handle. By default, the /// To update the window size, use the provided [`SurfaceSizeWriter`] handle. By default, the
/// window is resized to the value suggested by the OS, but it can be changed to any value. /// window is resized to the value suggested by the OS, but it can be changed to any value.
/// ///
/// For more information about DPI in general, see the [`dpi`] crate. /// For more information about DPI in general, see the [`dpi`] crate.
ScaleFactorChanged { ScaleFactorChanged {
scale_factor: f64, scale_factor: f64,
/// Handle to update inner size during scale changes. /// Handle to update surface size during scale changes.
/// ///
/// See [`InnerSizeWriter`] docs for more details. /// See [`SurfaceSizeWriter`] docs for more details.
inner_size_writer: InnerSizeWriter, surface_size_writer: SurfaceSizeWriter,
}, },
/// The system window theme has changed. /// The system window theme has changed.
@ -995,26 +1000,25 @@ pub enum MouseScrollDelta {
PixelDelta(PhysicalPosition<f64>), PixelDelta(PhysicalPosition<f64>),
} }
/// Handle to synchronously change the size of the window from the /// Handle to synchronously change the size of the window from the [`WindowEvent`].
/// [`WindowEvent`].
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct InnerSizeWriter { pub struct SurfaceSizeWriter {
pub(crate) new_inner_size: Weak<Mutex<PhysicalSize<u32>>>, pub(crate) new_surface_size: Weak<Mutex<PhysicalSize<u32>>>,
} }
impl InnerSizeWriter { impl SurfaceSizeWriter {
#[cfg(not(orbital_platform))] #[cfg(not(orbital_platform))]
pub(crate) fn new(new_inner_size: Weak<Mutex<PhysicalSize<u32>>>) -> Self { pub(crate) fn new(new_surface_size: Weak<Mutex<PhysicalSize<u32>>>) -> Self {
Self { new_inner_size } Self { new_surface_size }
} }
/// Try to request inner size which will be set synchronously on the window. /// Try to request surface size which will be set synchronously on the window.
pub fn request_inner_size( pub fn request_surface_size(
&mut self, &mut self,
new_inner_size: PhysicalSize<u32>, new_surface_size: PhysicalSize<u32>,
) -> Result<(), ExternalError> { ) -> Result<(), ExternalError> {
if let Some(inner) = self.new_inner_size.upgrade() { if let Some(inner) = self.new_surface_size.upgrade() {
*inner.lock().unwrap() = new_inner_size; *inner.lock().unwrap() = new_surface_size;
Ok(()) Ok(())
} else { } else {
Err(ExternalError::Ignored) Err(ExternalError::Ignored)
@ -1022,13 +1026,13 @@ impl InnerSizeWriter {
} }
} }
impl PartialEq for InnerSizeWriter { impl PartialEq for SurfaceSizeWriter {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.new_inner_size.as_ptr() == other.new_inner_size.as_ptr() self.new_surface_size.as_ptr() == other.new_surface_size.as_ptr()
} }
} }
impl Eq for InnerSizeWriter {} impl Eq for SurfaceSizeWriter {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
@ -1066,7 +1070,7 @@ mod tests {
with_window_event(Destroyed); with_window_event(Destroyed);
with_window_event(Focused(true)); with_window_event(Focused(true));
with_window_event(Moved((0, 0).into())); with_window_event(Moved((0, 0).into()));
with_window_event(Resized((0, 0).into())); with_window_event(SurfaceResized((0, 0).into()));
with_window_event(DroppedFile("x.txt".into())); with_window_event(DroppedFile("x.txt".into()));
with_window_event(HoveredFile("x.txt".into())); with_window_event(HoveredFile("x.txt".into()));
with_window_event(HoveredFileCancelled); with_window_event(HoveredFileCancelled);

View file

@ -47,9 +47,9 @@ impl Ord for VideoModeHandle {
impl VideoModeHandle { impl VideoModeHandle {
/// Returns the resolution of this video mode. This **must not** be used to create your /// Returns the resolution of this video mode. This **must not** be used to create your
/// rendering surface. Use [`Window::inner_size()`] instead. /// rendering surface. Use [`Window::surface_size()`] instead.
/// ///
/// [`Window::inner_size()`]: crate::window::Window::inner_size /// [`Window::surface_size()`]: crate::window::Window::surface_size
#[inline] #[inline]
pub fn size(&self) -> PhysicalSize<u32> { pub fn size(&self) -> PhysicalSize<u32> {
self.video_mode.size() self.video_mode.size()

View file

@ -27,14 +27,14 @@
//! - [`padding`](https://developer.mozilla.org/en-US/docs/Web/CSS/padding) //! - [`padding`](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
//! //!
//! The following APIs can't take them into account and will therefore provide inaccurate results: //! The following APIs can't take them into account and will therefore provide inaccurate results:
//! - [`WindowEvent::Resized`] and [`Window::(set_)inner_size()`] //! - [`WindowEvent::SurfaceResized`] and [`Window::(set_)surface_size()`]
//! - [`WindowEvent::Occluded`] //! - [`WindowEvent::Occluded`]
//! - [`WindowEvent::CursorMoved`], [`WindowEvent::CursorEntered`], [`WindowEvent::CursorLeft`], and //! - [`WindowEvent::CursorMoved`], [`WindowEvent::CursorEntered`], [`WindowEvent::CursorLeft`], and
//! [`WindowEvent::Touch`]. //! [`WindowEvent::Touch`].
//! - [`Window::set_outer_position()`] //! - [`Window::set_outer_position()`]
//! //!
//! [`WindowEvent::Resized`]: crate::event::WindowEvent::Resized //! [`WindowEvent::SurfaceResized`]: crate::event::WindowEvent::SurfaceResized
//! [`Window::(set_)inner_size()`]: crate::window::Window::inner_size //! [`Window::(set_)surface_size()`]: crate::window::Window::surface_size
//! [`WindowEvent::Occluded`]: crate::event::WindowEvent::Occluded //! [`WindowEvent::Occluded`]: crate::event::WindowEvent::Occluded
//! [`WindowEvent::CursorMoved`]: crate::event::WindowEvent::CursorMoved //! [`WindowEvent::CursorMoved`]: crate::event::WindowEvent::CursorMoved
//! [`WindowEvent::CursorEntered`]: crate::event::WindowEvent::CursorEntered //! [`WindowEvent::CursorEntered`]: crate::event::WindowEvent::CursorEntered

View file

@ -15,7 +15,7 @@ use crate::application::ApplicationHandler;
use crate::cursor::Cursor; use crate::cursor::Cursor;
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{self, EventLoopError, ExternalError, NotSupportedError}; use crate::error::{self, EventLoopError, ExternalError, NotSupportedError};
use crate::event::{self, Force, InnerSizeWriter, StartCause}; use crate::event::{self, Force, StartCause, SurfaceSizeWriter};
use crate::event_loop::{ use crate::event_loop::{
ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents,
EventLoopProxy as RootEventLoopProxy, OwnedDisplayHandle as RootOwnedDisplayHandle, EventLoopProxy as RootEventLoopProxy, OwnedDisplayHandle as RootOwnedDisplayHandle,
@ -201,11 +201,11 @@ impl EventLoop {
let old_scale_factor = scale_factor(&self.android_app); let old_scale_factor = scale_factor(&self.android_app);
let scale_factor = scale_factor(&self.android_app); let scale_factor = scale_factor(&self.android_app);
if (scale_factor - old_scale_factor).abs() < f64::EPSILON { if (scale_factor - old_scale_factor).abs() < f64::EPSILON {
let new_inner_size = Arc::new(Mutex::new(screen_size(&self.android_app))); let new_surface_size = Arc::new(Mutex::new(screen_size(&self.android_app)));
let window_id = window::WindowId(WindowId); let window_id = window::WindowId(WindowId);
let event = event::WindowEvent::ScaleFactorChanged { let event = event::WindowEvent::ScaleFactorChanged {
inner_size_writer: InnerSizeWriter::new(Arc::downgrade( surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(
&new_inner_size, &new_surface_size,
)), )),
scale_factor, scale_factor,
}; };
@ -287,7 +287,7 @@ impl EventLoop {
PhysicalSize::new(0, 0) PhysicalSize::new(0, 0)
}; };
let window_id = window::WindowId(WindowId); let window_id = window::WindowId(WindowId);
let event = event::WindowEvent::Resized(size); let event = event::WindowEvent::SurfaceResized(size);
app.window_event(&self.window_target, window_id, event); app.window_event(&self.window_target, window_id, event);
} }
@ -808,27 +808,27 @@ impl CoreWindow for Window {
// no effect // no effect
} }
fn inner_size(&self) -> PhysicalSize<u32> { fn surface_size(&self) -> PhysicalSize<u32> {
self.outer_size() self.outer_size()
} }
fn request_inner_size(&self, _size: Size) -> Option<PhysicalSize<u32>> { fn request_surface_size(&self, _size: Size) -> Option<PhysicalSize<u32>> {
Some(self.inner_size()) Some(self.surface_size())
} }
fn outer_size(&self) -> PhysicalSize<u32> { fn outer_size(&self) -> PhysicalSize<u32> {
screen_size(&self.app) screen_size(&self.app)
} }
fn set_min_inner_size(&self, _: Option<Size>) {} fn set_min_surface_size(&self, _: Option<Size>) {}
fn set_max_inner_size(&self, _: Option<Size>) {} fn set_max_surface_size(&self, _: Option<Size>) {}
fn resize_increments(&self) -> Option<PhysicalSize<u32>> { fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
None None
} }
fn set_resize_increments(&self, _increments: Option<Size>) {} fn set_surface_resize_increments(&self, _increments: Option<Size>) {}
fn set_title(&self, _title: &str) {} fn set_title(&self, _title: &str) {}

View file

@ -198,7 +198,7 @@ declare_class!(
// 2. Even when a window resize does occur on a new tabbed window, it contains the wrong size (includes tab height). // 2. Even when a window resize does occur on a new tabbed window, it contains the wrong size (includes tab height).
let logical_size = LogicalSize::new(rect.size.width as f64, rect.size.height as f64); let logical_size = LogicalSize::new(rect.size.width as f64, rect.size.height as f64);
let size = logical_size.to_physical::<u32>(self.scale_factor()); let size = logical_size.to_physical::<u32>(self.scale_factor());
self.queue_event(WindowEvent::Resized(size)); self.queue_event(WindowEvent::SurfaceResized(size));
} }
#[method(drawRect:)] #[method(drawRect:)]

View file

@ -127,32 +127,32 @@ impl CoreWindow for Window {
self.maybe_wait_on_main(|delegate| delegate.set_outer_position(position)); self.maybe_wait_on_main(|delegate| delegate.set_outer_position(position));
} }
fn inner_size(&self) -> dpi::PhysicalSize<u32> { fn surface_size(&self) -> dpi::PhysicalSize<u32> {
self.maybe_wait_on_main(|delegate| delegate.inner_size()) self.maybe_wait_on_main(|delegate| delegate.surface_size())
} }
fn request_inner_size(&self, size: Size) -> Option<dpi::PhysicalSize<u32>> { fn request_surface_size(&self, size: Size) -> Option<dpi::PhysicalSize<u32>> {
self.maybe_wait_on_main(|delegate| delegate.request_inner_size(size)) self.maybe_wait_on_main(|delegate| delegate.request_surface_size(size))
} }
fn outer_size(&self) -> dpi::PhysicalSize<u32> { fn outer_size(&self) -> dpi::PhysicalSize<u32> {
self.maybe_wait_on_main(|delegate| delegate.outer_size()) self.maybe_wait_on_main(|delegate| delegate.outer_size())
} }
fn set_min_inner_size(&self, min_size: Option<Size>) { fn set_min_surface_size(&self, min_size: Option<Size>) {
self.maybe_wait_on_main(|delegate| delegate.set_min_inner_size(min_size)) self.maybe_wait_on_main(|delegate| delegate.set_min_surface_size(min_size))
} }
fn set_max_inner_size(&self, max_size: Option<Size>) { fn set_max_surface_size(&self, max_size: Option<Size>) {
self.maybe_wait_on_main(|delegate| delegate.set_max_inner_size(max_size)); self.maybe_wait_on_main(|delegate| delegate.set_max_surface_size(max_size));
} }
fn resize_increments(&self) -> Option<dpi::PhysicalSize<u32>> { fn surface_resize_increments(&self) -> Option<dpi::PhysicalSize<u32>> {
self.maybe_wait_on_main(|delegate| delegate.resize_increments()) self.maybe_wait_on_main(|delegate| delegate.surface_resize_increments())
} }
fn set_resize_increments(&self, increments: Option<Size>) { fn set_surface_resize_increments(&self, increments: Option<Size>) {
self.maybe_wait_on_main(|delegate| delegate.set_resize_increments(increments)); self.maybe_wait_on_main(|delegate| delegate.set_surface_resize_increments(increments));
} }
fn set_title(&self, title: &str) { fn set_title(&self, title: &str) {

View file

@ -36,7 +36,7 @@ use super::window::WinitWindow;
use super::{ffi, Fullscreen, MonitorHandle, OsError, WindowId}; use super::{ffi, Fullscreen, MonitorHandle, OsError, WindowId};
use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size}; use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError}; use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError};
use crate::event::{InnerSizeWriter, WindowEvent}; use crate::event::{SurfaceSizeWriter, WindowEvent};
use crate::platform::macos::{OptionAsAlt, WindowExtMacOS}; use crate::platform::macos::{OptionAsAlt, WindowExtMacOS};
use crate::window::{ use crate::window::{
Cursor, CursorGrabMode, Icon, ImePurpose, ResizeDirection, Theme, UserAttentionType, Cursor, CursorGrabMode, Icon, ImePurpose, ResizeDirection, Theme, UserAttentionType,
@ -95,7 +95,7 @@ pub(crate) struct State {
previous_scale_factor: Cell<f64>, previous_scale_factor: Cell<f64>,
/// The current resize increments for the window content. /// The current resize increments for the window content.
resize_increments: Cell<NSSize>, surface_resize_increments: Cell<NSSize>,
/// Whether the window is showing decorations. /// Whether the window is showing decorations.
decorations: Cell<bool>, decorations: Cell<bool>,
resizable: Cell<bool>, resizable: Cell<bool>,
@ -164,7 +164,7 @@ declare_class!(
#[method(windowDidResize:)] #[method(windowDidResize:)]
fn window_did_resize(&self, _: Option<&AnyObject>) { fn window_did_resize(&self, _: Option<&AnyObject>) {
trace_scope!("windowDidResize:"); trace_scope!("windowDidResize:");
// NOTE: WindowEvent::Resized is reported in frameDidChange. // NOTE: WindowEvent::SurfaceResized is reported in frameDidChange.
self.emit_move_event(); self.emit_move_event();
} }
@ -172,7 +172,7 @@ declare_class!(
fn window_will_start_live_resize(&self, _: Option<&AnyObject>) { fn window_will_start_live_resize(&self, _: Option<&AnyObject>) {
trace_scope!("windowWillStartLiveResize:"); trace_scope!("windowWillStartLiveResize:");
let increments = self.ivars().resize_increments.get(); let increments = self.ivars().surface_resize_increments.get();
self.set_resize_increments_inner(increments); self.set_resize_increments_inner(increments);
} }
@ -505,7 +505,7 @@ fn new_window(
let scale_factor = NSScreen::mainScreen(mtm) let scale_factor = NSScreen::mainScreen(mtm)
.map(|screen| screen.backingScaleFactor() as f64) .map(|screen| screen.backingScaleFactor() as f64)
.unwrap_or(1.0); .unwrap_or(1.0);
let size = match attrs.inner_size { let size = match attrs.surface_size {
Some(size) => { Some(size) => {
let size = size.to_logical(scale_factor); let size = size.to_logical(scale_factor);
NSSize::new(size.width, size.height) NSSize::new(size.width, size.height)
@ -703,13 +703,15 @@ impl WindowDelegate {
None => (), None => (),
} }
let resize_increments = let surface_resize_increments = match attrs
match attrs.resize_increments.map(|i| i.to_logical(window.backingScaleFactor() as _)) { .surface_resize_increments
Some(LogicalSize { width, height }) if width >= 1. && height >= 1. => { .map(|i| i.to_logical(window.backingScaleFactor() as _))
NSSize::new(width, height) {
}, Some(LogicalSize { width, height }) if width >= 1. && height >= 1. => {
_ => NSSize::new(1., 1.), NSSize::new(width, height)
}; },
_ => NSSize::new(1., 1.),
};
let scale_factor = window.backingScaleFactor() as _; let scale_factor = window.backingScaleFactor() as _;
@ -722,7 +724,7 @@ impl WindowDelegate {
window: window.retain(), window: window.retain(),
previous_position: Cell::new(None), previous_position: Cell::new(None),
previous_scale_factor: Cell::new(scale_factor), previous_scale_factor: Cell::new(scale_factor),
resize_increments: Cell::new(resize_increments), surface_resize_increments: Cell::new(surface_resize_increments),
decorations: Cell::new(attrs.decorations), decorations: Cell::new(attrs.decorations),
resizable: Cell::new(attrs.resizable), resizable: Cell::new(attrs.resizable),
maximized: Cell::new(attrs.maximized), maximized: Cell::new(attrs.maximized),
@ -763,11 +765,11 @@ impl WindowDelegate {
delegate.set_blur(attrs.blur); delegate.set_blur(attrs.blur);
} }
if let Some(dim) = attrs.min_inner_size { if let Some(dim) = attrs.min_surface_size {
delegate.set_min_inner_size(Some(dim)); delegate.set_min_surface_size(Some(dim));
} }
if let Some(dim) = attrs.max_inner_size { if let Some(dim) = attrs.max_surface_size {
delegate.set_max_inner_size(Some(dim)); delegate.set_max_surface_size(Some(dim));
} }
delegate.set_window_level(attrs.window_level); delegate.set_window_level(attrs.window_level);
@ -830,20 +832,20 @@ impl WindowDelegate {
let content_size = LogicalSize::new(content_size.width, content_size.height); let content_size = LogicalSize::new(content_size.width, content_size.height);
let suggested_size = content_size.to_physical(scale_factor); let suggested_size = content_size.to_physical(scale_factor);
let new_inner_size = Arc::new(Mutex::new(suggested_size)); let new_surface_size = Arc::new(Mutex::new(suggested_size));
self.queue_event(WindowEvent::ScaleFactorChanged { self.queue_event(WindowEvent::ScaleFactorChanged {
scale_factor, scale_factor,
inner_size_writer: InnerSizeWriter::new(Arc::downgrade(&new_inner_size)), surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)),
}); });
let physical_size = *new_inner_size.lock().unwrap(); let physical_size = *new_surface_size.lock().unwrap();
drop(new_inner_size); drop(new_surface_size);
if physical_size != suggested_size { if physical_size != suggested_size {
let logical_size = physical_size.to_logical(scale_factor); let logical_size = physical_size.to_logical(scale_factor);
let size = NSSize::new(logical_size.width, logical_size.height); let size = NSSize::new(logical_size.width, logical_size.height);
window.setContentSize(size); window.setContentSize(size);
} }
self.queue_event(WindowEvent::Resized(physical_size)); self.queue_event(WindowEvent::SurfaceResized(physical_size));
} }
fn emit_move_event(&self) { fn emit_move_event(&self) {
@ -944,7 +946,7 @@ impl WindowDelegate {
} }
#[inline] #[inline]
pub fn inner_size(&self) -> PhysicalSize<u32> { pub fn surface_size(&self) -> PhysicalSize<u32> {
let content_rect = self.window().contentRectForFrameRect(self.window().frame()); let content_rect = self.window().contentRectForFrameRect(self.window().frame());
let logical = LogicalSize::new(content_rect.size.width, content_rect.size.height); let logical = LogicalSize::new(content_rect.size.width, content_rect.size.height);
logical.to_physical(self.scale_factor()) logical.to_physical(self.scale_factor())
@ -958,14 +960,14 @@ impl WindowDelegate {
} }
#[inline] #[inline]
pub fn request_inner_size(&self, size: Size) -> Option<PhysicalSize<u32>> { pub fn request_surface_size(&self, size: Size) -> Option<PhysicalSize<u32>> {
let scale_factor = self.scale_factor(); let scale_factor = self.scale_factor();
let size = size.to_logical(scale_factor); let size = size.to_logical(scale_factor);
self.window().setContentSize(NSSize::new(size.width, size.height)); self.window().setContentSize(NSSize::new(size.width, size.height));
None None
} }
pub fn set_min_inner_size(&self, dimensions: Option<Size>) { pub fn set_min_surface_size(&self, dimensions: Option<Size>) {
let dimensions = let dimensions =
dimensions.unwrap_or(Size::Logical(LogicalSize { width: 0.0, height: 0.0 })); dimensions.unwrap_or(Size::Logical(LogicalSize { width: 0.0, height: 0.0 }));
let min_size = dimensions.to_logical::<CGFloat>(self.scale_factor()); let min_size = dimensions.to_logical::<CGFloat>(self.scale_factor());
@ -984,7 +986,7 @@ impl WindowDelegate {
self.window().setContentSize(current_size); self.window().setContentSize(current_size);
} }
pub fn set_max_inner_size(&self, dimensions: Option<Size>) { pub fn set_max_surface_size(&self, dimensions: Option<Size>) {
let dimensions = dimensions.unwrap_or(Size::Logical(LogicalSize { let dimensions = dimensions.unwrap_or(Size::Logical(LogicalSize {
width: f32::MAX as f64, width: f32::MAX as f64,
height: f32::MAX as f64, height: f32::MAX as f64,
@ -1006,8 +1008,8 @@ impl WindowDelegate {
self.window().setContentSize(current_size); self.window().setContentSize(current_size);
} }
pub fn resize_increments(&self) -> Option<PhysicalSize<u32>> { pub fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
let increments = self.ivars().resize_increments.get(); let increments = self.ivars().surface_resize_increments.get();
let (w, h) = (increments.width, increments.height); let (w, h) = (increments.width, increments.height);
if w > 1.0 || h > 1.0 { if w > 1.0 || h > 1.0 {
Some(LogicalSize::new(w, h).to_physical(self.scale_factor())) Some(LogicalSize::new(w, h).to_physical(self.scale_factor()))
@ -1016,9 +1018,9 @@ impl WindowDelegate {
} }
} }
pub fn set_resize_increments(&self, increments: Option<Size>) { pub fn set_surface_resize_increments(&self, increments: Option<Size>) {
// XXX the resize increments are only used during live resizes. // XXX the resize increments are only used during live resizes.
self.ivars().resize_increments.set( self.ivars().surface_resize_increments.set(
increments increments
.map(|increments| { .map(|increments| {
let logical = increments.to_logical::<f64>(self.scale_factor()); let logical = increments.to_logical::<f64>(self.scale_factor());

View file

@ -27,7 +27,7 @@ use super::window::WinitUIWindow;
use super::ActiveEventLoop; use super::ActiveEventLoop;
use crate::application::ApplicationHandler; use crate::application::ApplicationHandler;
use crate::dpi::PhysicalSize; use crate::dpi::PhysicalSize;
use crate::event::{Event, InnerSizeWriter, StartCause, WindowEvent}; use crate::event::{Event, StartCause, SurfaceSizeWriter, WindowEvent};
use crate::event_loop::ControlFlow; use crate::event_loop::ControlFlow;
use crate::window::WindowId as RootWindowId; use crate::window::WindowId as RootWindowId;
@ -669,18 +669,18 @@ pub(crate) fn terminated(application: &UIApplication) {
fn handle_hidpi_proxy(mtm: MainThreadMarker, event: ScaleFactorChanged) { fn handle_hidpi_proxy(mtm: MainThreadMarker, event: ScaleFactorChanged) {
let ScaleFactorChanged { suggested_size, scale_factor, window } = event; let ScaleFactorChanged { suggested_size, scale_factor, window } = event;
let new_inner_size = Arc::new(Mutex::new(suggested_size)); let new_surface_size = Arc::new(Mutex::new(suggested_size));
let event = Event::WindowEvent { let event = Event::WindowEvent {
window_id: RootWindowId(window.id()), window_id: RootWindowId(window.id()),
event: WindowEvent::ScaleFactorChanged { event: WindowEvent::ScaleFactorChanged {
scale_factor, scale_factor,
inner_size_writer: InnerSizeWriter::new(Arc::downgrade(&new_inner_size)), surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)),
}, },
}; };
handle_event(mtm, event); handle_event(mtm, event);
let (view, screen_frame) = get_view_and_screen_frame(&window); let (view, screen_frame) = get_view_and_screen_frame(&window);
let physical_size = *new_inner_size.lock().unwrap(); let physical_size = *new_surface_size.lock().unwrap();
drop(new_inner_size); drop(new_surface_size);
let logical_size = physical_size.to_logical(scale_factor); let logical_size = physical_size.to_logical(scale_factor);
let size = CGSize::new(logical_size.width, logical_size.height); let size = CGSize::new(logical_size.width, logical_size.height);
let new_frame: CGRect = CGRect::new(screen_frame.origin, size); let new_frame: CGRect = CGRect::new(screen_frame.origin, size);

View file

@ -93,7 +93,7 @@ declare_class!(
mtm, mtm,
EventWrapper::StaticEvent(Event::WindowEvent { EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.id()), window_id: RootWindowId(window.id()),
event: WindowEvent::Resized(size), event: WindowEvent::SurfaceResized(size),
}), }),
); );
} }
@ -144,7 +144,7 @@ declare_class!(
.chain(std::iter::once(EventWrapper::StaticEvent( .chain(std::iter::once(EventWrapper::StaticEvent(
Event::WindowEvent { Event::WindowEvent {
window_id, window_id,
event: WindowEvent::Resized(size.to_physical(scale_factor)), event: WindowEvent::SurfaceResized(size.to_physical(scale_factor)),
}, },
))), ))),
); );

View file

@ -187,7 +187,7 @@ impl Inner {
self.window.setBounds(bounds); self.window.setBounds(bounds);
} }
pub fn inner_size(&self) -> PhysicalSize<u32> { pub fn surface_size(&self) -> PhysicalSize<u32> {
let scale_factor = self.scale_factor(); let scale_factor = self.scale_factor();
let safe_area = self.safe_area_screen_space(); let safe_area = self.safe_area_screen_space();
let size = LogicalSize { let size = LogicalSize {
@ -207,25 +207,25 @@ impl Inner {
size.to_physical(scale_factor) size.to_physical(scale_factor)
} }
pub fn request_inner_size(&self, _size: Size) -> Option<PhysicalSize<u32>> { pub fn request_surface_size(&self, _size: Size) -> Option<PhysicalSize<u32>> {
Some(self.inner_size()) Some(self.surface_size())
} }
pub fn set_min_inner_size(&self, _dimensions: Option<Size>) { pub fn set_min_surface_size(&self, _dimensions: Option<Size>) {
warn!("`Window::set_min_inner_size` is ignored on iOS") warn!("`Window::set_min_surface_size` is ignored on iOS")
} }
pub fn set_max_inner_size(&self, _dimensions: Option<Size>) { pub fn set_max_surface_size(&self, _dimensions: Option<Size>) {
warn!("`Window::set_max_inner_size` is ignored on iOS") warn!("`Window::set_max_surface_size` is ignored on iOS")
} }
pub fn resize_increments(&self) -> Option<PhysicalSize<u32>> { pub fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
None None
} }
#[inline] #[inline]
pub fn set_resize_increments(&self, _increments: Option<Size>) { pub fn set_surface_resize_increments(&self, _increments: Option<Size>) {
warn!("`Window::set_resize_increments` is ignored on iOS") warn!("`Window::set_surface_resize_increments` is ignored on iOS")
} }
pub fn set_resizable(&self, _resizable: bool) { pub fn set_resizable(&self, _resizable: bool) {
@ -469,11 +469,11 @@ impl Window {
) -> Result<Window, RootOsError> { ) -> Result<Window, RootOsError> {
let mtm = event_loop.mtm; let mtm = event_loop.mtm;
if window_attributes.min_inner_size.is_some() { if window_attributes.min_surface_size.is_some() {
warn!("`WindowAttributes::min_inner_size` is ignored on iOS"); warn!("`WindowAttributes::min_surface_size` is ignored on iOS");
} }
if window_attributes.max_inner_size.is_some() { if window_attributes.max_surface_size.is_some() {
warn!("`WindowAttributes::max_inner_size` is ignored on iOS"); warn!("`WindowAttributes::max_surface_size` is ignored on iOS");
} }
// TODO: transparency, visible // TODO: transparency, visible
@ -489,7 +489,7 @@ impl Window {
let screen_bounds = screen.bounds(); let screen_bounds = screen.bounds();
let frame = match window_attributes.inner_size { let frame = match window_attributes.surface_size {
Some(dim) => { Some(dim) => {
let scale_factor = screen.scale(); let scale_factor = screen.scale();
let size = dim.to_logical::<f64>(scale_factor as f64); let size = dim.to_logical::<f64>(scale_factor as f64);
@ -510,7 +510,7 @@ impl Window {
let window = WinitUIWindow::new(mtm, &window_attributes, frame, &view_controller); let window = WinitUIWindow::new(mtm, &window_attributes, frame, &view_controller);
window.makeKeyAndVisible(); window.makeKeyAndVisible();
// Like the Windows and macOS backends, we send a `ScaleFactorChanged` and `Resized` // Like the Windows and macOS backends, we send a `ScaleFactorChanged` and `SurfaceResized`
// event on window creation if the DPI factor != 1.0 // event on window creation if the DPI factor != 1.0
let scale_factor = view.contentScaleFactor(); let scale_factor = view.contentScaleFactor();
let scale_factor = scale_factor as f64; let scale_factor = scale_factor as f64;
@ -534,7 +534,7 @@ impl Window {
.chain(std::iter::once(EventWrapper::StaticEvent( .chain(std::iter::once(EventWrapper::StaticEvent(
Event::WindowEvent { Event::WindowEvent {
window_id, window_id,
event: WindowEvent::Resized(size.to_physical(scale_factor)), event: WindowEvent::SurfaceResized(size.to_physical(scale_factor)),
}, },
))), ))),
); );
@ -622,32 +622,32 @@ impl CoreWindow for Window {
self.maybe_wait_on_main(|delegate| delegate.set_outer_position(position)); self.maybe_wait_on_main(|delegate| delegate.set_outer_position(position));
} }
fn inner_size(&self) -> dpi::PhysicalSize<u32> { fn surface_size(&self) -> dpi::PhysicalSize<u32> {
self.maybe_wait_on_main(|delegate| delegate.inner_size()) self.maybe_wait_on_main(|delegate| delegate.surface_size())
} }
fn request_inner_size(&self, size: Size) -> Option<dpi::PhysicalSize<u32>> { fn request_surface_size(&self, size: Size) -> Option<dpi::PhysicalSize<u32>> {
self.maybe_wait_on_main(|delegate| delegate.request_inner_size(size)) self.maybe_wait_on_main(|delegate| delegate.request_surface_size(size))
} }
fn outer_size(&self) -> dpi::PhysicalSize<u32> { fn outer_size(&self) -> dpi::PhysicalSize<u32> {
self.maybe_wait_on_main(|delegate| delegate.outer_size()) self.maybe_wait_on_main(|delegate| delegate.outer_size())
} }
fn set_min_inner_size(&self, min_size: Option<Size>) { fn set_min_surface_size(&self, min_size: Option<Size>) {
self.maybe_wait_on_main(|delegate| delegate.set_min_inner_size(min_size)) self.maybe_wait_on_main(|delegate| delegate.set_min_surface_size(min_size))
} }
fn set_max_inner_size(&self, max_size: Option<Size>) { fn set_max_surface_size(&self, max_size: Option<Size>) {
self.maybe_wait_on_main(|delegate| delegate.set_max_inner_size(max_size)); self.maybe_wait_on_main(|delegate| delegate.set_max_surface_size(max_size));
} }
fn resize_increments(&self) -> Option<dpi::PhysicalSize<u32>> { fn surface_resize_increments(&self) -> Option<dpi::PhysicalSize<u32>> {
self.maybe_wait_on_main(|delegate| delegate.resize_increments()) self.maybe_wait_on_main(|delegate| delegate.surface_resize_increments())
} }
fn set_resize_increments(&self, increments: Option<Size>) { fn set_surface_resize_increments(&self, increments: Option<Size>) {
self.maybe_wait_on_main(|delegate| delegate.set_resize_increments(increments)); self.maybe_wait_on_main(|delegate| delegate.set_surface_resize_increments(increments));
} }
fn set_title(&self, title: &str) { fn set_title(&self, title: &str) {

View file

@ -16,7 +16,7 @@ use crate::application::ApplicationHandler;
use crate::cursor::OnlyCursorImage; use crate::cursor::OnlyCursorImage;
use crate::dpi::LogicalSize; use crate::dpi::LogicalSize;
use crate::error::{EventLoopError, ExternalError, OsError as RootOsError}; use crate::error::{EventLoopError, ExternalError, OsError as RootOsError};
use crate::event::{Event, InnerSizeWriter, StartCause, WindowEvent}; use crate::event::{Event, StartCause, SurfaceSizeWriter, WindowEvent};
use crate::event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents}; use crate::event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents};
use crate::platform::pump_events::PumpStatus; use crate::platform::pump_events::PumpStatus;
use crate::platform_impl::platform::min_timeout; use crate::platform_impl::platform::min_timeout;
@ -317,24 +317,24 @@ impl EventLoop {
let windows = state.windows.get_mut(); let windows = state.windows.get_mut();
let window = windows.get(&window_id).unwrap().lock().unwrap(); let window = windows.get(&window_id).unwrap().lock().unwrap();
let scale_factor = window.scale_factor(); let scale_factor = window.scale_factor();
let size = logical_to_physical_rounded(window.inner_size(), scale_factor); let size = logical_to_physical_rounded(window.surface_size(), scale_factor);
(size, scale_factor) (size, scale_factor)
}); });
// Stash the old window size. // Stash the old window size.
let old_physical_size = physical_size; let old_physical_size = physical_size;
let new_inner_size = Arc::new(Mutex::new(physical_size)); let new_surface_size = Arc::new(Mutex::new(physical_size));
let root_window_id = crate::window::WindowId(window_id); let root_window_id = crate::window::WindowId(window_id);
let event = WindowEvent::ScaleFactorChanged { let event = WindowEvent::ScaleFactorChanged {
scale_factor, scale_factor,
inner_size_writer: InnerSizeWriter::new(Arc::downgrade(&new_inner_size)), surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)),
}; };
app.window_event(&self.active_event_loop, root_window_id, event); app.window_event(&self.active_event_loop, root_window_id, event);
let physical_size = *new_inner_size.lock().unwrap(); let physical_size = *new_surface_size.lock().unwrap();
drop(new_inner_size); drop(new_surface_size);
// Resize the window when user altered the size. // Resize the window when user altered the size.
if old_physical_size != physical_size { if old_physical_size != physical_size {
@ -344,7 +344,7 @@ impl EventLoop {
let new_logical_size: LogicalSize<f64> = let new_logical_size: LogicalSize<f64> =
physical_size.to_logical(scale_factor); physical_size.to_logical(scale_factor);
window.request_inner_size(new_logical_size.into()); window.request_surface_size(new_logical_size.into());
}); });
// Make it queue resize. // Make it queue resize.
@ -360,7 +360,7 @@ impl EventLoop {
let window = windows.get(&window_id).unwrap().lock().unwrap(); let window = windows.get(&window_id).unwrap().lock().unwrap();
let scale_factor = window.scale_factor(); let scale_factor = window.scale_factor();
let size = logical_to_physical_rounded(window.inner_size(), scale_factor); let size = logical_to_physical_rounded(window.surface_size(), scale_factor);
// Mark the window as needed a redraw. // Mark the window as needed a redraw.
state state
@ -375,7 +375,7 @@ impl EventLoop {
}); });
let window_id = crate::window::WindowId(window_id); let window_id = crate::window::WindowId(window_id);
let event = WindowEvent::Resized(physical_size); let event = WindowEvent::SurfaceResized(physical_size);
app.window_event(&self.active_event_loop, window_id, event); app.window_event(&self.active_event_loop, window_id, event);
} }

View file

@ -89,7 +89,7 @@ impl Window {
state.xdg_activation.as_ref().map(|activation_state| activation_state.global().clone()); state.xdg_activation.as_ref().map(|activation_state| activation_state.global().clone());
let display = event_loop_window_target.connection.display(); let display = event_loop_window_target.connection.display();
let size: Size = attributes.inner_size.unwrap_or(LogicalSize::new(800., 600.).into()); let size: Size = attributes.surface_size.unwrap_or(LogicalSize::new(800., 600.).into());
// We prefer server side decorations, however to not have decorations we ask for client // We prefer server side decorations, however to not have decorations we ask for client
// side decorations instead. // side decorations instead.
@ -129,10 +129,10 @@ impl Window {
// Set the min and max sizes. We must set the hints upon creating a window, so // Set the min and max sizes. We must set the hints upon creating a window, so
// we use the default `1.` scaling... // we use the default `1.` scaling...
let min_size = attributes.min_inner_size.map(|size| size.to_logical(1.)); let min_size = attributes.min_surface_size.map(|size| size.to_logical(1.));
let max_size = attributes.max_inner_size.map(|size| size.to_logical(1.)); let max_size = attributes.max_surface_size.map(|size| size.to_logical(1.));
window_state.set_min_inner_size(min_size); window_state.set_min_surface_size(min_size);
window_state.set_max_inner_size(max_size); window_state.set_max_surface_size(max_size);
// Non-resizable implies that the min and max sizes are set to the same value. // Non-resizable implies that the min and max sizes are set to the same value.
window_state.set_resizable(attributes.resizable); window_state.set_resizable(attributes.resizable);
@ -321,15 +321,15 @@ impl CoreWindow for Window {
// Not possible. // Not possible.
} }
fn inner_size(&self) -> PhysicalSize<u32> { fn surface_size(&self) -> PhysicalSize<u32> {
let window_state = self.window_state.lock().unwrap(); let window_state = self.window_state.lock().unwrap();
let scale_factor = window_state.scale_factor(); let scale_factor = window_state.scale_factor();
super::logical_to_physical_rounded(window_state.inner_size(), scale_factor) super::logical_to_physical_rounded(window_state.surface_size(), scale_factor)
} }
fn request_inner_size(&self, size: Size) -> Option<PhysicalSize<u32>> { fn request_surface_size(&self, size: Size) -> Option<PhysicalSize<u32>> {
let mut window_state = self.window_state.lock().unwrap(); let mut window_state = self.window_state.lock().unwrap();
let new_size = window_state.request_inner_size(size); let new_size = window_state.request_surface_size(size);
self.request_redraw(); self.request_redraw();
Some(new_size) Some(new_size)
} }
@ -340,30 +340,30 @@ impl CoreWindow for Window {
super::logical_to_physical_rounded(window_state.outer_size(), scale_factor) super::logical_to_physical_rounded(window_state.outer_size(), scale_factor)
} }
fn set_min_inner_size(&self, min_size: Option<Size>) { fn set_min_surface_size(&self, min_size: Option<Size>) {
let scale_factor = self.scale_factor(); let scale_factor = self.scale_factor();
let min_size = min_size.map(|size| size.to_logical(scale_factor)); let min_size = min_size.map(|size| size.to_logical(scale_factor));
self.window_state.lock().unwrap().set_min_inner_size(min_size); self.window_state.lock().unwrap().set_min_surface_size(min_size);
// NOTE: Requires commit to be applied. // NOTE: Requires commit to be applied.
self.request_redraw(); self.request_redraw();
} }
/// Set the maximum inner size for the window. /// Set the maximum surface size for the window.
#[inline] #[inline]
fn set_max_inner_size(&self, max_size: Option<Size>) { fn set_max_surface_size(&self, max_size: Option<Size>) {
let scale_factor = self.scale_factor(); let scale_factor = self.scale_factor();
let max_size = max_size.map(|size| size.to_logical(scale_factor)); let max_size = max_size.map(|size| size.to_logical(scale_factor));
self.window_state.lock().unwrap().set_max_inner_size(max_size); self.window_state.lock().unwrap().set_max_surface_size(max_size);
// NOTE: Requires commit to be applied. // NOTE: Requires commit to be applied.
self.request_redraw(); self.request_redraw();
} }
fn resize_increments(&self) -> Option<PhysicalSize<u32>> { fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
None None
} }
fn set_resize_increments(&self, _increments: Option<Size>) { fn set_surface_resize_increments(&self, _increments: Option<Size>) {
warn!("`set_resize_increments` is not implemented for Wayland"); warn!("`set_surface_resize_increments` is not implemented for Wayland");
} }
fn set_title(&self, title: &str) { fn set_title(&self, title: &str) {

View file

@ -46,7 +46,7 @@ pub type WinitFrame = sctk_adwaita::AdwaitaFrame<WinitState>;
#[cfg(not(feature = "sctk-adwaita"))] #[cfg(not(feature = "sctk-adwaita"))]
pub type WinitFrame = sctk::shell::xdg::fallback_frame::FallbackFrame<WinitState>; pub type WinitFrame = sctk::shell::xdg::fallback_frame::FallbackFrame<WinitState>;
// Minimum window inner size. // Minimum window surface size.
const MIN_WINDOW_SIZE: LogicalSize<u32> = LogicalSize::new(2, 1); const MIN_WINDOW_SIZE: LogicalSize<u32> = LogicalSize::new(2, 1);
/// The state of the window which is being updated from the [`WinitState`]. /// The state of the window which is being updated from the [`WinitState`].
@ -112,7 +112,7 @@ pub struct WindowState {
/// The text inputs observed on the window. /// The text inputs observed on the window.
text_inputs: Vec<ZwpTextInputV3>, text_inputs: Vec<ZwpTextInputV3>,
/// The inner size of the window, as in without client side decorations. /// The surface size of the window, as in without client side decorations.
size: LogicalSize<u32>, size: LogicalSize<u32>,
/// Whether the CSD fail to create, so we don't try to create them on each iteration. /// Whether the CSD fail to create, so we don't try to create them on each iteration.
@ -122,8 +122,8 @@ pub struct WindowState {
decorate: bool, decorate: bool,
/// Min size. /// Min size.
min_inner_size: LogicalSize<u32>, min_surface_size: LogicalSize<u32>,
max_inner_size: Option<LogicalSize<u32>>, max_surface_size: Option<LogicalSize<u32>>,
/// The size of the window when no states were applied to it. The primary use for it /// The size of the window when no states were applied to it. The primary use for it
/// is to fallback to original window size, before it was maximized, if the compositor /// is to fallback to original window size, before it was maximized, if the compositor
@ -197,8 +197,8 @@ impl WindowState {
ime_allowed: false, ime_allowed: false,
ime_purpose: ImePurpose::Normal, ime_purpose: ImePurpose::Normal,
last_configure: None, last_configure: None,
max_inner_size: None, max_surface_size: None,
min_inner_size: MIN_WINDOW_SIZE, min_surface_size: MIN_WINDOW_SIZE,
pointer_constraints, pointer_constraints,
pointers: Default::default(), pointers: Default::default(),
queue_handle: queue_handle.clone(), queue_handle: queue_handle.clone(),
@ -328,7 +328,7 @@ impl WindowState {
// Apply configure bounds only when compositor let the user decide what size to pick. // Apply configure bounds only when compositor let the user decide what size to pick.
if constrain { if constrain {
let bounds = self.inner_size_bounds(&configure); let bounds = self.surface_size_bounds(&configure);
new_size.width = new_size.width =
bounds.0.map(|bound_w| new_size.width.min(bound_w.get())).unwrap_or(new_size.width); bounds.0.map(|bound_w| new_size.width.min(bound_w.get())).unwrap_or(new_size.width);
new_size.height = bounds new_size.height = bounds
@ -353,7 +353,7 @@ impl WindowState {
// NOTE: Set the configure before doing a resize, since we query it during it. // NOTE: Set the configure before doing a resize, since we query it during it.
self.last_configure = Some(configure); self.last_configure = Some(configure);
if state_change_requires_resize || new_size != self.inner_size() { if state_change_requires_resize || new_size != self.surface_size() {
self.resize(new_size); self.resize(new_size);
true true
} else { } else {
@ -361,8 +361,8 @@ impl WindowState {
} }
} }
/// Compute the bounds for the inner size of the surface. /// Compute the bounds for the surface size of the surface.
fn inner_size_bounds( fn surface_size_bounds(
&self, &self,
configure: &WindowConfigure, configure: &WindowConfigure,
) -> (Option<NonZeroU32>, Option<NonZeroU32>) { ) -> (Option<NonZeroU32>, Option<NonZeroU32>) {
@ -507,8 +507,8 @@ impl WindowState {
// Restore min/max sizes of the window. // Restore min/max sizes of the window.
self.reload_min_max_hints(); self.reload_min_max_hints();
} else { } else {
self.set_min_inner_size(Some(self.size)); self.set_min_surface_size(Some(self.size));
self.set_max_inner_size(Some(self.size)); self.set_max_surface_size(Some(self.size));
} }
// Reload the state on the frame as well. // Reload the state on the frame as well.
@ -533,7 +533,7 @@ impl WindowState {
/// Get the size of the window. /// Get the size of the window.
#[inline] #[inline]
pub fn inner_size(&self) -> LogicalSize<u32> { pub fn surface_size(&self) -> LogicalSize<u32> {
self.size self.size
} }
@ -628,21 +628,21 @@ impl WindowState {
} }
/// Try to resize the window when the user can do so. /// Try to resize the window when the user can do so.
pub fn request_inner_size(&mut self, inner_size: Size) -> PhysicalSize<u32> { pub fn request_surface_size(&mut self, surface_size: Size) -> PhysicalSize<u32> {
if self.last_configure.as_ref().map(Self::is_stateless).unwrap_or(true) { if self.last_configure.as_ref().map(Self::is_stateless).unwrap_or(true) {
self.resize(inner_size.to_logical(self.scale_factor())) self.resize(surface_size.to_logical(self.scale_factor()))
} }
logical_to_physical_rounded(self.inner_size(), self.scale_factor()) logical_to_physical_rounded(self.surface_size(), self.scale_factor())
} }
/// Resize the window to the new inner size. /// Resize the window to the new surface size.
fn resize(&mut self, inner_size: LogicalSize<u32>) { fn resize(&mut self, surface_size: LogicalSize<u32>) {
self.size = inner_size; self.size = surface_size;
// Update the stateless size. // Update the stateless size.
if Some(true) == self.last_configure.as_ref().map(Self::is_stateless) { if Some(true) == self.last_configure.as_ref().map(Self::is_stateless) {
self.stateless_size = inner_size; self.stateless_size = surface_size;
} }
// Update the inner frame. // Update the inner frame.
@ -673,7 +673,7 @@ impl WindowState {
// Update the target viewport, this is used if and only if fractional scaling is in use. // Update the target viewport, this is used if and only if fractional scaling is in use.
if let Some(viewport) = self.viewport.as_ref() { if let Some(viewport) = self.viewport.as_ref() {
// Set inner size without the borders. // Set surface size without the borders.
viewport.set_destination(self.size.width as _, self.size.height as _); viewport.set_destination(self.size.width as _, self.size.height as _);
} }
} }
@ -753,7 +753,7 @@ impl WindowState {
} }
/// Set maximum inner window size. /// Set maximum inner window size.
pub fn set_min_inner_size(&mut self, size: Option<LogicalSize<u32>>) { pub fn set_min_surface_size(&mut self, size: Option<LogicalSize<u32>>) {
// Ensure that the window has the right minimum size. // Ensure that the window has the right minimum size.
let mut size = size.unwrap_or(MIN_WINDOW_SIZE); let mut size = size.unwrap_or(MIN_WINDOW_SIZE);
size.width = size.width.max(MIN_WINDOW_SIZE.width); size.width = size.width.max(MIN_WINDOW_SIZE.width);
@ -766,12 +766,12 @@ impl WindowState {
.map(|frame| frame.add_borders(size.width, size.height).into()) .map(|frame| frame.add_borders(size.width, size.height).into())
.unwrap_or(size); .unwrap_or(size);
self.min_inner_size = size; self.min_surface_size = size;
self.window.set_min_size(Some(size.into())); self.window.set_min_size(Some(size.into()));
} }
/// Set maximum inner window size. /// Set maximum inner window size.
pub fn set_max_inner_size(&mut self, size: Option<LogicalSize<u32>>) { pub fn set_max_surface_size(&mut self, size: Option<LogicalSize<u32>>) {
let size = size.map(|size| { let size = size.map(|size| {
self.frame self.frame
.as_ref() .as_ref()
@ -779,7 +779,7 @@ impl WindowState {
.unwrap_or(size) .unwrap_or(size)
}); });
self.max_inner_size = size; self.max_surface_size = size;
self.window.set_max_size(size.map(Into::into)); self.window.set_max_size(size.map(Into::into));
} }
@ -812,8 +812,8 @@ impl WindowState {
/// Reload the hints for minimum and maximum sizes. /// Reload the hints for minimum and maximum sizes.
pub fn reload_min_max_hints(&mut self) { pub fn reload_min_max_hints(&mut self) {
self.set_min_inner_size(Some(self.min_inner_size)); self.set_min_surface_size(Some(self.min_surface_size));
self.set_max_inner_size(self.max_inner_size); self.set_max_surface_size(self.max_surface_size);
} }
/// Set the grabbing state on the surface. /// Set the grabbing state on the surface.

View file

@ -22,8 +22,8 @@ use xkbcommon_dl::xkb_mod_mask_t;
use crate::dpi::{PhysicalPosition, PhysicalSize}; use crate::dpi::{PhysicalPosition, PhysicalSize};
use crate::event::{ use crate::event::{
DeviceEvent, ElementState, Event, Ime, InnerSizeWriter, MouseButton, MouseScrollDelta, DeviceEvent, ElementState, Event, Ime, MouseButton, MouseScrollDelta, RawKeyEvent,
RawKeyEvent, Touch, TouchPhase, WindowEvent, SurfaceSizeWriter, Touch, TouchPhase, WindowEvent,
}; };
use crate::keyboard::ModifiersState; use crate::keyboard::ModifiersState;
use crate::platform_impl::common::xkb::{self, XkbState}; use crate::platform_impl::common::xkb::{self, XkbState};
@ -598,19 +598,19 @@ impl EventProcessor {
// `XSendEvent` (synthetic `ConfigureNotify`) -> position relative to root // `XSendEvent` (synthetic `ConfigureNotify`) -> position relative to root
// `XConfigureNotify` (real `ConfigureNotify`) -> position relative to parent // `XConfigureNotify` (real `ConfigureNotify`) -> position relative to parent
// https://tronche.com/gui/x/icccm/sec-4.html#s-4.1.5 // https://tronche.com/gui/x/icccm/sec-4.html#s-4.1.5
// We don't want to send `Moved` when this is false, since then every `Resized` // We don't want to send `Moved` when this is false, since then every `SurfaceResized`
// (whether the window moved or not) is accompanied by an extraneous `Moved` event // (whether the window moved or not) is accompanied by an extraneous `Moved` event
// that has a position relative to the parent window. // that has a position relative to the parent window.
let is_synthetic = xev.send_event == xlib::True; let is_synthetic = xev.send_event == xlib::True;
// These are both in physical space. // These are both in physical space.
let new_inner_size = (xev.width as u32, xev.height as u32); let new_surface_size = (xev.width as u32, xev.height as u32);
let new_inner_position = (xev.x, xev.y); let new_inner_position = (xev.x, xev.y);
let (mut resized, moved) = { let (mut resized, moved) = {
let mut shared_state_lock = window.shared_state_lock(); let mut shared_state_lock = window.shared_state_lock();
let resized = util::maybe_change(&mut shared_state_lock.size, new_inner_size); let resized = util::maybe_change(&mut shared_state_lock.size, new_surface_size);
let moved = if is_synthetic { let moved = if is_synthetic {
util::maybe_change(&mut shared_state_lock.inner_position, new_inner_position) util::maybe_change(&mut shared_state_lock.inner_position, new_inner_position)
} else { } else {
@ -671,7 +671,7 @@ impl EventProcessor {
let last_scale_factor = shared_state_lock.last_monitor.scale_factor; let last_scale_factor = shared_state_lock.last_monitor.scale_factor;
let new_scale_factor = { let new_scale_factor = {
let window_rect = util::AaRect::new(new_outer_position, new_inner_size); let window_rect = util::AaRect::new(new_outer_position, new_surface_size);
let monitor = self let monitor = self
.target .target
.xconn .xconn
@ -695,27 +695,30 @@ impl EventProcessor {
&shared_state_lock, &shared_state_lock,
); );
let old_inner_size = PhysicalSize::new(width, height); let old_surface_size = PhysicalSize::new(width, height);
let new_inner_size = PhysicalSize::new(new_width, new_height); let new_surface_size = PhysicalSize::new(new_width, new_height);
// Unlock shared state to prevent deadlock in callback below // Unlock shared state to prevent deadlock in callback below
drop(shared_state_lock); drop(shared_state_lock);
let inner_size = Arc::new(Mutex::new(new_inner_size)); let surface_size = Arc::new(Mutex::new(new_surface_size));
callback(&self.target, Event::WindowEvent { callback(&self.target, Event::WindowEvent {
window_id, window_id,
event: WindowEvent::ScaleFactorChanged { event: WindowEvent::ScaleFactorChanged {
scale_factor: new_scale_factor, scale_factor: new_scale_factor,
inner_size_writer: InnerSizeWriter::new(Arc::downgrade(&inner_size)), surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&surface_size)),
}, },
}); });
let new_inner_size = *inner_size.lock().unwrap(); let new_surface_size = *surface_size.lock().unwrap();
drop(inner_size); drop(surface_size);
if new_inner_size != old_inner_size { if new_surface_size != old_surface_size {
window.request_inner_size_physical(new_inner_size.width, new_inner_size.height); window.request_surface_size_physical(
window.shared_state_lock().dpi_adjusted = Some(new_inner_size.into()); new_surface_size.width,
new_surface_size.height,
);
window.shared_state_lock().dpi_adjusted = Some(new_surface_size.into());
// if the DPI factor changed, force a resize event to ensure the logical // if the DPI factor changed, force a resize event to ensure the logical
// size is computed with the right DPI factor // size is computed with the right DPI factor
resized = true; resized = true;
@ -736,13 +739,13 @@ impl EventProcessor {
// XResizeWindow requests, making Xorg, the winit client, and the WM // XResizeWindow requests, making Xorg, the winit client, and the WM
// consume 100% of CPU. // consume 100% of CPU.
if let Some(adjusted_size) = shared_state_lock.dpi_adjusted { if let Some(adjusted_size) = shared_state_lock.dpi_adjusted {
if new_inner_size == adjusted_size || !util::wm_name_is_one_of(&["Xfwm4"]) { if new_surface_size == adjusted_size || !util::wm_name_is_one_of(&["Xfwm4"]) {
// When this finally happens, the event will not be synthetic. // When this finally happens, the event will not be synthetic.
shared_state_lock.dpi_adjusted = None; shared_state_lock.dpi_adjusted = None;
} else { } else {
// Unlock shared state to prevent deadlock in callback below // Unlock shared state to prevent deadlock in callback below
drop(shared_state_lock); drop(shared_state_lock);
window.request_inner_size_physical(adjusted_size.0, adjusted_size.1); window.request_surface_size_physical(adjusted_size.0, adjusted_size.1);
} }
} }
@ -757,7 +760,7 @@ impl EventProcessor {
if resized { if resized {
callback(&self.target, Event::WindowEvent { callback(&self.target, Event::WindowEvent {
window_id, window_id,
event: WindowEvent::Resized(new_inner_size.into()), event: WindowEvent::SurfaceResized(new_surface_size.into()),
}); });
} }
} }

View file

@ -76,7 +76,7 @@ impl FrameExtentsHeuristic {
} }
} }
pub fn inner_size_to_outer(&self, width: u32, height: u32) -> (u32, u32) { pub fn surface_size_to_outer(&self, width: u32, height: u32) -> (u32, u32) {
( (
width.saturating_add( width.saturating_add(
self.frame_extents.left.saturating_add(self.frame_extents.right) as _ self.frame_extents.left.saturating_add(self.frame_extents.right) as _
@ -98,7 +98,7 @@ impl XConnection {
self.xcb_connection().translate_coordinates(window, root, 0, 0)?.reply().map_err(Into::into) self.xcb_connection().translate_coordinates(window, root, 0, 0)?.reply().map_err(Into::into)
} }
// This is adequate for inner_size // This is adequate for surface_size
pub fn get_geometry( pub fn get_geometry(
&self, &self,
window: xproto::Window, window: xproto::Window,

View file

@ -23,7 +23,7 @@ use super::{
use crate::cursor::{Cursor, CustomCursor as RootCustomCursor}; use crate::cursor::{Cursor, CustomCursor as RootCustomCursor};
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError}; use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError};
use crate::event::{Event, InnerSizeWriter, WindowEvent}; use crate::event::{Event, SurfaceSizeWriter, WindowEvent};
use crate::event_loop::AsyncRequestSerial; use crate::event_loop::AsyncRequestSerial;
use crate::platform::x11::WindowType; use crate::platform::x11::WindowType;
use crate::platform_impl::x11::atoms::*; use crate::platform_impl::x11::atoms::*;
@ -94,32 +94,32 @@ impl CoreWindow for Window {
self.0.set_outer_position(position) self.0.set_outer_position(position)
} }
fn inner_size(&self) -> PhysicalSize<u32> { fn surface_size(&self) -> PhysicalSize<u32> {
self.0.inner_size() self.0.surface_size()
} }
fn request_inner_size(&self, size: Size) -> Option<PhysicalSize<u32>> { fn request_surface_size(&self, size: Size) -> Option<PhysicalSize<u32>> {
self.0.request_inner_size(size) self.0.request_surface_size(size)
} }
fn outer_size(&self) -> PhysicalSize<u32> { fn outer_size(&self) -> PhysicalSize<u32> {
self.0.outer_size() self.0.outer_size()
} }
fn set_min_inner_size(&self, min_size: Option<Size>) { fn set_min_surface_size(&self, min_size: Option<Size>) {
self.0.set_min_inner_size(min_size) self.0.set_min_surface_size(min_size)
} }
fn set_max_inner_size(&self, max_size: Option<Size>) { fn set_max_surface_size(&self, max_size: Option<Size>) {
self.0.set_max_inner_size(max_size) self.0.set_max_surface_size(max_size)
} }
fn resize_increments(&self) -> Option<PhysicalSize<u32>> { fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
self.0.resize_increments() self.0.surface_resize_increments()
} }
fn set_resize_increments(&self, increments: Option<Size>) { fn set_surface_resize_increments(&self, increments: Option<Size>) {
self.0.set_resize_increments(increments) self.0.set_surface_resize_increments(increments)
} }
fn set_title(&self, title: &str) { fn set_title(&self, title: &str) {
@ -356,9 +356,9 @@ pub struct SharedState {
// Used to restore video mode after exiting fullscreen // Used to restore video mode after exiting fullscreen
pub desktop_video_mode: Option<(randr::Crtc, randr::Mode)>, pub desktop_video_mode: Option<(randr::Crtc, randr::Mode)>,
pub frame_extents: Option<util::FrameExtentsHeuristic>, pub frame_extents: Option<util::FrameExtentsHeuristic>,
pub min_inner_size: Option<Size>, pub min_surface_size: Option<Size>,
pub max_inner_size: Option<Size>, pub max_surface_size: Option<Size>,
pub resize_increments: Option<Size>, pub surface_resize_increments: Option<Size>,
pub base_size: Option<Size>, pub base_size: Option<Size>,
pub visibility: Visibility, pub visibility: Visibility,
pub has_focus: bool, pub has_focus: bool,
@ -396,9 +396,9 @@ impl SharedState {
restore_position: None, restore_position: None,
desktop_video_mode: None, desktop_video_mode: None,
frame_extents: None, frame_extents: None,
min_inner_size: None, min_surface_size: None,
max_inner_size: None, max_surface_size: None,
resize_increments: None, surface_resize_increments: None,
base_size: None, base_size: None,
has_focus: false, has_focus: false,
cursor_hittest: None, cursor_hittest: None,
@ -479,10 +479,10 @@ impl UnownedWindow {
info!("Guessed window scale factor: {}", scale_factor); info!("Guessed window scale factor: {}", scale_factor);
let max_inner_size: Option<(u32, u32)> = let max_surface_size: Option<(u32, u32)> =
window_attrs.max_inner_size.map(|size| size.to_physical::<u32>(scale_factor).into()); window_attrs.max_surface_size.map(|size| size.to_physical::<u32>(scale_factor).into());
let min_inner_size: Option<(u32, u32)> = let min_surface_size: Option<(u32, u32)> =
window_attrs.min_inner_size.map(|size| size.to_physical::<u32>(scale_factor).into()); window_attrs.min_surface_size.map(|size| size.to_physical::<u32>(scale_factor).into());
let position = let position =
window_attrs.position.map(|position| position.to_physical::<i32>(scale_factor)); window_attrs.position.map(|position| position.to_physical::<i32>(scale_factor));
@ -491,16 +491,16 @@ impl UnownedWindow {
// x11 only applies constraints when the window is actively resized // x11 only applies constraints when the window is actively resized
// by the user, so we have to manually apply the initial constraints // by the user, so we have to manually apply the initial constraints
let mut dimensions: (u32, u32) = window_attrs let mut dimensions: (u32, u32) = window_attrs
.inner_size .surface_size
.map(|size| size.to_physical::<u32>(scale_factor)) .map(|size| size.to_physical::<u32>(scale_factor))
.or_else(|| Some((800, 600).into())) .or_else(|| Some((800, 600).into()))
.map(Into::into) .map(Into::into)
.unwrap(); .unwrap();
if let Some(max) = max_inner_size { if let Some(max) = max_surface_size {
dimensions.0 = cmp::min(dimensions.0, max.0); dimensions.0 = cmp::min(dimensions.0, max.0);
dimensions.1 = cmp::min(dimensions.1, max.1); dimensions.1 = cmp::min(dimensions.1, max.1);
} }
if let Some(min) = min_inner_size { if let Some(min) = min_surface_size {
dimensions.0 = cmp::max(dimensions.0, min.0); dimensions.0 = cmp::max(dimensions.0, min.0);
dimensions.1 = cmp::max(dimensions.1, min.1); dimensions.1 = cmp::max(dimensions.1, min.1);
} }
@ -717,24 +717,24 @@ impl UnownedWindow {
.ignore_error(); .ignore_error();
// Set size hints. // Set size hints.
let mut min_inner_size = let mut min_surface_size =
window_attrs.min_inner_size.map(|size| size.to_physical::<u32>(scale_factor)); window_attrs.min_surface_size.map(|size| size.to_physical::<u32>(scale_factor));
let mut max_inner_size = let mut max_surface_size =
window_attrs.max_inner_size.map(|size| size.to_physical::<u32>(scale_factor)); window_attrs.max_surface_size.map(|size| size.to_physical::<u32>(scale_factor));
if !window_attrs.resizable { if !window_attrs.resizable {
if util::wm_name_is_one_of(&["Xfwm4"]) { if util::wm_name_is_one_of(&["Xfwm4"]) {
warn!("To avoid a WM bug, disabling resizing has no effect on Xfwm4"); warn!("To avoid a WM bug, disabling resizing has no effect on Xfwm4");
} else { } else {
max_inner_size = Some(dimensions.into()); max_surface_size = Some(dimensions.into());
min_inner_size = Some(dimensions.into()); min_surface_size = Some(dimensions.into());
} }
} }
let shared_state = window.shared_state.get_mut().unwrap(); let shared_state = window.shared_state.get_mut().unwrap();
shared_state.min_inner_size = min_inner_size.map(Into::into); shared_state.min_surface_size = min_surface_size.map(Into::into);
shared_state.max_inner_size = max_inner_size.map(Into::into); shared_state.max_surface_size = max_surface_size.map(Into::into);
shared_state.resize_increments = window_attrs.resize_increments; shared_state.surface_resize_increments = window_attrs.surface_resize_increments;
shared_state.base_size = window_attrs.platform_specific.x11.base_size; shared_state.base_size = window_attrs.platform_specific.x11.base_size;
let normal_hints = WmSizeHints { let normal_hints = WmSizeHints {
@ -746,10 +746,10 @@ impl UnownedWindow {
cast_dimension_to_hint(dimensions.0), cast_dimension_to_hint(dimensions.0),
cast_dimension_to_hint(dimensions.1), cast_dimension_to_hint(dimensions.1),
)), )),
max_size: max_inner_size.map(cast_physical_size_to_hint), max_size: max_surface_size.map(cast_physical_size_to_hint),
min_size: min_inner_size.map(cast_physical_size_to_hint), min_size: min_surface_size.map(cast_physical_size_to_hint),
size_increment: window_attrs size_increment: window_attrs
.resize_increments .surface_resize_increments
.map(|size| cast_size_to_hint(size, scale_factor)), .map(|size| cast_size_to_hint(size, scale_factor)),
base_size: window_attrs base_size: window_attrs
.platform_specific .platform_specific
@ -1210,7 +1210,7 @@ impl UnownedWindow {
// Check if the self is on this monitor // Check if the self is on this monitor
let monitor = self.shared_state_lock().last_monitor.clone(); let monitor = self.shared_state_lock().last_monitor.clone();
if monitor.name == new_monitor.name { if monitor.name == new_monitor.name {
let (width, height) = self.inner_size_physical(); let (width, height) = self.surface_size_physical();
let (new_width, new_height) = self.adjust_for_dpi( let (new_width, new_height) = self.adjust_for_dpi(
// If we couldn't determine the previous scale // If we couldn't determine the previous scale
// factor (e.g., because all monitors were closed // factor (e.g., because all monitors were closed
@ -1224,22 +1224,22 @@ impl UnownedWindow {
); );
let window_id = crate::window::WindowId(self.id()); let window_id = crate::window::WindowId(self.id());
let old_inner_size = PhysicalSize::new(width, height); let old_surface_size = PhysicalSize::new(width, height);
let inner_size = Arc::new(Mutex::new(PhysicalSize::new(new_width, new_height))); let surface_size = Arc::new(Mutex::new(PhysicalSize::new(new_width, new_height)));
callback(Event::WindowEvent { callback(Event::WindowEvent {
window_id, window_id,
event: WindowEvent::ScaleFactorChanged { event: WindowEvent::ScaleFactorChanged {
scale_factor: new_monitor.scale_factor, scale_factor: new_monitor.scale_factor,
inner_size_writer: InnerSizeWriter::new(Arc::downgrade(&inner_size)), surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&surface_size)),
}, },
}); });
let new_inner_size = *inner_size.lock().unwrap(); let new_surface_size = *surface_size.lock().unwrap();
drop(inner_size); drop(surface_size);
if new_inner_size != old_inner_size { if new_surface_size != old_surface_size {
let (new_width, new_height) = new_inner_size.into(); let (new_width, new_height) = new_surface_size.into();
self.request_inner_size_physical(new_width, new_height); self.request_surface_size_physical(new_width, new_height);
} }
} }
} }
@ -1559,7 +1559,7 @@ impl UnownedWindow {
self.set_position_physical(x, y); self.set_position_physical(x, y);
} }
pub(crate) fn inner_size_physical(&self) -> (u32, u32) { pub(crate) fn surface_size_physical(&self) -> (u32, u32) {
// This should be okay to unwrap since the only error XGetGeometry can return // This should be okay to unwrap since the only error XGetGeometry can return
// is BadWindow, and if the window handle is bad we have bigger problems. // is BadWindow, and if the window handle is bad we have bigger problems.
self.xconn self.xconn
@ -1569,23 +1569,23 @@ impl UnownedWindow {
} }
#[inline] #[inline]
pub fn inner_size(&self) -> PhysicalSize<u32> { pub fn surface_size(&self) -> PhysicalSize<u32> {
self.inner_size_physical().into() self.surface_size_physical().into()
} }
#[inline] #[inline]
pub fn outer_size(&self) -> PhysicalSize<u32> { pub fn outer_size(&self) -> PhysicalSize<u32> {
let extents = self.shared_state_lock().frame_extents.clone(); let extents = self.shared_state_lock().frame_extents.clone();
if let Some(extents) = extents { if let Some(extents) = extents {
let (width, height) = self.inner_size_physical(); let (width, height) = self.surface_size_physical();
extents.inner_size_to_outer(width, height).into() extents.surface_size_to_outer(width, height).into()
} else { } else {
self.update_cached_frame_extents(); self.update_cached_frame_extents();
self.outer_size() self.outer_size()
} }
} }
pub(crate) fn request_inner_size_physical(&self, width: u32, height: u32) { pub(crate) fn request_surface_size_physical(&self, width: u32, height: u32) {
self.xconn self.xconn
.xcb_connection() .xcb_connection()
.configure_window( .configure_window(
@ -1601,7 +1601,7 @@ impl UnownedWindow {
} }
#[inline] #[inline]
pub fn request_inner_size(&self, size: Size) -> Option<PhysicalSize<u32>> { pub fn request_surface_size(&self, size: Size) -> Option<PhysicalSize<u32>> {
let scale_factor = self.scale_factor(); let scale_factor = self.scale_factor();
let size = size.to_physical::<u32>(scale_factor).into(); let size = size.to_physical::<u32>(scale_factor).into();
if !self.shared_state_lock().is_resizable { if !self.shared_state_lock().is_resizable {
@ -1611,7 +1611,7 @@ impl UnownedWindow {
}) })
.expect("Failed to call `XSetWMNormalHints`"); .expect("Failed to call `XSetWMNormalHints`");
} }
self.request_inner_size_physical(size.0 as u32, size.1 as u32); self.request_surface_size_physical(size.0 as u32, size.1 as u32);
None None
} }
@ -1638,7 +1638,7 @@ impl UnownedWindow {
Ok(()) Ok(())
} }
pub(crate) fn set_min_inner_size_physical(&self, dimensions: Option<(u32, u32)>) { pub(crate) fn set_min_surface_size_physical(&self, dimensions: Option<(u32, u32)>) {
self.update_normal_hints(|normal_hints| { self.update_normal_hints(|normal_hints| {
normal_hints.min_size = normal_hints.min_size =
dimensions.map(|(w, h)| (cast_dimension_to_hint(w), cast_dimension_to_hint(h))) dimensions.map(|(w, h)| (cast_dimension_to_hint(w), cast_dimension_to_hint(h)))
@ -1647,14 +1647,14 @@ impl UnownedWindow {
} }
#[inline] #[inline]
pub fn set_min_inner_size(&self, dimensions: Option<Size>) { pub fn set_min_surface_size(&self, dimensions: Option<Size>) {
self.shared_state_lock().min_inner_size = dimensions; self.shared_state_lock().min_surface_size = dimensions;
let physical_dimensions = let physical_dimensions =
dimensions.map(|dimensions| dimensions.to_physical::<u32>(self.scale_factor()).into()); dimensions.map(|dimensions| dimensions.to_physical::<u32>(self.scale_factor()).into());
self.set_min_inner_size_physical(physical_dimensions); self.set_min_surface_size_physical(physical_dimensions);
} }
pub(crate) fn set_max_inner_size_physical(&self, dimensions: Option<(u32, u32)>) { pub(crate) fn set_max_surface_size_physical(&self, dimensions: Option<(u32, u32)>) {
self.update_normal_hints(|normal_hints| { self.update_normal_hints(|normal_hints| {
normal_hints.max_size = normal_hints.max_size =
dimensions.map(|(w, h)| (cast_dimension_to_hint(w), cast_dimension_to_hint(h))) dimensions.map(|(w, h)| (cast_dimension_to_hint(w), cast_dimension_to_hint(h)))
@ -1663,15 +1663,15 @@ impl UnownedWindow {
} }
#[inline] #[inline]
pub fn set_max_inner_size(&self, dimensions: Option<Size>) { pub fn set_max_surface_size(&self, dimensions: Option<Size>) {
self.shared_state_lock().max_inner_size = dimensions; self.shared_state_lock().max_surface_size = dimensions;
let physical_dimensions = let physical_dimensions =
dimensions.map(|dimensions| dimensions.to_physical::<u32>(self.scale_factor()).into()); dimensions.map(|dimensions| dimensions.to_physical::<u32>(self.scale_factor()).into());
self.set_max_inner_size_physical(physical_dimensions); self.set_max_surface_size_physical(physical_dimensions);
} }
#[inline] #[inline]
pub fn resize_increments(&self) -> Option<PhysicalSize<u32>> { pub fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
WmSizeHints::get( WmSizeHints::get(
self.xconn.xcb_connection(), self.xconn.xcb_connection(),
self.xwindow as xproto::Window, self.xwindow as xproto::Window,
@ -1685,8 +1685,8 @@ impl UnownedWindow {
} }
#[inline] #[inline]
pub fn set_resize_increments(&self, increments: Option<Size>) { pub fn set_surface_resize_increments(&self, increments: Option<Size>) {
self.shared_state_lock().resize_increments = increments; self.shared_state_lock().surface_resize_increments = increments;
let physical_increments = let physical_increments =
increments.map(|increments| cast_size_to_hint(increments, self.scale_factor())); increments.map(|increments| cast_size_to_hint(increments, self.scale_factor()));
self.update_normal_hints(|hints| hints.size_increment = physical_increments) self.update_normal_hints(|hints| hints.size_increment = physical_increments)
@ -1704,14 +1704,15 @@ impl UnownedWindow {
let scale_factor = new_scale_factor / old_scale_factor; let scale_factor = new_scale_factor / old_scale_factor;
self.update_normal_hints(|normal_hints| { self.update_normal_hints(|normal_hints| {
let dpi_adjuster = |size: Size| -> (i32, i32) { cast_size_to_hint(size, scale_factor) }; let dpi_adjuster = |size: Size| -> (i32, i32) { cast_size_to_hint(size, scale_factor) };
let max_size = shared_state.max_inner_size.map(dpi_adjuster); let max_size = shared_state.max_surface_size.map(dpi_adjuster);
let min_size = shared_state.min_inner_size.map(dpi_adjuster); let min_size = shared_state.min_surface_size.map(dpi_adjuster);
let resize_increments = shared_state.resize_increments.map(dpi_adjuster); let surface_resize_increments =
shared_state.surface_resize_increments.map(dpi_adjuster);
let base_size = shared_state.base_size.map(dpi_adjuster); let base_size = shared_state.base_size.map(dpi_adjuster);
normal_hints.max_size = max_size; normal_hints.max_size = max_size;
normal_hints.min_size = min_size; normal_hints.min_size = min_size;
normal_hints.size_increment = resize_increments; normal_hints.size_increment = surface_resize_increments;
normal_hints.base_size = base_size; normal_hints.base_size = base_size;
}) })
.expect("Failed to update normal hints"); .expect("Failed to update normal hints");
@ -1734,9 +1735,9 @@ impl UnownedWindow {
let (min_size, max_size) = if resizable { let (min_size, max_size) = if resizable {
let shared_state_lock = self.shared_state_lock(); let shared_state_lock = self.shared_state_lock();
(shared_state_lock.min_inner_size, shared_state_lock.max_inner_size) (shared_state_lock.min_surface_size, shared_state_lock.max_surface_size)
} else { } else {
let window_size = Some(Size::from(self.inner_size())); let window_size = Some(Size::from(self.surface_size()));
(window_size, window_size) (window_size, window_size)
}; };
self.shared_state_lock().is_resizable = resizable; self.shared_state_lock().is_resizable = resizable;
@ -1745,11 +1746,11 @@ impl UnownedWindow {
.expect_then_ignore_error("Failed to call `XSetWMNormalHints`"); .expect_then_ignore_error("Failed to call `XSetWMNormalHints`");
let scale_factor = self.scale_factor(); let scale_factor = self.scale_factor();
let min_inner_size = min_size.map(|size| cast_size_to_hint(size, scale_factor)); let min_surface_size = min_size.map(|size| cast_size_to_hint(size, scale_factor));
let max_inner_size = max_size.map(|size| cast_size_to_hint(size, scale_factor)); let max_surface_size = max_size.map(|size| cast_size_to_hint(size, scale_factor));
self.update_normal_hints(|normal_hints| { self.update_normal_hints(|normal_hints| {
normal_hints.min_size = min_inner_size; normal_hints.min_size = min_surface_size;
normal_hints.max_size = max_inner_size; normal_hints.max_size = max_surface_size;
}) })
.expect("Failed to call `XSetWMNormalHints`"); .expect("Failed to call `XSetWMNormalHints`");
} }
@ -1946,7 +1947,7 @@ impl UnownedWindow {
pub fn set_cursor_hittest(&self, hittest: bool) -> Result<(), ExternalError> { pub fn set_cursor_hittest(&self, hittest: bool) -> Result<(), ExternalError> {
let mut rectangles: Vec<Rectangle> = Vec::new(); let mut rectangles: Vec<Rectangle> = Vec::new();
if hittest { if hittest {
let size = self.inner_size(); let size = self.surface_size();
rectangles.push(Rectangle { rectangles.push(Rectangle {
x: 0, x: 0,
y: 0, y: 0,

View file

@ -476,7 +476,7 @@ impl EventLoop {
app.window_event( app.window_event(
window_target, window_target,
RootWindowId(window_id), RootWindowId(window_id),
event::WindowEvent::Resized((width, height).into()), event::WindowEvent::SurfaceResized((width, height).into()),
); );
// Acknowledge resize after event loop. // Acknowledge resize after event loop.
@ -523,7 +523,7 @@ impl EventLoop {
let window_id = RootWindowId(window_id); let window_id = RootWindowId(window_id);
// Send resize event on create to indicate first size. // Send resize event on create to indicate first size.
let event = event::WindowEvent::Resized((properties.w, properties.h).into()); let event = event::WindowEvent::SurfaceResized((properties.w, properties.h).into());
app.window_event(&self.window_target, window_id, event); app.window_event(&self.window_target, window_id, event);
// Send moved event on create to indicate first position. // Send moved event on create to indicate first position.

View file

@ -42,13 +42,13 @@ impl Window {
(-1, -1) (-1, -1)
}; };
let (w, h): (u32, u32) = if let Some(size) = attrs.inner_size { let (w, h): (u32, u32) = if let Some(size) = attrs.surface_size {
size.to_physical::<u32>(scale).into() size.to_physical::<u32>(scale).into()
} else { } else {
(1024, 768) (1024, 768)
}; };
// TODO: min/max inner_size // TODO: min/max surface_size
// Async by default. // Async by default.
let mut flag_str = ORBITAL_FLAG_ASYNC.to_string(); let mut flag_str = ORBITAL_FLAG_ASYNC.to_string();
@ -225,7 +225,7 @@ impl CoreWindow for Window {
} }
#[inline] #[inline]
fn inner_size(&self) -> PhysicalSize<u32> { fn surface_size(&self) -> PhysicalSize<u32> {
let mut buf: [u8; 4096] = [0; 4096]; let mut buf: [u8; 4096] = [0; 4096];
let path = self.window_socket.fpath(&mut buf).expect("failed to read properties"); let path = self.window_socket.fpath(&mut buf).expect("failed to read properties");
let properties = WindowProperties::new(path); let properties = WindowProperties::new(path);
@ -233,7 +233,7 @@ impl CoreWindow for Window {
} }
#[inline] #[inline]
fn request_inner_size(&self, size: Size) -> Option<PhysicalSize<u32>> { fn request_surface_size(&self, size: Size) -> Option<PhysicalSize<u32>> {
let (w, h): (u32, u32) = size.to_physical::<u32>(self.scale_factor()).into(); let (w, h): (u32, u32) = size.to_physical::<u32>(self.scale_factor()).into();
self.window_socket.write(format!("S,{w},{h}").as_bytes()).expect("failed to set size"); self.window_socket.write(format!("S,{w},{h}").as_bytes()).expect("failed to set size");
None None
@ -242,14 +242,14 @@ impl CoreWindow for Window {
#[inline] #[inline]
fn outer_size(&self) -> PhysicalSize<u32> { fn outer_size(&self) -> PhysicalSize<u32> {
// TODO: adjust for window decorations // TODO: adjust for window decorations
self.inner_size() self.surface_size()
} }
#[inline] #[inline]
fn set_min_inner_size(&self, _: Option<Size>) {} fn set_min_surface_size(&self, _: Option<Size>) {}
#[inline] #[inline]
fn set_max_inner_size(&self, _: Option<Size>) {} fn set_max_surface_size(&self, _: Option<Size>) {}
#[inline] #[inline]
fn title(&self) -> String { fn title(&self) -> String {
@ -283,12 +283,12 @@ impl CoreWindow for Window {
} }
#[inline] #[inline]
fn resize_increments(&self) -> Option<PhysicalSize<u32>> { fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
None None
} }
#[inline] #[inline]
fn set_resize_increments(&self, _increments: Option<Size>) {} fn set_surface_resize_increments(&self, _increments: Option<Size>) {}
#[inline] #[inline]
fn set_resizable(&self, resizeable: bool) { fn set_resizable(&self, resizeable: bool) {

View file

@ -556,7 +556,7 @@ impl ActiveEventLoop {
canvas.set_old_size(new_size); canvas.set_old_size(new_size);
runner.send_event(Event::WindowEvent { runner.send_event(Event::WindowEvent {
window_id: RootWindowId(id), window_id: RootWindowId(id),
event: WindowEvent::Resized(new_size), event: WindowEvent::SurfaceResized(new_size),
}); });
canvas.request_animation_frame(); canvas.request_animation_frame();
} }

View file

@ -23,7 +23,7 @@ use super::pointer::PointerHandler;
use super::{event, fullscreen, ButtonsState, ResizeScaleHandle}; use super::{event, fullscreen, ButtonsState, ResizeScaleHandle};
use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize}; use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
use crate::error::OsError as RootOE; use crate::error::OsError as RootOE;
use crate::event::{Force, InnerSizeWriter, MouseButton, MouseScrollDelta}; use crate::event::{Force, MouseButton, MouseScrollDelta, SurfaceSizeWriter};
use crate::keyboard::{Key, KeyLocation, ModifiersState, PhysicalKey}; use crate::keyboard::{Key, KeyLocation, ModifiersState, PhysicalKey};
use crate::platform_impl::{Fullscreen, OsError}; use crate::platform_impl::{Fullscreen, OsError};
use crate::window::{WindowAttributes, WindowId as RootWindowId}; use crate::window::{WindowAttributes, WindowId as RootWindowId};
@ -126,17 +126,17 @@ impl Canvas {
current_size: Rc::default(), current_size: Rc::default(),
}; };
if let Some(size) = attr.inner_size { if let Some(size) = attr.surface_size {
let size = size.to_logical(super::scale_factor(&common.window)); let size = size.to_logical(super::scale_factor(&common.window));
super::set_canvas_size(&common.document, &common.raw, &common.style, size); super::set_canvas_size(&common.document, &common.raw, &common.style, size);
} }
if let Some(size) = attr.min_inner_size { if let Some(size) = attr.min_surface_size {
let size = size.to_logical(super::scale_factor(&common.window)); let size = size.to_logical(super::scale_factor(&common.window));
super::set_canvas_min_size(&common.document, &common.raw, &common.style, Some(size)); super::set_canvas_min_size(&common.document, &common.raw, &common.style, Some(size));
} }
if let Some(size) = attr.max_inner_size { if let Some(size) = attr.max_surface_size {
let size = size.to_logical(super::scale_factor(&common.window)); let size = size.to_logical(super::scale_factor(&common.window));
super::set_canvas_max_size(&common.document, &common.raw, &common.style, Some(size)); super::set_canvas_max_size(&common.document, &common.raw, &common.style, Some(size));
} }
@ -213,7 +213,7 @@ impl Canvas {
} }
#[inline] #[inline]
pub fn inner_size(&self) -> PhysicalSize<u32> { pub fn surface_size(&self) -> PhysicalSize<u32> {
self.common.current_size.get() self.common.current_size.get()
} }
@ -504,7 +504,7 @@ impl Canvas {
window_id: RootWindowId(self.id), window_id: RootWindowId(self.id),
event: crate::event::WindowEvent::ScaleFactorChanged { event: crate::event::WindowEvent::ScaleFactorChanged {
scale_factor: scale, scale_factor: scale,
inner_size_writer: InnerSizeWriter::new(Arc::downgrade(&new_size)), surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_size)),
}, },
}); });
@ -513,8 +513,8 @@ impl Canvas {
}; };
if current_size != new_size { if current_size != new_size {
// Then we resize the canvas to the new size, a new // Then we resize the canvas to the new size, a new `SurfaceResized` event will be sent
// `Resized` event will be sent by the `ResizeObserver`: // by the `ResizeObserver`:
let new_size = new_size.to_logical(scale); let new_size = new_size.to_logical(scale);
super::set_canvas_size(self.document(), self.raw(), self.style(), new_size); super::set_canvas_size(self.document(), self.raw(), self.style(), new_size);
@ -530,7 +530,7 @@ impl Canvas {
self.set_old_size(new_size); self.set_old_size(new_size);
runner.send_event(crate::event::Event::WindowEvent { runner.send_event(crate::event::Event::WindowEvent {
window_id: RootWindowId(self.id), window_id: RootWindowId(self.id),
event: crate::event::WindowEvent::Resized(new_size), event: crate::event::WindowEvent::SurfaceResized(new_size),
}) })
} }
} }

View file

@ -127,11 +127,11 @@ impl RootWindow for Window {
}) })
} }
fn inner_size(&self) -> PhysicalSize<u32> { fn surface_size(&self) -> PhysicalSize<u32> {
self.inner.queue(|inner| inner.canvas.inner_size()) self.inner.queue(|inner| inner.canvas.surface_size())
} }
fn request_inner_size(&self, size: Size) -> Option<PhysicalSize<u32>> { fn request_surface_size(&self, size: Size) -> Option<PhysicalSize<u32>> {
self.inner.queue(|inner| { self.inner.queue(|inner| {
let size = size.to_logical(self.scale_factor()); let size = size.to_logical(self.scale_factor());
backend::set_canvas_size( backend::set_canvas_size(
@ -145,11 +145,11 @@ impl RootWindow for Window {
} }
fn outer_size(&self) -> PhysicalSize<u32> { fn outer_size(&self) -> PhysicalSize<u32> {
// Note: the canvas element has no window decorations, so this is equal to `inner_size`. // Note: the canvas element has no window decorations, so this is equal to `surface_size`.
self.inner_size() self.surface_size()
} }
fn set_min_inner_size(&self, min_size: Option<Size>) { fn set_min_surface_size(&self, min_size: Option<Size>) {
self.inner.dispatch(move |inner| { self.inner.dispatch(move |inner| {
let dimensions = min_size.map(|min_size| min_size.to_logical(inner.scale_factor())); let dimensions = min_size.map(|min_size| min_size.to_logical(inner.scale_factor()));
backend::set_canvas_min_size( backend::set_canvas_min_size(
@ -161,7 +161,7 @@ impl RootWindow for Window {
}) })
} }
fn set_max_inner_size(&self, max_size: Option<Size>) { fn set_max_surface_size(&self, max_size: Option<Size>) {
self.inner.dispatch(move |inner| { self.inner.dispatch(move |inner| {
let dimensions = max_size.map(|dimensions| dimensions.to_logical(inner.scale_factor())); let dimensions = max_size.map(|dimensions| dimensions.to_logical(inner.scale_factor()));
backend::set_canvas_max_size( backend::set_canvas_max_size(
@ -173,11 +173,11 @@ impl RootWindow for Window {
}) })
} }
fn resize_increments(&self) -> Option<PhysicalSize<u32>> { fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
None None
} }
fn set_resize_increments(&self, _: Option<Size>) { fn set_surface_resize_increments(&self, _: Option<Size>) {
// Intentionally a no-op: users can't resize canvas elements // Intentionally a no-op: users can't resize canvas elements
} }

View file

@ -58,7 +58,7 @@ use crate::application::ApplicationHandler;
use crate::dpi::{PhysicalPosition, PhysicalSize}; use crate::dpi::{PhysicalPosition, PhysicalSize};
use crate::error::{EventLoopError, ExternalError, OsError}; use crate::error::{EventLoopError, ExternalError, OsError};
use crate::event::{ use crate::event::{
Event, FingerId as RootFingerId, Force, Ime, InnerSizeWriter, RawKeyEvent, Touch, TouchPhase, Event, FingerId as RootFingerId, Force, Ime, RawKeyEvent, SurfaceSizeWriter, Touch, TouchPhase,
WindowEvent, WindowEvent,
}; };
use crate::event_loop::{ use crate::event_loop::{
@ -1274,14 +1274,14 @@ unsafe fn public_window_callback_inner(
}, },
WM_SIZE => { WM_SIZE => {
use crate::event::WindowEvent::Resized; use crate::event::WindowEvent::SurfaceResized;
let w = super::loword(lparam as u32) as u32; let w = super::loword(lparam as u32) as u32;
let h = super::hiword(lparam as u32) as u32; let h = super::hiword(lparam as u32) as u32;
let physical_size = PhysicalSize::new(w, h); let physical_size = PhysicalSize::new(w, h);
let event = Event::WindowEvent { let event = Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), window_id: CoreWindowId(WindowId(window)),
event: Resized(physical_size), event: SurfaceResized(physical_size),
}; };
{ {
@ -1308,7 +1308,7 @@ unsafe fn public_window_callback_inner(
let scale_factor = userdata.window_state_lock().scale_factor; let scale_factor = userdata.window_state_lock().scale_factor;
let Some(inc) = userdata let Some(inc) = userdata
.window_state_lock() .window_state_lock()
.resize_increments .surface_resize_increments
.map(|inc| inc.to_physical(scale_factor)) .map(|inc| inc.to_physical(scale_factor))
.filter(|inc| inc.width > 0 && inc.height > 0) .filter(|inc| inc.width > 0 && inc.height > 0)
else { else {
@ -2131,7 +2131,7 @@ unsafe fn public_window_callback_inner(
// New size as suggested by Windows. // New size as suggested by Windows.
let suggested_rect = unsafe { *(lparam as *const RECT) }; let suggested_rect = unsafe { *(lparam as *const RECT) };
// The window rect provided is the window's outer size, not it's inner size. However, // The window rect provided is the window's outer size, not it's surface size. However,
// win32 doesn't provide an `UnadjustWindowRectEx` function to get the client rect from // win32 doesn't provide an `UnadjustWindowRectEx` function to get the client rect from
// the outer rect, so we instead adjust the window rect to get the decoration margins // the outer rect, so we instead adjust the window rect to get the decoration margins
// and remove them from the outer size. // and remove them from the outer size.
@ -2151,33 +2151,33 @@ unsafe fn public_window_callback_inner(
let old_physical_inner_rect = util::WindowArea::Inner let old_physical_inner_rect = util::WindowArea::Inner
.get_rect(window) .get_rect(window)
.expect("failed to query (old) inner window area"); .expect("failed to query (old) inner window area");
let old_physical_inner_size = PhysicalSize::new( let old_physical_surface_size = PhysicalSize::new(
(old_physical_inner_rect.right - old_physical_inner_rect.left) as u32, (old_physical_inner_rect.right - old_physical_inner_rect.left) as u32,
(old_physical_inner_rect.bottom - old_physical_inner_rect.top) as u32, (old_physical_inner_rect.bottom - old_physical_inner_rect.top) as u32,
); );
// `allow_resize` prevents us from re-applying DPI adjustment to the restored size after // `allow_resize` prevents us from re-applying DPI adjustment to the restored size after
// exiting fullscreen (the restored size is already DPI adjusted). // exiting fullscreen (the restored size is already DPI adjusted).
let new_physical_inner_size = match allow_resize { let new_physical_surface_size = match allow_resize {
// We calculate our own size because the default suggested rect doesn't do a great // We calculate our own size because the default suggested rect doesn't do a great
// job of preserving the window's logical size. // job of preserving the window's logical size.
true => old_physical_inner_size true => old_physical_surface_size
.to_logical::<f64>(old_scale_factor) .to_logical::<f64>(old_scale_factor)
.to_physical::<u32>(new_scale_factor), .to_physical::<u32>(new_scale_factor),
false => old_physical_inner_size, false => old_physical_surface_size,
}; };
let new_inner_size = Arc::new(Mutex::new(new_physical_inner_size)); let new_surface_size = Arc::new(Mutex::new(new_physical_surface_size));
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), window_id: CoreWindowId(WindowId(window)),
event: ScaleFactorChanged { event: ScaleFactorChanged {
scale_factor: new_scale_factor, scale_factor: new_scale_factor,
inner_size_writer: InnerSizeWriter::new(Arc::downgrade(&new_inner_size)), surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)),
}, },
}); });
let new_physical_inner_size = *new_inner_size.lock().unwrap(); let new_physical_surface_size = *new_surface_size.lock().unwrap();
drop(new_inner_size); drop(new_surface_size);
let dragging_window: bool; let dragging_window: bool;
@ -2186,7 +2186,7 @@ unsafe fn public_window_callback_inner(
dragging_window = dragging_window =
window_state.window_flags().contains(WindowFlags::MARKER_IN_SIZE_MOVE); window_state.window_flags().contains(WindowFlags::MARKER_IN_SIZE_MOVE);
// Unset maximized if we're changing the window's size. // Unset maximized if we're changing the window's size.
if new_physical_inner_size != old_physical_inner_size { if new_physical_surface_size != old_physical_surface_size {
WindowState::set_window_flags(window_state, window, |f| { WindowState::set_window_flags(window_state, window, |f| {
f.set(WindowFlags::MAXIMIZED, false) f.set(WindowFlags::MAXIMIZED, false)
}); });
@ -2201,8 +2201,8 @@ unsafe fn public_window_callback_inner(
let mut conservative_rect = RECT { let mut conservative_rect = RECT {
left: suggested_ul.0, left: suggested_ul.0,
top: suggested_ul.1, top: suggested_ul.1,
right: suggested_ul.0 + new_physical_inner_size.width as i32, right: suggested_ul.0 + new_physical_surface_size.width as i32,
bottom: suggested_ul.1 + new_physical_inner_size.height as i32, bottom: suggested_ul.1 + new_physical_surface_size.height as i32,
}; };
conservative_rect = window_flags conservative_rect = window_flags

View file

@ -9,7 +9,7 @@ use windows_sys::Win32::Foundation::HWND;
use super::ControlFlow; use super::ControlFlow;
use crate::dpi::PhysicalSize; use crate::dpi::PhysicalSize;
use crate::event::{Event, InnerSizeWriter, StartCause, WindowEvent}; use crate::event::{Event, StartCause, SurfaceSizeWriter, WindowEvent};
use crate::platform_impl::platform::event_loop::{WindowData, GWL_USERDATA}; use crate::platform_impl::platform::event_loop::{WindowData, GWL_USERDATA};
use crate::platform_impl::platform::get_window_long; use crate::platform_impl::platform::get_window_long;
use crate::window::WindowId; use crate::window::WindowId;
@ -357,12 +357,12 @@ impl BufferedEvent {
pub fn from_event(event: Event) -> BufferedEvent { pub fn from_event(event: Event) -> BufferedEvent {
match event { match event {
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::ScaleFactorChanged { scale_factor, inner_size_writer }, event: WindowEvent::ScaleFactorChanged { scale_factor, surface_size_writer },
window_id, window_id,
} => BufferedEvent::ScaleFactorChanged( } => BufferedEvent::ScaleFactorChanged(
window_id, window_id,
scale_factor, scale_factor,
*inner_size_writer.new_inner_size.upgrade().unwrap().lock().unwrap(), *surface_size_writer.new_surface_size.upgrade().unwrap().lock().unwrap(),
), ),
event => BufferedEvent::Event(event), event => BufferedEvent::Event(event),
} }
@ -371,29 +371,29 @@ impl BufferedEvent {
pub fn dispatch_event(self, dispatch: impl FnOnce(Event)) { pub fn dispatch_event(self, dispatch: impl FnOnce(Event)) {
match self { match self {
Self::Event(event) => dispatch(event), Self::Event(event) => dispatch(event),
Self::ScaleFactorChanged(window_id, scale_factor, new_inner_size) => { Self::ScaleFactorChanged(window_id, scale_factor, new_surface_size) => {
let user_new_inner_size = Arc::new(Mutex::new(new_inner_size)); let user_new_surface_size = Arc::new(Mutex::new(new_surface_size));
dispatch(Event::WindowEvent { dispatch(Event::WindowEvent {
window_id, window_id,
event: WindowEvent::ScaleFactorChanged { event: WindowEvent::ScaleFactorChanged {
scale_factor, scale_factor,
inner_size_writer: InnerSizeWriter::new(Arc::downgrade( surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(
&user_new_inner_size, &user_new_surface_size,
)), )),
}, },
}); });
let inner_size = *user_new_inner_size.lock().unwrap(); let surface_size = *user_new_surface_size.lock().unwrap();
drop(user_new_inner_size); drop(user_new_surface_size);
if inner_size != new_inner_size { if surface_size != new_surface_size {
let window_flags = unsafe { let window_flags = unsafe {
let userdata = let userdata =
get_window_long(window_id.0.into(), GWL_USERDATA) as *mut WindowData; get_window_long(window_id.0.into(), GWL_USERDATA) as *mut WindowData;
(*userdata).window_state_lock().window_flags (*userdata).window_state_lock().window_flags
}; };
window_flags.set_size((window_id.0).0, inner_size); window_flags.set_size((window_id.0).0, surface_size);
} }
}, },
} }

View file

@ -458,7 +458,7 @@ impl CoreWindow for Window {
} }
} }
fn inner_size(&self) -> PhysicalSize<u32> { fn surface_size(&self) -> PhysicalSize<u32> {
let mut rect: RECT = unsafe { mem::zeroed() }; let mut rect: RECT = unsafe { mem::zeroed() };
if unsafe { GetClientRect(self.hwnd(), &mut rect) } == false.into() { if unsafe { GetClientRect(self.hwnd(), &mut rect) } == false.into() {
panic!( panic!(
@ -478,14 +478,14 @@ impl CoreWindow for Window {
.unwrap() .unwrap()
} }
fn request_inner_size(&self, size: Size) -> Option<PhysicalSize<u32>> { fn request_surface_size(&self, size: Size) -> Option<PhysicalSize<u32>> {
let scale_factor = self.scale_factor(); let scale_factor = self.scale_factor();
let physical_size = size.to_physical::<u32>(scale_factor); let physical_size = size.to_physical::<u32>(scale_factor);
let window_flags = self.window_state_lock().window_flags; let window_flags = self.window_state_lock().window_flags;
window_flags.set_size(self.hwnd(), physical_size); window_flags.set_size(self.hwnd(), physical_size);
if physical_size != self.inner_size() { if physical_size != self.surface_size() {
let window_state = Arc::clone(&self.window_state); let window_state = Arc::clone(&self.window_state);
let window = self.window; let window = self.window;
self.thread_executor.execute_in_thread(move || { self.thread_executor.execute_in_thread(move || {
@ -499,28 +499,28 @@ impl CoreWindow for Window {
None None
} }
fn set_min_inner_size(&self, size: Option<Size>) { fn set_min_surface_size(&self, size: Option<Size>) {
self.window_state_lock().min_size = size; self.window_state_lock().min_size = size;
// Make windows re-check the window size bounds. // Make windows re-check the window size bounds.
let size = self.inner_size(); let size = self.surface_size();
let _ = self.request_inner_size(size.into()); let _ = self.request_surface_size(size.into());
} }
fn set_max_inner_size(&self, size: Option<Size>) { fn set_max_surface_size(&self, size: Option<Size>) {
self.window_state_lock().max_size = size; self.window_state_lock().max_size = size;
// Make windows re-check the window size bounds. // Make windows re-check the window size bounds.
let size = self.inner_size(); let size = self.surface_size();
let _ = self.request_inner_size(size.into()); let _ = self.request_surface_size(size.into());
} }
fn resize_increments(&self) -> Option<PhysicalSize<u32>> { fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
let w = self.window_state_lock(); let w = self.window_state_lock();
let scale_factor = w.scale_factor; let scale_factor = w.scale_factor;
w.resize_increments.map(|size| size.to_physical(scale_factor)) w.surface_resize_increments.map(|size| size.to_physical(scale_factor))
} }
fn set_resize_increments(&self, increments: Option<Size>) { fn set_surface_resize_increments(&self, increments: Option<Size>) {
self.window_state_lock().resize_increments = increments; self.window_state_lock().surface_resize_increments = increments;
} }
fn set_resizable(&self, resizable: bool) { fn set_resizable(&self, resizable: bool) {
@ -1209,13 +1209,14 @@ impl<'a> InitData<'a> {
win.set_enabled_buttons(attributes.enabled_buttons); win.set_enabled_buttons(attributes.enabled_buttons);
let size = attributes.inner_size.unwrap_or_else(|| PhysicalSize::new(800, 600).into()); let size = attributes.surface_size.unwrap_or_else(|| PhysicalSize::new(800, 600).into());
let max_size = attributes let max_size = attributes
.max_inner_size .max_surface_size
.unwrap_or_else(|| PhysicalSize::new(f64::MAX, f64::MAX).into()); .unwrap_or_else(|| PhysicalSize::new(f64::MAX, f64::MAX).into());
let min_size = attributes.min_inner_size.unwrap_or_else(|| PhysicalSize::new(0, 0).into()); let min_size =
attributes.min_surface_size.unwrap_or_else(|| PhysicalSize::new(0, 0).into());
let clamped_size = Size::clamp(size, min_size, max_size, win.scale_factor()); let clamped_size = Size::clamp(size, min_size, max_size, win.scale_factor());
let _ = win.request_inner_size(clamped_size); let _ = win.request_surface_size(clamped_size);
// let margins = MARGINS { // let margins = MARGINS {
// cxLeftWidth: 1, // cxLeftWidth: 1,

View file

@ -30,7 +30,7 @@ pub(crate) struct WindowState {
pub min_size: Option<Size>, pub min_size: Option<Size>,
pub max_size: Option<Size>, pub max_size: Option<Size>,
pub resize_increments: Option<Size>, pub surface_resize_increments: Option<Size>,
pub window_icon: Option<Icon>, pub window_icon: Option<Icon>,
pub taskbar_icon: Option<Icon>, pub taskbar_icon: Option<Icon>,
@ -151,10 +151,10 @@ impl WindowState {
last_position: None, last_position: None,
}, },
min_size: attributes.min_inner_size, min_size: attributes.min_surface_size,
max_size: attributes.max_inner_size, max_size: attributes.max_surface_size,
resize_increments: attributes.resize_increments, surface_resize_increments: attributes.surface_resize_increments,
window_icon: attributes.window_icon.clone(), window_icon: attributes.window_icon.clone(),
taskbar_icon: None, taskbar_icon: None,

View file

@ -57,9 +57,10 @@ impl From<u64> for WindowId {
/// Attributes used when creating a window. /// Attributes used when creating a window.
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub struct WindowAttributes { pub struct WindowAttributes {
pub inner_size: Option<Size>, pub surface_size: Option<Size>,
pub min_inner_size: Option<Size>, pub min_surface_size: Option<Size>,
pub max_inner_size: Option<Size>, pub max_surface_size: Option<Size>,
pub surface_resize_increments: Option<Size>,
pub position: Option<Position>, pub position: Option<Position>,
pub resizable: bool, pub resizable: bool,
pub enabled_buttons: WindowButtons, pub enabled_buttons: WindowButtons,
@ -71,7 +72,6 @@ pub struct WindowAttributes {
pub decorations: bool, pub decorations: bool,
pub window_icon: Option<Icon>, pub window_icon: Option<Icon>,
pub preferred_theme: Option<Theme>, pub preferred_theme: Option<Theme>,
pub resize_increments: Option<Size>,
pub content_protected: bool, pub content_protected: bool,
pub window_level: WindowLevel, pub window_level: WindowLevel,
pub active: bool, pub active: bool,
@ -88,9 +88,10 @@ impl Default for WindowAttributes {
#[inline] #[inline]
fn default() -> WindowAttributes { fn default() -> WindowAttributes {
WindowAttributes { WindowAttributes {
inner_size: None, surface_size: None,
min_inner_size: None, min_surface_size: None,
max_inner_size: None, max_surface_size: None,
surface_resize_increments: None,
position: None, position: None,
resizable: true, resizable: true,
enabled_buttons: WindowButtons::all(), enabled_buttons: WindowButtons::all(),
@ -104,7 +105,6 @@ impl Default for WindowAttributes {
window_level: Default::default(), window_level: Default::default(),
window_icon: None, window_icon: None,
preferred_theme: None, preferred_theme: None,
resize_increments: None,
content_protected: false, content_protected: false,
cursor: Cursor::default(), cursor: Cursor::default(),
#[cfg(feature = "rwh_06")] #[cfg(feature = "rwh_06")]
@ -137,38 +137,51 @@ impl WindowAttributes {
self.parent_window.as_ref().map(|handle| &handle.0) self.parent_window.as_ref().map(|handle| &handle.0)
} }
/// Requests the window to be of specific dimensions. /// Requests the surface to be of specific dimensions.
/// ///
/// If this is not set, some platform-specific dimensions will be used. /// If this is not set, some platform-specific dimensions will be used.
/// ///
/// See [`Window::request_inner_size`] for details. /// See [`Window::request_surface_size`] for details.
#[inline] #[inline]
pub fn with_inner_size<S: Into<Size>>(mut self, size: S) -> Self { pub fn with_surface_size<S: Into<Size>>(mut self, size: S) -> Self {
self.inner_size = Some(size.into()); self.surface_size = Some(size.into());
self self
} }
/// Sets the minimum dimensions a window can have. /// Sets the minimum dimensions the surface can have.
/// ///
/// If this is not set, the window will have no minimum dimensions (aside /// If this is not set, the surface will have no minimum dimensions (aside from reserved).
/// from reserved).
/// ///
/// See [`Window::set_min_inner_size`] for details. /// See [`Window::set_min_surface_size`] for details.
#[inline] #[inline]
pub fn with_min_inner_size<S: Into<Size>>(mut self, min_size: S) -> Self { pub fn with_min_surface_size<S: Into<Size>>(mut self, min_size: S) -> Self {
self.min_inner_size = Some(min_size.into()); self.min_surface_size = Some(min_size.into());
self self
} }
/// Sets the maximum dimensions a window can have. /// Sets the maximum dimensions the surface can have.
/// ///
/// If this is not set, the window will have no maximum or will be set to /// If this is not set, the surface will have no maximum, or the maximum will be restricted to
/// the primary monitor's dimensions by the platform. /// the primary monitor's dimensions by the platform.
/// ///
/// See [`Window::set_max_inner_size`] for details. /// See [`Window::set_max_surface_size`] for details.
#[inline] #[inline]
pub fn with_max_inner_size<S: Into<Size>>(mut self, max_size: S) -> Self { pub fn with_max_surface_size<S: Into<Size>>(mut self, max_size: S) -> Self {
self.max_inner_size = Some(max_size.into()); self.max_surface_size = Some(max_size.into());
self
}
/// Build window with resize increments hint.
///
/// The default is `None`.
///
/// See [`Window::set_surface_resize_increments`] for details.
#[inline]
pub fn with_surface_resize_increments<S: Into<Size>>(
mut self,
surface_resize_increments: S,
) -> Self {
self.surface_resize_increments = Some(surface_resize_increments.into());
self self
} }
@ -182,7 +195,7 @@ impl WindowAttributes {
/// ///
/// - **macOS:** The top left corner position of the window content, the window's "inner" /// - **macOS:** The top left corner position of the window content, the window's "inner"
/// position. The window title bar will be placed above it. The window will be positioned such /// position. The window title bar will be placed above it. The window will be positioned such
/// that it fits on screen, maintaining set `inner_size` if any. If you need to precisely /// that it fits on screen, maintaining set `surface_size` if any. If you need to precisely
/// position the top left corner of the whole window you have to use /// position the top left corner of the whole window you have to use
/// [`Window::set_outer_position`] after creating the window. /// [`Window::set_outer_position`] after creating the window.
/// - **Windows:** The top left corner position of the window title bar, the window's "outer" /// - **Windows:** The top left corner position of the window title bar, the window's "outer"
@ -346,17 +359,6 @@ impl WindowAttributes {
self self
} }
/// Build window with resize increments hint.
///
/// The default is `None`.
///
/// See [`Window::set_resize_increments`] for details.
#[inline]
pub fn with_resize_increments<S: Into<Size>>(mut self, resize_increments: S) -> Self {
self.resize_increments = Some(resize_increments.into());
self
}
/// Prevents the window contents from being captured by other apps. /// Prevents the window contents from being captured by other apps.
/// ///
/// The default is `false`. /// The default is `false`.
@ -650,9 +652,9 @@ pub trait Window: AsAny + Send + Sync {
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
fn set_outer_position(&self, position: Position); fn set_outer_position(&self, position: Position);
/// Returns the physical size of the window's client area. /// Returns the size of the window's render-able surface.
/// ///
/// The client area is the content of the window, excluding the title bar and borders. /// This is the dimensions you should pass to things like Wgpu or Glutin when configuring.
/// ///
/// ## Platform-specific /// ## Platform-specific
/// ///
@ -662,21 +664,21 @@ pub trait Window: AsAny + Send + Sync {
/// ///
/// [safe area]: https://developer.apple.com/documentation/uikit/uiview/2891103-safeareainsets?language=objc /// [safe area]: https://developer.apple.com/documentation/uikit/uiview/2891103-safeareainsets?language=objc
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
fn inner_size(&self) -> PhysicalSize<u32>; fn surface_size(&self) -> PhysicalSize<u32>;
/// Request the new size for the window. /// Request the new size for the surface.
/// ///
/// On platforms where the size is entirely controlled by the user the /// On platforms where the size is entirely controlled by the user the
/// applied size will be returned immediately, resize event in such case /// applied size will be returned immediately, resize event in such case
/// may not be generated. /// may not be generated.
/// ///
/// On platforms where resizing is disallowed by the windowing system, the current /// On platforms where resizing is disallowed by the windowing system, the current surface size
/// inner size is returned immediately, and the user one is ignored. /// is returned immediately, and the user one is ignored.
/// ///
/// When `None` is returned, it means that the request went to the display system, /// When `None` is returned, it means that the request went to the display system,
/// and the actual size will be delivered later with the [`WindowEvent::Resized`]. /// and the actual size will be delivered later with the [`WindowEvent::SurfaceResized`].
/// ///
/// See [`Window::inner_size`] for more information about the values. /// See [`Window::surface_size`] for more information about the values.
/// ///
/// The request could automatically un-maximize the window if it's maximized. /// The request could automatically un-maximize the window if it's maximized.
/// ///
@ -685,10 +687,10 @@ pub trait Window: AsAny + Send + Sync {
/// # use winit::window::Window; /// # use winit::window::Window;
/// # fn scope(window: &dyn Window) { /// # fn scope(window: &dyn Window) {
/// // Specify the size in logical dimensions like this: /// // Specify the size in logical dimensions like this:
/// let _ = window.request_inner_size(LogicalSize::new(400.0, 200.0).into()); /// let _ = window.request_surface_size(LogicalSize::new(400.0, 200.0).into());
/// ///
/// // Or specify the size in physical dimensions like this: /// // Or specify the size in physical dimensions like this:
/// let _ = window.request_inner_size(PhysicalSize::new(400, 200).into()); /// let _ = window.request_surface_size(PhysicalSize::new(400, 200).into());
/// # } /// # }
/// ``` /// ```
/// ///
@ -696,72 +698,72 @@ pub trait Window: AsAny + Send + Sync {
/// ///
/// - **Web:** Sets the size of the canvas element. Doesn't account for CSS [`transform`]. /// - **Web:** Sets the size of the canvas element. Doesn't account for CSS [`transform`].
/// ///
/// [`WindowEvent::Resized`]: crate::event::WindowEvent::Resized /// [`WindowEvent::SurfaceResized`]: crate::event::WindowEvent::SurfaceResized
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
#[must_use] #[must_use]
fn request_inner_size(&self, size: Size) -> Option<PhysicalSize<u32>>; fn request_surface_size(&self, size: Size) -> Option<PhysicalSize<u32>>;
/// Returns the physical size of the entire window. /// Returns the size of the entire window.
/// ///
/// These dimensions include the title bar and borders. If you don't want that (and you usually /// These dimensions include window decorations like the title bar and borders. If you don't
/// don't), use [`Window::inner_size`] instead. /// want that (and you usually don't), use [`Window::surface_size`] instead.
/// ///
/// ## Platform-specific /// ## Platform-specific
/// ///
/// - **iOS:** Returns the [`PhysicalSize`] of the window in screen space coordinates. /// - **iOS:** Returns the [`PhysicalSize`] of the window in screen space coordinates.
/// - **Web:** Returns the size of the canvas element. _Note: this returns the same value as /// - **Web:** Returns the size of the canvas element. _Note: this returns the same value as
/// [`Window::inner_size`]._ /// [`Window::surface_size`]._
fn outer_size(&self) -> PhysicalSize<u32>; fn outer_size(&self) -> PhysicalSize<u32>;
/// Sets a minimum dimension size for the window. /// Sets a minimum dimensions of the window's surface.
/// ///
/// ```no_run /// ```no_run
/// # use winit::dpi::{LogicalSize, PhysicalSize}; /// # use winit::dpi::{LogicalSize, PhysicalSize};
/// # use winit::window::Window; /// # use winit::window::Window;
/// # fn scope(window: &dyn Window) { /// # fn scope(window: &dyn Window) {
/// // Specify the size in logical dimensions like this: /// // Specify the size in logical dimensions like this:
/// window.set_min_inner_size(Some(LogicalSize::new(400.0, 200.0).into())); /// window.set_min_surface_size(Some(LogicalSize::new(400.0, 200.0).into()));
/// ///
/// // Or specify the size in physical dimensions like this: /// // Or specify the size in physical dimensions like this:
/// window.set_min_inner_size(Some(PhysicalSize::new(400, 200).into())); /// window.set_min_surface_size(Some(PhysicalSize::new(400, 200).into()));
/// # } /// # }
/// ``` /// ```
/// ///
/// ## Platform-specific /// ## Platform-specific
/// ///
/// - **iOS / Android / Orbital:** Unsupported. /// - **iOS / Android / Orbital:** Unsupported.
fn set_min_inner_size(&self, min_size: Option<Size>); fn set_min_surface_size(&self, min_size: Option<Size>);
/// Sets a maximum dimension size for the window. /// Sets a maximum dimensions of the window's surface.
/// ///
/// ```no_run /// ```no_run
/// # use winit::dpi::{LogicalSize, PhysicalSize}; /// # use winit::dpi::{LogicalSize, PhysicalSize};
/// # use winit::window::Window; /// # use winit::window::Window;
/// # fn scope(window: &dyn Window) { /// # fn scope(window: &dyn Window) {
/// // Specify the size in logical dimensions like this: /// // Specify the size in logical dimensions like this:
/// window.set_max_inner_size(Some(LogicalSize::new(400.0, 200.0).into())); /// window.set_max_surface_size(Some(LogicalSize::new(400.0, 200.0).into()));
/// ///
/// // Or specify the size in physical dimensions like this: /// // Or specify the size in physical dimensions like this:
/// window.set_max_inner_size(Some(PhysicalSize::new(400, 200).into())); /// window.set_max_surface_size(Some(PhysicalSize::new(400, 200).into()));
/// # } /// # }
/// ``` /// ```
/// ///
/// ## Platform-specific /// ## Platform-specific
/// ///
/// - **iOS / Android / Orbital:** Unsupported. /// - **iOS / Android / Orbital:** Unsupported.
fn set_max_inner_size(&self, max_size: Option<Size>); fn set_max_surface_size(&self, max_size: Option<Size>);
/// Returns window resize increments if any were set. /// Returns surface resize increments if any were set.
/// ///
/// ## Platform-specific /// ## Platform-specific
/// ///
/// - **iOS / Android / Web / Wayland / Orbital:** Always returns [`None`]. /// - **iOS / Android / Web / Wayland / Orbital:** Always returns [`None`].
fn resize_increments(&self) -> Option<PhysicalSize<u32>>; fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>>;
/// Sets window resize increments. /// Sets resize increments of the surface.
/// ///
/// This is a niche constraint hint usually employed by terminal emulators /// This is a niche constraint hint usually employed by terminal emulators and other such apps
/// and other apps that need "blocky" resizes. /// that need "blocky" resizes.
/// ///
/// ## Platform-specific /// ## Platform-specific
/// ///
@ -769,7 +771,7 @@ pub trait Window: AsAny + Send + Sync {
/// numbers. /// numbers.
/// - **Wayland:** Not implemented. /// - **Wayland:** Not implemented.
/// - **iOS / Android / Web / Orbital:** Unsupported. /// - **iOS / Android / Web / Orbital:** Unsupported.
fn set_resize_increments(&self, increments: Option<Size>); fn set_surface_resize_increments(&self, increments: Option<Size>);
/// Modifies the title of the window. /// Modifies the title of the window.
/// ///
@ -828,9 +830,9 @@ pub trait Window: AsAny + Send + Sync {
/// Sets whether the window is resizable or not. /// Sets whether the window is resizable or not.
/// ///
/// Note that making the window unresizable doesn't exempt you from handling /// Note that making the window unresizable doesn't exempt you from handling
/// [`WindowEvent::Resized`], as that event can still be triggered by DPI scaling, entering /// [`WindowEvent::SurfaceResized`], as that event can still be triggered by DPI scaling,
/// fullscreen mode, etc. Also, the window could still be resized by calling /// entering fullscreen mode, etc. Also, the window could still be resized by calling
/// [`Window::request_inner_size`]. /// [`Window::request_surface_size`].
/// ///
/// ## Platform-specific /// ## Platform-specific
/// ///
@ -839,7 +841,7 @@ pub trait Window: AsAny + Send + Sync {
/// - **X11:** Due to a bug in XFCE, this has no effect on Xfwm. /// - **X11:** Due to a bug in XFCE, this has no effect on Xfwm.
/// - **iOS / Android / Web:** Unsupported. /// - **iOS / Android / Web:** Unsupported.
/// ///
/// [`WindowEvent::Resized`]: crate::event::WindowEvent::Resized /// [`WindowEvent::SurfaceResized`]: crate::event::WindowEvent::SurfaceResized
fn set_resizable(&self, resizable: bool); fn set_resizable(&self, resizable: bool);
/// Gets the window's current resizable state. /// Gets the window's current resizable state.