From e3c9c784b6ce4241db5d4839c2cee055c287b8a2 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sat, 5 Jul 2025 15:24:12 +0800 Subject: [PATCH 1/2] feat: add shadow_only_floating option --- config.conf | 1 + src/config/parse_config.h | 5 +++++ src/config/preset.h | 1 + src/maomao.c | 2 +- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config.conf b/config.conf index 87eb814..7aa1dd4 100644 --- a/config.conf +++ b/config.conf @@ -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 diff --git a/src/config/parse_config.h b/src/config/parse_config.h index e6fdf4c..17c8a75 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -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; diff --git a/src/config/preset.h b/src/config/preset.h index 9468074..ae854e7 100644 --- a/src/config/preset.h +++ b/src/config/preset.h @@ -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; diff --git a/src/maomao.c b/src/maomao.c index ef23986..8742fcb 100644 --- a/src/maomao.c +++ b/src/maomao.c @@ -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; } From 239fcd64eb7143f5ddb34568cda36084afb7cf74 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sat, 5 Jul 2025 16:18:41 +0800 Subject: [PATCH 2/2] fix: optimize border clip and fix shadow miss clip --- src/maomao.c | 67 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/src/maomao.c b/src/maomao.c index 8742fcb..af43429 100644 --- a/src/maomao.c +++ b/src/maomao.c @@ -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; }