use std::rc::Rc; use std::time::Duration; use niri::layout::Options; use niri::render_helpers::RenderTarget; use niri_config::{Color, FloatOrInt}; use smithay::backend::renderer::element::RenderElement; use smithay::backend::renderer::gles::GlesRenderer; use smithay::utils::{Logical, Physical, Point, Rectangle, Scale, Size}; use super::TestCase; use crate::test_window::TestWindow; pub struct Tile { window: TestWindow, tile: niri::layout::tile::Tile, } impl Tile { pub fn freeform(size: Size) -> Self { let window = TestWindow::freeform(0); let mut rv = Self::with_window(window); rv.tile.request_tile_size(size.to_f64(), false, None); rv.window.communicate(); rv } pub fn fixed_size(size: Size) -> Self { let window = TestWindow::fixed_size(0); let mut rv = Self::with_window(window); rv.tile.request_tile_size(size.to_f64(), false, None); rv.window.communicate(); rv } pub fn fixed_size_with_csd_shadow(size: Size) -> Self { let window = TestWindow::fixed_size(0); window.set_csd_shadow_width(64); let mut rv = Self::with_window(window); rv.tile.request_tile_size(size.to_f64(), false, None); rv.window.communicate(); rv } pub fn freeform_open(size: Size) -> Self { let mut rv = Self::freeform(size); rv.window.set_color([0.1, 0.1, 0.1, 1.]); rv.tile.start_open_animation(); rv } pub fn fixed_size_open(size: Size) -> Self { let mut rv = Self::fixed_size(size); rv.window.set_color([0.1, 0.1, 0.1, 1.]); rv.tile.start_open_animation(); rv } pub fn fixed_size_with_csd_shadow_open(size: Size) -> Self { let mut rv = Self::fixed_size_with_csd_shadow(size); rv.window.set_color([0.1, 0.1, 0.1, 1.]); rv.tile.start_open_animation(); rv } pub fn with_window(window: TestWindow) -> Self { let options = Options { focus_ring: niri_config::FocusRing { off: true, ..Default::default() }, border: niri_config::Border { off: false, width: FloatOrInt(32.), active_color: Color::from_rgba8_unpremul(255, 163, 72, 255), ..Default::default() }, ..Default::default() }; let tile = niri::layout::tile::Tile::new(window.clone(), 1., Rc::new(options)); Self { window, tile } } } impl TestCase for Tile { fn resize(&mut self, width: i32, height: i32) { self.tile .request_tile_size(Size::from((width, height)).to_f64(), false, None); self.window.communicate(); } fn are_animations_ongoing(&self) -> bool { self.tile.are_animations_ongoing() } fn advance_animations(&mut self, current_time: Duration) { self.tile.advance_animations(current_time); } fn render( &mut self, renderer: &mut GlesRenderer, size: Size, ) -> Vec>> { let size = size.to_f64(); let tile_size = self.tile.tile_size().to_physical(1.); let location = Point::from((size.w - tile_size.w, size.h - tile_size.h)).downscale(2.); self.tile.update( true, Rectangle::from_loc_and_size((-location.x, -location.y), size.to_logical(1.)), ); self.tile .render( renderer, location, Scale::from(1.), true, RenderTarget::Output, ) .map(|elem| Box::new(elem) as _) .collect() } }