Skip to content

Commit 09a9525

Browse files
committed
subsurface_widget: Use neagtive z to place below parent surface
Now uses `i32` for `z`.
1 parent 8017f30 commit 09a9525

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

runtime/src/platform_specific/wayland/subsurface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct SctkSubsurfaceSettings {
2323
pub size: Option<Size>,
2424
// pub subsurface_view: Option<Arc<dyn Any + Send + Sync>>,
2525
/// Z
26-
pub z: u32,
26+
pub z: i32,
2727
/// Steal Keyboard focus from parent while open.
2828
/// Will not work on a regular window.
2929
pub steal_keyboard_focus: bool,

winit/src/platform_specific/wayland/sctk_event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub enum SubsurfaceEventVariant {
293293
surface_id: SurfaceId,
294294
common: Arc<Mutex<Common>>,
295295
display: WlDisplay,
296-
z: u32,
296+
z: i32,
297297
},
298298
/// Destroyed
299299
Destroyed(SubsurfaceInstance),

winit/src/platform_specific/wayland/subsurface_widget.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

730741
thread_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

735746
pub(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

777788
impl<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

Comments
 (0)