aboutsummaryrefslogtreecommitdiff
path: root/niri-visual-tests/src/cases/tile.rs
blob: 5b2f7cb8d74c73e614aef3e7294c6fc8edb6540a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use std::rc::Rc;
use std::time::Duration;

use niri::layout::Options;
use niri::render_helpers::RenderTarget;
use niri_config::Color;
use smithay::backend::renderer::element::RenderElement;
use smithay::backend::renderer::gles::GlesRenderer;
use smithay::utils::{Logical, Physical, Point, Scale, Size};

use super::TestCase;
use crate::test_window::TestWindow;

pub struct Tile {
    window: TestWindow,
    tile: niri::layout::tile::Tile<TestWindow>,
}

impl Tile {
    pub fn freeform(size: Size<i32, Logical>) -> Self {
        let window = TestWindow::freeform(0);
        let mut rv = Self::with_window(window);
        rv.tile.request_tile_size(size);
        rv.window.communicate();
        rv
    }

    pub fn fixed_size(size: Size<i32, Logical>) -> Self {
        let window = TestWindow::fixed_size(0);
        let mut rv = Self::with_window(window);
        rv.tile.request_tile_size(size);
        rv.window.communicate();
        rv
    }

    pub fn fixed_size_with_csd_shadow(size: Size<i32, Logical>) -> 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);
        rv.window.communicate();
        rv
    }

    pub fn freeform_open(size: Size<i32, Logical>) -> 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<i32, Logical>) -> 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<i32, Logical>) -> 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: 32,
                active_color: Color::new(255, 163, 72, 255),
                ..Default::default()
            },
            ..Default::default()
        };
        let tile = niri::layout::tile::Tile::new(window.clone(), 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)));
        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, true);
    }

    fn render(
        &mut self,
        renderer: &mut GlesRenderer,
        size: Size<i32, Physical>,
    ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> {
        let tile_size = self.tile.tile_size().to_physical(1);
        let location = Point::from(((size.w - tile_size.w) / 2, (size.h - tile_size.h) / 2));

        self.tile
            .render(
                renderer,
                location,
                Scale::from(1.),
                size.to_logical(1),
                true,
                RenderTarget::Output,
            )
            .map(|elem| Box::new(elem) as _)
            .collect()
    }
}