diff --git a/CHANGELOG.md b/CHANGELOG.md index b7bacfef0c..e728d1de74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ Unreleased` header. - On Windows, fix consecutive calls to `window.set_fullscreen(Some(Fullscreen::Borderless(None)))` resulting in losing previous window state when eventually exiting fullscreen using `window.set_fullscreen(None)`. - On Web, remove queuing fullscreen request in absence of transient activation. - On Web, fix setting cursor icon overriding cursor visibility. +- On Wayland, fix resize being sent on focus change. # 0.29.4 diff --git a/src/platform_impl/linux/wayland/state.rs b/src/platform_impl/linux/wayland/state.rs index a3ff57c330..eae215bb6b 100644 --- a/src/platform_impl/linux/wayland/state.rs +++ b/src/platform_impl/linux/wayland/state.rs @@ -307,7 +307,11 @@ impl WindowHandler for WinitState { &mut self.events_sink, ); - self.window_compositor_updates[pos].size = Some(new_size); + // NOTE: Only update when the value is `Some` to not override consequent configures with + // the same sizes. + if new_size.is_some() { + self.window_compositor_updates[pos].size = new_size; + } } } diff --git a/src/platform_impl/linux/wayland/window/state.rs b/src/platform_impl/linux/wayland/window/state.rs index 9355bb8ab4..5ba1b53604 100644 --- a/src/platform_impl/linux/wayland/window/state.rs +++ b/src/platform_impl/linux/wayland/window/state.rs @@ -262,7 +262,7 @@ impl WindowState { shm: &Shm, subcompositor: &Option>, event_sink: &mut EventSink, - ) -> LogicalSize { + ) -> Option> { // NOTE: when using fractional scaling or wl_compositor@v6 the scaling // should be delivered before the first configure, thus apply it to // properly scale the physical sizes provided by the users. @@ -325,14 +325,9 @@ impl WindowState { match configure.new_size { (Some(width), Some(height)) => { let (width, height) = frame.subtract_borders(width, height); - ( - ( - width.map(|w| w.get()).unwrap_or(1), - height.map(|h| h.get()).unwrap_or(1), - ) - .into(), - false, - ) + let width = width.map(|w| w.get()).unwrap_or(1); + let height = height.map(|h| h.get()).unwrap_or(1); + ((width, height).into(), false) } (_, _) if stateless => (self.stateless_size, true), _ => (self.size, true), @@ -358,13 +353,27 @@ impl WindowState { .unwrap_or(new_size.height); } - // XXX Set the configure before doing a resize. - self.last_configure = Some(configure); + let new_state = configure.state; + let old_state = self + .last_configure + .as_ref() + .map(|configure| configure.state) + .unwrap_or(XdgWindowState::empty()); + + let state_change_requires_resize = !new_state + .symmetric_difference(old_state) + .difference(XdgWindowState::ACTIVATED | XdgWindowState::SUSPENDED) + .is_empty(); - // XXX Update the new size right away. - self.resize(new_size); + // NOTE: Set the configure before doing a resize, since we query it during it. + self.last_configure = Some(configure); - new_size + if state_change_requires_resize || new_size != self.inner_size() { + self.resize(new_size); + Some(new_size) + } else { + None + } } /// Compute the bounds for the inner size of the surface. @@ -970,7 +979,7 @@ impl WindowState { /// Set the IME position. pub fn set_ime_cursor_area(&self, position: LogicalPosition, size: LogicalSize) { - // XXX This won't fly unless user will have a way to request IME window per seat, since + // FIXME: This won't fly unless user will have a way to request IME window per seat, since // the ime windows will be overlapping, but winit doesn't expose API to specify for // which seat we're setting IME position. let (x, y) = (position.x as i32, position.y as i32); @@ -1001,7 +1010,7 @@ impl WindowState { pub fn set_scale_factor(&mut self, scale_factor: f64) { self.scale_factor = scale_factor; - // XXX when fractional scaling is not used update the buffer scale. + // NOTE: When fractional scaling is not used update the buffer scale. if self.fractional_scale.is_none() { let _ = self.window.set_buffer_scale(self.scale_factor as _); } @@ -1149,7 +1158,7 @@ impl From for XdgResizeEdge { } } -// XXX rust doesn't allow from `Option`. +// NOTE: Rust doesn't allow `From>`. #[cfg(feature = "sctk-adwaita")] fn into_sctk_adwaita_config(theme: Option) -> sctk_adwaita::FrameConfig { match theme {