diff --git a/src/include/server/mir/shell/decoration.h b/src/include/server/mir/shell/decoration.h
deleted file mode 100644
index 85f6c05e312..00000000000
--- a/src/include/server/mir/shell/decoration.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright © Canonical Ltd.
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 or 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#ifndef MIR_SHELL_DECORATION_H_
-#define MIR_SHELL_DECORATION_H_
-
-#include "mir/geometry/forward.h"
-#include "mir_toolkit/common.h"
-
-namespace mir::shell::decoration
-{
- auto compute_size_with_decorations(geometry::Size content_size, MirWindowType type, MirWindowState state) -> geometry::Size;
-}
-
-#endif
diff --git a/src/server/shell/abstract_shell.cpp b/src/server/shell/abstract_shell.cpp
index a868d8fbcee..f6972e454b7 100644
--- a/src/server/shell/abstract_shell.cpp
+++ b/src/server/shell/abstract_shell.cpp
@@ -16,7 +16,6 @@
#include "mir/shell/abstract_shell.h"
-#include "mir/shell/decoration.h"
#include "mir/shell/input_targeter.h"
#include "mir/shell/shell_report.h"
#include "mir/shell/surface_specification.h"
@@ -233,7 +232,7 @@ auto msh::AbstractShell::create_surface(
if (wm_visible_spec.server_side_decorated.value_or(false) && wm_visible_spec.width.is_set() && wm_visible_spec.height.is_set())
{
geom::Size const content_size{wm_visible_spec.width.value(), wm_visible_spec.height.value()};
- auto const size = decoration::compute_size_with_decorations(
+ auto const size = decoration_manager->compute_size_with_decorations(
content_size,
wm_visible_spec.type.value(),
wm_visible_spec.state.value());
@@ -302,7 +301,7 @@ void msh::AbstractShell::modify_surface(std::shared_ptr const& s
wm_relevant_mods.height = content_size.height;
// When adding decorations we need to resize the window for WM
- window_size = decoration::compute_size_with_decorations(
+ window_size = decoration_manager->compute_size_with_decorations(
content_size,
modifications.type.value_or(surface->type()),
modifications.state.value_or(surface->state()));
diff --git a/src/server/shell/decoration/CMakeLists.txt b/src/server/shell/decoration/CMakeLists.txt
index 78785e7c0a2..22cc026d44b 100644
--- a/src/server/shell/decoration/CMakeLists.txt
+++ b/src/server/shell/decoration/CMakeLists.txt
@@ -9,7 +9,8 @@ set(
basic_decoration.h basic_decoration.cpp
window.h window.cpp
input.h input.cpp
- renderer.h renderer.cpp renderer_default.cpp
+ renderer.h renderer.cpp
+ decoration_strategy.h decoration_strategy.cpp
)
add_library(
diff --git a/src/server/shell/decoration/basic_decoration.cpp b/src/server/shell/decoration/basic_decoration.cpp
index 0674b8710a2..bf4d74a7e37 100644
--- a/src/server/shell/decoration/basic_decoration.cpp
+++ b/src/server/shell/decoration/basic_decoration.cpp
@@ -42,23 +42,6 @@ namespace geom = mir::geometry;
namespace msh = mir::shell;
namespace msd = mir::shell::decoration;
-namespace mir::shell::decoration
-{
-// See src/server/shell/decoration/window.h for a full description of each property
-StaticGeometry const default_geometry {
- geom::Height{24}, // titlebar_height
- geom::Width{6}, // side_border_width
- geom::Height{6}, // bottom_border_height
- geom::Size{16, 16}, // resize_corner_input_size
- geom::Width{24}, // button_width
- geom::Width{6}, // padding_between_buttons
- geom::Height{14}, // title_font_height
- geom::Point{8, 2}, // title_font_top_left
- geom::Displacement{5, 5}, // icon_padding
- geom::Width{1}, // detail_line_width
-};
-}
-
namespace
{
template
@@ -146,29 +129,22 @@ msd::BasicDecoration::BufferStreams::~BufferStreams()
session->destroy_buffer_stream(bottom_border);
}
-auto msd::BasicDecoration::BufferStreams::create_buffer_stream() -> std::shared_ptr
-{
- auto const stream = session->create_buffer_stream(mg::BufferProperties{
- geom::Size{1, 1},
- buffer_format,
- mg::BufferUsage::software});
- return stream;
-}
-
msd::BasicDecoration::BasicDecoration(
std::shared_ptr const& shell,
std::shared_ptr const& buffer_allocator,
std::shared_ptr const& executor,
std::shared_ptr const& cursor_images,
- std::shared_ptr const& window_surface)
+ std::shared_ptr const& window_surface,
+ std::shared_ptr decoration_strategy)
: threadsafe_self{std::make_shared>(executor)},
- static_geometry{std::make_shared(default_geometry)},
+ decoration_strategy{decoration_strategy},
+ static_geometry{decoration_strategy->static_geometry()},
shell{shell},
buffer_allocator{buffer_allocator},
cursor_images{cursor_images},
session{window_surface->session().lock()},
buffer_streams{std::make_unique(session, static_geometry->buffer_format)},
- renderer{std::make_unique(buffer_allocator, RendererStrategy::default_strategy(static_geometry))},
+ renderer{std::make_unique(buffer_allocator, decoration_strategy->render_strategy())},
window_surface{window_surface},
decoration_surface{create_surface()},
window_state{new_window_state()},
@@ -176,7 +152,7 @@ msd::BasicDecoration::BasicDecoration(
window_surface,
threadsafe_self)},
input_manager{std::make_unique(
- static_geometry,
+ decoration_strategy,
decoration_surface,
*window_state,
threadsafe_self)},
@@ -194,6 +170,15 @@ msd::BasicDecoration::BasicDecoration(
threadsafe_self->initialize(this);
}
+auto msd::BasicDecoration::BufferStreams::create_buffer_stream() -> std::shared_ptr
+{
+ auto const stream = session->create_buffer_stream(mg::BufferProperties{
+ geom::Size{1, 1},
+ buffer_format,
+ mg::BufferUsage::software});
+ return stream;
+}
+
msd::BasicDecoration::~BasicDecoration()
{
threadsafe_self->invalidate();
diff --git a/src/server/shell/decoration/basic_decoration.h b/src/server/shell/decoration/basic_decoration.h
index e4beabd2905..fb4bc0dbc6a 100644
--- a/src/server/shell/decoration/basic_decoration.h
+++ b/src/server/shell/decoration/basic_decoration.h
@@ -18,6 +18,7 @@
#define MIR_SHELL_DECORATION_BASIC_DECORATION_H_
#include "decoration.h"
+#include "decoration_strategy.h"
#include "mir/geometry/rectangle.h"
#include "mir_toolkit/common.h"
@@ -72,7 +73,8 @@ class BasicDecoration
std::shared_ptr const& buffer_allocator,
std::shared_ptr const& executor,
std::shared_ptr const& cursor_images,
- std::shared_ptr const& window_surface);
+ std::shared_ptr const& window_surface,
+ std::shared_ptr decoration_strategy);
~BasicDecoration();
void window_state_updated();
@@ -103,7 +105,8 @@ class BasicDecoration
std::optional previous_input_state);
std::shared_ptr> const threadsafe_self;
- std::shared_ptr const static_geometry;
+ std::shared_ptr const decoration_strategy;
+ std::shared_ptr const static_geometry;
std::shared_ptr const shell;
std::shared_ptr const buffer_allocator;
diff --git a/src/server/shell/decoration/basic_manager.cpp b/src/server/shell/decoration/basic_manager.cpp
index 4056707df00..43ab25f0689 100644
--- a/src/server/shell/decoration/basic_manager.cpp
+++ b/src/server/shell/decoration/basic_manager.cpp
@@ -16,6 +16,7 @@
#include "basic_manager.h"
#include "decoration.h"
+#include "decoration_strategy.h"
#include
#include
@@ -49,8 +50,10 @@ class msd::DisplayConfigurationListener : public mg::NullDisplayConfigurationOb
};
msd::BasicManager::BasicManager(
+ std::shared_ptr const& decoration_strategy,
ObserverRegistrar& display_configuration_observers,
DecorationBuilder&& decoration_builder) :
+ decoration_strategy{decoration_strategy},
decoration_builder{std::move(decoration_builder)},
display_config_monitor{std::make_shared(
[&](mg::DisplayConfiguration const& config)
@@ -92,7 +95,7 @@ void msd::BasicManager::decorate(std::shared_ptr const& surface)
{
decorations[surface.get()] = nullptr;
lock.unlock();
- auto decoration = decoration_builder(locked_shell, surface);
+ auto decoration = decoration_builder(decoration_strategy, locked_shell, surface);
lock.lock();
decoration->set_scale(scale);
decorations[surface.get()] = std::move(decoration);
@@ -128,6 +131,29 @@ void msd::BasicManager::undecorate_all()
to_destroy.clear();
}
+using mir::geometry::Size;
+
+auto msd::BasicManager::compute_size_with_decorations(Size content_size,
+ MirWindowType type, MirWindowState state) -> Size
+{
+ auto const geometry = decoration_strategy->static_geometry();
+
+ switch (border_type_for(type, state))
+ {
+ case msd::BorderType::Full:
+ content_size.width += geometry->side_border_width * 2;
+ content_size.height += geometry->titlebar_height + geometry->bottom_border_height;
+ break;
+ case msd::BorderType::Titlebar:
+ content_size.height += geometry->titlebar_height;
+ break;
+ case msd::BorderType::None:
+ break;
+ }
+
+ return content_size;
+}
+
void msd::BasicManager::set_scale(float new_scale)
{
std::lock_guard lock{mutex};
@@ -139,4 +165,4 @@ void msd::BasicManager::set_scale(float new_scale)
it.second->set_scale(scale);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/server/shell/decoration/basic_manager.h b/src/server/shell/decoration/basic_manager.h
index be4f2413924..5ae39b36f98 100644
--- a/src/server/shell/decoration/basic_manager.h
+++ b/src/server/shell/decoration/basic_manager.h
@@ -40,6 +40,7 @@ class Shell;
namespace decoration
{
class Decoration;
+class DecorationStrategy;
class DisplayConfigurationListener;
/// Facilitates decorating windows with Mir's built-in server size decorations
@@ -48,10 +49,12 @@ class BasicManager :
{
public:
using DecorationBuilder = std::function(
+ std::shared_ptr const& decoration_strategy,
std::shared_ptr const& shell,
std::shared_ptr const& surface)>;
BasicManager(
+ std::shared_ptr const& decoration_strategy,
mir::ObserverRegistrar& display_configuration_observers,
DecorationBuilder&& decoration_builder);
~BasicManager();
@@ -60,8 +63,11 @@ class BasicManager :
void decorate(std::shared_ptr const& surface) override;
void undecorate(std::shared_ptr const& surface) override;
void undecorate_all() override;
+ auto compute_size_with_decorations(geometry::Size content_size, MirWindowType type,
+ MirWindowState state) -> geometry::Size override;
private:
+ std::shared_ptr const decoration_strategy;
DecorationBuilder const decoration_builder;
std::shared_ptr const display_config_monitor;
std::weak_ptr shell;
diff --git a/src/server/shell/decoration/renderer_default.cpp b/src/server/shell/decoration/decoration_strategy.cpp
similarity index 84%
rename from src/server/shell/decoration/renderer_default.cpp
rename to src/server/shell/decoration/decoration_strategy.cpp
index 03c494b91f7..b025233a190 100644
--- a/src/server/shell/decoration/renderer_default.cpp
+++ b/src/server/shell/decoration/decoration_strategy.cpp
@@ -15,22 +15,24 @@
*/
-#include "renderer.h"
+#include "decoration_strategy.h"
#include "window.h"
+#include "mir/fatal.h"
#include "mir/geometry/displacement.h"
#include "mir/log.h"
#include
-#include
#include
#include FT_FREETYPE_H
+#include
#include
#include
+#include
+#include