@@ -374,7 +374,7 @@ pub struct SubsurfaceState {
374374 window:: Id ,
375375 WlSubsurface ,
376376 WlSurface ,
377- u32 ,
377+ i32 ,
378378 ) > ,
379379}
380380
@@ -542,15 +542,26 @@ impl SubsurfaceState {
542542 sorted_subsurfaces. sort_by ( |a, b| a. 3 . cmp ( & b. 3 ) ) ;
543543
544544 // Attach buffers to subsurfaces, set viewports, and commit.
545- for i in 1 ..sorted_subsurfaces. len ( ) {
546- let prev = & sorted_subsurfaces[ 0 ..i] ;
547- let subsurface = & sorted_subsurfaces[ i] ;
548- for prev in prev. iter ( ) . rev ( ) {
545+ ' outer: for ( i, subsurface) in sorted_subsurfaces. iter ( ) . enumerate ( ) {
546+ for prev in sorted_subsurfaces[ 0 ..i] . iter ( ) . rev ( ) {
549547 if prev. 0 == subsurface. 0 {
550- subsurface. 1 . place_above ( & prev. 2 ) ;
551- break ;
548+ // Fist surface that has `z` greater than 0, so place above parent,
549+ // rather than previous subsurface.
550+ if prev. 3 < 0 && subsurface. 3 >= 0 {
551+ subsurface. 1 . place_above ( & subsurface. 0 ) ;
552+ } else {
553+ subsurface. 1 . place_above ( & prev. 2 ) ;
554+ }
555+ continue ' outer;
552556 }
553557 }
558+ // No previous surface with same parent
559+ if subsurface. 3 < 0 {
560+ // Place below parent if z < 0
561+ subsurface. 1 . place_below ( & subsurface. 0 ) ;
562+ } else {
563+ subsurface. 1 . place_above ( & subsurface. 0 ) ;
564+ }
554565 }
555566 }
556567 if !self . new_iced_subsurfaces . is_empty ( ) {
@@ -621,7 +632,7 @@ pub(crate) struct SubsurfaceInstance {
621632 pub ( crate ) wl_buffer : Option < WlBuffer > ,
622633 pub ( crate ) bounds : Option < Rectangle < f32 > > ,
623634 pub ( crate ) transform : wl_output:: Transform ,
624- pub ( crate ) z : u32 ,
635+ pub ( crate ) z : i32 ,
625636 pub parent : WlSurface ,
626637}
627638
@@ -724,12 +735,12 @@ pub(crate) struct SubsurfaceInfo {
724735 pub bounds : Rectangle < f32 > ,
725736 pub alpha : f32 ,
726737 pub transform : wl_output:: Transform ,
727- pub z : u32 ,
738+ pub z : i32 ,
728739}
729740
730741thread_local ! {
731742 static SUBSURFACES : RefCell <Vec <SubsurfaceInfo >> = RefCell :: new( Vec :: new( ) ) ;
732- static ICED_SUBSURFACES : RefCell <Vec <( window:: Id , WlSurface , window:: Id , WlSubsurface , WlSurface , u32 ) >> = RefCell :: new( Vec :: new( ) ) ;
743+ static ICED_SUBSURFACES : RefCell <Vec <( window:: Id , WlSurface , window:: Id , WlSubsurface , WlSurface , i32 ) >> = RefCell :: new( Vec :: new( ) ) ;
733744}
734745
735746pub ( crate ) fn take_subsurfaces ( ) -> Vec < SubsurfaceInfo > {
@@ -771,7 +782,7 @@ pub struct Subsurface {
771782 content_fit : ContentFit ,
772783 alpha : f32 ,
773784 transform : wl_output:: Transform ,
774- pub z : u32 ,
785+ pub z : i32 ,
775786}
776787
777788impl < Message , Theme , Renderer > Widget < Message , Theme , Renderer > for Subsurface
@@ -877,7 +888,8 @@ impl Subsurface {
877888 self
878889 }
879890
880- pub fn z ( mut self , z : u32 ) -> Self {
891+ /// If `z` is less than 0, it will be below the main surface
892+ pub fn z ( mut self , z : i32 ) -> Self {
881893 self . z = z;
882894 self
883895 }
0 commit comments