add layer definition to RenderElement

This commit is contained in:
dragonn 2022-01-18 22:12:48 +01:00
parent 92d04ba8fe
commit b9ecc3c2d4
2 changed files with 65 additions and 7 deletions

View File

@ -10,6 +10,23 @@ use std::{
}; };
use wayland_server::protocol::wl_surface::WlSurface; use wayland_server::protocol::wl_surface::WlSurface;
/// Enum for indicating on with layer a render element schould be draw
#[derive(Debug, PartialEq, Eq)]
pub enum RenderLayer {
/// Bellow every other elements
Bottom,
/// Above WlrLayer::Background but bellow WlrLayer::Bottom
AboveBackground,
/// Right before programs windows are draw
BeforeWindows,
/// Right after programs windows are draw
AfterWindows,
/// Above WlrLayer::Top but bellow WlrLayer::Overlay
BeforeOverlay,
/// Above anything else
Top,
}
/// Trait for custom elements to be rendered during [`Space::render_output`]. /// Trait for custom elements to be rendered during [`Space::render_output`].
pub trait RenderElement<R, F, E, T> pub trait RenderElement<R, F, E, T>
where where
@ -55,6 +72,11 @@ where
damage: &[Rectangle<i32, Logical>], damage: &[Rectangle<i32, Logical>],
log: &slog::Logger, log: &slog::Logger,
) -> Result<(), R::Error>; ) -> Result<(), R::Error>;
/// Returns they layer the elements schould be draw on, defaults to Top
fn layer(&self) -> RenderLayer {
RenderLayer::Top
}
} }
pub(crate) trait SpaceElement<R, F, E, T> pub(crate) trait SpaceElement<R, F, E, T>

View File

@ -501,6 +501,7 @@ impl Space {
// This will hold all the damage we need for this rendering step // This will hold all the damage we need for this rendering step
let mut damage = Vec::<Rectangle<i32, Logical>>::new(); let mut damage = Vec::<Rectangle<i32, Logical>>::new();
// First add damage for windows gone // First add damage for windows gone
for old_toplevel in state for old_toplevel in state
.last_state .last_state
.iter() .iter()
@ -613,18 +614,53 @@ impl Space {
// Then re-draw all windows & layers overlapping with a damage rect. // Then re-draw all windows & layers overlapping with a damage rect.
for element in layer_map for element in custom_elements
.iter()
.filter(|c| c.layer() == RenderLayer::Bottom)
.map(|p| p as &SpaceElem<R>)
.chain(
layer_map
.layers_on(WlrLayer::Background) .layers_on(WlrLayer::Background)
.chain(layer_map.layers_on(WlrLayer::Bottom))
.map(|l| l as &SpaceElem<R>) .map(|l| l as &SpaceElem<R>)
.chain(
custom_elements
.iter()
.filter(|c| c.layer() == RenderLayer::AboveBackground)
.map(|c| c as &SpaceElem<R>),
)
.chain(layer_map.layers_on(WlrLayer::Bottom).map(|l| l as &SpaceElem<R>)),
)
.chain(
custom_elements
.iter()
.filter(|c| c.layer() == RenderLayer::BeforeWindows)
.map(|c| c as &SpaceElem<R>),
)
.chain(self.windows.iter().map(|w| w as &SpaceElem<R>)) .chain(self.windows.iter().map(|w| w as &SpaceElem<R>))
.chain(
custom_elements
.iter()
.filter(|c| c.layer() == RenderLayer::AfterWindows)
.map(|c| c as &SpaceElem<R>),
)
.chain( .chain(
layer_map layer_map
.layers_on(WlrLayer::Top) .layers_on(WlrLayer::Top)
.chain(layer_map.layers_on(WlrLayer::Overlay)) .map(|l| l as &SpaceElem<R>)
.map(|l| l as &SpaceElem<R>), .chain(
custom_elements
.iter()
.filter(|c| c.layer() == RenderLayer::BeforeOverlay)
.map(|c| c as &SpaceElem<R>),
)
.chain(layer_map.layers_on(WlrLayer::Overlay).map(|l| l as &SpaceElem<R>)),
)
.chain(
custom_elements
.iter()
.filter(|c| c.layer() == RenderLayer::Top)
.map(|c| c as &SpaceElem<R>),
) )
.chain(custom_elements.iter().map(|c| c as &SpaceElem<R>))
{ {
let geo = element.geometry(self.id); let geo = element.geometry(self.id);
if damage.iter().any(|d| d.overlaps(geo)) { if damage.iter().any(|d| d.overlaps(geo)) {