diff --git a/runtime/src/platform_specific/wayland/subsurface.rs b/runtime/src/platform_specific/wayland/subsurface.rs index 0fb5130d..0356d28d 100644 --- a/runtime/src/platform_specific/wayland/subsurface.rs +++ b/runtime/src/platform_specific/wayland/subsurface.rs @@ -23,7 +23,7 @@ pub struct SctkSubsurfaceSettings { pub size: Option, // pub subsurface_view: Option>, /// Z - pub z: u32, + pub z: i32, /// Steal Keyboard focus from parent while open. /// Will not work on a regular window. pub steal_keyboard_focus: bool, diff --git a/winit/src/platform_specific/wayland/sctk_event.rs b/winit/src/platform_specific/wayland/sctk_event.rs index e447fc60..b8a5762d 100755 --- a/winit/src/platform_specific/wayland/sctk_event.rs +++ b/winit/src/platform_specific/wayland/sctk_event.rs @@ -293,7 +293,7 @@ pub enum SubsurfaceEventVariant { surface_id: SurfaceId, common: Arc>, display: WlDisplay, - z: u32, + z: i32, }, /// Destroyed Destroyed(SubsurfaceInstance), diff --git a/winit/src/platform_specific/wayland/subsurface_widget.rs b/winit/src/platform_specific/wayland/subsurface_widget.rs index afc30c3b..fb853ef6 100644 --- a/winit/src/platform_specific/wayland/subsurface_widget.rs +++ b/winit/src/platform_specific/wayland/subsurface_widget.rs @@ -373,7 +373,7 @@ pub struct SubsurfaceState { window::Id, WlSubsurface, WlSurface, - u32, + i32, )>, } @@ -541,15 +541,26 @@ impl SubsurfaceState { sorted_subsurfaces.sort_by(|a, b| a.3.cmp(&b.3)); // Attach buffers to subsurfaces, set viewports, and commit. - for i in 1..sorted_subsurfaces.len() { - let prev = &sorted_subsurfaces[0..i]; - let subsurface = &sorted_subsurfaces[i]; - for prev in prev.iter().rev() { + 'outer: for (i, subsurface) in sorted_subsurfaces.iter().enumerate() { + for prev in sorted_subsurfaces[0..i].iter().rev() { if prev.0 == subsurface.0 { - subsurface.1.place_above(&prev.2); - break; + // Fist surface that has `z` greater than 0, so place above parent, + // rather than previous subsurface. + if prev.3 < 0 && subsurface.3 >= 0 { + subsurface.1.place_above(&subsurface.0); + } else { + subsurface.1.place_above(&prev.2); + } + continue 'outer; } } + // No previous surface with same parent + if subsurface.3 < 0 { + // Place below parent if z < 0 + subsurface.1.place_below(&subsurface.0); + } else { + subsurface.1.place_above(&subsurface.0); + } } } if !self.new_iced_subsurfaces.is_empty() { @@ -620,7 +631,7 @@ pub(crate) struct SubsurfaceInstance { pub(crate) wl_buffer: Option, pub(crate) bounds: Option>, pub(crate) transform: wl_output::Transform, - pub(crate) z: u32, + pub(crate) z: i32, pub parent: WlSurface, } @@ -723,12 +734,12 @@ pub(crate) struct SubsurfaceInfo { pub bounds: Rectangle, pub alpha: f32, pub transform: wl_output::Transform, - pub z: u32, + pub z: i32, } thread_local! { static SUBSURFACES: RefCell> = RefCell::new(Vec::new()); - static ICED_SUBSURFACES: RefCell> = RefCell::new(Vec::new()); + static ICED_SUBSURFACES: RefCell> = RefCell::new(Vec::new()); } pub(crate) fn take_subsurfaces() -> Vec { @@ -771,7 +782,7 @@ pub struct Subsurface { content_fit: ContentFit, alpha: f32, transform: wl_output::Transform, - pub z: u32, + pub z: i32, } impl Widget for Subsurface @@ -877,7 +888,8 @@ impl Subsurface { self } - pub fn z(mut self, z: u32) -> Self { + /// If `z` is less than 0, it will be below the main surface + pub fn z(mut self, z: i32) -> Self { self.z = z; self }