Skip to content

Commit

Permalink
Do not default window size (#3623)
Browse files Browse the repository at this point in the history
Stop pretending (mostly) that windows we don't know the size of are
640x480, 100x100, or 1x1.
  • Loading branch information
tarek-y-ismail authored Oct 15, 2024
2 parents 2ba30d8 + d715f56 commit c8aa9df
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 34 deletions.
19 changes: 8 additions & 11 deletions src/miral/basic_window_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1855,10 +1855,7 @@ auto miral::BasicWindowManager::place_new_surface(WindowSpecification parameters
if (!parameters.state().is_set())
parameters.state() = mir_window_state_restored;

if (!parameters.size().is_set())
{
parameters.size() = {640, 480};
}
auto const proposed_size = parameters.size().value_or({640, 480});

std::shared_ptr<DisplayArea> display_area;
if (parameters.output_id().is_set())
Expand Down Expand Up @@ -1890,7 +1887,7 @@ auto miral::BasicWindowManager::place_new_surface(WindowSpecification parameters
auto const position = place_relative(
parent_content_area,
parameters,
parameters.size().value());
proposed_size);

if (position.is_set())
{
Expand All @@ -1911,8 +1908,8 @@ auto miral::BasicWindowManager::place_new_surface(WindowSpecification parameters
auto const parent = info_for(parameters.parent().value()).window();
auto const parent_top_left = parent.top_left();
auto const centred = parent_top_left
+ 0.5*(as_displacement(parent.size()) - as_displacement(parameters.size().value()))
- (as_delta(parent.size().height) - as_delta(parameters.size().value().height)) / 6;
+ 0.5*(as_displacement(parent.size()) - as_displacement(proposed_size))
- (as_delta(parent.size().height) - as_delta(proposed_size.height)) / 6;

parameters.top_left() = centred;
positioned = true;
Expand All @@ -1932,8 +1929,8 @@ auto miral::BasicWindowManager::place_new_surface(WindowSpecification parameters
if (!positioned)
{
auto centred = application_zone.top_left
+ 0.5*(as_displacement(application_zone.size) - as_displacement(parameters.size().value()))
- (as_delta(application_zone.size.height) - as_delta(parameters.size().value().height)) / 6;
+ 0.5*(as_displacement(application_zone.size) - as_displacement(proposed_size))
- (as_delta(application_zone.size.height) - as_delta(proposed_size.height)) / 6;

switch (parameters.state().value())
{
Expand All @@ -1950,13 +1947,13 @@ auto miral::BasicWindowManager::place_new_surface(WindowSpecification parameters
case mir_window_state_vertmaximized:
centred.y = application_zone.top_left.y;
parameters.top_left() = centred;
parameters.size() = Size{parameters.size().value().width, application_zone.size.height};
parameters.size() = Size{proposed_size.width, application_zone.size.height};
break;

case mir_window_state_horizmaximized:
centred.x = application_zone.top_left.x;
parameters.top_left() = centred;
parameters.size() = Size{application_zone.size.width, parameters.size().value().height};
parameters.size() = Size{application_zone.size.width, proposed_size.height};
break;

default:
Expand Down
26 changes: 10 additions & 16 deletions src/server/frontend_wayland/window_wl_surface_role.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,22 +294,16 @@ auto mf::WindowWlSurfaceRole::pending_size() const -> geom::Size

auto mf::WindowWlSurfaceRole::current_size() const -> geom::Size
{
auto size = geom::Size{640, 480};
if ((!committed_width_set_explicitly || !committed_height_set_explicitly) && surface)
if (surface)
{
if (auto const buffer_size = surface.value().buffer_size())
{
if (!committed_width_set_explicitly)
{
size.width = buffer_size->width;
}
if (!committed_height_set_explicitly)
{
size.height = buffer_size->height;
}
}
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)};
}
return size;

return geom::Size{0, 0};
}

auto mf::WindowWlSurfaceRole::requested_window_size() const -> std::optional<geom::Size>
Expand Down Expand Up @@ -389,9 +383,9 @@ void mf::WindowWlSurfaceRole::commit(WlSurfaceState const& state)
}

if (pending_explicit_width)
committed_width_set_explicitly = true;
committed_width_set_explicitly = pending_explicit_width;
if (pending_explicit_height)
committed_height_set_explicitly = true;
committed_height_set_explicitly = pending_explicit_height;
pending_explicit_width = std::nullopt;
pending_explicit_height = std::nullopt;

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 @@ -155,8 +155,8 @@ class WindowWlSurfaceRole

/// If the committed window size was set explicitly, rather than being taken from the buffer size
/// @{
bool committed_width_set_explicitly{false};
bool committed_height_set_explicitly{false};
std::optional<geometry::Width> committed_width_set_explicitly;
std::optional<geometry::Height> committed_height_set_explicitly;
/// @}

/// The min and max size of the window as of last commit
Expand Down
4 changes: 2 additions & 2 deletions src/server/scene/basic_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,8 +982,8 @@ void mir::scene::BasicSurface::update_frame_posted_callbacks(State& state)
auto mir::scene::BasicSurface::content_size(State const& state) const -> geometry::Size
{
return geom::Size{
std::max(state.surface_rect.size.width - state.margins.left - state.margins.right, geom::Width{1}),
std::max(state.surface_rect.size.height - state.margins.top - state.margins.bottom, geom::Height{1})};
std::max(state.surface_rect.size.width - state.margins.left - state.margins.right, geom::Width{0}),
std::max(state.surface_rect.size.height - state.margins.top - state.margins.bottom, geom::Height{0})};
}

auto mir::scene::BasicSurface::content_top_left(State const& state) const -> geometry::Point
Expand Down
5 changes: 2 additions & 3 deletions src/server/scene/surface_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ std::shared_ptr<ms::Surface> ms::SurfaceAllocator::create_surface(
auto confine = params.confine_pointer.is_set() ? params.confine_pointer.value() : mir_pointer_unconfined;
auto const name = params.name.is_set() ? params.name.value() : "";
geom::Rectangle const rect{
params.top_left.is_set() ? params.top_left.value() : geom::Point{}, {
params.width.is_set() ? params.width.value() : geom::Width{100},
params.height.is_set() ? params.height.value() : geom::Height{100}}};
params.top_left.value_or(geom::Point{}),
{params.width.value_or(geom::Width{0}), params.height.value_or(geom::Height{0})}};
auto const parent = params.parent.is_set() ? params.parent.value() : std::weak_ptr<scene::Surface>{};
auto const surface = std::make_shared<BasicSurface>(
session,
Expand Down

0 comments on commit c8aa9df

Please sign in to comment.