From 745b8c63763b8cb1377eb399677c5292a1e2d692 Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Fri, 19 May 2023 01:29:21 -0400 Subject: [PATCH] created render_layer_iterator --- include/sway/config.h | 1 - .../sway/desktop/fx_renderer/fx_renderer.h | 2 - include/sway/layer_criteria.h | 1 + include/sway/layers.h | 5 ++- include/sway/output.h | 1 - sway/desktop/fx_renderer/fx_renderer.c | 13 ------ sway/desktop/layer_shell.c | 4 +- sway/desktop/output.c | 7 ++- sway/desktop/render.c | 45 ++++++++++++++++--- sway/ipc-json.c | 11 +++-- sway/layer_criteria.c | 6 +-- sway/tree/workspace.c | 3 +- 12 files changed, 60 insertions(+), 39 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index a4aa89aa..0e56445c 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -12,7 +12,6 @@ #include "../include/config.h" #include "gesture.h" #include "list.h" -#include "sway/desktop/fx_renderer/fx_renderer.h" #include "swaynag.h" #include "tree/container.h" #include "sway/input/tablet.h" diff --git a/include/sway/desktop/fx_renderer/fx_renderer.h b/include/sway/desktop/fx_renderer/fx_renderer.h index b57ad6d7..51f60557 100644 --- a/include/sway/desktop/fx_renderer/fx_renderer.h +++ b/include/sway/desktop/fx_renderer/fx_renderer.h @@ -36,8 +36,6 @@ struct decoration_data { bool shadow; }; -struct decoration_data get_undecorated_decoration_data(); - struct blur_shader { GLuint program; GLint proj; diff --git a/include/sway/layer_criteria.h b/include/sway/layer_criteria.h index f86576ea..f0906460 100644 --- a/include/sway/layer_criteria.h +++ b/include/sway/layer_criteria.h @@ -1,5 +1,6 @@ #include #include "sway/layers.h" +#include "sway/config.h" struct layer_criteria { char *namespace; diff --git a/include/sway/layers.h b/include/sway/layers.h index 6037ed09..b04990dc 100644 --- a/include/sway/layers.h +++ b/include/sway/layers.h @@ -3,7 +3,6 @@ #include #include #include -#include "sway/config.h" enum layer_parent { LAYER_PARENT_LAYER, @@ -29,7 +28,9 @@ struct sway_layer_surface { struct wl_list subsurfaces; - struct decoration_data deco_data; + bool has_shadow; + bool has_blur; + int corner_radius; }; struct sway_layer_popup { diff --git a/include/sway/output.h b/include/sway/output.h index 23c6dd19..3215c853 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -17,7 +17,6 @@ struct render_data { pixman_region32_t *damage; struct wlr_box *clip_box; struct decoration_data deco_data; - struct sway_layer_surface *sway_layer; }; struct sway_output_state { diff --git a/sway/desktop/fx_renderer/fx_renderer.c b/sway/desktop/fx_renderer/fx_renderer.c index c5cced4a..7122983e 100644 --- a/sway/desktop/fx_renderer/fx_renderer.c +++ b/sway/desktop/fx_renderer/fx_renderer.c @@ -36,19 +36,6 @@ static const GLfloat verts[] = { 0, 1, // bottom left }; -struct decoration_data get_undecorated_decoration_data() { - return (struct decoration_data) { - .alpha = 1.0f, - .dim = 0.0f, - .dim_color = config->dim_inactive_colors.unfocused, - .corner_radius = 0, - .saturation = 1.0f, - .has_titlebar = false, - .blur = false, - .shadow = false, - }; -} - static GLuint compile_shader(GLuint type, const GLchar *src) { GLuint shader = glCreateShader(type); glShaderSource(shader, 1, &src, NULL); diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index 9d0ed310..bbc2e6f3 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c @@ -703,7 +703,9 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { sway_layer->layer_surface = layer_surface; layer_surface->data = sway_layer; - sway_layer->deco_data = get_undecorated_decoration_data(); + sway_layer->has_blur = false; + sway_layer->has_shadow = false; + sway_layer->corner_radius = 0; struct sway_output *output = layer_surface->output->data; sway_layer->output_destroy.notify = handle_output_destroy; diff --git a/sway/desktop/output.c b/sway/desktop/output.c index f3dec283..3d592cd6 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -1,3 +1,4 @@ +#include "sway/desktop/fx_renderer/fx_renderer.h" #define _POSIX_C_SOURCE 200809L #include #include @@ -199,9 +200,11 @@ void output_layer_for_each_toplevel_surface(struct sway_output *output, wl_list_for_each(layer_surface, layer_surfaces, link) { struct wlr_layer_surface_v1 *wlr_layer_surface_v1 = layer_surface->layer_surface; + struct render_data *data = user_data; - data->sway_layer = layer_surface; - data->deco_data = layer_surface->deco_data; + data->deco_data.blur = layer_surface->has_blur; + data->deco_data.shadow = layer_surface->has_shadow; + data->deco_data.corner_radius = layer_surface->corner_radius; output_surface_for_each_surface(output, wlr_layer_surface_v1->surface, layer_surface->geo.x, layer_surface->geo.y, iterator, diff --git a/sway/desktop/render.c b/sway/desktop/render.c index e2b57ccf..0971b843 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -32,6 +32,19 @@ #include "sway/tree/view.h" #include "sway/tree/workspace.h" +struct decoration_data get_undecorated_decoration_data() { + return (struct decoration_data) { + .alpha = 1.0f, + .dim = 0.0f, + .dim_color = config->dim_inactive_colors.unfocused, + .corner_radius = 0, + .saturation = 1.0f, + .has_titlebar = false, + .blur = false, + .shadow = false, + }; +} + int get_blur_size() { return pow(2, config->blur_params.num_passes) * config->blur_params.radius; } @@ -406,7 +419,6 @@ damage_finish: pixman_region32_fini(&damage); } - static void render_surface_iterator(struct sway_output *output, struct sway_view *view, struct wlr_surface *surface, struct wlr_box *_box, void *_data) { @@ -441,13 +453,14 @@ static void render_surface_iterator(struct sway_output *output, struct decoration_data deco_data = data->deco_data; deco_data.corner_radius *= wlr_output->scale; - // render blur (view->surface == surface excludes blurring subsurfaces) bool is_subsurface = false; bool should_optimize_blur = false; if (view) { is_subsurface = view->surface != surface; should_optimize_blur = !container_is_floating(view->container) || config->blur_xray; } + /* + TODO if (data->sway_layer) { is_subsurface = data->sway_layer->layer_surface->surface != surface; enum zwlr_layer_shell_v1_layer layer = data->sway_layer->layer; @@ -455,6 +468,9 @@ static void render_surface_iterator(struct sway_output *output, && layer != ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM && layer != ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND; } + */ + + // render blur if (deco_data.blur && should_parameters_blur() && !is_subsurface) { pixman_region32_t opaque_region; pixman_region32_init(&opaque_region); @@ -490,9 +506,24 @@ static void render_surface_iterator(struct sway_output *output, wlr_presentation_surface_sampled_on_output(server.presentation, surface, wlr_output); +} - // render shadow (view->surface == surface excludes shadow on subsurfaces) - if (deco_data.shadow && should_parameters_shadow() && !is_subsurface && data->sway_layer) { +static void render_layer_iterator(struct sway_output *output, + struct sway_view *view, struct wlr_surface *surface, + struct wlr_box *_box, void *_data) { + // render the layer's surface + render_surface_iterator(output, view, surface, _box, _data); + + struct render_data *data = _data; + struct wlr_box dst_box = *_box; + pixman_region32_t *output_damage = data->damage; + + struct decoration_data deco_data = data->deco_data; + // TODO: can layers have subsurfaces? + bool is_subsurface = view ? view->surface != surface : false; + + // render shadow + if (deco_data.shadow && should_parameters_shadow() && !is_subsurface) { int corner_radius = deco_data.corner_radius; render_box_shadow(output, output_damage, &dst_box, config->shadow_color, config->shadow_blur_sigma, corner_radius); @@ -506,7 +537,7 @@ static void render_layer_toplevel(struct sway_output *output, .deco_data = get_undecorated_decoration_data(), }; output_layer_for_each_toplevel_surface(output, layer_surfaces, - render_surface_iterator, &data); + render_layer_iterator, &data); } static void render_layer_popups(struct sway_output *output, @@ -516,7 +547,7 @@ static void render_layer_popups(struct sway_output *output, .deco_data = get_undecorated_decoration_data(), }; output_layer_for_each_popup_surface(output, layer_surfaces, - render_surface_iterator, &data); + render_layer_iterator, &data); } #if HAVE_XWAYLAND @@ -1467,6 +1498,7 @@ static void render_containers_tabbed(struct sway_output *output, .saturation = current->saturation, .has_titlebar = true, .blur = current->blur_enabled, + .shadow = current->shadow_enabled, }; // Render tabs @@ -1562,6 +1594,7 @@ static void render_containers_stacked(struct sway_output *output, ? 0 : current->corner_radius, .has_titlebar = true, .blur = current->blur_enabled, + .shadow = current->shadow_enabled, }; // Render titles diff --git a/sway/ipc-json.c b/sway/ipc-json.c index c71c0a0d..717ebf78 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -374,14 +374,13 @@ static void ipc_json_describe_enabled_output(struct sway_output *output, json_object_object_add(layer, "extent", extent); json_object *effects = json_object_new_array(); - struct decoration_data deco_data = lsurface->deco_data; - if (deco_data.blur) { + if (lsurface->has_blur) { json_object_array_add(effects, json_object_new_string("blur")); } - if (deco_data.shadow) { + if (lsurface->has_shadow) { json_object_array_add(effects, json_object_new_string("shadows")); } - if (deco_data.corner_radius > 0) { + if (lsurface->corner_radius > 0) { json_object_array_add(effects, json_object_new_string("corner_radius")); } json_object_object_add(layer, "effects", effects); @@ -1113,9 +1112,9 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) { struct xkb_keymap *keymap = keyboard->keymap; struct xkb_state *state = keyboard->xkb_state; - json_object_object_add(object, "repeat_delay", + json_object_object_add(object, "repeat_delay", json_object_new_int(keyboard->repeat_info.delay)); - json_object_object_add(object, "repeat_rate", + json_object_object_add(object, "repeat_rate", json_object_new_int(keyboard->repeat_info.rate)); json_object *layouts_arr = json_object_new_array(); diff --git a/sway/layer_criteria.c b/sway/layer_criteria.c index 41e40411..694c5016 100644 --- a/sway/layer_criteria.c +++ b/sway/layer_criteria.c @@ -65,15 +65,15 @@ void layer_criteria_parse(struct sway_layer_surface *sway_layer, struct layer_cr } } if (strcmp(argv[0], "blur") == 0) { - sway_layer->deco_data.blur = parse_boolean(argv[1], true); + sway_layer->has_blur = parse_boolean(argv[1], true); continue; } else if (strcmp(argv[0], "shadows") == 0) { - sway_layer->deco_data.shadow = parse_boolean(argv[1], true); + sway_layer->has_shadow = parse_boolean(argv[1], true); continue; } else if (strcmp(argv[0], "corner_radius") == 0) { int value; if (cmd_corner_radius_parse_value(argv[1], &value)) { - sway_layer->deco_data.corner_radius = value; + sway_layer->corner_radius = value; continue; } sway_log(SWAY_ERROR, diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index aa37e70b..8bc62f3f 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -715,8 +715,7 @@ bool should_workspace_have_blur(struct sway_workspace *ws) { for (size_t i = 0; i < len; ++i) { struct sway_layer_surface *lsurface; wl_list_for_each(lsurface, &sway_output->layers[i], link) { - if (lsurface->deco_data.blur - && !lsurface->layer_surface->surface->opaque + if (lsurface->has_blur && !lsurface->layer_surface->surface->opaque && lsurface->layer != ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND) { return true; }