Skip to content

Commit

Permalink
refactor: after autosize surface resize wait to redraw until the resi…
Browse files Browse the repository at this point in the history
…ze has been applied
  • Loading branch information
wash2 committed Jul 26, 2023
1 parent 03bb205 commit 17a1024
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
33 changes: 22 additions & 11 deletions sctk/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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<
Expand All @@ -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 {
Expand Down
16 changes: 14 additions & 2 deletions sctk/src/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use sctk::{
seat::SeatState,
shell::{
wlr_layer::LayerShell,
xdg::{XdgShell, XdgSurface},
xdg::XdgShell,
WaylandSurface,
},
shm::Shm,
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 17a1024

Please sign in to comment.