Skip to main content

i_slint_backend_winit/
winit_compat.rs

1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4//! Polyfill for `winit::window::Window::surface_size()`, which becomes a built-in method in
5//! winit 0.31.
6
7pub(crate) trait WindowSurfaceSizeExt {
8    fn surface_size(&self) -> winit::dpi::PhysicalSize<u32>;
9}
10
11impl WindowSurfaceSizeExt for winit::window::Window {
12    /// The physical size of the rendering surface backing a winit window.
13    fn surface_size(&self) -> winit::dpi::PhysicalSize<u32> {
14        // winit 0.30's iOS `inner_size()` returns the safe-area frame but the `CAMetalLayer` fills the whole
15        // window, so the render surface must match `outer_size()`. That's also what `WindowEvent::Resized`
16        // delivers.
17        if cfg!(target_os = "ios") { self.outer_size() } else { self.inner_size() }
18    }
19}