@@ -58,6 +58,7 @@ enum wlr_scene_node_type {
5858 WLR_SCENE_NODE_TREE ,
5959 WLR_SCENE_NODE_RECT ,
6060 WLR_SCENE_NODE_SHADOW ,
61+ WLR_SCENE_NODE_DROP_SHADOW ,
6162 WLR_SCENE_NODE_BUFFER ,
6263 WLR_SCENE_NODE_OPTIMIZED_BLUR ,
6364 WLR_SCENE_NODE_BLUR ,
@@ -162,9 +163,20 @@ struct wlr_scene_shadow {
162163 float color [4 ];
163164 float blur_sigma ;
164165
166+ struct clipped_region clipped_region ;
167+ };
168+
169+ /** A scene-graph node displaying a dynamic drop-shadow */
170+ struct wlr_scene_drop_shadow {
171+ struct wlr_scene_node node ;
172+ int width , height ;
173+ float color [4 ];
174+ float blur_sigma ;
175+
165176 struct {
166- // Used to draw a drop-shadow
167- struct linked_node buffer_link ;
177+ float blur_sample_size ;
178+ // Skips drawing if NULL
179+ struct linked_node buffer_source ;
168180 } WLR_PRIVATE ;
169181
170182 struct clipped_region clipped_region ;
@@ -182,7 +194,9 @@ struct wlr_scene_blur {
182194
183195 bool should_only_blur_bottom_layer ;
184196
185- struct linked_node transparency_mask_source ;
197+ struct {
198+ struct linked_node transparency_mask_source ;
199+ } WLR_PRIVATE ;
186200};
187201
188202/** A scene-graph node telling SceneFX to render the optimized blur */
@@ -261,7 +275,7 @@ struct wlr_scene_buffer {
261275
262276 struct linked_node blur ;
263277 // Used to know which shadow's linked to this scene_buffer
264- struct linked_node drop_shadow_link ;
278+ struct linked_node drop_shadow ;
265279 } WLR_PRIVATE ;
266280};
267281
@@ -496,6 +510,16 @@ struct wlr_scene_rect *wlr_scene_rect_from_node(struct wlr_scene_node *node);
496510 */
497511struct wlr_scene_shadow * wlr_scene_shadow_from_node (struct wlr_scene_node * node );
498512
513+ /**
514+ * If this node represents a wlr_scene_drop_shadow, that shadow will be returned. It
515+ * is not legal to feed a node that does not represent a wlr_scene_drop_shadow.
516+ */
517+ struct wlr_scene_drop_shadow * wlr_scene_drop_shadow_from_node (struct wlr_scene_node * node );
518+
519+ /**
520+ * If this node represents a wlr_scene_blur node, that blur node will be returned.
521+ * It is not legal to feed a node that does not represent a wlr_scene_blur node.
522+ */
499523struct wlr_scene_blur * wlr_scene_blur_from_node (struct wlr_scene_node * node );
500524
501525/**
@@ -547,8 +571,7 @@ void wlr_scene_rect_set_clipped_region(struct wlr_scene_rect *rect,
547571void wlr_scene_rect_set_color (struct wlr_scene_rect * rect , const float color [static 4 ]);
548572
549573/**
550- * Add a node displaying a shadow to the scene-graph. The shadow type created is
551- * a regular box-shadow.
574+ * Add a node displaying a shadow to the scene-graph.
552575 */
553576struct wlr_scene_shadow * wlr_scene_shadow_create (struct wlr_scene_tree * parent ,
554577 int width , int height , int corner_radius , float blur_sigma ,
@@ -574,39 +597,97 @@ void wlr_scene_shadow_set_blur_sigma(struct wlr_scene_shadow *shadow, float blur
574597 */
575598void wlr_scene_shadow_set_color (struct wlr_scene_shadow * shadow , const float color [static 4 ]);
576599
600+ /**
601+ * Sets the region where to clip the shadow.
602+ *
603+ * For there to be corner rounding of the clipped region, the corner radius and
604+ * corners must be non-zero.
605+ *
606+ * NOTE: The positioning is node-relative.
607+ */
608+ void wlr_scene_shadow_set_clipped_region (struct wlr_scene_shadow * shadow ,
609+ struct clipped_region clipped_region );
610+
611+ /**
612+ * Add a node displaying a drop shadow to the scene-graph.
613+ *
614+ * It's recommended to use `wlr_scene_drop_shadow_calculate_offset` when first
615+ * setting the size and adjusting the nodes position.
616+ *
617+ * NOTE: A reference `wlr_scene_buffer` needs to be set using
618+ * `wlr_scene_drop_shadow_set_reference_buffer` for the shadow to render.
619+ */
620+ struct wlr_scene_drop_shadow * wlr_scene_drop_shadow_create (struct wlr_scene_tree * parent ,
621+ int width , int height , float blur_sigma , const float color [static 4 ]);
622+
623+ /**
624+ * Change the width and height of an existing drop shadow node.
625+ *
626+ * NOTE: The set size of the node doesn't include the blur sample size (offset),
627+ * It's recommended to include the offset in the calculations by using
628+ * `wlr_scene_drop_shadow_get_offset`.
629+ *
630+ * Proper Width example: `toplevel_width + offset * 2 = correctly_fitted_width`
631+ * Proper X Position example: `toplevel_x - offset = correctly_x_positioned`
632+ */
633+ void wlr_scene_drop_shadow_set_size (struct wlr_scene_drop_shadow * shadow , int width , int height );
634+
635+ /**
636+ * Change the blur_sigma of an existing drop shadow node.
637+ *
638+ * NOTE: This adjusts the drop-shadows offset, so it's recommended to also
639+ * adjust the nodes size and position to compensate.
640+ */
641+ void wlr_scene_drop_shadow_set_blur_sigma (struct wlr_scene_drop_shadow * shadow , float blur_sigma );
642+
643+ /**
644+ * Change the color of an existing drop shadow node.
645+ */
646+ void wlr_scene_drop_shadow_set_color (struct wlr_scene_drop_shadow * shadow , const float color [static 4 ]);
647+
577648/**
578649 * Change the reference scene_buffer.
579- * NOTE: Will fallback to a box-shadow if the provided buffer is NULL.
650+ * NOTE: Will skip rendering if the provided buffer is NULL.
580651 */
581- void wlr_scene_shadow_set_reference_buffer (struct wlr_scene_shadow * shadow ,
652+ void wlr_scene_drop_shadow_set_reference_buffer (struct wlr_scene_drop_shadow * shadow ,
582653 struct wlr_scene_buffer * ref_buffer );
583654
584655/**
585656 * Get the reference scene_buffer.
586657 */
587- struct wlr_scene_buffer * wlr_scene_shadow_get_reference_buffer (struct wlr_scene_shadow * shadow );
658+ struct wlr_scene_buffer * wlr_scene_drop_shadow_get_reference_buffer (struct wlr_scene_drop_shadow * shadow );
588659
589660/**
590- * Gets the sample size of the shadow. Can be used when setting the size of
591- * the shadow node. Returns the correct size offset used depending on the
592- * shadow-type. A drop-shadow returns a larger integer compared to the
593- * box-shadow, so this can be used to dynamically adjust the size and position
594- * depending on the shadow-type. Eg:
661+ * Gets the offset of a drop shadow, the recommended way. Can be used as an
662+ * offset for setting the correct size and position relative to a toplevel.
663+ * Proper Width example: `toplevel_width + offset * 2 = correctly_fitted_width`
664+ * Proper X Position example: `toplevel_x - offset = correctly_x_positioned`
595665 *
596- * Scene Buffer size: 100 x 100px
597- * Proper Shadow Node size: 100px + offset x 100px + offset = the correct size
666+ * This is the same as `wlr_scene_drop_shadow_calculate_offset`, but uses the
667+ * already cached offset instead of recalculating the offset.
598668 */
599- int wlr_scene_shadow_get_offset (struct wlr_scene_shadow * shadow );
669+ int wlr_scene_drop_shadow_get_offset (struct wlr_scene_drop_shadow * shadow );
600670
601671/**
602- * Sets the region where to clip the shadow.
672+ * Gets the sample size of a drop shadow.
673+ *
674+ * Tip: Recalculates the offset, so it's recommended to only use this function
675+ * to calculate the initial size and position of the node while using
676+ * `wlr_scene_drop_shadow_get_offset` in other cases.
677+ */
678+ __always_inline float wlr_scene_drop_shadow_calculate_offset (int blur_sigma ) {
679+ return drop_shadow_calc_size (blur_sigma );
680+ }
681+
682+ /**
683+ * Sets the region where to clip the drop shadow.
603684 *
604685 * For there to be corner rounding of the clipped region, the corner radius and
605686 * corners must be non-zero.
606687 *
607688 * NOTE: The positioning is node-relative.
608689 */
609- void wlr_scene_shadow_set_clipped_region (struct wlr_scene_shadow * shadow ,
690+ void wlr_scene_drop_shadow_set_clipped_region (struct wlr_scene_drop_shadow * shadow ,
610691 struct clipped_region clipped_region );
611692
612693/**
0 commit comments