Merge pull request #150 from DreamMaoMao/tile_shadow

feat: add tile shadow option
This commit is contained in:
DreamMaoMao 2025-07-05 17:36:30 +08:00 committed by GitHub
commit 0b46a34db3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 63 additions and 13 deletions

View file

@ -13,6 +13,7 @@ blur_params_saturation = 1.2
shadows = 0
layer_shadows = 0
shadow_only_floating = 1
shadows_size = 10
shadows_blur = 15
shadows_position_x = 0

View file

@ -217,6 +217,7 @@ typedef struct {
int border_radius;
struct blur_data blur_params;
int shadows;
int shadow_only_floating;
int layer_shadows;
unsigned int shadows_size;
float shadows_blur;
@ -940,6 +941,8 @@ void parse_config_line(Config *config, const char *line) {
config->blur_params.saturation = atof(value);
} else if (strcmp(key, "shadows") == 0) {
config->shadows = atoi(value);
} else if (strcmp(key, "shadow_only_floating") == 0) {
config->shadow_only_floating = atoi(value);
} else if (strcmp(key, "layer_shadows") == 0) {
config->layer_shadows = atoi(value);
} else if (strcmp(key, "shadows_size") == 0) {
@ -2218,6 +2221,7 @@ void override_config(void) {
blur_params.contrast = CLAMP_FLOAT(config.blur_params.contrast, 0, 1);
blur_params.saturation = CLAMP_FLOAT(config.blur_params.saturation, 0, 1);
shadows = CLAMP_INT(config.shadows, 0, 1);
shadow_only_floating = CLAMP_INT(config.shadow_only_floating, 0, 1);
layer_shadows = CLAMP_INT(config.layer_shadows, 0, 1);
shadows_size = CLAMP_INT(config.shadows_size, 0, 100);
shadows_blur = CLAMP_INT(config.shadows_blur, 0, 100);
@ -2358,6 +2362,7 @@ void set_value_default() {
config.blur_params.contrast = blur_params_contrast;
config.blur_params.saturation = blur_params_saturation;
config.shadows = shadows;
config.shadow_only_floating = shadow_only_floating;
config.layer_shadows = layer_shadows;
config.shadows_size = shadows_size;
config.shadows_blur = shadows_blur;

View file

@ -192,6 +192,7 @@ float blur_params_contrast = 0.9;
float blur_params_saturation = 1.2;
int shadows = 0;
int shadow_only_floating = 1;
int layer_shadows = 0;
unsigned int shadows_size = 10;
double shadows_blur = 15;

View file

@ -1214,7 +1214,7 @@ void client_draw_shadow(Client *c) {
if (c->iskilling || !client_surface(c)->mapped)
return;
if (!shadows || !c->isfloating) {
if (!shadows || (!c->isfloating && shadow_only_floating)) {
wlr_scene_shadow_set_size(c->shadow, 0, 0);
return;
}
@ -1252,9 +1252,43 @@ void client_draw_shadow(Client *c) {
.corners = border_radius_location_default,
};
wlr_scene_node_set_position(&c->shadow->node, shadow_box.x, shadow_box.y);
struct wlr_box absolute_shadow_box = {
.x = shadow_box.x + c->animation.current.x,
.y = shadow_box.y + c->animation.current.y,
.width = shadow_box.width,
.height = shadow_box.height,
};
wlr_scene_shadow_set_size(c->shadow, shadow_box.width, shadow_box.height);
int right_offset, bottom_offset, left_offset, top_offset;
if (c == grabc) {
right_offset = 0;
bottom_offset = 0;
left_offset = 0;
top_offset = 0;
} else {
right_offset =
GEZERO(absolute_shadow_box.x + absolute_shadow_box.width -
c->mon->m.x - c->mon->m.width);
bottom_offset =
GEZERO(absolute_shadow_box.y + absolute_shadow_box.height -
c->mon->m.y - c->mon->m.height);
left_offset = GEZERO(c->mon->m.x - absolute_shadow_box.x);
top_offset = GEZERO(c->mon->m.y - absolute_shadow_box.y);
}
left_offset = MIN(left_offset, shadow_box.width);
right_offset = MIN(right_offset, shadow_box.width);
top_offset = MIN(top_offset, shadow_box.height);
bottom_offset = MIN(bottom_offset, shadow_box.height);
wlr_scene_node_set_position(&c->shadow->node, shadow_box.x + left_offset,
shadow_box.y + top_offset);
wlr_scene_shadow_set_size(
c->shadow, GEZERO(shadow_box.width - left_offset - right_offset),
GEZERO(shadow_box.height - top_offset - bottom_offset));
wlr_scene_shadow_set_clipped_region(c->shadow, clipped_region);
}
@ -1287,15 +1321,24 @@ void apply_border(Client *c) {
// 一但在GEZERO如果使用无符号那么其他数据也会转换为无符号导致没有负数出错
int bw = (int)c->bw;
int right_offset =
GEZERO(c->animation.current.x + c->animation.current.width -
c->mon->m.x - c->mon->m.width);
int bottom_offset =
GEZERO(c->animation.current.y + c->animation.current.height -
c->mon->m.y - c->mon->m.height);
int right_offset, bottom_offset, left_offset, top_offset;
int left_offset = GEZERO(c->mon->m.x - c->animation.current.x);
int top_offset = GEZERO(c->mon->m.y - c->animation.current.y);
if (c == grabc) {
right_offset = 0;
bottom_offset = 0;
left_offset = 0;
top_offset = 0;
} else {
right_offset =
GEZERO(c->animation.current.x + c->animation.current.width -
c->mon->m.x - c->mon->m.width);
bottom_offset =
GEZERO(c->animation.current.y + c->animation.current.height -
c->mon->m.y - c->mon->m.height);
left_offset = GEZERO(c->mon->m.x - c->animation.current.x);
top_offset = GEZERO(c->mon->m.y - c->animation.current.y);
}
int inner_surface_width = GEZERO(clip_box.width - 2 * bw);
int inner_surface_height = GEZERO(clip_box.height - 2 * bw);
@ -1585,8 +1628,8 @@ bool client_draw_frame(Client *c) {
} else {
wlr_scene_node_set_position(&c->scene->node, c->pending.x,
c->pending.y);
c->animainit_geom = c->animation.initial = c->pending = c->current =
c->geom;
c->animation.current = c->animainit_geom = c->animation.initial =
c->pending = c->current = c->geom;
client_apply_clip(c);
c->need_output_flush = false;
}