Move tag render elements

This commit is contained in:
Ottatop 2023-09-20 15:18:26 -05:00
parent ce96d1d636
commit a0a6efe45a
4 changed files with 34 additions and 54 deletions

View file

@ -1509,11 +1509,10 @@ fn render_surface<'a>(
let output_render_elements = crate::render::generate_render_elements(
space,
windows,
focus_stack,
pointer_location,
cursor_status,
dnd_icon,
focus_stack,
renderer,
output,
input_method,

View file

@ -281,21 +281,12 @@ pub fn run_winit() -> anyhow::Result<()> {
state.focus_state.fix_up_focus(&mut state.space);
let windows = state
.focus_state
.focus_stack
.iter()
.filter(|win| win.alive())
.cloned()
.collect::<Vec<_>>();
let output_render_elements = crate::render::generate_render_elements(
&state.space,
&windows,
&state.focus_state.focus_stack,
state.pointer_location,
&mut state.cursor_status,
state.dnd_icon.as_ref(),
&state.focus_state.focus_stack,
backend.backend.renderer(),
&output,
state.seat.input_method(),

View file

@ -12,7 +12,7 @@ use smithay::{
},
desktop::{
layer_map_for_output,
space::{SpaceRenderElements, SurfaceTree},
space::{SpaceElement, SpaceRenderElements, SurfaceTree},
Space,
},
input::pointer::{CursorImageAttributes, CursorImageStatus},
@ -26,7 +26,7 @@ use smithay::{
wayland::{compositor, input_method::InputMethodHandle, shell::wlr_layer},
};
use crate::{state::WithState, tag::Tag, window::WindowElement};
use crate::{state::WithState, window::WindowElement};
use self::pointer::{PointerElement, PointerRenderElement};
@ -126,6 +126,33 @@ where
}
}
/// Get the render_elements for the provided tags.
fn tag_render_elements<R, C>(
windows: &[WindowElement],
space: &Space<WindowElement>,
renderer: &mut R,
) -> Vec<C>
where
R: Renderer + ImportAll + ImportMem,
<R as Renderer>::TextureId: 'static,
C: From<WaylandSurfaceRenderElement<R>>,
{
let elements = windows
.iter()
.rev() // rev because I treat the focus stack backwards vs how the renderer orders it
.filter(|win| win.is_on_active_tag(space.outputs()))
.flat_map(|win| {
// subtract win.geometry().loc to align decorations correctly
let loc = (space.element_location(win).unwrap_or((0, 0).into())
- win.geometry().loc)
.to_physical(1);
win.render_elements::<C>(renderer, loc, Scale::from(1.0), 1.0)
})
.collect::<Vec<_>>();
elements
}
#[allow(clippy::too_many_arguments)]
pub fn generate_render_elements<R, T>(
space: &Space<WindowElement>,
@ -133,7 +160,6 @@ pub fn generate_render_elements<R, T>(
pointer_location: Point<f64, Logical>,
cursor_status: &mut CursorImageStatus,
dnd_icon: Option<&WlSurface>,
focus_stack: &[WindowElement],
renderer: &mut R,
output: &Output,
input_method: &InputMethodHandle,
@ -218,7 +244,7 @@ where
}
let output_render_elements = {
let top_fullscreen_window = focus_stack.iter().rev().find(|win| {
let top_fullscreen_window = windows.iter().rev().find(|win| {
win.with_state(|state| {
// TODO: for wayland windows, check if current state has xdg_toplevel fullscreen
let is_wayland_actually_fullscreen = {
@ -269,7 +295,7 @@ where
} = layer_render_elements(output, renderer);
let window_render_elements: Vec<WaylandSurfaceRenderElement<R>> =
Tag::tag_render_elements(windows, space, renderer);
tag_render_elements(windows, space, renderer);
let mut output_render_elements =
Vec::<OutputRenderElements<R, WaylandSurfaceRenderElement<R>>>::new();

View file

@ -7,20 +7,11 @@ use std::{
sync::atomic::{AtomicU32, Ordering},
};
use smithay::{
backend::renderer::{
element::{surface::WaylandSurfaceRenderElement, AsRenderElements},
ImportAll, ImportMem, Renderer,
},
desktop::{space::SpaceElement, Space},
output::Output,
utils::Scale,
};
use smithay::output::Output;
use crate::{
layout::Layout,
state::{State, WithState},
window::WindowElement,
};
static TAG_ID_COUNTER: AtomicU32 = AtomicU32::new(0);
@ -117,31 +108,4 @@ impl Tag {
.find(|output| output.with_state(|state| state.tags.iter().any(|tg| tg == self)))
.cloned()
}
/// Get the render_elements for the provided tags.
pub fn tag_render_elements<R, C>(
windows: &[WindowElement],
space: &Space<WindowElement>,
renderer: &mut R,
) -> Vec<C>
where
R: Renderer + ImportAll + ImportMem,
<R as Renderer>::TextureId: 'static,
C: From<WaylandSurfaceRenderElement<R>>,
{
let elements = windows
.iter()
.rev() // rev because I treat the focus stack backwards vs how the renderer orders it
.filter(|win| win.is_on_active_tag(space.outputs()))
.flat_map(|win| {
// subtract win.geometry().loc to align decorations correctly
let loc = (space.element_location(win).unwrap_or((0, 0).into())
- win.geometry().loc)
.to_physical(1);
win.render_elements::<C>(renderer, loc, Scale::from(1.0), 1.0)
})
.collect::<Vec<_>>();
elements
}
}