created render_layer_iterator

This commit is contained in:
William McKinnon 2023-05-19 01:29:21 -04:00
parent 0b9524aa6d
commit 745b8c6376
12 changed files with 60 additions and 39 deletions

View file

@ -12,7 +12,6 @@
#include "../include/config.h" #include "../include/config.h"
#include "gesture.h" #include "gesture.h"
#include "list.h" #include "list.h"
#include "sway/desktop/fx_renderer/fx_renderer.h"
#include "swaynag.h" #include "swaynag.h"
#include "tree/container.h" #include "tree/container.h"
#include "sway/input/tablet.h" #include "sway/input/tablet.h"

View file

@ -36,8 +36,6 @@ struct decoration_data {
bool shadow; bool shadow;
}; };
struct decoration_data get_undecorated_decoration_data();
struct blur_shader { struct blur_shader {
GLuint program; GLuint program;
GLint proj; GLint proj;

View file

@ -1,5 +1,6 @@
#include <stdbool.h> #include <stdbool.h>
#include "sway/layers.h" #include "sway/layers.h"
#include "sway/config.h"
struct layer_criteria { struct layer_criteria {
char *namespace; char *namespace;

View file

@ -3,7 +3,6 @@
#include <stdbool.h> #include <stdbool.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_layer_shell_v1.h> #include <wlr/types/wlr_layer_shell_v1.h>
#include "sway/config.h"
enum layer_parent { enum layer_parent {
LAYER_PARENT_LAYER, LAYER_PARENT_LAYER,
@ -29,7 +28,9 @@ struct sway_layer_surface {
struct wl_list subsurfaces; struct wl_list subsurfaces;
struct decoration_data deco_data; bool has_shadow;
bool has_blur;
int corner_radius;
}; };
struct sway_layer_popup { struct sway_layer_popup {

View file

@ -17,7 +17,6 @@ struct render_data {
pixman_region32_t *damage; pixman_region32_t *damage;
struct wlr_box *clip_box; struct wlr_box *clip_box;
struct decoration_data deco_data; struct decoration_data deco_data;
struct sway_layer_surface *sway_layer;
}; };
struct sway_output_state { struct sway_output_state {

View file

@ -36,19 +36,6 @@ static const GLfloat verts[] = {
0, 1, // bottom left 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) { static GLuint compile_shader(GLuint type, const GLchar *src) {
GLuint shader = glCreateShader(type); GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, &src, NULL); glShaderSource(shader, 1, &src, NULL);

View file

@ -703,7 +703,9 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
sway_layer->layer_surface = layer_surface; sway_layer->layer_surface = layer_surface;
layer_surface->data = sway_layer; 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; struct sway_output *output = layer_surface->output->data;
sway_layer->output_destroy.notify = handle_output_destroy; sway_layer->output_destroy.notify = handle_output_destroy;

View file

@ -1,3 +1,4 @@
#include "sway/desktop/fx_renderer/fx_renderer.h"
#define _POSIX_C_SOURCE 200809L #define _POSIX_C_SOURCE 200809L
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
@ -199,9 +200,11 @@ void output_layer_for_each_toplevel_surface(struct sway_output *output,
wl_list_for_each(layer_surface, layer_surfaces, link) { wl_list_for_each(layer_surface, layer_surfaces, link) {
struct wlr_layer_surface_v1 *wlr_layer_surface_v1 = struct wlr_layer_surface_v1 *wlr_layer_surface_v1 =
layer_surface->layer_surface; layer_surface->layer_surface;
struct render_data *data = user_data; struct render_data *data = user_data;
data->sway_layer = layer_surface; data->deco_data.blur = layer_surface->has_blur;
data->deco_data = layer_surface->deco_data; 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, output_surface_for_each_surface(output, wlr_layer_surface_v1->surface,
layer_surface->geo.x, layer_surface->geo.y, iterator, layer_surface->geo.x, layer_surface->geo.y, iterator,

View file

@ -32,6 +32,19 @@
#include "sway/tree/view.h" #include "sway/tree/view.h"
#include "sway/tree/workspace.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() { int get_blur_size() {
return pow(2, config->blur_params.num_passes) * config->blur_params.radius; return pow(2, config->blur_params.num_passes) * config->blur_params.radius;
} }
@ -406,7 +419,6 @@ damage_finish:
pixman_region32_fini(&damage); pixman_region32_fini(&damage);
} }
static void render_surface_iterator(struct sway_output *output, static void render_surface_iterator(struct sway_output *output,
struct sway_view *view, struct wlr_surface *surface, struct sway_view *view, struct wlr_surface *surface,
struct wlr_box *_box, void *_data) { 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; struct decoration_data deco_data = data->deco_data;
deco_data.corner_radius *= wlr_output->scale; deco_data.corner_radius *= wlr_output->scale;
// render blur (view->surface == surface excludes blurring subsurfaces)
bool is_subsurface = false; bool is_subsurface = false;
bool should_optimize_blur = false; bool should_optimize_blur = false;
if (view) { if (view) {
is_subsurface = view->surface != surface; is_subsurface = view->surface != surface;
should_optimize_blur = !container_is_floating(view->container) || config->blur_xray; should_optimize_blur = !container_is_floating(view->container) || config->blur_xray;
} }
/*
TODO
if (data->sway_layer) { if (data->sway_layer) {
is_subsurface = data->sway_layer->layer_surface->surface != surface; is_subsurface = data->sway_layer->layer_surface->surface != surface;
enum zwlr_layer_shell_v1_layer layer = data->sway_layer->layer; 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_BOTTOM
&& layer != ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND; && layer != ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
} }
*/
// render blur
if (deco_data.blur && should_parameters_blur() && !is_subsurface) { if (deco_data.blur && should_parameters_blur() && !is_subsurface) {
pixman_region32_t opaque_region; pixman_region32_t opaque_region;
pixman_region32_init(&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_presentation_surface_sampled_on_output(server.presentation, surface,
wlr_output); wlr_output);
}
// render shadow (view->surface == surface excludes shadow on subsurfaces) static void render_layer_iterator(struct sway_output *output,
if (deco_data.shadow && should_parameters_shadow() && !is_subsurface && data->sway_layer) { 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; int corner_radius = deco_data.corner_radius;
render_box_shadow(output, output_damage, &dst_box, config->shadow_color, render_box_shadow(output, output_damage, &dst_box, config->shadow_color,
config->shadow_blur_sigma, corner_radius); 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(), .deco_data = get_undecorated_decoration_data(),
}; };
output_layer_for_each_toplevel_surface(output, layer_surfaces, 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, 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(), .deco_data = get_undecorated_decoration_data(),
}; };
output_layer_for_each_popup_surface(output, layer_surfaces, output_layer_for_each_popup_surface(output, layer_surfaces,
render_surface_iterator, &data); render_layer_iterator, &data);
} }
#if HAVE_XWAYLAND #if HAVE_XWAYLAND
@ -1467,6 +1498,7 @@ static void render_containers_tabbed(struct sway_output *output,
.saturation = current->saturation, .saturation = current->saturation,
.has_titlebar = true, .has_titlebar = true,
.blur = current->blur_enabled, .blur = current->blur_enabled,
.shadow = current->shadow_enabled,
}; };
// Render tabs // Render tabs
@ -1562,6 +1594,7 @@ static void render_containers_stacked(struct sway_output *output,
? 0 : current->corner_radius, ? 0 : current->corner_radius,
.has_titlebar = true, .has_titlebar = true,
.blur = current->blur_enabled, .blur = current->blur_enabled,
.shadow = current->shadow_enabled,
}; };
// Render titles // Render titles

View file

@ -374,14 +374,13 @@ static void ipc_json_describe_enabled_output(struct sway_output *output,
json_object_object_add(layer, "extent", extent); json_object_object_add(layer, "extent", extent);
json_object *effects = json_object_new_array(); json_object *effects = json_object_new_array();
struct decoration_data deco_data = lsurface->deco_data; if (lsurface->has_blur) {
if (deco_data.blur) {
json_object_array_add(effects, json_object_new_string("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")); 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_array_add(effects, json_object_new_string("corner_radius"));
} }
json_object_object_add(layer, "effects", effects); json_object_object_add(layer, "effects", effects);

View file

@ -65,15 +65,15 @@ void layer_criteria_parse(struct sway_layer_surface *sway_layer, struct layer_cr
} }
} }
if (strcmp(argv[0], "blur") == 0) { 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; continue;
} else if (strcmp(argv[0], "shadows") == 0) { } 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; continue;
} else if (strcmp(argv[0], "corner_radius") == 0) { } else if (strcmp(argv[0], "corner_radius") == 0) {
int value; int value;
if (cmd_corner_radius_parse_value(argv[1], &value)) { if (cmd_corner_radius_parse_value(argv[1], &value)) {
sway_layer->deco_data.corner_radius = value; sway_layer->corner_radius = value;
continue; continue;
} }
sway_log(SWAY_ERROR, sway_log(SWAY_ERROR,

View file

@ -715,8 +715,7 @@ bool should_workspace_have_blur(struct sway_workspace *ws) {
for (size_t i = 0; i < len; ++i) { for (size_t i = 0; i < len; ++i) {
struct sway_layer_surface *lsurface; struct sway_layer_surface *lsurface;
wl_list_for_each(lsurface, &sway_output->layers[i], link) { wl_list_for_each(lsurface, &sway_output->layers[i], link) {
if (lsurface->deco_data.blur if (lsurface->has_blur && !lsurface->layer_surface->surface->opaque
&& !lsurface->layer_surface->surface->opaque
&& lsurface->layer != ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND) { && lsurface->layer != ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND) {
return true; return true;
} }