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

@ -46,7 +46,7 @@ pub type WinitFrame = sctk_adwaita::AdwaitaFrame<WinitState>;
#[cfg(not(feature = "sctk-adwaita"))]
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);
/// 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.
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>,
/// 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,
/// Min size.
min_inner_size: LogicalSize<u32>,
max_inner_size: Option<LogicalSize<u32>>,
min_surface_size: 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
/// is to fallback to original window size, before it was maximized, if the compositor
@ -197,8 +197,8 @@ impl WindowState {
ime_allowed: false,
ime_purpose: ImePurpose::Normal,
last_configure: None,
max_inner_size: None,
min_inner_size: MIN_WINDOW_SIZE,
max_surface_size: None,
min_surface_size: MIN_WINDOW_SIZE,
pointer_constraints,
pointers: Default::default(),
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.
if constrain {
let bounds = self.inner_size_bounds(&configure);
let bounds = self.surface_size_bounds(&configure);
new_size.width =
bounds.0.map(|bound_w| new_size.width.min(bound_w.get())).unwrap_or(new_size.width);
new_size.height = bounds
@ -353,7 +353,7 @@ impl WindowState {
// NOTE: Set the configure before doing a resize, since we query it during it.
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);
true
} else {
@ -361,8 +361,8 @@ impl WindowState {
}
}
/// Compute the bounds for the inner size of the surface.
fn inner_size_bounds(
/// Compute the bounds for the surface size of the surface.
fn surface_size_bounds(
&self,
configure: &WindowConfigure,
) -> (Option<NonZeroU32>, Option<NonZeroU32>) {
@ -507,8 +507,8 @@ impl WindowState {
// Restore min/max sizes of the window.
self.reload_min_max_hints();
} else {
self.set_min_inner_size(Some(self.size));
self.set_max_inner_size(Some(self.size));
self.set_min_surface_size(Some(self.size));
self.set_max_surface_size(Some(self.size));
}
// Reload the state on the frame as well.
@ -533,7 +533,7 @@ impl WindowState {
/// Get the size of the window.
#[inline]
pub fn inner_size(&self) -> LogicalSize<u32> {
pub fn surface_size(&self) -> LogicalSize<u32> {
self.size
}
@ -628,21 +628,21 @@ impl WindowState {
}
/// 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) {
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.
fn resize(&mut self, inner_size: LogicalSize<u32>) {
self.size = inner_size;
/// Resize the window to the new surface size.
fn resize(&mut self, surface_size: LogicalSize<u32>) {
self.size = surface_size;
// Update the stateless size.
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.
@ -673,7 +673,7 @@ impl WindowState {
// Update the target viewport, this is used if and only if fractional scaling is in use.
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 _);
}
}
@ -753,7 +753,7 @@ impl WindowState {
}
/// 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.
let mut size = size.unwrap_or(MIN_WINDOW_SIZE);
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())
.unwrap_or(size);
self.min_inner_size = size;
self.min_surface_size = size;
self.window.set_min_size(Some(size.into()));
}
/// 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| {
self.frame
.as_ref()
@ -779,7 +779,7 @@ impl WindowState {
.unwrap_or(size)
});
self.max_inner_size = size;
self.max_surface_size = size;
self.window.set_max_size(size.map(Into::into));
}
@ -812,8 +812,8 @@ impl WindowState {
/// Reload the hints for minimum and maximum sizes.
pub fn reload_min_max_hints(&mut self) {
self.set_min_inner_size(Some(self.min_inner_size));
self.set_max_inner_size(self.max_inner_size);
self.set_min_surface_size(Some(self.min_surface_size));
self.set_max_surface_size(self.max_surface_size);
}
/// Set the grabbing state on the surface.