From 17a10240bee93add36c33f451bd028579f89718e Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 26 Jul 2023 13:31:47 -0400 Subject: [PATCH] refactor: after autosize surface resize wait to redraw until the resize has been applied --- sctk/src/application.rs | 33 ++++++++++++++++++++++----------- sctk/src/event_loop/mod.rs | 16 ++++++++++++++-- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/sctk/src/application.rs b/sctk/src/application.rs index 3f1e058a5e..dbab91df41 100644 --- a/sctk/src/application.rs +++ b/sctk/src/application.rs @@ -538,6 +538,9 @@ where if let Some(state) = states.get_mut(&id.inner()) { state.set_logical_size(configure.new_size.0.unwrap().get() as f64 , configure.new_size.1.unwrap().get() as f64); } + if let Some((_, _, limits, _)) = auto_size_surfaces.get(id) { + auto_size_surfaces.insert(*id, (configure.new_size.0.unwrap().get(), configure.new_size.1.unwrap().get(), *limits, false)); + } } } crate::sctk_event::WindowEventVariant::ScaleFactorChanged(sf, viewport) => { @@ -617,6 +620,9 @@ where configure.new_size.1 as f64, ); } + if let Some((_, _, limits, _)) = auto_size_surfaces.get(id) { + auto_size_surfaces.insert(*id, (configure.new_size.0, configure.new_size.1, *limits, false)); + } } } LayerSurfaceEventVariant::ScaleFactorChanged(sf, viewport) => { @@ -697,6 +703,9 @@ where height as f64, ); } + if let Some((_, _, limits, _)) = auto_size_surfaces.get(id) { + auto_size_surfaces.insert(*id, (width, height, *limits, false)); + } } }, PopupEventVariant::ScaleFactorChanged(sf, viewport) => { @@ -1002,15 +1011,6 @@ where runtime.broadcast(event, status); } - if let Some((w, h, limits, dirty)) = - auto_size_surfaces.remove(surface_id) - { - if dirty { - state.set_logical_size(w as f64, h as f64); - } - auto_size_surfaces - .insert(*surface_id, (w, h, limits, false)); - } needs_update = !messages.is_empty() || matches!( interface_state, @@ -1087,6 +1087,14 @@ where )); } for (object_id, surface_id) in &surface_ids { + // don't redraw yet if the autosize state is dirty + if let Some((_w, _h, _limits, dirty)) = + auto_size_surfaces.get(surface_id) + { + if *dirty { + continue; + } + } let state = match states.get_mut(&surface_id.inner()) { Some(s) => { if !s.needs_redraw() { @@ -1419,7 +1427,7 @@ where let mut view = application.view(id.inner()); debug.view_finished(); - let size = if let Some((w, h, limits, dirty)) = + let size = if let Some((auto_size_w, auto_size_h, limits, dirty)) = auto_size_surfaces.remove(&id) { let view: &mut dyn Widget< @@ -1437,7 +1445,10 @@ where ); let dirty = dirty || w != size.width.round() as u32 - || h != size.height.round() as u32; + || h != size.height.round() as u32 + || w != auto_size_w + || h != auto_size_h; + auto_size_surfaces.insert(id, (w, h, limits, dirty)); if dirty { match id { diff --git a/sctk/src/event_loop/mod.rs b/sctk/src/event_loop/mod.rs index c474877e51..144406a24d 100644 --- a/sctk/src/event_loop/mod.rs +++ b/sctk/src/event_loop/mod.rs @@ -45,7 +45,7 @@ use sctk::{ seat::SeatState, shell::{ wlr_layer::LayerShell, - xdg::{XdgShell, XdgSurface}, + xdg::XdgShell, WaylandSurface, }, shm::Shm, @@ -677,6 +677,18 @@ where if let Some(layer_surface) = self.state.layer_surfaces.iter_mut().find(|l| l.id == id) { layer_surface.set_size(width, height); pending_redraws.push(layer_surface.surface.wl_surface().id()); + let wl_surface = layer_surface.surface.wl_surface(); + + if let Some(mut prev_configure) = layer_surface.last_configure.clone() { + + prev_configure.new_size = (width.unwrap_or(prev_configure.new_size.0), width.unwrap_or(prev_configure.new_size.1)); + sticky_exit_callback( + IcedSctkEvent::SctkEvent(SctkEvent::LayerSurfaceEvent { variant: LayerSurfaceEventVariant::Configure(prev_configure, wl_surface.clone(), false), id: wl_surface.clone()}), + &self.state, + &mut control_flow, + &mut callback, + ); + } } }, platform_specific::wayland::layer_surface::Action::Destroy(id) => { @@ -767,7 +779,7 @@ where let adapter = self.init_a11y_adapter(&wl_surface, app_id, title, iced_accessibility::accesskit::Role::Window); sticky_exit_callback( - IcedSctkEvent::A11ySurfaceCreated(SurfaceIdWrapper::LayerSurface(id), adapter), + IcedSctkEvent::A11ySurfaceCreated(SurfaceIdWrapper::Window(id), adapter), &self.state, &mut control_flow, &mut callback,