Skip to content

Commit

Permalink
Decouple WindowState from DecorationStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanGriffiths committed Jan 28, 2025
1 parent 10dd1eb commit b58389b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 58 deletions.
27 changes: 7 additions & 20 deletions src/server/shell/decoration/decoration_strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ struct RendererStrategy : public msd::RendererStrategy
static auto alloc_pixels(geom::Size size) -> std::unique_ptr<Pixel[]>;
};

class DecorationStrategy : public msd::DecorationStrategy, public std::enable_shared_from_this<DecorationStrategy>
class DecorationStrategy : public msd::DecorationStrategy
{
public:
~DecorationStrategy() override = default;
Expand All @@ -335,26 +335,8 @@ class DecorationStrategy : public msd::DecorationStrategy, public std::enable_sh
auto new_window_state(const std::shared_ptr<mir::scene::Surface>& window_surface,
float scale) const -> std::unique_ptr<WindowState> override;
auto resize_corner_input_size() const -> geom::Size override;
auto titlebar_height() const -> geom::Height override;
auto side_border_width() const -> geom::Width override;
auto bottom_border_height() const -> geom::Height override;
};

auto DecorationStrategy::titlebar_height() const -> geom::Height
{
return static_geometry()->titlebar_height;
}

auto DecorationStrategy::side_border_width() const -> geom::Width
{
return static_geometry()->side_border_width;
}

auto DecorationStrategy::bottom_border_height() const -> geom::Height
{
return static_geometry()->bottom_border_height;
}

auto DecorationStrategy::resize_corner_input_size() const -> geom::Size
{
return static_geometry()->resize_corner_input_size;
Expand All @@ -369,7 +351,12 @@ auto DecorationStrategy::new_window_state(const std::shared_ptr<mir::scene::Surf
float scale) const -> std::unique_ptr<WindowState>

{
return std::make_unique<WindowState>(shared_from_this(), window_surface, scale);
return std::make_unique<WindowState>(
window_surface,
static_geometry()->titlebar_height,
static_geometry()->side_border_width,
static_geometry()->bottom_border_height,
scale);
}

auto DecorationStrategy::compute_size_with_decorations(
Expand Down
9 changes: 3 additions & 6 deletions src/server/shell/decoration/decoration_strategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ class WindowState
{
public:
WindowState(
std::shared_ptr<const DecorationStrategy>&& decoration_strategy,
std::shared_ptr<scene::Surface> const& window_surface,
geometry::Height fixed_titlebar_height,
geometry::Width fixed_side_border_width,
geometry::Height fixed_bottom_border_height,
float scale);

~WindowState();
Expand Down Expand Up @@ -166,11 +168,6 @@ class DecorationStrategy
virtual ~DecorationStrategy() = default;

private:
virtual auto titlebar_height() const -> geometry::Height = 0;
virtual auto side_border_width() const -> geometry::Width = 0;
virtual auto bottom_border_height() const -> geometry::Height = 0;
friend class WindowState;

DecorationStrategy(DecorationStrategy const&) = delete;
DecorationStrategy& operator=(DecorationStrategy const&) = delete;
};
Expand Down
79 changes: 47 additions & 32 deletions src/server/shell/decoration/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,64 +30,79 @@ class msd::WindowState::Self
{
public:
Self(
std::shared_ptr<const DecorationStrategy>&& decoration_strategy,
std::shared_ptr<scene::Surface> const& surface,
float scale);

std::shared_ptr<const DecorationStrategy> const decoration_strategy;
geometry::Size const window_size_;
BorderType const border_type_;
MirWindowFocusState const focus_state_;
std::string const window_name_;
float const scale_;
std::shared_ptr<scene::Surface> const& surface,
geometry::Height fixed_titlebar_height,
geometry::Width fixed_side_border_width,
geometry::Height fixed_bottom_border_height,
float scale);

geometry::Height const fixed_titlebar_height;
geometry::Width const fixed_side_border_width;
geometry::Height const fixed_bottom_border_height;
geometry::Size const window_size;
BorderType const border_type;
MirWindowFocusState const focus_state;
std::string const window_name;
float const scale;
};

msd::WindowState::Self::Self(
std::shared_ptr<const DecorationStrategy>&& decoration_strategy,
std::shared_ptr<scene::Surface> const& surface,
geometry::Height fixed_titlebar_height,
geometry::Width fixed_side_border_width,
geometry::Height fixed_bottom_border_height,
float scale)
: decoration_strategy{std::move(decoration_strategy)},
window_size_{surface->window_size()},
border_type_{border_type_for(surface->type(), surface->state())},
focus_state_{surface->focus_state()},
window_name_{surface->name()},
scale_{scale}
: fixed_titlebar_height(fixed_titlebar_height),
fixed_side_border_width(fixed_side_border_width),
fixed_bottom_border_height(fixed_bottom_border_height),
window_size{surface->window_size()},
border_type{border_type_for(surface->type(), surface->state())},
focus_state{surface->focus_state()},
window_name{surface->name()},
scale{scale}
{
}

msd::WindowState::WindowState(
std::shared_ptr<const DecorationStrategy>&& decoration_strategy,
std::shared_ptr<scene::Surface> const& surface,
geometry::Height fixed_titlebar_height,
geometry::Width fixed_side_border_width,
geometry::Height fixed_bottom_border_height,
float scale)
: self{std::make_unique<Self>(std::move(decoration_strategy), surface, scale)}
: self{std::make_unique<Self>(
surface,
fixed_titlebar_height,
fixed_side_border_width,
fixed_bottom_border_height,
scale)}
{
}

mir::shell::decoration::WindowState::~WindowState() = default;

auto msd::WindowState::window_size() const -> geom::Size
{
return self->window_size_;
return self->window_size;
}

auto msd::WindowState::border_type() const -> BorderType
{
return self->border_type_;
return self->border_type;
}

auto msd::WindowState::focused_state() const -> MirWindowFocusState
{
return self->focus_state_;
return self->focus_state;
}

auto msd::WindowState::window_name() const -> std::string
{
return self->window_name_;
return self->window_name;
}

auto msd::WindowState::titlebar_width() const -> geom::Width
{
switch (self->border_type_)
switch (self->border_type)
{
case BorderType::Full:
case BorderType::Titlebar:
Expand All @@ -102,11 +117,11 @@ auto msd::WindowState::titlebar_width() const -> geom::Width

auto msd::WindowState::titlebar_height() const -> geom::Height
{
switch (self->border_type_)
switch (self->border_type)
{
case BorderType::Full:
case BorderType::Titlebar:
return self->decoration_strategy->titlebar_height();
return self->fixed_titlebar_height;
case BorderType::None:
return {};
}
Expand All @@ -117,10 +132,10 @@ auto msd::WindowState::titlebar_height() const -> geom::Height

auto msd::WindowState::side_border_width() const -> geom::Width
{
switch (self->border_type_)
switch (self->border_type)
{
case BorderType::Full:
return self->decoration_strategy->side_border_width();
return self->fixed_side_border_width;
case BorderType::Titlebar:
case BorderType::None:
return {};
Expand All @@ -132,7 +147,7 @@ auto msd::WindowState::side_border_width() const -> geom::Width

auto msd::WindowState::side_border_height() const -> geom::Height
{
switch (self->border_type_)
switch (self->border_type)
{
case BorderType::Full:
return window_size().height - as_delta(titlebar_height()) - as_delta(bottom_border_height());
Expand All @@ -152,10 +167,10 @@ auto msd::WindowState::bottom_border_width() const -> geom::Width

auto msd::WindowState::bottom_border_height() const -> geom::Height
{
switch (self->border_type_)
switch (self->border_type)
{
case BorderType::Full:
return self->decoration_strategy->bottom_border_height();
return self->fixed_bottom_border_height;
case BorderType::Titlebar:
case BorderType::None:
return {};
Expand Down Expand Up @@ -195,7 +210,7 @@ auto msd::WindowState::bottom_border_rect() const -> geom::Rectangle

auto msd::WindowState::scale() const -> float
{
return self->scale_;
return self->scale;
}

class msd::WindowSurfaceObserverManager::Observer
Expand Down

0 comments on commit b58389b

Please sign in to comment.