fix: request logical size when autosizing

This commit is contained in:
Ashley Wulber 2024-11-19 12:58:25 -05:00
parent db8e74b7a3
commit eff664a035
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
2 changed files with 56 additions and 9 deletions

View file

@ -49,6 +49,7 @@ pub use error::Error;
pub use proxy::Proxy;
use winit::dpi::LogicalSize;
use winit::dpi::PhysicalPosition;
use winit::dpi::PhysicalSize;
use crate::core::mouse;
use crate::core::renderer;
@ -1283,17 +1284,18 @@ async fn run_instance<P>(
proxy.free_slots(actions);
actions = 0;
}
let skip = events.is_empty() && messages.is_empty();
if events.is_empty()
&& messages.is_empty()
&& window_manager.is_idle()
{
if skip && window_manager.is_idle() {
continue;
}
let mut uis_stale = false;
let mut resized = false;
for (id, window) in window_manager.iter_mut() {
if skip && !window.resize_enabled {
continue;
}
let interact_span = debug::interact(id);
let mut window_events = vec![];
@ -1306,9 +1308,13 @@ async fn run_instance<P>(
}
});
if window_events.is_empty() && messages.is_empty() {
continue;
}
let no_window_events = window_events.is_empty();
#[cfg(feature = "wayland")]
window_events.push(core::Event::PlatformSpecific(
core::event::PlatformSpecific::Wayland(
core::event::wayland::Event::RequestResize,
),
));
let (ui_state, statuses) = user_interfaces
.get_mut(&id)
@ -1320,10 +1326,49 @@ async fn run_instance<P>(
&mut clipboard,
&mut messages,
);
let mut needs_redraw =
!no_window_events || !messages.is_empty();
if let Some(requested_size) =
clipboard.requested_logical_size.lock().unwrap().take()
{
let requested_physical_size: PhysicalSize<u32> =
winit::dpi::PhysicalSize::from_logical(
requested_size.cast::<u32>(),
window.state.scale_factor(),
);
let physical_size = window.state.physical_size();
if requested_physical_size.width != physical_size.width
|| requested_physical_size.height
!= physical_size.height
{
// FIXME what to do when we are stuck in a configure event/resize request loop
// We don't have control over how winit handles this.
window.resize_enabled = true;
resized = true;
needs_redraw = true;
let s = winit::dpi::Size::Logical(
requested_size.cast(),
);
_ = window.raw.request_surface_size(s);
window.raw.set_min_surface_size(Some(s));
window.raw.set_max_surface_size(Some(s));
window.state.synchronize(
&program,
id,
window.raw.as_ref(),
);
}
}
#[cfg(feature = "unconditional-rendering")]
window.request_redraw(window::RedrawRequest::NextFrame);
if needs_redraw {
window.request_redraw(
core::window::RedrawRequest::NextFrame,
);
}
match ui_state {
user_interface::State::Updated {
redraw_request: _redraw_request,

View file

@ -87,6 +87,7 @@ where
prev_dnd_destination_rectangles_count: 0,
viewport_version: 0,
redraw_requested: false,
resize_enabled: false,
},
);
@ -102,7 +103,7 @@ where
pub fn is_idle(&self) -> bool {
self.entries
.values()
.all(|window| window.redraw_at.is_none())
.all(|window| window.redraw_at.is_none() && !window.resize_enabled)
}
pub fn redraw_at(&self) -> Option<Instant> {
@ -193,6 +194,7 @@ where
preedit: Option<Preedit<P::Renderer>>,
ime_state: Option<(Rectangle, input_method::Purpose)>,
pub(crate) redraw_requested: bool,
pub resize_enabled: bool,
}
impl<P, C> Window<P, C>