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

Decoration strategy #3708

Merged
merged 7 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 0 additions & 28 deletions src/include/server/mir/shell/decoration.h

This file was deleted.

5 changes: 2 additions & 3 deletions src/server/shell/abstract_shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -302,7 +301,7 @@ void msh::AbstractShell::modify_surface(std::shared_ptr<scene::Session> 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()));
Expand Down
3 changes: 2 additions & 1 deletion src/server/shell/decoration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
45 changes: 15 additions & 30 deletions src/server/shell/decoration/basic_decoration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename OBJ>
Expand Down Expand Up @@ -146,37 +129,30 @@ msd::BasicDecoration::BufferStreams::~BufferStreams()
session->destroy_buffer_stream(bottom_border);
}

auto msd::BasicDecoration::BufferStreams::create_buffer_stream() -> std::shared_ptr<mc::BufferStream>
{
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<msh::Shell> const& shell,
std::shared_ptr<mg::GraphicBufferAllocator> const& buffer_allocator,
std::shared_ptr<Executor> const& executor,
std::shared_ptr<input::CursorImages> const& cursor_images,
std::shared_ptr<ms::Surface> const& window_surface)
std::shared_ptr<ms::Surface> const& window_surface,
std::shared_ptr<DecorationStrategy> decoration_strategy)
: threadsafe_self{std::make_shared<ThreadsafeAccess<BasicDecoration>>(executor)},
static_geometry{std::make_shared<StaticGeometry>(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<BufferStreams>(session, static_geometry->buffer_format)},
renderer{std::make_unique<Renderer>(buffer_allocator, RendererStrategy::default_strategy(static_geometry))},
renderer{std::make_unique<Renderer>(buffer_allocator, decoration_strategy->render_strategy())},
window_surface{window_surface},
decoration_surface{create_surface()},
window_state{new_window_state()},
window_surface_observer_manager{std::make_unique<WindowSurfaceObserverManager>(
window_surface,
threadsafe_self)},
input_manager{std::make_unique<InputManager>(
static_geometry,
decoration_strategy,
decoration_surface,
*window_state,
threadsafe_self)},
Expand All @@ -194,6 +170,15 @@ msd::BasicDecoration::BasicDecoration(
threadsafe_self->initialize(this);
}

auto msd::BasicDecoration::BufferStreams::create_buffer_stream() -> std::shared_ptr<mc::BufferStream>
{
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();
Expand Down
7 changes: 5 additions & 2 deletions src/server/shell/decoration/basic_decoration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -72,7 +73,8 @@ class BasicDecoration
std::shared_ptr<graphics::GraphicBufferAllocator> const& buffer_allocator,
std::shared_ptr<Executor> const& executor,
std::shared_ptr<input::CursorImages> const& cursor_images,
std::shared_ptr<scene::Surface> const& window_surface);
std::shared_ptr<scene::Surface> const& window_surface,
std::shared_ptr<DecorationStrategy> decoration_strategy);
~BasicDecoration();

void window_state_updated();
Expand Down Expand Up @@ -103,7 +105,8 @@ class BasicDecoration
std::optional<InputState const*> previous_input_state);

std::shared_ptr<ThreadsafeAccess<BasicDecoration>> const threadsafe_self;
std::shared_ptr<StaticGeometry const> const static_geometry;
std::shared_ptr<DecorationStrategy> const decoration_strategy;
std::shared_ptr<StaticGeometry> const static_geometry;

std::shared_ptr<shell::Shell> const shell;
std::shared_ptr<graphics::GraphicBufferAllocator> const buffer_allocator;
Expand Down
30 changes: 28 additions & 2 deletions src/server/shell/decoration/basic_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "basic_manager.h"
#include "decoration.h"
#include "decoration_strategy.h"

#include <mir/graphics/display_configuration.h>
#include <mir/graphics/null_display_configuration_observer.h>
Expand Down Expand Up @@ -49,8 +50,10 @@ class msd::DisplayConfigurationListener : public mg::NullDisplayConfigurationOb
};

msd::BasicManager::BasicManager(
std::shared_ptr<DecorationStrategy> const& decoration_strategy,
ObserverRegistrar<mg::DisplayConfigurationObserver>& display_configuration_observers,
DecorationBuilder&& decoration_builder) :
decoration_strategy{decoration_strategy},
decoration_builder{std::move(decoration_builder)},
display_config_monitor{std::make_shared<DisplayConfigurationListener>(
[&](mg::DisplayConfiguration const& config)
Expand Down Expand Up @@ -92,7 +95,7 @@ void msd::BasicManager::decorate(std::shared_ptr<ms::Surface> 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);
Expand Down Expand Up @@ -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};
Expand All @@ -139,4 +165,4 @@ void msd::BasicManager::set_scale(float new_scale)
it.second->set_scale(scale);
}
}
}
}
6 changes: 6 additions & 0 deletions src/server/shell/decoration/basic_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,10 +49,12 @@ class BasicManager :
{
public:
using DecorationBuilder = std::function<std::unique_ptr<Decoration>(
std::shared_ptr<DecorationStrategy> const& decoration_strategy,
std::shared_ptr<shell::Shell> const& shell,
std::shared_ptr<scene::Surface> const& surface)>;

BasicManager(
std::shared_ptr<DecorationStrategy> const& decoration_strategy,
mir::ObserverRegistrar<mir::graphics::DisplayConfigurationObserver>& display_configuration_observers,
DecorationBuilder&& decoration_builder);
~BasicManager();
Expand All @@ -60,8 +63,11 @@ class BasicManager :
void decorate(std::shared_ptr<scene::Surface> const& surface) override;
void undecorate(std::shared_ptr<scene::Surface> 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<DecorationStrategy> const decoration_strategy;
DecorationBuilder const decoration_builder;
std::shared_ptr<DisplayConfigurationListener> const display_config_monitor;
std::weak_ptr<shell::Shell> shell;
Expand Down
Loading
Loading