From 0db15ecaf46bcb04f6c6156e34668f36fc5e7c16 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 2 Jan 2020 11:01:41 -0800 Subject: [PATCH] wayland: fix spurious resize event on focus change The resize event would be fine except that it happens to trigger the scroll position to reset to the bottom. --- window/src/lib.rs | 2 +- window/src/os/wayland/window.rs | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/window/src/lib.rs b/window/src/lib.rs index b8c1dbd5e..d4e9ee6db 100644 --- a/window/src/lib.rs +++ b/window/src/lib.rs @@ -48,7 +48,7 @@ pub enum Operator { MultiplyThenOver(Color), } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Dimensions { pub pixel_width: usize, pub pixel_height: usize, diff --git a/window/src/os/wayland/window.rs b/window/src/os/wayland/window.rs index 344e13300..1bf3a81bf 100644 --- a/window/src/os/wayland/window.rs +++ b/window/src/os/wayland/window.rs @@ -454,18 +454,23 @@ impl WaylandWindowInner { // Update the window decoration size self.window.as_mut().unwrap().resize(w, h); - // Store the new pixel dimensions - self.dimensions = Dimensions { + // Compute the new pixel dimensions + let new_dimensions = Dimensions { pixel_width: pixel_width.try_into().unwrap(), pixel_height: pixel_height.try_into().unwrap(), dpi: factor as usize * 96, }; + // Only trigger a resize if the new dimensions are different; + // this makes things more efficient and a little more smooth + if new_dimensions != self.dimensions { + self.dimensions = new_dimensions; - self.callbacks.resize(self.dimensions); - #[cfg(feature = "opengl")] - { - if let Some(wegl_surface) = self.wegl_surface.as_mut() { - wegl_surface.resize(pixel_width, pixel_height, 0, 0); + self.callbacks.resize(self.dimensions); + #[cfg(feature = "opengl")] + { + if let Some(wegl_surface) = self.wegl_surface.as_mut() { + wegl_surface.resize(pixel_width, pixel_height, 0, 0); + } } }