Skip to main content

cbf_compositor/
window.rs

1//! Host window abstractions used to attach native windows to the compositor.
2
3use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
4use std::sync::Arc;
5
6/// Narrow host-window abstraction required by the compositor.
7pub trait WindowHost: HasWindowHandle + HasDisplayHandle {
8    /// Return the current inner size in physical pixels.
9    fn inner_size(&self) -> (u32, u32);
10
11    /// Return the current scale factor for coordinate conversion.
12    fn scale_factor(&self) -> f64 {
13        1.0
14    }
15}
16
17#[cfg(feature = "winit")]
18impl WindowHost for winit::window::Window {
19    fn inner_size(&self) -> (u32, u32) {
20        let size = self.inner_size();
21        (size.width, size.height)
22    }
23
24    fn scale_factor(&self) -> f64 {
25        self.scale_factor()
26    }
27}
28
29impl<W> WindowHost for Arc<W>
30where
31    W: WindowHost,
32{
33    fn inner_size(&self) -> (u32, u32) {
34        (**self).inner_size()
35    }
36
37    fn scale_factor(&self) -> f64 {
38        (**self).scale_factor()
39    }
40}