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

Decoration strategy #3708

merged 7 commits into from
Jan 14, 2025

Conversation

AlanGriffiths
Copy link
Collaborator

Wrap all the SSD customization into an interface, and provides a default implementation

@AlanGriffiths
Copy link
Collaborator Author

This doesn't do much to fix the current design (which has far too much "ask" and not enough "tell" - c.f. StaticGeometry) but at least provides a single customization point

Base automatically changed from decorations-customization-points to main December 20, 2024 16:22
@AlanGriffiths
Copy link
Collaborator Author

This doesn't do much to fix the current design

I don't have clear ideas on addressing my dissatisfaction with the current design yet. So I'll propose it "as is" and see where other folks have feedback. Maybe next year all will become clear...

Happy holidays all! 🎄

@AlanGriffiths AlanGriffiths marked this pull request as ready for review December 20, 2024 17:18
@AlanGriffiths AlanGriffiths requested a review from a team as a code owner December 20, 2024 17:18
@AlanGriffiths
Copy link
Collaborator Author

To show some of the customization that can be done by changing the "strategy", this makes the borders transparent and moves the buttons to the left:

$ git diff
diff --git a/src/server/shell/decoration/decoration_strategy.cpp b/src/server/shell/decoration/decoration_strategy.cpp
index b025233a19..447b5da92e 100644
--- a/src/server/shell/decoration/decoration_strategy.cpp
+++ b/src/server/shell/decoration/decoration_strategy.cpp
@@ -44,7 +44,7 @@ using msd::InputState;
 
 namespace
 {
-static constexpr auto color(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 0xFF) -> uint32_t
+static constexpr auto color(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 0x7F) -> uint32_t
 {
 #if __BYTE_ORDER == __LITTLE_ENDIAN
     return ((uint32_t)b <<  0) |
@@ -820,7 +820,7 @@ void RendererStrategy::redraw_titlebar_text(geom::Size const scaled_titlebar_siz
         scaled_titlebar_size,
         name,
         geom::Point{
-            static_geometry->title_font_top_left.x.as_value() * scale,
+            scale * (static_geometry->title_font_top_left.x.as_value() + buttons.size() * (static_geometry->button_width.as_value() + static_geometry->padding_between_buttons.as_value())),
             static_geometry->title_font_top_left.y.as_value() * scale},
         static_geometry->title_font_height * scale,
         current_theme->text_color);
@@ -912,10 +912,9 @@ auto DecorationStrategy::button_placement(unsigned n, const WindowState& ws) con
     auto const geometry = static_geometry();
 
     geom::X x =
-        titlebar.right() -
-        as_delta(ws.side_border_width()) -
-        n * as_delta(geometry->button_width + geometry->padding_between_buttons) -
-        as_delta(geometry->button_width);
+        titlebar.left() +
+        as_delta(ws.side_border_width()) +
+        n * as_delta(geometry->button_width + geometry->padding_between_buttons);
     return geom::Rectangle{
                     {x, titlebar.top()},
                     {geometry->button_width, titlebar.size.height}};

Copy link
Contributor

@RAOF RAOF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. I also don't have a great idea for reworking this. I'd say it is an improvement, but it's still not great.

Comment on lines +166 to +171
struct RenderedPixels
{
MirPixelFormat const format;
geometry::Size const size;
Pixel const* const pixels;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I see I should add a mrs::as_write_mappable_buffer() to mirror as_read_mappable_buffer(); this should really just be mg::Buffer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to force the decoration strategy to deal with the likes of mrs::alloc_buffer_with_content() which needs a GraphicBufferAllocator. Yes, it is all rendering, but this seemed like a tractable seam to insert in the design

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, mrs::alloc_buffer_with_content() is the wrong interface here; what we really want from the decorator is a mg::Buffer, as long as it's easy enough for them to render to it.

Then again, I've had broader thoughts about the whole requirements, which I'll need to coalesce and transmit in a different forum.

@tarek-y-ismail
Copy link
Contributor

which has far too much "ask" and not enough "tell" - c.f. StaticGeometry

Not sure I understand. What do you mean by "ask"/"tell" Here?

I don't have clear ideas on addressing my dissatisfaction with the current design yet.

Well, you could start by writing them out.

To give things a bit more direction, I think we can start with what we want the user API to look like. The internal/default implementation doesn't really matter for users unless there something shared between user code and internal code (buffer management or input routing for example), the rest of the internal code can then be simplified or cleaned up once things are clear. Shamelessly plugging #3666 in case that helps inspire you.

@AlanGriffiths
Copy link
Collaborator Author

which has far too much "ask" and not enough "tell" - c.f. StaticGeometry

Not sure I understand. What do you mean by "ask"/"tell" Here?

https://martinfowler.com/bliki/TellDontAsk.html

I don't have clear ideas on addressing my dissatisfaction with the current design yet.

Well, you could start by writing them out.

Well, that's part of my problem

To give things a bit more direction, I think we can start with what we want the user API to look like. The internal/default implementation doesn't really matter for users unless there something shared between user code and internal code (buffer management or input routing for example), the rest of the internal code can then be simplified or cleaned up once things are clear. Shamelessly plugging #3666 in case that helps inspire you.

That includes a lot of other concerns. To aid comparison, which part of that corresponds to decoration_strategy.h?

@tarek-y-ismail
Copy link
Contributor

tarek-y-ismail commented Jan 6, 2025

which part of that corresponds to decoration_strategy.h?

I would say decoration_adapter.h. It's the central piece that connects input, rendering, and other event handling all together. It's a bit more bloated/verbose, but that can be taken care of.

@AlanGriffiths
Copy link
Collaborator Author

which part of that corresponds to decoration_strategy.h?

I would say decoration_adapter.h. It's the central piece that connects input, rendering, and other event handling all together. It's a bit more bloated/verbose, but that can be taken care of.

While I don't like decoration_strategy.h I think it does a better job of separating the concern a decoration implementor should be dealing with. (And that is what this PR is trying for)

@AlanGriffiths
Copy link
Collaborator Author

AlanGriffiths commented Jan 6, 2025

OK, I've had a chance to reflect, I think this PR achieves what it sets out to do: refactor the existing implementation so that the decoration strategy interface is clearly separated.

The next step is cleaning up that interface, but that could sensibly happen in a follow-up PR: #3712

@tarek-y-ismail tarek-y-ismail added this pull request to the merge queue Jan 14, 2025
Merged via the queue into main with commit ef521eb Jan 14, 2025
38 of 64 checks passed
@tarek-y-ismail tarek-y-ismail deleted the decoration-strategy branch January 14, 2025 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants