Skip to content

Commit 7ccc97b

Browse files
authored
feat: refactor to use new blur node (#465)
1 parent 91a8b80 commit 7ccc97b

10 files changed

Lines changed: 80 additions & 16 deletions

File tree

include/sway/layers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct sway_layer_surface {
2222
struct sway_output *output;
2323
struct wlr_scene_layer_surface_v1 *scene;
2424
struct wlr_scene_tree *tree;
25+
struct wlr_scene_blur *blur_node;
2526
struct wlr_scene_shadow *shadow_node;
2627
struct wlr_layer_surface_v1 *layer_surface;
2728

include/sway/tree/container.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct sway_container {
9090
struct wlr_scene_rect *right;
9191
} border;
9292

93+
struct wlr_scene_blur *blur;
9394
struct wlr_scene_shadow *shadow;
9495

9596
struct wlr_scene_tree *content_tree;

include/sway/tree/node.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,7 @@ struct wlr_scene_shadow *alloc_scene_shadow(struct wlr_scene_tree *parent,
9191
int width, int height, int corner_radius, float blur_sigma,
9292
const float color [static 4], bool *failed);
9393

94+
struct wlr_scene_blur *alloc_scene_blur(struct wlr_scene_tree *parent,
95+
int width, int height, bool *failed);
96+
9497
#endif

sway/desktop/layer_shell.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ static void arrange_surface(struct sway_output *output, const struct wlr_box *fu
9898
continue;
9999
}
100100

101+
wlr_scene_node_set_enabled(&surface->blur_node->node, surface->blur_enabled);
102+
wlr_scene_blur_set_size(surface->blur_node, surface->layer_surface->surface->current.width,
103+
surface->layer_surface->surface->current.height);
104+
101105
wlr_scene_node_set_enabled(&surface->shadow_node->node, surface->shadow_enabled);
106+
102107
if (surface->shadow_enabled) {
103108
// Adjust the size and position of the shadow node
104109
wlr_scene_shadow_set_size(surface->shadow_node,
@@ -242,6 +247,7 @@ static struct sway_layer_surface *sway_layer_surface_create(
242247
surface->shadow_enabled = false;
243248

244249
bool failed = false;
250+
surface->blur_node = alloc_scene_blur(surface->tree, 0, 0, &failed);
245251
surface->shadow_node = alloc_scene_shadow(surface->tree, 0, 0,
246252
0, config->shadow_blur_sigma, config->shadow_color, &failed);
247253
if (failed) {
@@ -377,6 +383,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
377383

378384
layer_parse_criteria(surface);
379385
wlr_scene_node_lower_to_bottom(&surface->shadow_node->node);
386+
wlr_scene_node_lower_to_bottom(&surface->blur_node->node);
380387

381388
// focus on new surface
382389
if (layer_surface->current.keyboard_interactive &&

sway/desktop/output.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ void output_configure_scene(struct sway_output *output, struct wlr_scene_node *n
222222
opacity = con->alpha;
223223
corner_radius = con->corner_radius;
224224
blur_enabled = con->blur_enabled;
225-
226225
enum sway_container_layout layout = con->current.layout;
227226
has_titlebar |= con->current.border == B_NORMAL || layout == L_STACKED || layout == L_TABBED;
228227
}
@@ -263,11 +262,6 @@ void output_configure_scene(struct sway_output *output, struct wlr_scene_node *n
263262
wlr_scene_buffer_set_corner_radius(buffer,
264263
container_has_corner_radius(closest_con) ? corner_radius : 0,
265264
has_titlebar ? CORNER_LOCATION_BOTTOM : CORNER_LOCATION_ALL);
266-
wlr_scene_buffer_set_backdrop_blur(buffer, blur_enabled);
267-
wlr_scene_buffer_set_backdrop_blur_ignore_transparent(buffer, false);
268-
// Only enable xray blur if tiled or when xray is explicitly enabled
269-
bool should_optimize_blur = (closest_con && !container_is_floating_or_child(closest_con)) || config->blur_xray;
270-
wlr_scene_buffer_set_backdrop_blur_optimized(buffer, should_optimize_blur);
271265
} else if (wlr_subsurface_try_from_wlr_surface(surface->surface)) {
272266
wlr_scene_buffer_set_corner_radius(buffer,
273267
container_has_corner_radius(closest_con) ? corner_radius : 0,
@@ -279,16 +273,32 @@ void output_configure_scene(struct sway_output *output, struct wlr_scene_node *n
279273
wlr_scene_buffer_set_corner_radius(buffer, surface->corner_radius, CORNER_LOCATION_ALL);
280274
wlr_scene_shadow_set_blur_sigma(surface->shadow_node, config->shadow_blur_sigma);
281275
wlr_scene_shadow_set_corner_radius(surface->shadow_node, surface->corner_radius);
282-
wlr_scene_buffer_set_backdrop_blur(buffer, surface->blur_enabled);
283-
wlr_scene_buffer_set_backdrop_blur_ignore_transparent(buffer, surface->blur_ignore_transparent);
284-
wlr_scene_buffer_set_backdrop_blur_optimized(buffer, surface->blur_xray);
276+
277+
wlr_scene_node_set_enabled(&surface->blur_node->node, surface->blur_enabled);
278+
279+
if (surface->blur_enabled) {
280+
if (surface->blur_ignore_transparent) {
281+
wlr_scene_blur_set_transparency_mask_source(surface->blur_node, buffer);
282+
} else {
283+
wlr_scene_blur_set_transparency_mask_source(surface->blur_node, NULL);
284+
}
285+
wlr_scene_blur_set_should_only_blur_bottom_layer(surface->blur_node, surface->blur_xray);
286+
wlr_scene_blur_set_corner_radius(surface->blur_node, surface->corner_radius, CORNER_LOCATION_ALL);
287+
}
285288
}
286289
} else if (node->type == WLR_SCENE_NODE_TREE) {
287290
struct wlr_scene_tree *tree = wlr_scene_tree_from_node(node);
288291
struct wlr_scene_node *node;
289292
wl_list_for_each(node, &tree->children, link) {
290293
output_configure_scene(output, node, opacity, corner_radius, blur_enabled, has_titlebar, closest_con);
291294
}
295+
} else if (node->type == WLR_SCENE_NODE_BLUR && closest_con) {
296+
struct wlr_scene_blur *blur = wlr_scene_blur_from_node(node);
297+
298+
// Only enable xray blur if tiled or when xray is explicitly enabled
299+
bool should_optimize_blur = !container_is_floating_or_child(closest_con) || config->blur_xray;
300+
wlr_scene_blur_set_should_only_blur_bottom_layer(blur, should_optimize_blur);
301+
wlr_scene_node_set_enabled(node, closest_con->blur_enabled);
292302
}
293303
}
294304

sway/desktop/transaction.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ static void arrange_children(enum sway_container_layout layout, list_t *children
311311
arrange_title_bar(child, title_offset, -title_bar_height,
312312
next_title_offset - title_offset, title_bar_height);
313313
wlr_scene_node_set_enabled(&child->border.tree->node, activated);
314+
wlr_scene_node_set_enabled(&child->blur->node, activated);
314315
wlr_scene_node_set_enabled(&child->shadow->node, false);
315316
wlr_scene_node_set_enabled(&child->scene_tree->node, true);
316317
wlr_scene_node_set_position(&child->scene_tree->node, 0, title_bar_height);
@@ -342,6 +343,7 @@ static void arrange_children(enum sway_container_layout layout, list_t *children
342343

343344
arrange_title_bar(child, 0, y - title_height, width, title_bar_height);
344345
wlr_scene_node_set_enabled(&child->border.tree->node, activated);
346+
wlr_scene_node_set_enabled(&child->blur->node, activated);
345347
wlr_scene_node_set_enabled(&child->shadow->node, false);
346348
wlr_scene_node_set_enabled(&child->scene_tree->node, true);
347349
wlr_scene_node_set_position(&child->scene_tree->node, 0, title_height);
@@ -363,6 +365,7 @@ static void arrange_children(enum sway_container_layout layout, list_t *children
363365
int cheight = child->current.height;
364366

365367
wlr_scene_node_set_enabled(&child->border.tree->node, true);
368+
wlr_scene_node_set_enabled(&child->blur->node, true);
366369
wlr_scene_node_set_enabled(&child->shadow->node,
367370
container_has_shadow(child) && child->view);
368371
wlr_scene_node_set_position(&child->scene_tree->node, 0, off);
@@ -381,6 +384,7 @@ static void arrange_children(enum sway_container_layout layout, list_t *children
381384
int cwidth = child->current.width;
382385

383386
wlr_scene_node_set_enabled(&child->border.tree->node, true);
387+
wlr_scene_node_set_enabled(&child->blur->node, true);
384388
wlr_scene_node_set_enabled(&child->shadow->node,
385389
container_has_shadow(child) && child->view);
386390
wlr_scene_node_set_position(&child->scene_tree->node, off, 0);
@@ -553,6 +557,11 @@ static void arrange_container(struct sway_container *con,
553557
wlr_scene_node_reparent(&con->view->scene_tree->node, con->content_tree);
554558
wlr_scene_node_set_position(&con->view->scene_tree->node,
555559
border_left, border_top);
560+
561+
wlr_scene_node_set_enabled(&con->blur->node, con->blur_enabled);
562+
wlr_scene_node_set_position(&con->blur->node, border_left, border_top);
563+
wlr_scene_blur_set_size(con->blur, con->current.content_width,
564+
con->current.content_height);
556565
} else {
557566
// make sure to disable the title bar if the parent is not managing it
558567
if (title_bar) {

sway/input/seatop_move_tiling.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ struct seatop_move_tiling_event {
2828
bool split_target;
2929
bool insert_after_target;
3030
struct wlr_scene_rect *indicator_rect;
31+
struct wlr_scene_blur *indicator_blur;
3132
};
3233

3334
static void handle_end(struct sway_seat *seat) {
3435
struct seatop_move_tiling_event *e = seat->seatop_data;
3536
wlr_scene_node_destroy(&e->indicator_rect->node);
37+
wlr_scene_node_destroy(&e->indicator_blur->node);
3638
e->indicator_rect = NULL;
3739
}
3840

@@ -55,6 +57,7 @@ static void handle_motion_prethreshold(struct sway_seat *seat) {
5557
// If the threshold has been exceeded, start the actual drag
5658
if ((cx - sx) * (cx - sx) + (cy - sy) * (cy - sy) > threshold) {
5759
wlr_scene_node_set_enabled(&e->indicator_rect->node, true);
60+
wlr_scene_node_set_enabled(&e->indicator_blur->node, true);
5861
e->threshold_reached = true;
5962
cursor_set_image(seat->cursor, "grab", NULL);
6063
}
@@ -154,6 +157,9 @@ static bool split_titlebar(struct sway_node *node, struct sway_container *avoid,
154157
}
155158

156159
static void update_indicator(struct seatop_move_tiling_event *e, struct wlr_box *box) {
160+
wlr_scene_node_set_position(&e->indicator_blur->node, box->x, box->y);
161+
wlr_scene_blur_set_size(e->indicator_blur, box->width, box->height);
162+
157163
wlr_scene_node_set_position(&e->indicator_rect->node, box->x, box->y);
158164
wlr_scene_rect_set_size(e->indicator_rect, box->width, box->height);
159165

@@ -166,9 +172,10 @@ static void update_indicator(struct seatop_move_tiling_event *e, struct wlr_box
166172
corner_radius += e->con->current.border_thickness;
167173
}
168174
}
169-
wlr_scene_rect_set_corner_radius(e->indicator_rect,
170-
MIN(corner_radius, MIN(box->width / 2, box->height / 2)),
171-
CORNER_LOCATION_ALL);
175+
176+
int corner_radius_real = MIN(corner_radius, MIN(box->width / 2, box->height / 2));
177+
wlr_scene_rect_set_corner_radius(e->indicator_rect, corner_radius_real, CORNER_LOCATION_ALL);
178+
wlr_scene_blur_set_corner_radius(e->indicator_blur, corner_radius_real, CORNER_LOCATION_ALL);
172179
}
173180

174181
static void handle_motion_postthreshold(struct sway_seat *seat) {
@@ -468,12 +475,19 @@ void seatop_begin_move_tiling_threshold(struct sway_seat *seat,
468475
indicator[2] * .5,
469476
indicator[3] * .5,
470477
};
478+
479+
e->indicator_blur = wlr_scene_blur_create(seat->scene_tree, 0, 0);
480+
if (!e->indicator_blur) {
481+
free(e);
482+
return;
483+
}
484+
471485
e->indicator_rect = wlr_scene_rect_create(seat->scene_tree, 0, 0, color);
472486
if (!e->indicator_rect) {
487+
wlr_scene_node_destroy(&e->indicator_blur->node);
473488
free(e);
474489
return;
475490
}
476-
wlr_scene_rect_set_backdrop_blur(e->indicator_rect, true);
477491

478492
e->con = con;
479493
e->ref_lx = seat->cursor->cursor->x;

sway/tree/container.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct sway_container *container_create(struct sway_view *view) {
9292

9393
// Container tree structure
9494
// - scene tree
95+
// - blur source
9596
// - shadow
9697
// - title bar
9798
// - border
@@ -107,6 +108,8 @@ struct sway_container *container_create(struct sway_view *view) {
107108
bool failed = false;
108109
c->scene_tree = alloc_scene_tree(root->staging, &failed);
109110

111+
c->blur = alloc_scene_blur(c->scene_tree, 0, 0, &failed);
112+
110113
c->shadow = alloc_scene_shadow(c->scene_tree, 0, 0,
111114
0, config->shadow_blur_sigma, config->shadow_color, &failed);
112115

@@ -303,6 +306,8 @@ void container_update(struct sway_container *con) {
303306
sway_text_node_set_background(con->title_bar.marks_text, colors->background);
304307
}
305308

309+
wlr_scene_node_set_enabled(&con->blur->node, con->blur_enabled);
310+
306311
if (con->dim_rect) {
307312
float *color = config->dim_inactive_colors.unfocused;
308313

sway/tree/node.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,20 @@ struct wlr_scene_shadow *alloc_scene_shadow(struct wlr_scene_tree *parent,
206206
return shadow;
207207
}
208208

209+
struct wlr_scene_blur *alloc_scene_blur(struct wlr_scene_tree *parent,
210+
int width, int height, bool *failed) {
211+
// fallthrough
212+
if (*failed) {
213+
return NULL;
214+
}
215+
216+
struct wlr_scene_blur *blur = wlr_scene_blur_create(
217+
parent, width, height);
218+
if (!blur) {
219+
sway_log(SWAY_ERROR, "Failed to allocate a scene node");
220+
*failed = true;
221+
}
222+
223+
return blur;
224+
}
225+

sway/tree/view.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,9 +1233,6 @@ static void view_save_buffer_iterator(struct wlr_scene_buffer *buffer,
12331233

12341234
// Set effects to saved views
12351235
wlr_scene_buffer_set_corner_radius(sbuf, buffer->corner_radius, buffer->corners);
1236-
wlr_scene_buffer_set_backdrop_blur(sbuf, buffer->backdrop_blur);
1237-
wlr_scene_buffer_set_backdrop_blur_optimized(sbuf, buffer->backdrop_blur_optimized);
1238-
wlr_scene_buffer_set_backdrop_blur_ignore_transparent(sbuf, buffer->backdrop_blur_ignore_transparent);
12391236
}
12401237

12411238
void view_save_buffer(struct sway_view *view) {

0 commit comments

Comments
 (0)