| 1 | use niri::layout::{LayoutElement, SizingMode}; |
| 2 | use niri::render_helpers::{RenderCtx, RenderTarget}; |
| 3 | use smithay::backend::renderer::element::RenderElement; |
| 4 | use smithay::backend::renderer::gles::GlesRenderer; |
| 5 | use smithay::utils::{Physical, Point, Scale, Size}; |
| 6 | |
| 7 | use super::{Args, TestCase}; |
| 8 | use crate::test_window::TestWindow; |
| 9 | |
| 10 | pub struct Window { |
| 11 | window: TestWindow, |
| 12 | } |
| 13 | |
| 14 | impl Window { |
| 15 | pub fn freeform(args: Args) -> Self { |
| 16 | let mut window = TestWindow::freeform(0); |
| 17 | window.request_size(args.size, SizingMode::Normal, false, None); |
| 18 | window.communicate(); |
| 19 | Self { window } |
| 20 | } |
| 21 | |
| 22 | pub fn fixed_size(args: Args) -> Self { |
| 23 | let mut window = TestWindow::fixed_size(0); |
| 24 | window.request_size(args.size, SizingMode::Normal, false, None); |
| 25 | window.communicate(); |
| 26 | Self { window } |
| 27 | } |
| 28 | |
| 29 | pub fn fixed_size_with_csd_shadow(args: Args) -> Self { |
| 30 | let mut window = TestWindow::fixed_size(0); |
| 31 | window.set_csd_shadow_width(64); |
| 32 | window.request_size(args.size, SizingMode::Normal, false, None); |
| 33 | window.communicate(); |
| 34 | Self { window } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | impl TestCase for Window { |
| 39 | fn resize(&mut self, width: i32, height: i32) { |
| 40 | self.window |
| 41 | .request_size(Size::from((width, height)), SizingMode::Normal, false, None); |
| 42 | self.window.communicate(); |
| 43 | } |
| 44 | |
| 45 | fn render( |
| 46 | &mut self, |
| 47 | renderer: &mut GlesRenderer, |
| 48 | size: Size<i32, Physical>, |
| 49 | ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> { |
| 50 | let win_size = self.window.size().to_physical(1); |
| 51 | let location = Point::from((size.w - win_size.w, size.h - win_size.h)) |
| 52 | .to_f64() |
| 53 | .downscale(2.); |
| 54 | |
| 55 | let mut rv = Vec::new(); |
| 56 | let ctx = RenderCtx { |
| 57 | renderer, |
| 58 | target: RenderTarget::Output, |
| 59 | xray: None, |
| 60 | }; |
| 61 | self.window |
| 62 | .render_normal(ctx, location, Scale::from(1.), 1., &mut |elem| { |
| 63 | rv.push(Box::new(elem) as _) |
| 64 | }); |
| 65 | rv |
| 66 | } |
| 67 | } |