Skip to content

Commit 5e1da12

Browse files
MikeWalrusemersion
authored andcommitted
Set wayland surface width per each mako_surface
Using the super style's width for all wayland surfaces causes extra space to be blurred when using the compositor to blur the background of notification surfaces.
1 parent c0c5373 commit 5e1da12

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

include/render.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
struct mako_state;
55
struct mako_surface;
66

7-
int render(struct mako_surface *surface, struct pool_buffer *buffer, int scale);
7+
void render(struct mako_surface *surface, struct pool_buffer *buffer, int scale,
8+
int *width, int *height);
89

910
#endif

render.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,15 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
321321
return notif_height;
322322
}
323323

324-
int render(struct mako_surface *surface, struct pool_buffer *buffer, int scale) {
324+
void render(struct mako_surface *surface, struct pool_buffer *buffer, int scale,
325+
int *rendered_width, int *rendered_height) {
325326
struct mako_state *state = surface->state;
326327
cairo_t *cairo = buffer->cairo;
327328

329+
*rendered_width = *rendered_height = 0;
330+
328331
if (wl_list_empty(&state->notifications)) {
329-
return 0;
332+
return;
330333
}
331334

332335
// Clear
@@ -339,6 +342,7 @@ int render(struct mako_surface *surface, struct pool_buffer *buffer, int scale)
339342
size_t visible_count = 0;
340343
size_t hidden_count = 0;
341344
int total_height = 0;
345+
int max_width = 0;
342346
int pending_bottom_margin = 0;
343347
struct mako_notification *notif;
344348
size_t total_notifications = 0;
@@ -401,7 +405,13 @@ int render(struct mako_surface *surface, struct pool_buffer *buffer, int scale)
401405
&notif->hotspot, notif->progress);
402406
free(text);
403407

408+
int notif_width =
409+
style->width + style->margin.left + style->margin.right;
410+
404411
total_height += notif_height;
412+
if (max_width < notif_width) {
413+
max_width = notif_width;
414+
}
405415
pending_bottom_margin = style->margin.bottom;
406416

407417
if (notif->group_index < 1) {
@@ -411,7 +421,6 @@ int render(struct mako_surface *surface, struct pool_buffer *buffer, int scale)
411421
// single entity for this purpose.
412422
++visible_count;
413423
}
414-
415424
}
416425

417426
if (hidden_count > 0) {
@@ -438,7 +447,7 @@ int render(struct mako_surface *surface, struct pool_buffer *buffer, int scale)
438447
char *text = malloc(text_ln + 1);
439448
if (text == NULL) {
440449
fprintf(stderr, "allocation failed");
441-
return 0;
450+
return;
442451
}
443452

444453
format_text(style->format, text, format_hidden_text, &data);
@@ -452,5 +461,6 @@ int render(struct mako_surface *surface, struct pool_buffer *buffer, int scale)
452461
destroy_notification(hidden_notif);
453462
}
454463

455-
return total_height + pending_bottom_margin;
464+
*rendered_width = max_width;
465+
*rendered_height = total_height;
456466
}

wayland.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,8 @@ static void send_frame(struct mako_surface *surface) {
609609
}
610610

611611
struct mako_output *output = get_configured_output(surface);
612-
int height = render(surface, surface->current_buffer, scale);
612+
int width = 0, height = 0;
613+
render(surface, surface->current_buffer, scale, &width, &height);
613614

614615
// There are two cases where we want to tear down the surface: zero
615616
// notifications (height = 0) or moving between outputs.
@@ -669,14 +670,11 @@ static void send_frame(struct mako_surface *surface) {
669670
// surface is brand new, it doesn't even have a size yet. If it already
670671
// exists, we might need to resize if the list of notifications has changed
671672
// since the last time we drew.
672-
if (surface->height != height) {
673+
if (surface->height != height || surface->width != width) {
673674
struct mako_style *style = &state->config.superstyle;
674675

675-
zwlr_layer_surface_v1_set_size(surface->layer_surface,
676-
style->width + style->margin.left + style->margin.right,
677-
height);
678-
zwlr_layer_surface_v1_set_anchor(surface->layer_surface,
679-
surface->anchor);
676+
zwlr_layer_surface_v1_set_size(surface->layer_surface, width, height);
677+
zwlr_layer_surface_v1_set_anchor(surface->layer_surface, surface->anchor);
680678
zwlr_layer_surface_v1_set_margin(surface->layer_surface,
681679
style->outer_margin.top, style->outer_margin.right,
682680
style->outer_margin.bottom, style->outer_margin.left);

0 commit comments

Comments
 (0)