Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Wayland decorations strategy #3454

Merged
merged 29 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7d848b0
Add mir server side decoration strategy
Jul 1, 2024
51f5fb3
Update naming of protocol mode and decorations type conversion functions
tarek-y-ismail Jul 2, 2024
6025dfc
Fix naming for function definitions
tarek-y-ismail Jul 2, 2024
fe33489
Make `decoration_strategy` const and move more instead of copying.
tarek-y-ismail Jul 2, 2024
bd287f8
Remove unnecessary default case.
tarek-y-ismail Jul 2, 2024
f30374f
Make `to_decorations_type` a method and improve logging on invalid
tarek-y-ismail Jul 2, 2024
6469f70
Drop the base for `mir::DecorationStrategy::DecorationsType`
tarek-y-ismail Jul 2, 2024
9225da0
Specify default constructor, disable copy constructor/operator in
tarek-y-ismail Jul 2, 2024
c695222
Revert unnecessary changes done to `src/core/symbols.map`
tarek-y-ismail Jul 2, 2024
3a75b0f
Remove incorrect use of `std::move` in `get_toplevel_decoration`
tarek-y-ismail Jul 2, 2024
10a2773
Fix incorrect curly brace placement in `the_decoration_strategy`
tarek-y-ismail Jul 2, 2024
d1a8a68
Implement some decoration strategies on the miral side.
tarek-y-ismail Jul 2, 2024
f5e92a1
Fix lifetime issues related to `toplevels_with_decorations`.
Jul 1, 2024
aa97067
Fix naming convention of `{register,unregister}Toplevel`.
Jul 1, 2024
2e60ad6
Remove redundant `ToplevelsWithDecorations` construction code and dis…
tarek-y-ismail Jul 1, 2024
2bcf711
Always unregister toplevel on destruction.
Jul 1, 2024
148715d
Improve semantics of `unregister_toplevel` and explain decoration
tarek-y-ismail Jul 2, 2024
f9b62e6
Rename `destroy_toplevel_before_decoration` to `destroy_toplevel_befo…
tarek-y-ismail Jul 2, 2024
4b65e2b
Add mir server side decoration strategy
Jul 1, 2024
98a011b
Merge branch 'wayland-server-side-decorations' into wayland-server-si…
tarek-y-ismail Jul 2, 2024
b79e5c3
Merge branch 'main' into wayland-server-side-decorations-strategy
tarek-y-ismail Jul 3, 2024
a1555bc
Dont expose `DecorationStrategy` in `miral::Decorations`'s interface.
tarek-y-ismail Jul 3, 2024
9c189ee
Make log message in `XdgToplevelDecorationV1::to_decorations_type` cl…
tarek-y-ismail Jul 3, 2024
75526c4
Undo changes done to `core/symbols.map` erroneously
tarek-y-ismail Jul 3, 2024
63c7287
Remove unnecessary `DecorationStrategy` forward declaration.
tarek-y-ismail Jul 3, 2024
2dc3ec6
Remove the base of `DecorationStrategy::DecorationsType`
tarek-y-ismail Jul 3, 2024
cdfc15c
Add debian symbols
tarek-y-ismail Jul 3, 2024
2aeb440
Add class documentation comments to `mir::Decorations`
tarek-y-ismail Jul 3, 2024
fc2d435
Properly scope `pid` inside `to_decorations_type`
tarek-y-ismail Jul 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions debian/libmiral7.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ libmiral.so.7 libmiral7 #MINVER#
(c++)"vtable for miral::MinimalWindowManager@MIRAL_5.0" 5.0.0
(c++)"vtable for miral::WindowManagementPolicy@MIRAL_5.0" 5.0.0
MIRAL_5.1@MIRAL_5.1 5.1.0
(c++)"miral::Decorations::Decorations(std::shared_ptr<miral::Decorations::Self>)@MIRAL_5.1" 5.1.0
(c++)"miral::Decorations::always_csd()@MIRAL_5.1" 5.1.0
(c++)"miral::Decorations::always_ssd()@MIRAL_5.1" 5.1.0
(c++)"miral::Decorations::operator()(mir::Server&) const@MIRAL_5.1" 5.1.0
(c++)"miral::Decorations::prefer_csd()@MIRAL_5.1" 5.1.0
(c++)"miral::Decorations::prefer_ssd()@MIRAL_5.1" 5.1.0
(c++)"miral::IdleListener::IdleListener()@MIRAL_5.1" 5.1.0
(c++)"miral::IdleListener::on_dim(std::function<void ()> const&)@MIRAL_5.1" 5.1.0
(c++)"miral::IdleListener::on_off(std::function<void ()> const&)@MIRAL_5.1" 5.1.0
Expand Down
63 changes: 63 additions & 0 deletions include/miral/miral/decorations.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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/>.
*/

#ifndef MIRAL_DECORATIONS_H
#define MIRAL_DECORATIONS_H


#include <memory>

namespace mir { class Server; }

namespace miral
{
/// Configures the window decoration strategy.
/// \note The strategy can only be applied to clients that are able to negotiate the decoration style with the server.
/// \remark Since MirAL 5.1
class Decorations
tarek-y-ismail marked this conversation as resolved.
Show resolved Hide resolved
{
public:
Decorations() = delete;
Decorations(Decorations const&) = default;
auto operator=(Decorations const&) -> Decorations& = default;

void operator()(mir::Server&) const;

/// Always use server side decorations regardless of the client's choice
static auto always_ssd() -> Decorations;

/// Always use client side decorations regardless of the client's choice
static auto always_csd() -> Decorations;

/// Prefer server side decorations if the client does not set a specific
/// mode. Otherwise use the mode specified by the client.
static auto prefer_ssd() -> Decorations;

/// Prefer client side decorations if the client does not set a specific
/// mode. Otherwise use the mode specified by the client.
static auto prefer_csd() -> Decorations;

private:
struct Self;

Decorations(std::shared_ptr<Self> strategy);

std::shared_ptr<Self> self;
};
}

#endif // MIRAL_DECORATIONS_H

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

namespace mir
{
class DecorationStrategy
AlanGriffiths marked this conversation as resolved.
Show resolved Hide resolved
{
public:
enum class DecorationsType
{
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 @@ -75,6 +75,7 @@ class RendererFactory;
class Fd;
class MainLoop;
class ServerStatusListener;
class DecorationStrategy;

enum class OptionType
{
Expand Down Expand Up @@ -476,6 +477,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
1 change: 1 addition & 0 deletions src/miral/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ add_library(miral-external OBJECT
${miral_include}/miral/lambda_as_function.h
x11_support.cpp ${miral_include}/miral/x11_support.h
zone.cpp ${miral_include}/miral/zone.h
decorations.cpp ${miral_include}/miral/decorations.h
)

add_library(miral SHARED
Expand Down
86 changes: 86 additions & 0 deletions src/miral/decorations.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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 "miral/decorations.h"

#include <memory>

#include <mir/default_server_configuration.h>
#include <mir/server.h>
#include <mir/decoration_strategy.h>


struct miral::Decorations::Self : mir::DecorationStrategy
{
};

void miral::Decorations::operator()(mir::Server& server) const
{
server.add_pre_init_callback(
[this, &server]()
{
server.set_the_decoration_strategy(self);
});
}

miral::Decorations::Decorations(std::shared_ptr<Self> strategy) :
self{std::move(strategy)}
{
}

auto miral::Decorations::always_ssd() -> Decorations
{
struct AlwaysServerSide : Self
{
DecorationsType default_style() const override { return DecorationsType::ssd; }
DecorationsType request_style(DecorationsType) const override { return DecorationsType::ssd; }
};

return Decorations(std::make_shared<AlwaysServerSide>());
}

auto miral::Decorations::always_csd() -> Decorations
{
struct AlwaysClientSide : Self
{
DecorationsType default_style() const override { return DecorationsType::csd; }
DecorationsType request_style(DecorationsType) const override { return DecorationsType::csd; }
};

return Decorations(std::make_shared<AlwaysClientSide>());
}

auto miral::Decorations::prefer_ssd() -> Decorations
{
struct PreferServerSide : Self
{
DecorationsType default_style() const override { return DecorationsType::ssd; }
DecorationsType request_style(DecorationsType type) const override { return type; }
};

return Decorations(std::make_shared<PreferServerSide>());
}

auto miral::Decorations::prefer_csd() -> Decorations
{
struct PreferClientSide : Self
{
DecorationsType default_style() const override { return DecorationsType::csd; }
DecorationsType request_style(DecorationsType type) const override { return type; }
};

return Decorations(std::make_shared<PreferClientSide>());
}
9 changes: 8 additions & 1 deletion src/miral/symbols.map
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,20 @@ local: *;
MIRAL_5.1 {
global:
extern "C++" {
miral::Decorations::Decorations*;
miral::Decorations::always_csd*;
miral::Decorations::always_ssd*;
miral::Decorations::operator*;
miral::Decorations::prefer_csd*;
miral::Decorations::prefer_ssd*;
miral::IdleListener::?IdleListener*;
miral::IdleListener::IdleListener*;
miral::IdleListener::on_dim*;
miral::IdleListener::on_off*;
miral::IdleListener::on_wake*;
miral::IdleListener::operator*;
typeinfo?for?miral::IdleListener;
miral::WindowManagerTools::move_cursor_to*;
typeinfo?for?miral::IdleListener;
typeinfo?for?miral::Decorations;
};
} MIRAL_5.0;
22 changes: 22 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,24 @@ 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
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
Loading