Skip to content

Commit

Permalink
bugfix: wlr layer shell surface are guaranteed to have a nonzero size
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Nov 18, 2024
1 parent a2da926 commit a12ba5a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/server/frontend_wayland/layer_shell_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 12 additions & 8 deletions src/server/frontend_wayland/window_wl_surface_role.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,26 +284,30 @@ 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)
size.height = pending_explicit_height.value();
return size;
}

auto mf::WindowWlSurfaceRole::current_size() const -> geom::Size
auto mf::WindowWlSurfaceRole::current_size() const -> std::optional<geom::Size>
{
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<geom::Size>
Expand Down
4 changes: 2 additions & 2 deletions src/server/frontend_wayland/window_wl_surface_role.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<geometry::Size>;

/// Window size requested by Mir
auto requested_window_size() const -> std::optional<geometry::Size>;
Expand Down

0 comments on commit a12ba5a

Please sign in to comment.