layout: Add TileRenderElement

This commit is contained in:
Ivan Molodetskikh 2024-02-04 22:52:11 +04:00
parent da826e42aa
commit 57521c69c3
2 changed files with 19 additions and 10 deletions

View File

@ -6,11 +6,11 @@ use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRen
use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement}; use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement};
use smithay::backend::renderer::element::Kind; use smithay::backend::renderer::element::Kind;
use smithay::backend::renderer::{ImportAll, Renderer}; use smithay::backend::renderer::{ImportAll, Renderer};
use smithay::render_elements;
use smithay::utils::{Logical, Point, Rectangle, Scale, Size}; use smithay::utils::{Logical, Point, Rectangle, Scale, Size};
use super::focus_ring::FocusRing; use super::focus_ring::FocusRing;
use super::workspace::WorkspaceRenderElement; use super::{LayoutElement, LayoutElementRenderElement, Options};
use super::{LayoutElement, Options};
/// Toplevel window with decorations. /// Toplevel window with decorations.
#[derive(Debug)] #[derive(Debug)]
@ -37,6 +37,13 @@ pub struct Tile<W: LayoutElement> {
options: Rc<Options>, options: Rc<Options>,
} }
render_elements! {
#[derive(Debug)]
pub TileRenderElement<R> where R: ImportAll;
LayoutElement = LayoutElementRenderElement<R>,
SolidColor = RelocateRenderElement<SolidColorRenderElement>,
}
impl<W: LayoutElement> Tile<W> { impl<W: LayoutElement> Tile<W> {
pub fn new(window: W, options: Rc<Options>) -> Self { pub fn new(window: W, options: Rc<Options>) -> Self {
Self { Self {
@ -237,7 +244,7 @@ impl<W: LayoutElement> Tile<W> {
renderer: &mut R, renderer: &mut R,
location: Point<i32, Logical>, location: Point<i32, Logical>,
scale: Scale<f64>, scale: Scale<f64>,
) -> Vec<WorkspaceRenderElement<R>> ) -> Vec<TileRenderElement<R>>
where where
<R as Renderer>::TextureId: 'static, <R as Renderer>::TextureId: 'static,
{ {
@ -274,7 +281,7 @@ impl<W: LayoutElement> Tile<W> {
1., 1.,
Kind::Unspecified, Kind::Unspecified,
); );
rv.push(elem.into()); rv.push(RelocateRenderElement::from_element(elem, (0, 0), Relocate::Relative).into());
} }
rv rv

View File

@ -5,7 +5,6 @@ use std::rc::Rc;
use std::time::Duration; use std::time::Duration;
use niri_config::{CenterFocusedColumn, PresetWidth, SizeChange, Struts}; use niri_config::{CenterFocusedColumn, PresetWidth, SizeChange, Struts};
use smithay::backend::renderer::element::utils::RelocateRenderElement;
use smithay::backend::renderer::{ImportAll, Renderer}; use smithay::backend::renderer::{ImportAll, Renderer};
use smithay::desktop::space::SpaceElement; use smithay::desktop::space::SpaceElement;
use smithay::desktop::{layer_map_for_output, Window}; use smithay::desktop::{layer_map_for_output, Window};
@ -15,8 +14,8 @@ use smithay::render_elements;
use smithay::utils::{Logical, Point, Rectangle, Scale, Size}; use smithay::utils::{Logical, Point, Rectangle, Scale, Size};
use super::focus_ring::{FocusRing, FocusRingRenderElement}; use super::focus_ring::{FocusRing, FocusRingRenderElement};
use super::tile::Tile; use super::tile::{Tile, TileRenderElement};
use super::{LayoutElement, LayoutElementRenderElement, Options}; use super::{LayoutElement, Options};
use crate::animation::Animation; use crate::animation::Animation;
use crate::utils::output_size; use crate::utils::output_size;
@ -82,9 +81,8 @@ pub struct OutputId(String);
render_elements! { render_elements! {
#[derive(Debug)] #[derive(Debug)]
pub WorkspaceRenderElement<R> where R: ImportAll; pub WorkspaceRenderElement<R> where R: ImportAll;
LayoutElement = LayoutElementRenderElement<R>, Tile = TileRenderElement<R>,
FocusRing = FocusRingRenderElement, FocusRing = FocusRingRenderElement,
Border = RelocateRenderElement<FocusRingRenderElement>,
} }
/// Width of a column. /// Width of a column.
@ -1095,7 +1093,11 @@ impl<W: LayoutElement> Workspace<W> {
self.with_tiles_in_render_order(|tile, tile_pos| { self.with_tiles_in_render_order(|tile, tile_pos| {
// Draw the window itself. // Draw the window itself.
rv.extend(tile.render(renderer, tile_pos, output_scale)); rv.extend(
tile.render(renderer, tile_pos, output_scale)
.into_iter()
.map(Into::into),
);
// For the active tile (which comes first), draw the focus ring. // For the active tile (which comes first), draw the focus ring.
if first { if first {