diff --git a/examples/miral-shell/decoration/decoration.cpp b/examples/miral-shell/decoration/decoration.cpp index 1bcc29bf69..6c12241949 100644 --- a/examples/miral-shell/decoration/decoration.cpp +++ b/examples/miral-shell/decoration/decoration.cpp @@ -26,7 +26,6 @@ #include "miral/decoration.h" #include "miral/decoration_window_state.h" #include "miral/decoration_basic_manager.h" -#include "miral/decoration_manager_builder.h" #include diff --git a/include/miral/miral/custom_decorations.h b/include/miral/miral/custom_decorations.h index d887f84f08..9d22152c4b 100644 --- a/include/miral/miral/custom_decorations.h +++ b/include/miral/miral/custom_decorations.h @@ -17,13 +17,14 @@ #ifndef MIRAL_CUSTOM_DECORATIONS_H #define MIRAL_CUSTOM_DECORATIONS_H -#include "miral/decoration_manager_builder.h" +#include #include namespace mir { class Server; } namespace miral { +class DecorationManagerAdapter; class CustomDecorations { public: diff --git a/include/miral/miral/decoration_manager_builder.h b/include/miral/miral/decoration_manager_builder.h deleted file mode 100644 index 515a261b89..0000000000 --- a/include/miral/miral/decoration_manager_builder.h +++ /dev/null @@ -1,57 +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 MIRAL_DECORATION_MANAGER_BUILDER_H -#define MIRAL_DECORATION_MANAGER_BUILDER_H - -#include -#include - -namespace mir -{ -namespace shell -{ -class Shell; -} -namespace scene -{ -class Surface; -} -} - -namespace miral -{ - -class DecorationManagerAdapter; -class DecorationManagerBuilder -{ -public: - static auto build( - std::function const& shell)> on_init, - std::function const& surface)> on_decorate, - std::function const& surface)> on_undecorate, - std::function on_undecorate_all) -> DecorationManagerBuilder; - - auto done() -> std::shared_ptr; -private: - DecorationManagerBuilder(); - - struct Self; - std::shared_ptr self; -}; -} - -#endif diff --git a/src/include/server/mir/shell/decoration/basic_manager.h b/src/include/server/mir/shell/decoration/basic_manager.h index 4280123fd7..f1779c1b7e 100644 --- a/src/include/server/mir/shell/decoration/basic_manager.h +++ b/src/include/server/mir/shell/decoration/basic_manager.h @@ -63,9 +63,10 @@ class BasicManager : protected: DecorationBuilder const decoration_builder; + std::weak_ptr shell; + private: std::shared_ptr const display_config_monitor; - std::weak_ptr shell; std::mutex mutex; std::unordered_map> decorations; diff --git a/src/miral/CMakeLists.txt b/src/miral/CMakeLists.txt index 5346cbe3df..02a48db7b5 100644 --- a/src/miral/CMakeLists.txt +++ b/src/miral/CMakeLists.txt @@ -33,6 +33,7 @@ add_library(miral-internal STATIC window_info_defaults.h window_specification_internal.cpp window_specification_internal.h decoration_window_state.cpp + decoration_manager_adapter.cpp ) # Already implied by the linker's symbol version script, but can avoid accidents @@ -90,7 +91,6 @@ add_library(miral-external OBJECT zone.cpp ${miral_include}/miral/zone.h decorations.cpp ${miral_include}/miral/decorations.h custom_decorations.cpp ${miral_include}/miral/custom_decorations.h - decoration_manager_builder.cpp ${miral_include}/miral/decoration_manager_builder.h decoration_basic_manager.cpp ${miral_include}/miral/decoration_basic_manager.h decoration_adapter.cpp ${miral_include}/miral/decoration_adapter.h decoration.cpp diff --git a/src/miral/custom_decorations.cpp b/src/miral/custom_decorations.cpp index efce986f13..d3f23f6883 100644 --- a/src/miral/custom_decorations.cpp +++ b/src/miral/custom_decorations.cpp @@ -18,7 +18,6 @@ #include "decoration_manager_adapter.h" #include "mir/shell/decoration/manager.h" -#include "miral/decoration_manager_builder.h" #include "mir/options/option.h" #include "mir/log.h" diff --git a/src/miral/decoration_adapter.cpp b/src/miral/decoration_adapter.cpp index 3894643906..c615449ccf 100644 --- a/src/miral/decoration_adapter.cpp +++ b/src/miral/decoration_adapter.cpp @@ -21,7 +21,6 @@ #include "mir/geometry/forward.h" #include "miral/decoration_window_state.h" #include "miral/decoration.h" -#include "miral/decoration_manager_builder.h" #include "mir/compositor/buffer_stream.h" #include "mir/geometry/displacement.h" @@ -35,7 +34,6 @@ #include "mir/shell/surface_specification.h" #include "mir/log.h" -#include #include namespace msh = mir::shell; diff --git a/src/miral/decoration_basic_manager.cpp b/src/miral/decoration_basic_manager.cpp index 4202d48999..bd7c89d99d 100644 --- a/src/miral/decoration_basic_manager.cpp +++ b/src/miral/decoration_basic_manager.cpp @@ -15,6 +15,8 @@ */ #include "miral/decoration_basic_manager.h" +#include "mir/compositor/buffer_stream.h" +#include "mir/optional_value.h" #include "mir/scene/session.h" #include "mir/scene/surface.h" #include "mir/server.h" @@ -22,14 +24,11 @@ #include "mir/shell/decoration/basic_manager.h" #include "mir/shell/shell.h" #include "mir/shell/surface_specification.h" -#include "mir/optional_value.h" #include "mir/wayland/weak.h" -#include "mir/compositor/buffer_stream.h" #include "miral/decoration_adapter.h" -#include "miral/decoration_manager_builder.h" +#include "decoration_manager_adapter.h" -#include #include #include @@ -84,6 +83,11 @@ struct miral::DecorationBasicManager::Self : public mir::shell::decoration::Basi }) { } + + void init(std::weak_ptr const& shell) + { + this->shell = shell; + } }; miral::DecorationBasicManager::DecorationBasicManager( @@ -94,10 +98,24 @@ miral::DecorationBasicManager::DecorationBasicManager( auto miral::DecorationBasicManager::to_adapter() -> std::shared_ptr { - return DecorationManagerBuilder::build( - [self=this->self](auto... args) { self->init(args...); }, - [self=this->self](auto... args) { self->decorate(args...); }, - [self=this->self](auto... args) { self->undecorate(args...); }, - [self=this->self]() { self->undecorate_all(); } - ).done(); + auto adapter = std::shared_ptr(new DecorationManagerAdapter()); + + adapter->on_init = [self = this->self](auto shell) + { + self->init(shell); + }; + adapter->on_decorate = [self = this->self](auto... args) + { + self->decorate(args...); + }; + adapter->on_undecorate = [self = this->self](auto... args) + { + self->undecorate(args...); + }; + adapter->on_undecorate_all = [self = this->self]() + { + self->undecorate_all(); + }; + + return adapter; } diff --git a/src/miral/decoration_manager_builder.cpp b/src/miral/decoration_manager_adapter.cpp similarity index 50% rename from src/miral/decoration_manager_builder.cpp rename to src/miral/decoration_manager_adapter.cpp index 0eec6454ec..bb1a9d45f1 100644 --- a/src/miral/decoration_manager_builder.cpp +++ b/src/miral/decoration_manager_adapter.cpp @@ -14,23 +14,13 @@ * along with this program. If not, see . */ -#include "miral/decoration_manager_builder.h" #include "decoration_manager_adapter.h" - #include "mir/shell/decoration/manager.h" -#include -struct miral::DecorationManagerBuilder::Self -{ - Self(std::shared_ptr adapter) : - adapter{adapter} - { - } - - std::shared_ptr adapter; -}; +#include miral::DecorationManagerAdapter::DecorationManagerAdapter() = default; +miral::DecorationManagerAdapter::~DecorationManagerAdapter() = default; void miral::DecorationManagerAdapter::init(std::weak_ptr const& shell) { @@ -51,31 +41,3 @@ void miral::DecorationManagerAdapter::undecorate_all() { on_undecorate_all(); } - -miral::DecorationManagerBuilder::DecorationManagerBuilder() : - self{std::make_shared(std::shared_ptr(new DecorationManagerAdapter{}))} -{ -} - -auto miral::DecorationManagerBuilder::build( - std::function const& shell)> on_init, - std::function const& surface)> on_decorate, - std::function const& surface)> on_undecorate, - std::function on_undecorate_all) -> DecorationManagerBuilder -{ - auto builder = DecorationManagerBuilder{}; - auto& adapter = builder.self->adapter; - - adapter->on_init = on_init; - adapter->on_decorate = on_decorate; - adapter->on_undecorate = on_undecorate; - adapter->on_undecorate_all = on_undecorate_all; - - return builder; -} - - -auto miral::DecorationManagerBuilder::done() -> std::shared_ptr -{ - return std::move(self->adapter); -} diff --git a/src/miral/decoration_manager_adapter.h b/src/miral/decoration_manager_adapter.h index af1286b591..23d85df053 100644 --- a/src/miral/decoration_manager_adapter.h +++ b/src/miral/decoration_manager_adapter.h @@ -32,7 +32,7 @@ class Surface; namespace miral { -class DecorationManagerBuilder; +class DecorationBasicManager; class DecorationManagerAdapter : public mir::shell::decoration::Manager { public: @@ -41,8 +41,9 @@ class DecorationManagerAdapter : public mir::shell::decoration::Manager void undecorate(std::shared_ptr const& surface) override; void undecorate_all() override; + virtual ~DecorationManagerAdapter(); private: - friend DecorationManagerBuilder; + friend miral::DecorationBasicManager; DecorationManagerAdapter(); std::function const& shell)> on_init;