From a12ba5a8a2f9ec08b1787dd8aeaad7ef0c142491 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Mon, 18 Nov 2024 13:52:31 -0500 Subject: [PATCH] bugfix: wlr layer shell surface are guaranteed to have a nonzero size --- .../frontend_wayland/layer_shell_v1.cpp | 2 +- .../window_wl_surface_role.cpp | 20 +++++++++++-------- .../frontend_wayland/window_wl_surface_role.h | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/server/frontend_wayland/layer_shell_v1.cpp b/src/server/frontend_wayland/layer_shell_v1.cpp index 2b6ca3b0a02..c78ef657072 100644 --- a/src/server/frontend_wayland/layer_shell_v1.cpp +++ b/src/server/frontend_wayland/layer_shell_v1.cpp @@ -409,7 +409,7 @@ auto mf::LayerSurfaceV1::vert_padding(Anchors const& anchors, Margin const& marg auto mf::LayerSurfaceV1::unpadded_requested_size() const -> geom::Size { - auto size = requested_window_size().value_or(current_size()); + auto size = requested_window_size().value_or(current_size().value_or(geom::Size(640, 480))); size.width -= horiz_padding(anchors.committed(), margin.committed()); size.height -= vert_padding(anchors.committed(), margin.committed()); return size; diff --git a/src/server/frontend_wayland/window_wl_surface_role.cpp b/src/server/frontend_wayland/window_wl_surface_role.cpp index f76e29953ff..dece35021c0 100644 --- a/src/server/frontend_wayland/window_wl_surface_role.cpp +++ b/src/server/frontend_wayland/window_wl_surface_role.cpp @@ -284,7 +284,7 @@ void mf::WindowWlSurfaceRole::remove_state_now(MirWindowState state) auto mf::WindowWlSurfaceRole::pending_size() const -> geom::Size { - auto size = current_size(); + auto size = current_size().value_or(geom::Size{0, 0}); if (pending_explicit_width) size.width = pending_explicit_width.value(); if (pending_explicit_height) @@ -292,18 +292,22 @@ auto mf::WindowWlSurfaceRole::pending_size() const -> geom::Size return size; } -auto mf::WindowWlSurfaceRole::current_size() const -> geom::Size +auto mf::WindowWlSurfaceRole::current_size() const -> std::optional { if (surface) { - auto const buffer_size = surface.value().buffer_size().value_or(geom::Size{}); - - return { - committed_width_set_explicitly.value_or(buffer_size.width), - committed_height_set_explicitly.value_or(buffer_size.height)}; + auto buffer_size = surface.value().buffer_size(); + if (committed_width_set_explicitly || committed_height_set_explicitly) + { + return geom::Size{ + committed_width_set_explicitly.value_or(buffer_size ? buffer_size.value().width : geom::Width{0}), + committed_height_set_explicitly.value_or(buffer_size ? buffer_size.value().height : geom::Height{0})}; + } + else + return buffer_size; } - return geom::Size{0, 0}; + return std::nullopt; } auto mf::WindowWlSurfaceRole::requested_window_size() const -> std::optional diff --git a/src/server/frontend_wayland/window_wl_surface_role.h b/src/server/frontend_wayland/window_wl_surface_role.h index 7a1f7dc1f07..0aa74eb92b3 100644 --- a/src/server/frontend_wayland/window_wl_surface_role.h +++ b/src/server/frontend_wayland/window_wl_surface_role.h @@ -119,8 +119,8 @@ class WindowWlSurfaceRole /// The size the window will be after the next commit auto pending_size() const -> geometry::Size; - /// The size the window currently is (the committed size, or a reasonable default if it has never committed) - auto current_size() const -> geometry::Size; + /// The size the window currently is (the committed size, or std::nullopt if it has never committed) + auto current_size() const -> std::optional; /// Window size requested by Mir auto requested_window_size() const -> std::optional;