diff --git a/src/platform_impl/linux/wayland/seat/keyboard/mod.rs b/src/platform_impl/linux/wayland/seat/keyboard/mod.rs index 6f59733b3e..12e9390b19 100644 --- a/src/platform_impl/linux/wayland/seat/keyboard/mod.rs +++ b/src/platform_impl/linux/wayland/seat/keyboard/mod.rs @@ -111,7 +111,7 @@ impl KeyboardHandler for WinitState { ) { let window_id = wayland::make_wid(surface); - // Mark the window as not focused. + // XXX The check whether the window exists is essential as we might get a nil surface... match self.windows.get_mut().get(&window_id) { Some(window) => window.lock().unwrap().set_has_focus(false), None => return, diff --git a/src/platform_impl/linux/wayland/seat/text_input/mod.rs b/src/platform_impl/linux/wayland/seat/text_input/mod.rs index 4b425930c1..85136cc19f 100644 --- a/src/platform_impl/linux/wayland/seat/text_input/mod.rs +++ b/src/platform_impl/linux/wayland/seat/text_input/mod.rs @@ -92,6 +92,8 @@ impl Dispatch for TextInputState { let window_id = wayland::make_wid(&surface); + // XXX this check is essential, because `leave` could have a + // refence to nil surface... let mut window = match windows.get(&window_id) { Some(window) => window.lock().unwrap(), None => return, diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index 197e943845..76168f3620 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -67,9 +67,6 @@ pub struct Window { /// Handle to the main queue to perform requests. queue_handle: QueueHandle, - /// Whether the window is resizeable. - resizeable: AtomicBool, - /// Window requests to the event loop. window_requests: Arc, @@ -123,29 +120,22 @@ impl Window { attributes.preferred_theme, ); + // Set the app_id. + if let Some(name) = platform_attributes.name.map(|name| name.general) { + window.set_app_id(name); + } + // Set the window title. window_state.set_title(attributes.title); + // Set the min and max sizes. let min_size = attributes.min_inner_size.map(|size| size.to_logical(1.)); let max_size = attributes.max_inner_size.map(|size| size.to_logical(1.)); + window_state.set_min_inner_size(min_size); + window_state.set_max_inner_size(max_size); - // Set the min and max sizes. - { - let (min_size, max_size) = if attributes.resizable { - (min_size.map(Into::into), max_size.map(Into::into)) - } else { - // Non-resizable implies that the min and max sizes are set to the same value. - (Some(size), Some(size)) - }; - - window_state.set_min_inner_size(min_size); - window_state.set_max_inner_size(max_size); - } - - // Set the app_id. - if let Some(name) = platform_attributes.name.map(|name| name.general) { - window.set_app_id(name); - } + // Non-resizable implies that the min and max sizes are set to the same value. + window_state.set_resizable(attributes.resizable); // Set startup mode. match attributes.fullscreen.map(Into::into) { @@ -221,7 +211,6 @@ impl Window { window_state, queue_handle, xdg_activation, - resizeable: AtomicBool::new(attributes.resizable), attention_requested: Arc::new(AtomicBool::new(false)), event_loop_awakener, window_requests, @@ -360,20 +349,12 @@ impl Window { #[inline] pub fn set_resizable(&self, resizable: bool) { - self.resizeable.store(resizable, Ordering::Relaxed); - if resizable { - // Restore min/max sizes of the window. - self.window_state.lock().unwrap().reload_min_max_hints(); - } else { - let size = self.window_state.lock().unwrap().inner_size().into(); - self.set_min_inner_size(Some(size)); - self.set_max_inner_size(Some(size)); - } + self.window_state.lock().unwrap().set_resizable(resizable); } #[inline] pub fn is_resizable(&self) -> bool { - self.resizeable.load(Ordering::Relaxed) + self.window_state.lock().unwrap().resizable() } #[inline] diff --git a/src/platform_impl/linux/wayland/window/state.rs b/src/platform_impl/linux/wayland/window/state.rs index af824dee40..98f82bc969 100644 --- a/src/platform_impl/linux/wayland/window/state.rs +++ b/src/platform_impl/linux/wayland/window/state.rs @@ -79,6 +79,9 @@ pub struct WindowState { /// The current window title. title: String, + /// Whether the frame is resizable. + resizable: bool, + /// Whether the window has focus. has_focus: bool, @@ -293,6 +296,34 @@ impl WindowState { } } + /// Get the stored resizable state. + #[inline] + pub fn resizable(&self) -> bool { + self.resizable + } + + /// Set the resizable state on the window. + #[inline] + pub fn set_resizable(&mut self, resizable: bool) { + if self.resizable == resizable { + return; + } + + self.resizable = resizable; + if resizable { + // Restore min/max sizes of the window. + self.reload_min_max_hints(); + } else { + self.set_min_inner_size(Some(self.size)); + self.set_max_inner_size(Some(self.size)); + } + + // Reload the state on the frame as well. + if let Some(frame) = self.frame.as_mut() { + frame.set_resizable(resizable); + } + } + /// Whether the window is focused. #[inline] pub fn has_focus(&self) -> bool { @@ -378,6 +409,7 @@ impl WindowState { text_inputs: Vec::new(), title: String::default(), transparent: false, + resizable: true, viewport, window: ManuallyDrop::new(window), }