Skip to content

Commit

Permalink
Add mir server side decoration strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarek Yasser committed Jul 1, 2024
1 parent f52391e commit e95d038
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 36 deletions.
3 changes: 2 additions & 1 deletion src/core/symbols.map
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MIR_CORE_2.9 {
global:
global:
extern "C++" {
mir::AnonymousShmFile::?AnonymousShmFile*;
mir::AnonymousShmFile::AnonymousShmFile*;
Expand Down Expand Up @@ -29,3 +29,4 @@ MIR_CORE_2.9 {
};
local: *;
};

33 changes: 33 additions & 0 deletions src/include/server/mir/decoration_strategy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

#include <cstdint>
namespace mir
{
class DecorationStrategy
{
public:
enum class DecorationsType : uint32_t
{
csd,
ssd
};

virtual ~DecorationStrategy() = default;
virtual auto default_style() const -> DecorationsType = 0;
virtual auto request_style(DecorationsType type) const -> DecorationsType = 0;
};
}
5 changes: 5 additions & 0 deletions src/include/server/mir/default_server_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ template<class Observer>
class ObserverMultiplexer;

class ConsoleServices;
class DecorationStrategy;

namespace dispatch
{
Expand Down Expand Up @@ -334,6 +335,9 @@ class DefaultServerConfiguration : public virtual ServerConfiguration

auto default_reports() -> std::shared_ptr<void>;

auto the_decoration_strategy() -> std::shared_ptr<DecorationStrategy> override;
void set_the_decoration_strategy(std::shared_ptr<DecorationStrategy> strategy) override;

protected:
std::shared_ptr<options::Option> the_options() const;
std::shared_ptr<input::DefaultInputDeviceHub> the_default_input_device_hub();
Expand Down Expand Up @@ -420,6 +424,7 @@ class DefaultServerConfiguration : public virtual ServerConfiguration
CachedPtr<cookie::Authority> cookie_authority;
CachedPtr<input::KeyMapper> key_mapper;
std::shared_ptr<ConsoleServices> console_services;
std::shared_ptr<DecorationStrategy> decoration_strategy;

private:
std::shared_ptr<options::Configuration> const configuration_options;
Expand Down
3 changes: 3 additions & 0 deletions src/include/server/mir/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class RendererFactory;
class Fd;
class MainLoop;
class ServerStatusListener;
class DecorationStrategy;

enum class OptionType
{
Expand Down Expand Up @@ -469,6 +470,8 @@ class Server
void set_enabled_wayland_extensions(std::vector<std::string> const& extensions);
/** @} */

auto the_decoration_strategy() const -> std::shared_ptr<DecorationStrategy>;
void set_the_decoration_strategy(std::shared_ptr<DecorationStrategy> strategy);
private:
struct ServerConfiguration;
struct Self;
Expand Down
3 changes: 3 additions & 0 deletions src/include/server/mir/server_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ServerStatusListener;
class DisplayChanger;
class EmergencyCleanup;
class ConsoleServices;
class DecorationStrategy;

class ServerConfiguration
{
Expand Down Expand Up @@ -111,6 +112,8 @@ class ServerConfiguration
virtual void set_wayland_extension_filter(WaylandProtocolExtensionFilter const& extension_filter) = 0;
virtual void set_enabled_wayland_extensions(std::vector<std::string> const& extensions) = 0;

virtual auto the_decoration_strategy() -> std::shared_ptr<DecorationStrategy> = 0;
virtual void set_the_decoration_strategy(std::shared_ptr<DecorationStrategy> strategy) = 0;
protected:
ServerConfiguration() = default;
virtual ~ServerConfiguration() = default;
Expand Down
21 changes: 21 additions & 0 deletions src/server/default_server_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "default_emergency_cleanup.h"
#include "mir/graphics/platform.h"
#include "mir/console_services.h"
#include "mir/decoration_strategy.h"

namespace mc = mir::compositor;
namespace geom = mir::geometry;
Expand Down Expand Up @@ -198,3 +199,23 @@ auto mir::DefaultServerConfiguration::the_logger()
return std::make_shared<ml::DumbConsoleLogger>();
});
}

auto mir::DefaultServerConfiguration::the_decoration_strategy() -> std::shared_ptr<mir::DecorationStrategy>
{
if(!decoration_strategy) {
class DefaultDecorationStrategy: public mir::DecorationStrategy
{
DecorationsType default_style() const override { return DecorationsType::csd; }
DecorationsType request_style(DecorationsType type) const override { return type; }
};

decoration_strategy = std::make_shared<DefaultDecorationStrategy>();
}

return decoration_strategy;
}

void mir::DefaultServerConfiguration::set_the_decoration_strategy(std::shared_ptr<mir::DecorationStrategy> strategy)
{
decoration_strategy = strategy;
}
6 changes: 4 additions & 2 deletions src/server/frontend_wayland/wayland_connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ mf::WaylandConnector::WaylandConnector(
std::unique_ptr<WaylandExtensions> extensions_,
WaylandProtocolExtensionFilter const& extension_filter,
bool enable_key_repeat,
std::shared_ptr<scene::SessionLock> const& session_lock)
std::shared_ptr<scene::SessionLock> const& session_lock,
std::shared_ptr<mir::DecorationStrategy> const& decoration_strategy)
: extension_filter{extension_filter},
display{wl_display_create(), &cleanup_display},
pause_signal{eventfd(0, EFD_CLOEXEC | EFD_SEMAPHORE)},
Expand Down Expand Up @@ -325,7 +326,8 @@ mf::WaylandConnector::WaylandConnector(
screen_shooter,
main_loop,
desktop_file_manager,
session_lock_});
session_lock_,
decoration_strategy});

shm_global = std::make_unique<WlShm>(display.get(), executor);

Expand Down
5 changes: 4 additions & 1 deletion src/server/frontend_wayland/wayland_connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Executor;
class MainLoop;
template<typename>
class ObserverRegistrar;
class DecorationStrategy;

namespace compositor
{
Expand Down Expand Up @@ -110,6 +111,7 @@ class WaylandExtensions
std::shared_ptr<MainLoop> main_loop;
std::shared_ptr<DesktopFileManager> desktop_file_manager;
std::shared_ptr<scene::SessionLock> session_lock;
std::shared_ptr<mir::DecorationStrategy> decoration_strategy;
};

WaylandExtensions() = default;
Expand Down Expand Up @@ -161,7 +163,8 @@ class WaylandConnector : public Connector
std::unique_ptr<WaylandExtensions> extensions,
WaylandProtocolExtensionFilter const& extension_filter,
bool enable_key_repeat,
std::shared_ptr<scene::SessionLock> const& session_lock);
std::shared_ptr<scene::SessionLock> const& session_lock,
std::shared_ptr<DecorationStrategy> const& decoration_strategy);

~WaylandConnector() override;

Expand Down
5 changes: 3 additions & 2 deletions src/server/frontend_wayland/wayland_default_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ std::vector<ExtensionBuilder> const internal_extension_builders = {
}),
make_extension_builder<mw::XdgDecorationManagerV1>([](auto const& ctx)
{
return mf::create_xdg_decoration_unstable_v1(ctx.display);
return mf::create_xdg_decoration_unstable_v1(ctx.display, ctx.decoration_strategy);
})
};

Expand Down Expand Up @@ -375,7 +375,8 @@ std::shared_ptr<mf::Connector>
wayland_extension_hooks),
wayland_extension_filter,
enable_repeat,
the_session_lock());
the_session_lock(),
the_decoration_strategy());
});
}

Expand Down
Loading

0 comments on commit e95d038

Please sign in to comment.