From 15ebbfda5b7f75a7f9bcbafc4fe9be7e71e09226 Mon Sep 17 00:00:00 2001 From: bbb651 Date: Wed, 18 Dec 2024 21:55:41 +0200 Subject: [PATCH] simple_layer example: Handle 0 width/height in configure correctly The `wlr-layer-shell-unstable` protocol says: > If the width or height arguments are zero, it means the client should decide its own window dimension. While the wording doesn't make it clear, I think it's reasonable to assume it's talking about each dimension *separately* - the word "dimension" isn't plural, and there's legitimate use cases for this behavior (e.g. scrolling compositors like niri). Relevent issue: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/issues/155 (about xdg-shell not layer-shell, the wording comes from there) --- examples/simple_layer.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/examples/simple_layer.rs b/examples/simple_layer.rs index a11b84e1b..7bc64d580 100644 --- a/examples/simple_layer.rs +++ b/examples/simple_layer.rs @@ -1,6 +1,6 @@ //! This example is horrible. Please make a better one soon. -use std::convert::TryInto; +use std::{convert::TryInto, num::NonZeroU32}; use smithay_client_toolkit::{ compositor::{CompositorHandler, CompositorState}, @@ -215,13 +215,8 @@ impl LayerShellHandler for SimpleLayer { configure: LayerSurfaceConfigure, _serial: u32, ) { - if configure.new_size.0 == 0 || configure.new_size.1 == 0 { - self.width = 256; - self.height = 256; - } else { - self.width = configure.new_size.0; - self.height = configure.new_size.1; - } + self.width = NonZeroU32::new(configure.new_size.0).map_or(256, NonZeroU32::get); + self.height = NonZeroU32::new(configure.new_size.1).map_or(256, NonZeroU32::get); // Initiate the first draw. if self.first_configure {