Skip to content

Commit

Permalink
Plumb the decoration strategy through msd::BasicManager so that the s…
Browse files Browse the repository at this point in the history
…trategy always supplies StaticGeometry
  • Loading branch information
AlanGriffiths committed Dec 20, 2024
1 parent ec350ee commit c6d8e20
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 121 deletions.
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
17 changes: 0 additions & 17 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
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
61 changes: 60 additions & 1 deletion src/server/shell/decoration/decoration_strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "decoration_strategy.h"
#include "window.h"

#include "mir/fatal.h"
#include "mir/geometry/displacement.h"
#include "mir/log.h"

Expand Down Expand Up @@ -297,10 +298,68 @@ class DecorationStrategy : public msd::DecorationStrategy
auto button_placement(unsigned n, const WindowState& ws) const -> mir::geometry::Rectangle override;

private:
std::shared_ptr<StaticGeometry> const static_geometry_{std::make_shared<StaticGeometry>(msd::default_geometry)};
static StaticGeometry const default_geometry;
std::shared_ptr<StaticGeometry> const static_geometry_{std::make_shared<StaticGeometry>(default_geometry)};
};

StaticGeometry const DecorationStrategy::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
};
}

auto msd::border_type_for(MirWindowType type, MirWindowState state) -> msd::BorderType
{
using BorderType = msd::BorderType;

switch (type)
{
case mir_window_type_normal:
case mir_window_type_utility:
case mir_window_type_dialog:
case mir_window_type_freestyle:
case mir_window_type_satellite:
break;

case mir_window_type_gloss:
case mir_window_type_menu:
case mir_window_type_inputmethod:
case mir_window_type_tip:
case mir_window_type_decoration:
case mir_window_types:
return BorderType::None;
}

switch (state)
{
case mir_window_state_unknown:
case mir_window_state_restored:
return BorderType::Full;

case mir_window_state_maximized:
case mir_window_state_vertmaximized:
case mir_window_state_horizmaximized:
return BorderType::Titlebar;

case mir_window_state_minimized:
case mir_window_state_fullscreen:
case mir_window_state_hidden:
case mir_window_state_attached:
case mir_window_states:
return BorderType::None;
}

mir::fatal_error("%s:%d: should be unreachable", __FILE__, __LINE__);
return {};
}

auto msd::DecorationStrategy::default_decoration_strategy() -> std::unique_ptr<DecorationStrategy>
{
Expand Down
3 changes: 2 additions & 1 deletion src/server/shell/decoration/decoration_strategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ struct StaticGeometry

MirPixelFormat const buffer_format = mir_pixel_format_argb_8888;
};
extern StaticGeometry const default_geometry;

enum class ButtonState
{
Expand All @@ -74,6 +73,8 @@ enum class BorderType
None, ///< No decorations (for fullscreen windows or popups)
};

auto border_type_for(MirWindowType type, MirWindowState state) -> BorderType;

struct ButtonInfo
{
ButtonFunction function;
Expand Down
7 changes: 7 additions & 0 deletions src/server/shell/decoration/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#ifndef MIR_SHELL_DECORATION_MANAGER_H_
#define MIR_SHELL_DECORATION_MANAGER_H_

#include "mir/geometry/size.h"
#include "mir_toolkit/client_types.h"

#include <memory>

namespace mir
Expand Down Expand Up @@ -49,6 +52,10 @@ class Manager
/// Removes decorations from all currently decorated windows
virtual void undecorate_all() = 0;

/// Compute the corresponding size
virtual auto compute_size_with_decorations(geometry::Size content_size, MirWindowType type, MirWindowState state)
-> geometry::Size = 0;

private:
Manager(Manager const&) = delete;
Manager& operator=(Manager const&) = delete;
Expand Down
2 changes: 2 additions & 0 deletions src/server/shell/decoration/null_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class NullManager
void decorate(std::shared_ptr<scene::Surface> const&) override {}
void undecorate(std::shared_ptr<scene::Surface> const&) override {}
void undecorate_all() override {}
auto compute_size_with_decorations(geometry::Size sz, MirWindowType, MirWindowState) -> geometry::Size override
{ return sz; }
};
}
}
Expand Down
68 changes: 0 additions & 68 deletions src/server/shell/decoration/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,60 +21,11 @@

#include "mir/scene/surface.h"
#include "mir/scene/null_surface_observer.h"
#include "mir/shell/decoration.h"

namespace ms = mir::scene;
namespace geom = mir::geometry;
namespace msd = mir::shell::decoration;

namespace
{
auto border_type_for(MirWindowType type, MirWindowState state) -> msd::BorderType
{
using BorderType = msd::BorderType;

switch (type)
{
case mir_window_type_normal:
case mir_window_type_utility:
case mir_window_type_dialog:
case mir_window_type_freestyle:
case mir_window_type_satellite:
break;

case mir_window_type_gloss:
case mir_window_type_menu:
case mir_window_type_inputmethod:
case mir_window_type_tip:
case mir_window_type_decoration:
case mir_window_types:
return BorderType::None;
}

switch (state)
{
case mir_window_state_unknown:
case mir_window_state_restored:
return BorderType::Full;

case mir_window_state_maximized:
case mir_window_state_vertmaximized:
case mir_window_state_horizmaximized:
return BorderType::Titlebar;

case mir_window_state_minimized:
case mir_window_state_fullscreen:
case mir_window_state_hidden:
case mir_window_state_attached:
case mir_window_states:
return BorderType::None;
}

mir::fatal_error("%s:%d: should be unreachable", __FILE__, __LINE__);
return {};
}
}

msd::WindowState::WindowState(
std::shared_ptr<StaticGeometry const> const& static_geometry,
std::shared_ptr<scene::Surface> const& surface,
Expand Down Expand Up @@ -286,22 +237,3 @@ msd::WindowSurfaceObserverManager::~WindowSurfaceObserverManager()
{
surface_->unregister_interest(*observer);
}

auto msd::compute_size_with_decorations(geometry::Size content_size, MirWindowType type, MirWindowState state)
-> geometry::Size
{
switch (border_type_for(type, state))
{
case msd::BorderType::Full:
content_size.width += msd::default_geometry.side_border_width * 2;
content_size.height += msd::default_geometry.titlebar_height + msd::default_geometry.bottom_border_height;
break;
case msd::BorderType::Titlebar:
content_size.height += msd::default_geometry.titlebar_height;
break;
case msd::BorderType::None:
break;
}

return content_size;
}
Loading

0 comments on commit c6d8e20

Please sign in to comment.