diff --git a/README.md b/README.md index 81109c407..7533796cc 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ Sway is an incredible window manager, and certainly one of the most well establi blur_xray enable; blur_ignore_transparent enable; shadows enable; + use_drop_shadow enable; corner_radius 20; } ``` @@ -61,6 +62,7 @@ Sway is an incredible window manager, and certainly one of the most well establi - `blur_xray ` - `blur_ignore_transparent ` - `shadows ` + - `use_drop_shadow ` - `corner_radius ` - `reset`: To reset/disable all previously applied effects to the layer application + Dim unfocused windows: diff --git a/include/sway/layer_criteria.h b/include/sway/layer_criteria.h index 554a482d6..34ed9e191 100644 --- a/include/sway/layer_criteria.h +++ b/include/sway/layer_criteria.h @@ -5,6 +5,7 @@ struct layer_criteria { char *cmdlist; bool shadow_enabled; + bool use_drop_shadow; bool blur_enabled; bool blur_xray; bool blur_ignore_transparent; diff --git a/include/sway/layers.h b/include/sway/layers.h index edc7e65ef..908b329a6 100644 --- a/include/sway/layers.h +++ b/include/sway/layers.h @@ -26,6 +26,7 @@ struct sway_layer_surface { struct wlr_layer_surface_v1 *layer_surface; bool shadow_enabled; + bool use_drop_shadow; bool blur_enabled; bool blur_xray; bool blur_ignore_transparent; diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index 76b4e4e7e..671a9cfe1 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c @@ -60,6 +60,7 @@ void layer_apply_criteria(struct sway_layer_surface *surface, struct layer_crite surface->blur_xray = criteria->blur_xray; surface->blur_ignore_transparent = criteria->blur_ignore_transparent; surface->shadow_enabled = criteria->shadow_enabled; + surface->use_drop_shadow = criteria->use_drop_shadow; } else { // Reset surface->corner_radius = 0; @@ -67,6 +68,7 @@ void layer_apply_criteria(struct sway_layer_surface *surface, struct layer_crite surface->blur_xray = false; surface->blur_ignore_transparent = false; surface->shadow_enabled = false; + surface->use_drop_shadow = false; } } @@ -99,26 +101,27 @@ static void arrange_surface(struct sway_output *output, const struct wlr_box *fu } wlr_scene_node_set_enabled(&surface->shadow_node->node, surface->shadow_enabled); - if (surface->shadow_enabled) { - // Adjust the size and position of the shadow node - wlr_scene_shadow_set_size(surface->shadow_node, - surface->layer_surface->surface->current.width + config->shadow_blur_sigma * 2, - surface->layer_surface->surface->current.height + config->shadow_blur_sigma * 2); - int x = config->shadow_offset_x - config->shadow_blur_sigma; - int y = config->shadow_offset_y - config->shadow_blur_sigma; - wlr_scene_node_set_position(&surface->shadow_node->node, x, y); - - wlr_scene_shadow_set_clipped_region(surface->shadow_node, (struct clipped_region) { - .corner_radius = surface->corner_radius, - .corners = CORNER_LOCATION_ALL, - .area = { - .x = -x, - .y = -y, - .width = surface->layer_surface->surface->current.width, - .height = surface->layer_surface->surface->current.height, - }, - }); - } + wlr_scene_shadow_set_type(surface->shadow_node, + surface->use_drop_shadow ? WLR_SCENE_SHADOW_TYPE_DROP : WLR_SCENE_SHADOW_TYPE_BOX); + // Adjust the size and position of the shadow node + const int shadow_size = wlr_scene_shadow_get_offset(surface->shadow_node); + wlr_scene_shadow_set_size(surface->shadow_node, + surface->layer_surface->surface->current.width + shadow_size * 2, + surface->layer_surface->surface->current.height + shadow_size * 2); + int x = config->shadow_offset_x - shadow_size; + int y = config->shadow_offset_y - shadow_size; + wlr_scene_node_set_position(&surface->shadow_node->node, x, y); + + wlr_scene_shadow_set_clipped_region(surface->shadow_node, (struct clipped_region) { + .corner_radius = surface->corner_radius, + .corners = CORNER_LOCATION_ALL, + .area = { + .x = -x, + .y = -y, + .width = surface->layer_surface->surface->current.width, + .height = surface->layer_surface->surface->current.height, + }, + }); wlr_scene_layer_surface_v1_configure(surface->scene, full_area, usable_area); } @@ -240,6 +243,7 @@ static struct sway_layer_surface *sway_layer_surface_create( surface->blur_xray = false; surface->blur_ignore_transparent = false; surface->shadow_enabled = false; + surface->use_drop_shadow = false; bool failed = false; surface->shadow_node = alloc_scene_shadow(surface->tree, 0, 0, diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 03d99eaac..a617f9cf4 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -279,6 +279,9 @@ void output_configure_scene(struct sway_output *output, struct wlr_scene_node *n wlr_scene_buffer_set_corner_radius(buffer, surface->corner_radius, CORNER_LOCATION_ALL); wlr_scene_shadow_set_blur_sigma(surface->shadow_node, config->shadow_blur_sigma); wlr_scene_shadow_set_corner_radius(surface->shadow_node, surface->corner_radius); + if (surface->shadow_node->type == WLR_SCENE_SHADOW_TYPE_DROP) { + wlr_scene_shadow_set_reference_buffer(surface->shadow_node, buffer); + } wlr_scene_buffer_set_backdrop_blur(buffer, surface->blur_enabled); wlr_scene_buffer_set_backdrop_blur_ignore_transparent(buffer, surface->blur_ignore_transparent); wlr_scene_buffer_set_backdrop_blur_optimized(buffer, surface->blur_xray); diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index 9efa5143e..dd2d13ff3 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c @@ -417,12 +417,12 @@ static void arrange_container(struct sway_container *con, corner_radius = con->corner_radius + config->border_thickness; } + const int shadow_size = wlr_scene_shadow_get_offset(con->shadow); wlr_scene_shadow_set_size(con->shadow, - width + config->shadow_blur_sigma * 2, - height + config->shadow_blur_sigma * 2); + width + shadow_size * 2, height + shadow_size * 2); - int x = config->shadow_offset_x - config->shadow_blur_sigma; - int y = config->shadow_offset_y - config->shadow_blur_sigma; + int x = config->shadow_offset_x - shadow_size; + int y = config->shadow_offset_y - shadow_size; wlr_scene_node_set_position(&con->shadow->node, x, y); wlr_scene_shadow_set_clipped_region(con->shadow, (struct clipped_region) { diff --git a/sway/layer_criteria.c b/sway/layer_criteria.c index 56521693f..c92e3eda4 100644 --- a/sway/layer_criteria.c +++ b/sway/layer_criteria.c @@ -13,6 +13,7 @@ static void init_criteria_effects(struct layer_criteria *criteria) { criteria->blur_xray = false; criteria->blur_ignore_transparent = false; criteria->shadow_enabled = false; + criteria->use_drop_shadow = false; } static void copy_criteria_effects(struct layer_criteria *dst, struct layer_criteria *src) { @@ -21,6 +22,7 @@ static void copy_criteria_effects(struct layer_criteria *dst, struct layer_crite dst->blur_xray = src->blur_xray; dst->blur_ignore_transparent = src->blur_ignore_transparent; dst->shadow_enabled = src->shadow_enabled; + dst->use_drop_shadow = src->use_drop_shadow; } static bool layer_criteria_find(char *namespace, @@ -81,6 +83,9 @@ static bool layer_criteria_parse(struct layer_criteria *criteria) { } else if (strcmp(argv[0], "shadows") == 0) { criteria->shadow_enabled = parse_boolean(argv[1], true); continue; + } else if (strcmp(argv[0], "use_drop_shadow") == 0) { + criteria->use_drop_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)) { diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 4ecfcc96d..8dd92a85f 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -862,6 +862,7 @@ The default colors are: - *blur_xray* - *blur_ignore_transparent* - *shadows* + - *use_drop_shadow* - *corner_radius* - *reset* Resets all previously applied effects - *reset* To reset/disable all previously applied effects to the layer application @@ -873,6 +874,7 @@ The default colors are: blur_xray enable; blur_ignore_transparent enable; shadows enable; + use_drop_shadow enable; corner_radius 6; }