feat: add shadow color for inactive windows (#230)

This commit is contained in:
eri 2023-10-23 16:58:47 +02:00 committed by GitHub
parent d89c365106
commit 2d6944dc14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 40 additions and 1 deletions

View file

@ -36,6 +36,7 @@ Sway is an incredible window manager, and certainly one of the most well establi
- `shadows_on_csd enable|disable` (**Note**: The shadow might not fit some windows)
- `shadow_blur_radius <integer value 0 - 100>`
- `shadow_color <hex color with alpha> ex, #0000007F`
- `shadow_inactive_color <hex color with alpha> ex, #0000007F`
+ LayerShell effects (to blur panels / notifications etc):
- `layer_effects <layer namespace> <effects>`
- The current layer namespaces can be shown with `swaymsg -r -t get_outputs | jq '.[0].layer_shell_surfaces | .[] | .namespace'`

View file

@ -192,6 +192,7 @@ sway_cmd cmd_set;
sway_cmd cmd_shortcuts_inhibitor;
sway_cmd cmd_shadow_blur_radius;
sway_cmd cmd_shadow_color;
sway_cmd cmd_shadow_inactive_color;
sway_cmd cmd_shadows;
sway_cmd cmd_shadows_on_csd;
sway_cmd cmd_show_marks;

View file

@ -492,6 +492,7 @@ struct sway_config {
bool shadows_on_csd_enabled;
int shadow_blur_sigma;
float shadow_color[4];
float shadow_inactive_color[4];
bool blur_enabled;
bool blur_xray;

View file

@ -96,6 +96,7 @@ static const struct cmd_handler handlers[] = {
{ "set", cmd_set },
{ "shadow_blur_radius", cmd_shadow_blur_radius },
{ "shadow_color", cmd_shadow_color },
{ "shadow_inactive_color", cmd_shadow_inactive_color },
{ "shadows", cmd_shadows },
{ "shadows_on_csd", cmd_shadows_on_csd },
{ "show_marks", cmd_show_marks },

View file

@ -17,6 +17,9 @@ struct cmd_results *cmd_shadow_color(int argc, char **argv) {
return cmd_results_new(CMD_INVALID, "Invalid %s color %s",
"shadow_color", argv[0]);
}
if (memcmp(config->shadow_color, config->shadow_inactive_color, sizeof(config->shadow_color)) == 0) {
color_to_rgba(config->shadow_inactive_color, color);
}
color_to_rgba(config->shadow_color, color);
arrange_root();

View file

@ -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_inactive_color(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "shadow_inactive_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_inactive_color", argv[0]);
}
color_to_rgba(config->shadow_inactive_color, color);
arrange_root();
return cmd_results_new(CMD_SUCCESS, NULL);
}

View file

@ -352,6 +352,7 @@ static void config_defaults(struct sway_config *config) {
config->shadows_on_csd_enabled = false;
config->shadow_blur_sigma = 20.0f;
color_to_rgba(config->shadow_color, 0x0000007F);
color_to_rgba(config->shadow_inactive_color, 0x0000007F);
config->blur_enabled = false;
config->blur_xray = false;

View file

@ -884,7 +884,9 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
scale_box(&box, output_scale);
int scaled_corner_radius = deco_data.corner_radius == 0 ?
0 : (deco_data.corner_radius + state->border_thickness) * output_scale;
render_box_shadow(output, damage, &box, config->shadow_color, config->shadow_blur_sigma,
float* shadow_color = view_is_urgent(view) || state->focused ?
config->shadow_color : config->shadow_inactive_color;
render_box_shadow(output, damage, &box, shadow_color, config->shadow_blur_sigma,
scaled_corner_radius);
}

View file

@ -123,6 +123,7 @@ sway_sources = files(
'commands/set.c',
'commands/shadow_blur_radius.c',
'commands/shadow_color.c',
'commands/shadow_inactive_color.c',
'commands/shadows.c',
'commands/shadows_on_csd.c',
'commands/show_marks.c',

View file

@ -686,6 +686,9 @@ The default colors are:
*shadow_color* <hex color with alpha>
The shadow color. Default color: #0000007F
*shadow_inactive_color* <hex color with alpha>
The shadow color for inactive windows. Default value: *shadow_color*
*blur* enable|disable
Sets whether blur should be drawn. Can also be set per window with
*for_window*.