diff --git a/README.md b/README.md index cf082ccf..a2deb1b6 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,11 @@ Sway is an incredible window manager, and certainly one of the most well establi + Corner radius: `corner_radius ` + Application saturation: `for_window [CRITERIA HERE] saturation 2.0>` -+ Dim unfocused windows: ++ Window shadows: + - `shadows on|off` + - `shadow_blur_radius ` + - `shadow_color ex, #0000007F` ++ Dim unfocused windows: - `dim_inactive ` - `dim_inactive_colors.unfocused ex, #000000FF` - `dim_inactive_colors.urgent ex, #900000FF` @@ -23,7 +27,6 @@ Sway is an incredible window manager, and certainly one of the most well establi + fade in / out animations + window movement animations -+ drop shadows + blur ## Installation diff --git a/config.in b/config.in index f1a23036..5351d6bd 100644 --- a/config.in +++ b/config.in @@ -24,6 +24,10 @@ set $menu dmenu_path | dmenu | xargs swaymsg exec -- # window corner radius in px corner_radius 10 +shadows off +shadow_blur_radius 20 +shadow_color #0000007F + # inactive window fade amount. 0.0 = no dimming, 1.0 = fully dimmed dim_inactive 0.0 dim_inactive_colors.unfocused #000000FF diff --git a/include/sway/commands.h b/include/sway/commands.h index 86856fcf..5ab84e25 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -177,6 +177,9 @@ sway_cmd cmd_scratchpad; sway_cmd cmd_seamless_mouse; sway_cmd cmd_set; sway_cmd cmd_shortcuts_inhibitor; +sway_cmd cmd_shadow_blur_radius; +sway_cmd cmd_shadow_color; +sway_cmd cmd_shadows; sway_cmd cmd_show_marks; sway_cmd cmd_smart_borders; sway_cmd cmd_smart_gaps; diff --git a/include/sway/config.h b/include/sway/config.h index 4ec035c2..37e135fb 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -474,6 +474,9 @@ struct sway_config { float unfocused[4]; float urgent[4]; } dim_inactive_colors; + bool shadow_enabled; + int shadow_blur_sigma; + float shadow_color[4]; char *swaynag_command; struct swaynag_instance swaynag_config_errors; diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index ebe9568c..37504d39 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -113,6 +113,8 @@ struct sway_container { // Hidden scratchpad containers have a NULL parent. bool scratchpad; + bool shadow_enabled; + float saturation; float alpha; diff --git a/sway/commands.c b/sway/commands.c index 91e559a1..dddba83a 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -87,6 +87,9 @@ static const struct cmd_handler handlers[] = { { "popup_during_fullscreen", cmd_popup_during_fullscreen }, { "seat", cmd_seat }, { "set", cmd_set }, + { "shadow_blur_radius", cmd_shadow_blur_radius }, + { "shadow_color", cmd_shadow_color }, + { "shadows", cmd_shadows }, { "show_marks", cmd_show_marks }, { "smart_borders", cmd_smart_borders }, { "smart_gaps", cmd_smart_gaps }, diff --git a/sway/commands/shadow_blur_radius.c b/sway/commands/shadow_blur_radius.c new file mode 100644 index 00000000..036341f8 --- /dev/null +++ b/sway/commands/shadow_blur_radius.c @@ -0,0 +1,25 @@ +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/tree/arrange.h" +#include "sway/tree/container.h" +#include "log.h" + +struct cmd_results *cmd_shadow_blur_radius(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "shadow_blur_radius", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + char *inv; + int value = strtol(argv[0], &inv, 10); + if (*inv != '\0' || value < 0 || value > 99) { + return cmd_results_new(CMD_FAILURE, "Invalid size specified"); + } + + config->shadow_blur_sigma = value; + + arrange_root(); + + return cmd_results_new(CMD_SUCCESS, NULL); +} diff --git a/sway/commands/shadow_color.c b/sway/commands/shadow_color.c new file mode 100644 index 00000000..02952bdd --- /dev/null +++ b/sway/commands/shadow_color.c @@ -0,0 +1,25 @@ +#include "log.h" +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/output.h" +#include "sway/tree/arrange.h" +#include "sway/tree/container.h" +#include "util.h" + +struct cmd_results *cmd_shadow_color(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "shadow_color", EXPECTED_AT_LEAST, 1))) { + return error; + } + + uint32_t color; + if (!parse_color(argv[0], &color)) { + return cmd_results_new(CMD_INVALID, "Invalid %s color %s", + "shadow_color", argv[0]); + } + color_to_rgba(config->shadow_color, color); + + arrange_root(); + + return cmd_results_new(CMD_SUCCESS, NULL); +} diff --git a/sway/commands/shadows.c b/sway/commands/shadows.c new file mode 100644 index 00000000..2b57b2e6 --- /dev/null +++ b/sway/commands/shadows.c @@ -0,0 +1,31 @@ +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/tree/arrange.h" +#include "sway/tree/view.h" +#include "sway/tree/container.h" +#include "log.h" +#include "stringop.h" +#include "util.h" + +struct cmd_results *cmd_shadows(int argc, char **argv) { + struct cmd_results *error = checkarg(argc, "shadows", EXPECTED_AT_LEAST, 1); + + if (error) { + return error; + } + + struct sway_container *con = config->handler_context.container; + + bool result = parse_boolean(argv[0], config->shadow_enabled); + if (con == NULL) { + config->shadow_enabled = result; + } else { + con->shadow_enabled = result; + container_damage_whole(con); + } + + arrange_root(); + + return cmd_results_new(CMD_SUCCESS, NULL); +} diff --git a/sway/config.c b/sway/config.c index f7ff49b3..7fb5d68a 100644 --- a/sway/config.c +++ b/sway/config.c @@ -330,6 +330,9 @@ static void config_defaults(struct sway_config *config) { config->dim_inactive = 0.0f; color_to_rgba(config->dim_inactive_colors.unfocused, 0x000000FF); color_to_rgba(config->dim_inactive_colors.urgent, 0x900000FF); + config->shadow_enabled = false; + config->shadow_blur_sigma = 20.0f; + color_to_rgba(config->shadow_color, 0x0000007F); // The keysym to keycode translation struct xkb_rule_names rules = {0}; diff --git a/sway/desktop/render.c b/sway/desktop/render.c index 0de870bf..3b9054fa 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -1008,12 +1008,15 @@ static void render_containers_linear(struct sway_output *output, } // render shadow - const float color[4] = {0.0, 0.0, 0.0, 0.5}; - float blur_sigma = 20; - struct wlr_box box = { state->x, state->y, state->width, state->height }; - scale_box(&box, output->wlr_output->scale); - render_box_shadow(output, damage, &box, color, blur_sigma, - deco_data.corner_radius, child->current.border_thickness); + if (child->shadow_enabled + && config->shadow_blur_sigma > 0 + && config->shadow_color[3] > 0.0) { + struct wlr_box box = { state->x, state->y, state->width, state->height }; + scale_box(&box, output->wlr_output->scale); + render_box_shadow(output, damage, &box, config->shadow_color, + config->shadow_blur_sigma, deco_data.corner_radius, + child->current.border_thickness); + } } else { render_container(output, damage, child, parent->focused || child->current.focused); diff --git a/sway/meson.build b/sway/meson.build index ac3d408d..e71b5ef2 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -103,6 +103,9 @@ sway_sources = files( 'commands/seat/shortcuts_inhibitor.c', 'commands/seat/xcursor_theme.c', 'commands/set.c', + 'commands/shadow_blur_radius.c', + 'commands/shadow_color.c', + 'commands/shadows.c', 'commands/show_marks.c', 'commands/shortcuts_inhibitor.c', 'commands/smart_borders.c', diff --git a/sway/sway.5.scd b/sway/sway.5.scd index bf936a27..afff4891 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -598,6 +598,17 @@ The default colors are: *dim_inactive_colors.urgent* The color to dim inactive urgent windows with. Example color: #900000FF +*shadows* + Adjusts if shadows should be enabled or not (on|off). Can also be set per + window with *for_window*. + +*shadow_blur_radius* + Adjusts the shadow blur radius of windows between 0 (disabled) and 100 + while 20 is the default value. + +*shadow_color* + The shadow color. Default color: #0000007F + *default_border* normal|none|pixel [] Set default border style for new tiled windows. diff --git a/sway/tree/container.c b/sway/tree/container.c index 73bb865c..6ed0e2d3 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -41,6 +41,7 @@ struct sway_container *container_create(struct sway_view *view) { c->view = view; c->alpha = 1.0f; c->saturation = 1.0f; + c->shadow_enabled = config->shadow_enabled; c->corner_radius = config->corner_radius; if (!view) {