Add a SplitRenderElements type, with useful methods

`(w_elements, p_elements)` tuples are used in a bunch of places. A
struct with named fields is generally an improvement just due to the
fact the order is non-obvious.

But we can also add methods. In particular,
`extend_from_workspace_elements` abstracts out some of the more
redundant code in `workspace_elements`.

It would be nice to avoid allocation everywhere, but iterators would
complicate lifetimes, run into issues with needing multiple mutable
borrows to things like the `Renderer`, and be awkward in certain
functions without generator syntax. In any case, cosmic-comp already
relies on allocating vectors here.

If this abstraction is commonly useful in compositors, perhaps it could
be moved to Smithay.
This commit is contained in:
Ian Douglas Scott 2024-07-09 15:21:16 -07:00 committed by Victoria Brekenfeld
parent c506d94ac8
commit 94fecec9cb
9 changed files with 374 additions and 379 deletions

View file

@ -4,7 +4,7 @@ use crate::{
backend::render::{
cursor::{CursorShape, CursorState},
element::AsGlowRenderer,
BackdropShader, IndicatorShader, Key, Usage,
BackdropShader, IndicatorShader, Key, SplitRenderElements, Usage,
},
shell::{
element::{
@ -182,7 +182,10 @@ impl MoveGrabState {
_ => vec![],
};
let (window_elements, popup_elements) = self
let SplitRenderElements {
w_elements,
p_elements,
} = self
.window
.split_render_elements::<R, CosmicMappedRenderElement<R>>(
renderer,
@ -202,9 +205,9 @@ impl MoveGrabState {
1.0,
)
})
.chain(popup_elements)
.chain(p_elements)
.chain(focus_element)
.chain(window_elements.into_iter().map(|elem| match elem {
.chain(w_elements.into_iter().map(|elem| match elem {
CosmicMappedRenderElement::Stack(stack) => {
CosmicMappedRenderElement::GrabbedStack(
RescaleRenderElement::from_element(