From 7ae183c0aa6625a58bbbe449df935ec0bcf83152 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Sat, 24 Feb 2024 18:13:31 +0000 Subject: [PATCH] Window: always size immediately instead of prior logic It seems that X11 doesn't always resize when requested, so we can't rely on this. --- crates/kas-core/src/app/window.rs | 33 +++++++++++-------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/crates/kas-core/src/app/window.rs b/crates/kas-core/src/app/window.rs index 3c71b9faf..e0c613441 100644 --- a/crates/kas-core/src/app/window.rs +++ b/crates/kas-core/src/app/window.rs @@ -39,7 +39,6 @@ struct WindowData> { theme_window: T::Window, next_avail_frame_time: Instant, queued_frame_time: Option, - is_sized: bool, } /// Per-window data @@ -122,7 +121,6 @@ impl> Window { // Now that we have a scale factor, we may need to resize: let scale_factor = window.scale_factor(); - let apply_size; if scale_factor != 1.0 { let sf32 = scale_factor as f32; state.shared.theme.update_window(&mut theme_window, sf32); @@ -143,20 +141,18 @@ impl> Window { if let Some(size) = window.request_inner_size(ideal) { debug_assert_eq!(size, window.inner_size()); - apply_size = true; } else { - // We will receive WindowEvent::Resized - apply_size = false; + // We will receive WindowEvent::Resized and resize then. + // Unfortunately we can't rely on this since some platforms (X11) + // don't always behave as expected, thus we must resize now. } - } else { - apply_size = true; } let size: Size = window.inner_size().cast(); log::info!( - "new: constructed with physical size {:?}, scale factor {}", + "Window::resume: constructed with physical size {:?}, scale factor {}", size, - scale_factor + scale_factor, ); #[cfg(all(wayland_platform, feature = "clipboard"))] @@ -175,9 +171,7 @@ impl> Window { // NOTE: usage of Arc is inelegant, but avoids lots of unsafe code let window = Arc::new(window); let mut surface = G::new_surface(&mut state.shared.draw.draw, window.clone())?; - if apply_size { - surface.do_resize(&mut state.shared.draw.draw, size); - } + surface.do_resize(&mut state.shared.draw.draw, size); let winit_id = window.id(); @@ -193,12 +187,9 @@ impl> Window { theme_window, next_avail_frame_time: time, queued_frame_time: Some(time), - is_sized: apply_size, }); - if apply_size { - self.apply_size(state, true); - } + self.apply_size(state, true); log::trace!(target: "kas_perf::wgpu::window", "resume: {}µs", time.elapsed().as_micros()); Ok(winit_id) @@ -221,6 +212,7 @@ impl> Window { let Some(ref mut window) = self.window else { return false; }; + match event { WindowEvent::Moved(_) | WindowEvent::Destroyed => false, WindowEvent::Resized(size) => { @@ -245,7 +237,6 @@ impl> Window { // NOTE: we could try resizing here in case the window is too // small due to non-linear scaling, but it appears unnecessary. window.solve_cache.invalidate_rule_cache(); - window.is_sized = false; false } WindowEvent::RedrawRequested => self.do_draw(state).is_err(), @@ -275,6 +266,7 @@ impl> Window { let Some(ref window) = self.window else { return (Action::empty(), None); }; + let mut messages = MessageStack::new(); let action = self.ev_state.flush_pending( &mut state.shared, @@ -349,6 +341,7 @@ impl> Window { let Some(ref window) = self.window else { return None; }; + let widget = self.widget.as_node(&state.data); let mut messages = MessageStack::new(); self.ev_state @@ -368,6 +361,7 @@ impl> Window { let Some(ref window) = self.window else { return; }; + let mut messages = MessageStack::new(); self.ev_state .with(&mut state.shared, window, &mut messages, |cx| { @@ -453,7 +447,6 @@ impl> Window { window.set_max_inner_size(Some(ideal)); }; - window.is_sized = true; window.set_visible(true); window.request_redraw(); log::trace!( @@ -471,10 +464,6 @@ impl> Window { let Some(ref mut window) = self.window else { return Ok(()); }; - if !window.is_sized { - log::debug!("Ignoring redraw request before window is (re)sized."); - return Err(()); - } window.next_avail_frame_time = start + self.ev_state.config().frame_dur();