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:
parent
d37c591378
commit
8db3e0e043
32 changed files with 466 additions and 436 deletions
|
|
@ -15,7 +15,7 @@ use crate::application::ApplicationHandler;
|
|||
use crate::cursor::Cursor;
|
||||
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
|
||||
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::{
|
||||
ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents,
|
||||
EventLoopProxy as RootEventLoopProxy, OwnedDisplayHandle as RootOwnedDisplayHandle,
|
||||
|
|
@ -201,11 +201,11 @@ impl EventLoop {
|
|||
let old_scale_factor = scale_factor(&self.android_app);
|
||||
let scale_factor = scale_factor(&self.android_app);
|
||||
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 event = event::WindowEvent::ScaleFactorChanged {
|
||||
inner_size_writer: InnerSizeWriter::new(Arc::downgrade(
|
||||
&new_inner_size,
|
||||
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(
|
||||
&new_surface_size,
|
||||
)),
|
||||
scale_factor,
|
||||
};
|
||||
|
|
@ -287,7 +287,7 @@ impl EventLoop {
|
|||
PhysicalSize::new(0, 0)
|
||||
};
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -808,27 +808,27 @@ impl CoreWindow for Window {
|
|||
// no effect
|
||||
}
|
||||
|
||||
fn inner_size(&self) -> PhysicalSize<u32> {
|
||||
fn surface_size(&self) -> PhysicalSize<u32> {
|
||||
self.outer_size()
|
||||
}
|
||||
|
||||
fn request_inner_size(&self, _size: Size) -> Option<PhysicalSize<u32>> {
|
||||
Some(self.inner_size())
|
||||
fn request_surface_size(&self, _size: Size) -> Option<PhysicalSize<u32>> {
|
||||
Some(self.surface_size())
|
||||
}
|
||||
|
||||
fn outer_size(&self) -> PhysicalSize<u32> {
|
||||
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
|
||||
}
|
||||
|
||||
fn set_resize_increments(&self, _increments: Option<Size>) {}
|
||||
fn set_surface_resize_increments(&self, _increments: Option<Size>) {}
|
||||
|
||||
fn set_title(&self, _title: &str) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -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).
|
||||
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());
|
||||
self.queue_event(WindowEvent::Resized(size));
|
||||
self.queue_event(WindowEvent::SurfaceResized(size));
|
||||
}
|
||||
|
||||
#[method(drawRect:)]
|
||||
|
|
|
|||
|
|
@ -127,32 +127,32 @@ impl CoreWindow for Window {
|
|||
self.maybe_wait_on_main(|delegate| delegate.set_outer_position(position));
|
||||
}
|
||||
|
||||
fn inner_size(&self) -> dpi::PhysicalSize<u32> {
|
||||
self.maybe_wait_on_main(|delegate| delegate.inner_size())
|
||||
fn surface_size(&self) -> dpi::PhysicalSize<u32> {
|
||||
self.maybe_wait_on_main(|delegate| delegate.surface_size())
|
||||
}
|
||||
|
||||
fn request_inner_size(&self, size: Size) -> Option<dpi::PhysicalSize<u32>> {
|
||||
self.maybe_wait_on_main(|delegate| delegate.request_inner_size(size))
|
||||
fn request_surface_size(&self, size: Size) -> Option<dpi::PhysicalSize<u32>> {
|
||||
self.maybe_wait_on_main(|delegate| delegate.request_surface_size(size))
|
||||
}
|
||||
|
||||
fn outer_size(&self) -> dpi::PhysicalSize<u32> {
|
||||
self.maybe_wait_on_main(|delegate| delegate.outer_size())
|
||||
}
|
||||
|
||||
fn set_min_inner_size(&self, min_size: Option<Size>) {
|
||||
self.maybe_wait_on_main(|delegate| delegate.set_min_inner_size(min_size))
|
||||
fn set_min_surface_size(&self, min_size: Option<Size>) {
|
||||
self.maybe_wait_on_main(|delegate| delegate.set_min_surface_size(min_size))
|
||||
}
|
||||
|
||||
fn set_max_inner_size(&self, max_size: Option<Size>) {
|
||||
self.maybe_wait_on_main(|delegate| delegate.set_max_inner_size(max_size));
|
||||
fn set_max_surface_size(&self, max_size: Option<Size>) {
|
||||
self.maybe_wait_on_main(|delegate| delegate.set_max_surface_size(max_size));
|
||||
}
|
||||
|
||||
fn resize_increments(&self) -> Option<dpi::PhysicalSize<u32>> {
|
||||
self.maybe_wait_on_main(|delegate| delegate.resize_increments())
|
||||
fn surface_resize_increments(&self) -> Option<dpi::PhysicalSize<u32>> {
|
||||
self.maybe_wait_on_main(|delegate| delegate.surface_resize_increments())
|
||||
}
|
||||
|
||||
fn set_resize_increments(&self, increments: Option<Size>) {
|
||||
self.maybe_wait_on_main(|delegate| delegate.set_resize_increments(increments));
|
||||
fn set_surface_resize_increments(&self, increments: Option<Size>) {
|
||||
self.maybe_wait_on_main(|delegate| delegate.set_surface_resize_increments(increments));
|
||||
}
|
||||
|
||||
fn set_title(&self, title: &str) {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ use super::window::WinitWindow;
|
|||
use super::{ffi, Fullscreen, MonitorHandle, OsError, WindowId};
|
||||
use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
|
||||
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::window::{
|
||||
Cursor, CursorGrabMode, Icon, ImePurpose, ResizeDirection, Theme, UserAttentionType,
|
||||
|
|
@ -95,7 +95,7 @@ pub(crate) struct State {
|
|||
previous_scale_factor: Cell<f64>,
|
||||
|
||||
/// The current resize increments for the window content.
|
||||
resize_increments: Cell<NSSize>,
|
||||
surface_resize_increments: Cell<NSSize>,
|
||||
/// Whether the window is showing decorations.
|
||||
decorations: Cell<bool>,
|
||||
resizable: Cell<bool>,
|
||||
|
|
@ -164,7 +164,7 @@ declare_class!(
|
|||
#[method(windowDidResize:)]
|
||||
fn window_did_resize(&self, _: Option<&AnyObject>) {
|
||||
trace_scope!("windowDidResize:");
|
||||
// NOTE: WindowEvent::Resized is reported in frameDidChange.
|
||||
// NOTE: WindowEvent::SurfaceResized is reported in frameDidChange.
|
||||
self.emit_move_event();
|
||||
}
|
||||
|
||||
|
|
@ -172,7 +172,7 @@ declare_class!(
|
|||
fn window_will_start_live_resize(&self, _: Option<&AnyObject>) {
|
||||
trace_scope!("windowWillStartLiveResize:");
|
||||
|
||||
let increments = self.ivars().resize_increments.get();
|
||||
let increments = self.ivars().surface_resize_increments.get();
|
||||
self.set_resize_increments_inner(increments);
|
||||
}
|
||||
|
||||
|
|
@ -505,7 +505,7 @@ fn new_window(
|
|||
let scale_factor = NSScreen::mainScreen(mtm)
|
||||
.map(|screen| screen.backingScaleFactor() as f64)
|
||||
.unwrap_or(1.0);
|
||||
let size = match attrs.inner_size {
|
||||
let size = match attrs.surface_size {
|
||||
Some(size) => {
|
||||
let size = size.to_logical(scale_factor);
|
||||
NSSize::new(size.width, size.height)
|
||||
|
|
@ -703,13 +703,15 @@ impl WindowDelegate {
|
|||
None => (),
|
||||
}
|
||||
|
||||
let resize_increments =
|
||||
match attrs.resize_increments.map(|i| i.to_logical(window.backingScaleFactor() as _)) {
|
||||
Some(LogicalSize { width, height }) if width >= 1. && height >= 1. => {
|
||||
NSSize::new(width, height)
|
||||
},
|
||||
_ => NSSize::new(1., 1.),
|
||||
};
|
||||
let surface_resize_increments = match attrs
|
||||
.surface_resize_increments
|
||||
.map(|i| i.to_logical(window.backingScaleFactor() as _))
|
||||
{
|
||||
Some(LogicalSize { width, height }) if width >= 1. && height >= 1. => {
|
||||
NSSize::new(width, height)
|
||||
},
|
||||
_ => NSSize::new(1., 1.),
|
||||
};
|
||||
|
||||
let scale_factor = window.backingScaleFactor() as _;
|
||||
|
||||
|
|
@ -722,7 +724,7 @@ impl WindowDelegate {
|
|||
window: window.retain(),
|
||||
previous_position: Cell::new(None),
|
||||
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),
|
||||
resizable: Cell::new(attrs.resizable),
|
||||
maximized: Cell::new(attrs.maximized),
|
||||
|
|
@ -763,11 +765,11 @@ impl WindowDelegate {
|
|||
delegate.set_blur(attrs.blur);
|
||||
}
|
||||
|
||||
if let Some(dim) = attrs.min_inner_size {
|
||||
delegate.set_min_inner_size(Some(dim));
|
||||
if let Some(dim) = attrs.min_surface_size {
|
||||
delegate.set_min_surface_size(Some(dim));
|
||||
}
|
||||
if let Some(dim) = attrs.max_inner_size {
|
||||
delegate.set_max_inner_size(Some(dim));
|
||||
if let Some(dim) = attrs.max_surface_size {
|
||||
delegate.set_max_surface_size(Some(dim));
|
||||
}
|
||||
|
||||
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 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 {
|
||||
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();
|
||||
drop(new_inner_size);
|
||||
let physical_size = *new_surface_size.lock().unwrap();
|
||||
drop(new_surface_size);
|
||||
|
||||
if physical_size != suggested_size {
|
||||
let logical_size = physical_size.to_logical(scale_factor);
|
||||
let size = NSSize::new(logical_size.width, logical_size.height);
|
||||
window.setContentSize(size);
|
||||
}
|
||||
self.queue_event(WindowEvent::Resized(physical_size));
|
||||
self.queue_event(WindowEvent::SurfaceResized(physical_size));
|
||||
}
|
||||
|
||||
fn emit_move_event(&self) {
|
||||
|
|
@ -944,7 +946,7 @@ impl WindowDelegate {
|
|||
}
|
||||
|
||||
#[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 logical = LogicalSize::new(content_rect.size.width, content_rect.size.height);
|
||||
logical.to_physical(self.scale_factor())
|
||||
|
|
@ -958,14 +960,14 @@ impl WindowDelegate {
|
|||
}
|
||||
|
||||
#[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_logical(scale_factor);
|
||||
self.window().setContentSize(NSSize::new(size.width, size.height));
|
||||
None
|
||||
}
|
||||
|
||||
pub fn set_min_inner_size(&self, dimensions: Option<Size>) {
|
||||
pub fn set_min_surface_size(&self, dimensions: Option<Size>) {
|
||||
let dimensions =
|
||||
dimensions.unwrap_or(Size::Logical(LogicalSize { width: 0.0, height: 0.0 }));
|
||||
let min_size = dimensions.to_logical::<CGFloat>(self.scale_factor());
|
||||
|
|
@ -984,7 +986,7 @@ impl WindowDelegate {
|
|||
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 {
|
||||
width: f32::MAX as f64,
|
||||
height: f32::MAX as f64,
|
||||
|
|
@ -1006,8 +1008,8 @@ impl WindowDelegate {
|
|||
self.window().setContentSize(current_size);
|
||||
}
|
||||
|
||||
pub fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
|
||||
let increments = self.ivars().resize_increments.get();
|
||||
pub fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
|
||||
let increments = self.ivars().surface_resize_increments.get();
|
||||
let (w, h) = (increments.width, increments.height);
|
||||
if w > 1.0 || h > 1.0 {
|
||||
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.
|
||||
self.ivars().resize_increments.set(
|
||||
self.ivars().surface_resize_increments.set(
|
||||
increments
|
||||
.map(|increments| {
|
||||
let logical = increments.to_logical::<f64>(self.scale_factor());
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use super::window::WinitUIWindow;
|
|||
use super::ActiveEventLoop;
|
||||
use crate::application::ApplicationHandler;
|
||||
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::window::WindowId as RootWindowId;
|
||||
|
||||
|
|
@ -669,18 +669,18 @@ pub(crate) fn terminated(application: &UIApplication) {
|
|||
|
||||
fn handle_hidpi_proxy(mtm: MainThreadMarker, event: ScaleFactorChanged) {
|
||||
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 {
|
||||
window_id: RootWindowId(window.id()),
|
||||
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)),
|
||||
},
|
||||
};
|
||||
handle_event(mtm, event);
|
||||
let (view, screen_frame) = get_view_and_screen_frame(&window);
|
||||
let physical_size = *new_inner_size.lock().unwrap();
|
||||
drop(new_inner_size);
|
||||
let physical_size = *new_surface_size.lock().unwrap();
|
||||
drop(new_surface_size);
|
||||
let logical_size = physical_size.to_logical(scale_factor);
|
||||
let size = CGSize::new(logical_size.width, logical_size.height);
|
||||
let new_frame: CGRect = CGRect::new(screen_frame.origin, size);
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ declare_class!(
|
|||
mtm,
|
||||
EventWrapper::StaticEvent(Event::WindowEvent {
|
||||
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(
|
||||
Event::WindowEvent {
|
||||
window_id,
|
||||
event: WindowEvent::Resized(size.to_physical(scale_factor)),
|
||||
event: WindowEvent::SurfaceResized(size.to_physical(scale_factor)),
|
||||
},
|
||||
))),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ impl Inner {
|
|||
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 safe_area = self.safe_area_screen_space();
|
||||
let size = LogicalSize {
|
||||
|
|
@ -207,25 +207,25 @@ impl Inner {
|
|||
size.to_physical(scale_factor)
|
||||
}
|
||||
|
||||
pub fn request_inner_size(&self, _size: Size) -> Option<PhysicalSize<u32>> {
|
||||
Some(self.inner_size())
|
||||
pub fn request_surface_size(&self, _size: Size) -> Option<PhysicalSize<u32>> {
|
||||
Some(self.surface_size())
|
||||
}
|
||||
|
||||
pub fn set_min_inner_size(&self, _dimensions: Option<Size>) {
|
||||
warn!("`Window::set_min_inner_size` is ignored on iOS")
|
||||
pub fn set_min_surface_size(&self, _dimensions: Option<Size>) {
|
||||
warn!("`Window::set_min_surface_size` is ignored on iOS")
|
||||
}
|
||||
|
||||
pub fn set_max_inner_size(&self, _dimensions: Option<Size>) {
|
||||
warn!("`Window::set_max_inner_size` is ignored on iOS")
|
||||
pub fn set_max_surface_size(&self, _dimensions: Option<Size>) {
|
||||
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
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_resize_increments(&self, _increments: Option<Size>) {
|
||||
warn!("`Window::set_resize_increments` is ignored on iOS")
|
||||
pub fn set_surface_resize_increments(&self, _increments: Option<Size>) {
|
||||
warn!("`Window::set_surface_resize_increments` is ignored on iOS")
|
||||
}
|
||||
|
||||
pub fn set_resizable(&self, _resizable: bool) {
|
||||
|
|
@ -469,11 +469,11 @@ impl Window {
|
|||
) -> Result<Window, RootOsError> {
|
||||
let mtm = event_loop.mtm;
|
||||
|
||||
if window_attributes.min_inner_size.is_some() {
|
||||
warn!("`WindowAttributes::min_inner_size` is ignored on iOS");
|
||||
if window_attributes.min_surface_size.is_some() {
|
||||
warn!("`WindowAttributes::min_surface_size` is ignored on iOS");
|
||||
}
|
||||
if window_attributes.max_inner_size.is_some() {
|
||||
warn!("`WindowAttributes::max_inner_size` is ignored on iOS");
|
||||
if window_attributes.max_surface_size.is_some() {
|
||||
warn!("`WindowAttributes::max_surface_size` is ignored on iOS");
|
||||
}
|
||||
|
||||
// TODO: transparency, visible
|
||||
|
|
@ -489,7 +489,7 @@ impl Window {
|
|||
|
||||
let screen_bounds = screen.bounds();
|
||||
|
||||
let frame = match window_attributes.inner_size {
|
||||
let frame = match window_attributes.surface_size {
|
||||
Some(dim) => {
|
||||
let scale_factor = screen.scale();
|
||||
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);
|
||||
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
|
||||
let scale_factor = view.contentScaleFactor();
|
||||
let scale_factor = scale_factor as f64;
|
||||
|
|
@ -534,7 +534,7 @@ impl Window {
|
|||
.chain(std::iter::once(EventWrapper::StaticEvent(
|
||||
Event::WindowEvent {
|
||||
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));
|
||||
}
|
||||
|
||||
fn inner_size(&self) -> dpi::PhysicalSize<u32> {
|
||||
self.maybe_wait_on_main(|delegate| delegate.inner_size())
|
||||
fn surface_size(&self) -> dpi::PhysicalSize<u32> {
|
||||
self.maybe_wait_on_main(|delegate| delegate.surface_size())
|
||||
}
|
||||
|
||||
fn request_inner_size(&self, size: Size) -> Option<dpi::PhysicalSize<u32>> {
|
||||
self.maybe_wait_on_main(|delegate| delegate.request_inner_size(size))
|
||||
fn request_surface_size(&self, size: Size) -> Option<dpi::PhysicalSize<u32>> {
|
||||
self.maybe_wait_on_main(|delegate| delegate.request_surface_size(size))
|
||||
}
|
||||
|
||||
fn outer_size(&self) -> dpi::PhysicalSize<u32> {
|
||||
self.maybe_wait_on_main(|delegate| delegate.outer_size())
|
||||
}
|
||||
|
||||
fn set_min_inner_size(&self, min_size: Option<Size>) {
|
||||
self.maybe_wait_on_main(|delegate| delegate.set_min_inner_size(min_size))
|
||||
fn set_min_surface_size(&self, min_size: Option<Size>) {
|
||||
self.maybe_wait_on_main(|delegate| delegate.set_min_surface_size(min_size))
|
||||
}
|
||||
|
||||
fn set_max_inner_size(&self, max_size: Option<Size>) {
|
||||
self.maybe_wait_on_main(|delegate| delegate.set_max_inner_size(max_size));
|
||||
fn set_max_surface_size(&self, max_size: Option<Size>) {
|
||||
self.maybe_wait_on_main(|delegate| delegate.set_max_surface_size(max_size));
|
||||
}
|
||||
|
||||
fn resize_increments(&self) -> Option<dpi::PhysicalSize<u32>> {
|
||||
self.maybe_wait_on_main(|delegate| delegate.resize_increments())
|
||||
fn surface_resize_increments(&self) -> Option<dpi::PhysicalSize<u32>> {
|
||||
self.maybe_wait_on_main(|delegate| delegate.surface_resize_increments())
|
||||
}
|
||||
|
||||
fn set_resize_increments(&self, increments: Option<Size>) {
|
||||
self.maybe_wait_on_main(|delegate| delegate.set_resize_increments(increments));
|
||||
fn set_surface_resize_increments(&self, increments: Option<Size>) {
|
||||
self.maybe_wait_on_main(|delegate| delegate.set_surface_resize_increments(increments));
|
||||
}
|
||||
|
||||
fn set_title(&self, title: &str) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -476,7 +476,7 @@ impl EventLoop {
|
|||
app.window_event(
|
||||
window_target,
|
||||
RootWindowId(window_id),
|
||||
event::WindowEvent::Resized((width, height).into()),
|
||||
event::WindowEvent::SurfaceResized((width, height).into()),
|
||||
);
|
||||
|
||||
// Acknowledge resize after event loop.
|
||||
|
|
@ -523,7 +523,7 @@ impl EventLoop {
|
|||
let window_id = RootWindowId(window_id);
|
||||
|
||||
// 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);
|
||||
|
||||
// Send moved event on create to indicate first position.
|
||||
|
|
|
|||
|
|
@ -42,13 +42,13 @@ impl Window {
|
|||
(-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()
|
||||
} else {
|
||||
(1024, 768)
|
||||
};
|
||||
|
||||
// TODO: min/max inner_size
|
||||
// TODO: min/max surface_size
|
||||
|
||||
// Async by default.
|
||||
let mut flag_str = ORBITAL_FLAG_ASYNC.to_string();
|
||||
|
|
@ -225,7 +225,7 @@ impl CoreWindow for Window {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn inner_size(&self) -> PhysicalSize<u32> {
|
||||
fn surface_size(&self) -> PhysicalSize<u32> {
|
||||
let mut buf: [u8; 4096] = [0; 4096];
|
||||
let path = self.window_socket.fpath(&mut buf).expect("failed to read properties");
|
||||
let properties = WindowProperties::new(path);
|
||||
|
|
@ -233,7 +233,7 @@ impl CoreWindow for Window {
|
|||
}
|
||||
|
||||
#[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();
|
||||
self.window_socket.write(format!("S,{w},{h}").as_bytes()).expect("failed to set size");
|
||||
None
|
||||
|
|
@ -242,14 +242,14 @@ impl CoreWindow for Window {
|
|||
#[inline]
|
||||
fn outer_size(&self) -> PhysicalSize<u32> {
|
||||
// TODO: adjust for window decorations
|
||||
self.inner_size()
|
||||
self.surface_size()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_min_inner_size(&self, _: Option<Size>) {}
|
||||
fn set_min_surface_size(&self, _: Option<Size>) {}
|
||||
|
||||
#[inline]
|
||||
fn set_max_inner_size(&self, _: Option<Size>) {}
|
||||
fn set_max_surface_size(&self, _: Option<Size>) {}
|
||||
|
||||
#[inline]
|
||||
fn title(&self) -> String {
|
||||
|
|
@ -283,12 +283,12 @@ impl CoreWindow for Window {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn resize_increments(&self) -> Option<PhysicalSize<u32>> {
|
||||
fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
|
||||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_resize_increments(&self, _increments: Option<Size>) {}
|
||||
fn set_surface_resize_increments(&self, _increments: Option<Size>) {}
|
||||
|
||||
#[inline]
|
||||
fn set_resizable(&self, resizeable: bool) {
|
||||
|
|
|
|||
|
|
@ -556,7 +556,7 @@ impl ActiveEventLoop {
|
|||
canvas.set_old_size(new_size);
|
||||
runner.send_event(Event::WindowEvent {
|
||||
window_id: RootWindowId(id),
|
||||
event: WindowEvent::Resized(new_size),
|
||||
event: WindowEvent::SurfaceResized(new_size),
|
||||
});
|
||||
canvas.request_animation_frame();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ use super::pointer::PointerHandler;
|
|||
use super::{event, fullscreen, ButtonsState, ResizeScaleHandle};
|
||||
use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
|
||||
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::platform_impl::{Fullscreen, OsError};
|
||||
use crate::window::{WindowAttributes, WindowId as RootWindowId};
|
||||
|
|
@ -126,17 +126,17 @@ impl Canvas {
|
|||
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));
|
||||
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));
|
||||
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));
|
||||
super::set_canvas_max_size(&common.document, &common.raw, &common.style, Some(size));
|
||||
}
|
||||
|
|
@ -213,7 +213,7 @@ impl Canvas {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn inner_size(&self) -> PhysicalSize<u32> {
|
||||
pub fn surface_size(&self) -> PhysicalSize<u32> {
|
||||
self.common.current_size.get()
|
||||
}
|
||||
|
||||
|
|
@ -504,7 +504,7 @@ impl Canvas {
|
|||
window_id: RootWindowId(self.id),
|
||||
event: crate::event::WindowEvent::ScaleFactorChanged {
|
||||
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 {
|
||||
// Then we resize the canvas to the new size, a new
|
||||
// `Resized` event will be sent by the `ResizeObserver`:
|
||||
// Then we resize the canvas to the new size, a new `SurfaceResized` event will be sent
|
||||
// by the `ResizeObserver`:
|
||||
let new_size = new_size.to_logical(scale);
|
||||
super::set_canvas_size(self.document(), self.raw(), self.style(), new_size);
|
||||
|
||||
|
|
@ -530,7 +530,7 @@ impl Canvas {
|
|||
self.set_old_size(new_size);
|
||||
runner.send_event(crate::event::Event::WindowEvent {
|
||||
window_id: RootWindowId(self.id),
|
||||
event: crate::event::WindowEvent::Resized(new_size),
|
||||
event: crate::event::WindowEvent::SurfaceResized(new_size),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,11 +127,11 @@ impl RootWindow for Window {
|
|||
})
|
||||
}
|
||||
|
||||
fn inner_size(&self) -> PhysicalSize<u32> {
|
||||
self.inner.queue(|inner| inner.canvas.inner_size())
|
||||
fn surface_size(&self) -> PhysicalSize<u32> {
|
||||
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| {
|
||||
let size = size.to_logical(self.scale_factor());
|
||||
backend::set_canvas_size(
|
||||
|
|
@ -145,11 +145,11 @@ impl RootWindow for Window {
|
|||
}
|
||||
|
||||
fn outer_size(&self) -> PhysicalSize<u32> {
|
||||
// Note: the canvas element has no window decorations, so this is equal to `inner_size`.
|
||||
self.inner_size()
|
||||
// Note: the canvas element has no window decorations, so this is equal to `surface_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| {
|
||||
let dimensions = min_size.map(|min_size| min_size.to_logical(inner.scale_factor()));
|
||||
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| {
|
||||
let dimensions = max_size.map(|dimensions| dimensions.to_logical(inner.scale_factor()));
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ use crate::application::ApplicationHandler;
|
|||
use crate::dpi::{PhysicalPosition, PhysicalSize};
|
||||
use crate::error::{EventLoopError, ExternalError, OsError};
|
||||
use crate::event::{
|
||||
Event, FingerId as RootFingerId, Force, Ime, InnerSizeWriter, RawKeyEvent, Touch, TouchPhase,
|
||||
Event, FingerId as RootFingerId, Force, Ime, RawKeyEvent, SurfaceSizeWriter, Touch, TouchPhase,
|
||||
WindowEvent,
|
||||
};
|
||||
use crate::event_loop::{
|
||||
|
|
@ -1274,14 +1274,14 @@ unsafe fn public_window_callback_inner(
|
|||
},
|
||||
|
||||
WM_SIZE => {
|
||||
use crate::event::WindowEvent::Resized;
|
||||
use crate::event::WindowEvent::SurfaceResized;
|
||||
let w = super::loword(lparam as u32) as u32;
|
||||
let h = super::hiword(lparam as u32) as u32;
|
||||
|
||||
let physical_size = PhysicalSize::new(w, h);
|
||||
let event = Event::WindowEvent {
|
||||
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 Some(inc) = userdata
|
||||
.window_state_lock()
|
||||
.resize_increments
|
||||
.surface_resize_increments
|
||||
.map(|inc| inc.to_physical(scale_factor))
|
||||
.filter(|inc| inc.width > 0 && inc.height > 0)
|
||||
else {
|
||||
|
|
@ -2131,7 +2131,7 @@ unsafe fn public_window_callback_inner(
|
|||
// New size as suggested by Windows.
|
||||
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
|
||||
// the outer rect, so we instead adjust the window rect to get the decoration margins
|
||||
// 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
|
||||
.get_rect(window)
|
||||
.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.bottom - old_physical_inner_rect.top) as u32,
|
||||
);
|
||||
|
||||
// `allow_resize` prevents us from re-applying DPI adjustment to the restored size after
|
||||
// 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
|
||||
// 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_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 {
|
||||
window_id: CoreWindowId(WindowId(window)),
|
||||
event: ScaleFactorChanged {
|
||||
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();
|
||||
drop(new_inner_size);
|
||||
let new_physical_surface_size = *new_surface_size.lock().unwrap();
|
||||
drop(new_surface_size);
|
||||
|
||||
let dragging_window: bool;
|
||||
|
||||
|
|
@ -2186,7 +2186,7 @@ unsafe fn public_window_callback_inner(
|
|||
dragging_window =
|
||||
window_state.window_flags().contains(WindowFlags::MARKER_IN_SIZE_MOVE);
|
||||
// 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| {
|
||||
f.set(WindowFlags::MAXIMIZED, false)
|
||||
});
|
||||
|
|
@ -2201,8 +2201,8 @@ unsafe fn public_window_callback_inner(
|
|||
let mut conservative_rect = RECT {
|
||||
left: suggested_ul.0,
|
||||
top: suggested_ul.1,
|
||||
right: suggested_ul.0 + new_physical_inner_size.width as i32,
|
||||
bottom: suggested_ul.1 + new_physical_inner_size.height as i32,
|
||||
right: suggested_ul.0 + new_physical_surface_size.width as i32,
|
||||
bottom: suggested_ul.1 + new_physical_surface_size.height as i32,
|
||||
};
|
||||
|
||||
conservative_rect = window_flags
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use windows_sys::Win32::Foundation::HWND;
|
|||
|
||||
use super::ControlFlow;
|
||||
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::get_window_long;
|
||||
use crate::window::WindowId;
|
||||
|
|
@ -357,12 +357,12 @@ impl BufferedEvent {
|
|||
pub fn from_event(event: Event) -> BufferedEvent {
|
||||
match event {
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::ScaleFactorChanged { scale_factor, inner_size_writer },
|
||||
event: WindowEvent::ScaleFactorChanged { scale_factor, surface_size_writer },
|
||||
window_id,
|
||||
} => BufferedEvent::ScaleFactorChanged(
|
||||
window_id,
|
||||
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),
|
||||
}
|
||||
|
|
@ -371,29 +371,29 @@ impl BufferedEvent {
|
|||
pub fn dispatch_event(self, dispatch: impl FnOnce(Event)) {
|
||||
match self {
|
||||
Self::Event(event) => dispatch(event),
|
||||
Self::ScaleFactorChanged(window_id, scale_factor, new_inner_size) => {
|
||||
let user_new_inner_size = Arc::new(Mutex::new(new_inner_size));
|
||||
Self::ScaleFactorChanged(window_id, scale_factor, new_surface_size) => {
|
||||
let user_new_surface_size = Arc::new(Mutex::new(new_surface_size));
|
||||
dispatch(Event::WindowEvent {
|
||||
window_id,
|
||||
event: WindowEvent::ScaleFactorChanged {
|
||||
scale_factor,
|
||||
inner_size_writer: InnerSizeWriter::new(Arc::downgrade(
|
||||
&user_new_inner_size,
|
||||
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(
|
||||
&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 userdata =
|
||||
get_window_long(window_id.0.into(), GWL_USERDATA) as *mut WindowData;
|
||||
(*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);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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() };
|
||||
if unsafe { GetClientRect(self.hwnd(), &mut rect) } == false.into() {
|
||||
panic!(
|
||||
|
|
@ -478,14 +478,14 @@ impl CoreWindow for Window {
|
|||
.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 physical_size = size.to_physical::<u32>(scale_factor);
|
||||
|
||||
let window_flags = self.window_state_lock().window_flags;
|
||||
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 = self.window;
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
|
|
@ -499,28 +499,28 @@ impl CoreWindow for Window {
|
|||
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;
|
||||
// Make windows re-check the window size bounds.
|
||||
let size = self.inner_size();
|
||||
let _ = self.request_inner_size(size.into());
|
||||
let size = self.surface_size();
|
||||
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;
|
||||
// Make windows re-check the window size bounds.
|
||||
let size = self.inner_size();
|
||||
let _ = self.request_inner_size(size.into());
|
||||
let size = self.surface_size();
|
||||
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 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>) {
|
||||
self.window_state_lock().resize_increments = increments;
|
||||
fn set_surface_resize_increments(&self, increments: Option<Size>) {
|
||||
self.window_state_lock().surface_resize_increments = increments;
|
||||
}
|
||||
|
||||
fn set_resizable(&self, resizable: bool) {
|
||||
|
|
@ -1209,13 +1209,14 @@ impl<'a> InitData<'a> {
|
|||
|
||||
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
|
||||
.max_inner_size
|
||||
.max_surface_size
|
||||
.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 _ = win.request_inner_size(clamped_size);
|
||||
let _ = win.request_surface_size(clamped_size);
|
||||
|
||||
// let margins = MARGINS {
|
||||
// cxLeftWidth: 1,
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ pub(crate) struct WindowState {
|
|||
pub min_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 taskbar_icon: Option<Icon>,
|
||||
|
|
@ -151,10 +151,10 @@ impl WindowState {
|
|||
last_position: None,
|
||||
},
|
||||
|
||||
min_size: attributes.min_inner_size,
|
||||
max_size: attributes.max_inner_size,
|
||||
min_size: attributes.min_surface_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(),
|
||||
taskbar_icon: None,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue