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

@ -16,7 +16,7 @@ use crate::application::ApplicationHandler;
use crate::cursor::OnlyCursorImage;
use crate::dpi::LogicalSize;
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::platform::pump_events::PumpStatus;
use crate::platform_impl::platform::min_timeout;
@ -317,24 +317,24 @@ impl EventLoop {
let windows = state.windows.get_mut();
let window = windows.get(&window_id).unwrap().lock().unwrap();
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)
});
// Stash the old window 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 event = WindowEvent::ScaleFactorChanged {
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);
let physical_size = *new_inner_size.lock().unwrap();
drop(new_inner_size);
let physical_size = *new_surface_size.lock().unwrap();
drop(new_surface_size);
// Resize the window when user altered the size.
if old_physical_size != physical_size {
@ -344,7 +344,7 @@ impl EventLoop {
let new_logical_size: LogicalSize<f64> =
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.
@ -360,7 +360,7 @@ impl EventLoop {
let window = windows.get(&window_id).unwrap().lock().unwrap();
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.
state
@ -375,7 +375,7 @@ impl EventLoop {
});
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);
}

View file

@ -89,7 +89,7 @@ impl Window {
state.xdg_activation.as_ref().map(|activation_state| activation_state.global().clone());
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
// 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
// we use the default `1.` scaling...
let min_size = attributes.min_inner_size.map(|size| size.to_logical(1.));
let max_size = attributes.max_inner_size.map(|size| size.to_logical(1.));
window_state.set_min_inner_size(min_size);
window_state.set_max_inner_size(max_size);
let min_size = attributes.min_surface_size.map(|size| size.to_logical(1.));
let max_size = attributes.max_surface_size.map(|size| size.to_logical(1.));
window_state.set_min_surface_size(min_size);
window_state.set_max_surface_size(max_size);
// Non-resizable implies that the min and max sizes are set to the same value.
window_state.set_resizable(attributes.resizable);
@ -321,15 +321,15 @@ impl CoreWindow for Window {
// Not possible.
}
fn inner_size(&self) -> PhysicalSize<u32> {
fn surface_size(&self) -> PhysicalSize<u32> {
let window_state = self.window_state.lock().unwrap();
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 new_size = window_state.request_inner_size(size);
let new_size = window_state.request_surface_size(size);
self.request_redraw();
Some(new_size)
}
@ -340,30 +340,30 @@ impl CoreWindow for Window {
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 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.
self.request_redraw();
}
/// Set the maximum inner size for the window.
/// Set the maximum surface size for the window.
#[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 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.
self.request_redraw();
}
fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
None
}
fn set_resize_increments(&self, _increments: Option<Size>) {
warn!("`set_resize_increments` is not implemented for Wayland");
fn set_surface_resize_increments(&self, _increments: Option<Size>) {
warn!("`set_surface_resize_increments` is not implemented for Wayland");
}
fn set_title(&self, title: &str) {

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.

View file

@ -22,8 +22,8 @@ use xkbcommon_dl::xkb_mod_mask_t;
use crate::dpi::{PhysicalPosition, PhysicalSize};
use crate::event::{
DeviceEvent, ElementState, Event, Ime, InnerSizeWriter, MouseButton, MouseScrollDelta,
RawKeyEvent, Touch, TouchPhase, WindowEvent,
DeviceEvent, ElementState, Event, Ime, MouseButton, MouseScrollDelta, RawKeyEvent,
SurfaceSizeWriter, Touch, TouchPhase, WindowEvent,
};
use crate::keyboard::ModifiersState;
use crate::platform_impl::common::xkb::{self, XkbState};
@ -598,19 +598,19 @@ impl EventProcessor {
// `XSendEvent` (synthetic `ConfigureNotify`) -> position relative to root
// `XConfigureNotify` (real `ConfigureNotify`) -> position relative to parent
// 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
// that has a position relative to the parent window.
let is_synthetic = xev.send_event == xlib::True;
// 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 (mut resized, moved) = {
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 {
util::maybe_change(&mut shared_state_lock.inner_position, new_inner_position)
} else {
@ -671,7 +671,7 @@ impl EventProcessor {
let last_scale_factor = shared_state_lock.last_monitor.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
.target
.xconn
@ -695,27 +695,30 @@ impl EventProcessor {
&shared_state_lock,
);
let old_inner_size = PhysicalSize::new(width, height);
let new_inner_size = PhysicalSize::new(new_width, new_height);
let old_surface_size = PhysicalSize::new(width, height);
let new_surface_size = PhysicalSize::new(new_width, new_height);
// Unlock shared state to prevent deadlock in callback below
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 {
window_id,
event: WindowEvent::ScaleFactorChanged {
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();
drop(inner_size);
let new_surface_size = *surface_size.lock().unwrap();
drop(surface_size);
if new_inner_size != old_inner_size {
window.request_inner_size_physical(new_inner_size.width, new_inner_size.height);
window.shared_state_lock().dpi_adjusted = Some(new_inner_size.into());
if new_surface_size != old_surface_size {
window.request_surface_size_physical(
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
// size is computed with the right DPI factor
resized = true;
@ -736,13 +739,13 @@ impl EventProcessor {
// XResizeWindow requests, making Xorg, the winit client, and the WM
// consume 100% of CPU.
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.
shared_state_lock.dpi_adjusted = None;
} else {
// Unlock shared state to prevent deadlock in callback below
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 {
callback(&self.target, Event::WindowEvent {
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(
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)
}
// This is adequate for inner_size
// This is adequate for surface_size
pub fn get_geometry(
&self,
window: xproto::Window,

View file

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