Add option for enabling shadows for CSD windows (#106)

* Add option for enabling shadows for CSD windows

* Disable drawing borders when CSD and shadows csd is enabled
This commit is contained in:
Erik Reider 2023-02-01 01:13:04 +01:00 committed by GitHub
parent 9345749a90
commit 3efd3b558f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 37 additions and 3 deletions

View file

@ -16,6 +16,7 @@ Sway is an incredible window manager, and certainly one of the most well establi
+ Application saturation: `for_window [CRITERIA HERE] saturation <set|plus|minus> <val 0.0 <-> 2.0>`
+ Window shadows: *ONLY ON SWAYFX-GIT, NOT YET RELEASED*
- `shadows on|off`
- `shadows_on_csd on|off` (**Note**: The shadow might not fit some windows)
- `shadow_blur_radius <integer value 0 - 100>`
- `shadow_color <hex color with alpha> ex, #0000007F`
+ Dim unfocused windows:

View file

@ -25,6 +25,7 @@ set $menu dmenu_path | dmenu | xargs swaymsg exec --
corner_radius 10
shadows off
shadows_on_csd off
shadow_blur_radius 20
shadow_color #0000007F

View file

@ -181,6 +181,7 @@ sway_cmd cmd_shortcuts_inhibitor;
sway_cmd cmd_shadow_blur_radius;
sway_cmd cmd_shadow_color;
sway_cmd cmd_shadows;
sway_cmd cmd_shadows_on_csd;
sway_cmd cmd_show_marks;
sway_cmd cmd_smart_borders;
sway_cmd cmd_smart_corner_radius;

View file

@ -484,6 +484,7 @@ struct sway_config {
float urgent[4];
} dim_inactive_colors;
bool shadow_enabled;
bool shadows_on_csd_enabled;
int shadow_blur_sigma;
float shadow_color[4];

View file

@ -91,6 +91,7 @@ static const struct cmd_handler handlers[] = {
{ "shadow_blur_radius", cmd_shadow_blur_radius },
{ "shadow_color", cmd_shadow_color },
{ "shadows", cmd_shadows },
{ "shadows_on_csd", cmd_shadows_on_csd },
{ "show_marks", cmd_show_marks },
{ "smart_borders", cmd_smart_borders },
{ "smart_corner_radius", cmd_smart_corner_radius },

View file

@ -0,0 +1,23 @@
#include <string.h>
#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_on_csd(int argc, char **argv) {
struct cmd_results *error = checkarg(argc, "shadows_on_csd", EXPECTED_AT_LEAST, 1);
if (error) {
return error;
}
config->shadows_on_csd_enabled = parse_boolean(argv[0], config->shadows_on_csd_enabled);
arrange_root();
return cmd_results_new(CMD_SUCCESS, NULL);
}

View file

@ -340,6 +340,7 @@ static void config_defaults(struct sway_config *config) {
color_to_rgba(config->dim_inactive_colors.unfocused, 0x000000FF);
color_to_rgba(config->dim_inactive_colors.urgent, 0x900000FF);
config->shadow_enabled = false;
config->shadows_on_csd_enabled = false;
config->shadow_blur_sigma = 20.0f;
color_to_rgba(config->shadow_color, 0x0000007F);

View file

@ -489,8 +489,8 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
render_view_toplevels(view, output, damage, deco_data);
}
// if CSD borders, don't render borders or shadow
if (con->current.border == B_CSD) {
// Only draw shadows on CSD windows if shadows_on_csd is enabled
if (con->current.border == B_CSD && !config->shadows_on_csd_enabled) {
return;
}
@ -504,7 +504,7 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
state->border_thickness);
}
if (con->current.border == B_NONE) {
if (con->current.border == B_NONE || con->current.border == B_CSD) {
return;
}

View file

@ -110,6 +110,7 @@ sway_sources = files(
'commands/shadow_blur_radius.c',
'commands/shadow_color.c',
'commands/shadows.c',
'commands/shadows_on_csd.c',
'commands/show_marks.c',
'commands/shortcuts_inhibitor.c',
'commands/smart_borders.c',

View file

@ -666,6 +666,10 @@ The default colors are:
Adjusts if shadows should be enabled or not (on|off). Can also be set per
window with *for_window*.
*shadows_on_csd* <value>
Adjusts if shadows should be drawn on windows that draw their own
decorations (on|off). *Note:* The shadow might not fit some windows.
*shadow_blur_radius* <value>
Adjusts the shadow blur radius of windows between 0 (disabled) and 100
while 20 is the default value.