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

sway_text_node: Fix issues with large dimensions #8586

Merged
merged 2 commits into from
Feb 25, 2025

Conversation

kennylevinsen
Copy link
Member

@kennylevinsen kennylevinsen commented Feb 25, 2025

sway_text_node was not respecting max_width during rendering, which could lead to very large cairo surfaces and failures during rendering.

Minimal reproduction: https://gitlab.freedesktop.org/emersion/wleird/-/merge_requests/36

@@ -87,7 +87,7 @@ static void render_backing_buffer(struct text_buffer *buffer) {
}

float scale = buffer->scale;
int width = ceil(buffer->props.width * scale);
int width = ceil(get_text_width(&buffer->props) * scale);
Copy link
Member

Choose a reason for hiding this comment

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

The whole text was rendered to avoid rendering again when resizing a window.

I believe this change breaks sway_text_node_set_max_width().

Copy link
Member

@emersion emersion Feb 25, 2025

Choose a reason for hiding this comment

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

Oh, but we call render_backing_buffer() in sway_text_node_set_max_width(). According to git log it seems like it was there since the beginning.

This begs the question: do we need update_source_box() for anything? Isn't the source box always the full size of the buffer?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I also thought that the source box was to optimize resize, but as you mention it's rendered ineffective.

It makes sense to do, but the question is if we want to fix that now or just whack it for now and try again later. From the perspective of fixing the crash I'm leaning towards the latter.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, makes sense to fix now and leave optimizations for later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the source box.

@@ -60,6 +60,8 @@ static int get_text_width(struct sway_text_node *props) {
int width = props->width;
if (props->max_width >= 0) {
width = MIN(width, props->max_width);
} else {
width = MIN(width, 3840);
Copy link
Member

Choose a reason for hiding this comment

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

8K monitors are 7680px large, so this seems a bit low?

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean, it's the boundary for the title text before the max_width has been set by the container code.

We should always be setting the max_width from what I can tell, so I don't think it really makes sense for us to render anything before the max width is determined. I think the code has been written as too generalized for our needs...

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I guess we already skip rendering if max_width == 0, so the else branch doens't matter at all. I'll remove it.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yeah. I suppose max_width isn't a great name here.

max_width was applied to the source box, but not to the cairo surface.
The cairo surface would therefore take on arbitrarily large dimensions
according to the required dimensions to fit the text input, which if
large enough would cause failures during output rendering and leave a
black hole in the titlebar.
The source box is always set to the full buffer dimensions, making it
ineffective. Remove it.
Copy link
Member

@emersion emersion left a comment

Choose a reason for hiding this comment

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

LGTM! Maybe we should wait for a bit in case @Nefsen402 has something else to add :)

@Nefsen402
Copy link
Member

I have nothing to add. Nice and simple, should have done this since day 1.

@Nefsen402 Nefsen402 merged commit 962e1e7 into swaywm:master Feb 25, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants