forge
Explore
Log in

Don't you dare go Hollow

Implement window open animations

Browse files at this commit

f9085db5648bc6bad7fb0abf45e2a11f2e03d1afIvan MolodetskikhParent: 49ce791
niri-visual-tests/src/cases/layout.rsadded+228 -0
@@ -0,0 +1,228 @@
1+use std::collections::HashMap;
2+use std::time::Duration;
3+
4+use niri::layout::workspace::ColumnWidth;
5+use niri::layout::Options;
6+use niri::utils::get_monotonic_time;
7+use niri_config::Color;
8+use smithay::backend::renderer::element::RenderElement;
9+use smithay::backend::renderer::gles::GlesRenderer;
10+use smithay::desktop::layer_map_for_output;
11+use smithay::output::{Mode, Output, PhysicalProperties, Subpixel};
12+use smithay::utils::{Logical, Physical, Size};
13+
14+use super::TestCase;
15+use crate::test_window::TestWindow;
16+
17+type DynStepFn = Box<dyn FnOnce(&mut Layout)>;
18+
19+pub struct Layout {
20+ output: Output,
21+ windows: Vec<TestWindow>,
22+ layout: niri::layout::Layout<TestWindow>,
23+ start_time: Duration,
24+ steps: HashMap<Duration, DynStepFn>,
25+}
26+
27+impl Layout {
28+ pub fn new(size: Size<i32, Logical>) -> Self {
29+ let output = Output::new(
30+ String::new(),
31+ PhysicalProperties {
32+ size: Size::from((size.w, size.h)),
33+ subpixel: Subpixel::Unknown,
34+ make: String::new(),
35+ model: String::new(),
36+ },
37+ );
38+ let mode = Some(Mode {
39+ size: size.to_physical(1),
40+ refresh: 60000,
41+ });
42+ output.change_current_state(mode, None, None, None);
43+
44+ let options = Options {
45+ focus_ring: niri_config::FocusRing {
46+ off: true,
47+ ..Default::default()
48+ },
49+ border: niri_config::FocusRing {
50+ off: false,
51+ width: 4,
52+ active_color: Color::new(255, 163, 72, 255),
53+ inactive_color: Color::new(50, 50, 50, 255),
54+ },
55+ ..Default::default()
56+ };
57+ let mut layout = niri::layout::Layout::with_options(options);
58+ layout.add_output(output.clone());
59+
60+ Self {
61+ output,
62+ windows: Vec::new(),
63+ layout,
64+ start_time: get_monotonic_time(),
65+ steps: HashMap::new(),
66+ }
67+ }
68+
69+ pub fn open_in_between(size: Size<i32, Logical>) -> Self {
70+ let mut rv = Self::new(size);
71+
72+ rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3)));
73+ rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.3)));
74+ rv.layout.activate_window(&rv.windows[0]);
75+
76+ rv.add_step(500, |l| {
77+ let win = TestWindow::freeform(2);
78+ l.add_window(win.clone(), Some(ColumnWidth::Proportion(0.3)));
79+ l.layout.start_open_animation_for_window(&win);
80+ });
81+
82+ rv
83+ }
84+
85+ pub fn open_multiple_quickly(size: Size<i32, Logical>) -> Self {
86+ let mut rv = Self::new(size);
87+
88+ for delay in [100, 200, 300] {
89+ rv.add_step(delay, move |l| {
90+ let win = TestWindow::freeform(delay as usize);
91+ l.add_window(win.clone(), Some(ColumnWidth::Proportion(0.3)));
92+ l.layout.start_open_animation_for_window(&win);
93+ });
94+ }
95+
96+ rv
97+ }
98+
99+ pub fn open_multiple_quickly_big(size: Size<i32, Logical>) -> Self {
100+ let mut rv = Self::new(size);
101+
102+ for delay in [100, 200, 300] {
103+ rv.add_step(delay, move |l| {
104+ let win = TestWindow::freeform(delay as usize);
105+ l.add_window(win.clone(), Some(ColumnWidth::Proportion(0.5)));
106+ l.layout.start_open_animation_for_window(&win);
107+ });
108+ }
109+
110+ rv
111+ }
112+
113+ pub fn open_to_the_left(size: Size<i32, Logical>) -> Self {
114+ let mut rv = Self::new(size);
115+
116+ rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3)));
117+ rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.3)));
118+
119+ rv.add_step(500, |l| {
120+ let win = TestWindow::freeform(2);
121+ let right_of = l.windows[0].clone();
122+ l.add_window_right_of(&right_of, win.clone(), Some(ColumnWidth::Proportion(0.3)));
123+ l.layout.start_open_animation_for_window(&win);
124+ });
125+
126+ rv
127+ }
128+
129+ pub fn open_to_the_left_big(size: Size<i32, Logical>) -> Self {
130+ let mut rv = Self::new(size);
131+
132+ rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3)));
133+ rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.8)));
134+
135+ rv.add_step(500, |l| {
136+ let win = TestWindow::freeform(2);
137+ let right_of = l.windows[0].clone();
138+ l.add_window_right_of(&right_of, win.clone(), Some(ColumnWidth::Proportion(0.5)));
139+ l.layout.start_open_animation_for_window(&win);
140+ });
141+
142+ rv
143+ }
144+
145+ fn add_window(&mut self, window: TestWindow, width: Option<ColumnWidth>) {
146+ self.layout.add_window(window.clone(), width, false);
147+ if window.communicate() {
148+ self.layout.update_window(&window);
149+ }
150+ self.windows.push(window);
151+ }
152+
153+ fn add_window_right_of(
154+ &mut self,
155+ right_of: &TestWindow,
156+ window: TestWindow,
157+ width: Option<ColumnWidth>,
158+ ) {
159+ self.layout
160+ .add_window_right_of(right_of, window.clone(), width, false);
161+ if window.communicate() {
162+ self.layout.update_window(&window);
163+ }
164+ self.windows.push(window);
165+ }
166+
167+ fn add_step(&mut self, delay_ms: u64, f: impl FnOnce(&mut Self) + 'static) {
168+ self.steps
169+ .insert(Duration::from_millis(delay_ms), Box::new(f) as _);
170+ }
171+}
172+
173+impl TestCase for Layout {
174+ fn resize(&mut self, width: i32, height: i32) {
175+ let mode = Some(Mode {
176+ size: Size::from((width, height)),
177+ refresh: 60000,
178+ });
179+ self.output.change_current_state(mode, None, None, None);
180+ layer_map_for_output(&self.output).arrange();
181+ self.layout.update_output_size(&self.output);
182+ for win in &self.windows {
183+ if win.communicate() {
184+ self.layout.update_window(win);
185+ }
186+ }
187+ }
188+
189+ fn are_animations_ongoing(&self) -> bool {
190+ self.layout
191+ .monitor_for_output(&self.output)
192+ .unwrap()
193+ .are_animations_ongoing()
194+ || !self.steps.is_empty()
195+ }
196+
197+ fn advance_animations(&mut self, mut current_time: Duration) {
198+ let run = self
199+ .steps
200+ .keys()
201+ .copied()
202+ .filter(|delay| self.start_time + *delay <= current_time)
203+ .collect::<Vec<_>>();
204+ for key in &run {
205+ let f = self.steps.remove(key).unwrap();
206+ f(self);
207+ }
208+ if !run.is_empty() {
209+ current_time = get_monotonic_time();
210+ }
211+
212+ self.layout.advance_animations(current_time);
213+ }
214+
215+ fn render(
216+ &mut self,
217+ renderer: &mut GlesRenderer,
218+ _size: Size<i32, Physical>,
219+ ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> {
220+ self.layout
221+ .monitor_for_output(&self.output)
222+ .unwrap()
223+ .render_elements(renderer)
224+ .into_iter()
225+ .map(|elem| Box::new(elem) as _)
226+ .collect()
227+ }
228+}
niri-visual-tests/src/cases/mod.rsmodified+1 -0
@@ -4,6 +4,7 @@ use smithay::backend::renderer::element::RenderElement;
4 use smithay::backend::renderer::gles::GlesRenderer;4 use smithay::backend::renderer::gles::GlesRenderer;
5 use smithay::utils::{Physical, Size};5 use smithay::utils::{Physical, Size};
6 6
7+pub mod layout;
7 pub mod tile;8 pub mod tile;
8 pub mod window;9 pub mod window;
9 10
niri-visual-tests/src/cases/tile.rsmodified+25 -0
@@ -41,6 +41,27 @@ impl Tile {
41 rv41 rv
42 }42 }
43 43
44+ pub fn freeform_open(size: Size<i32, Logical>) -> Self {
45+ let mut rv = Self::freeform(size);
46+ rv.window.set_color([0.1, 0.1, 0.1, 1.]);
47+ rv.tile.start_open_animation();
48+ rv
49+ }
50+
51+ pub fn fixed_size_open(size: Size<i32, Logical>) -> Self {
52+ let mut rv = Self::fixed_size(size);
53+ rv.window.set_color([0.1, 0.1, 0.1, 1.]);
54+ rv.tile.start_open_animation();
55+ rv
56+ }
57+
58+ pub fn fixed_size_with_csd_shadow_open(size: Size<i32, Logical>) -> Self {
59+ let mut rv = Self::fixed_size_with_csd_shadow(size);
60+ rv.window.set_color([0.1, 0.1, 0.1, 1.]);
61+ rv.tile.start_open_animation();
62+ rv
63+ }
64+
44 pub fn with_window(window: TestWindow) -> Self {65 pub fn with_window(window: TestWindow) -> Self {
45 let options = Options {66 let options = Options {
46 focus_ring: niri_config::FocusRing {67 focus_ring: niri_config::FocusRing {
@@ -66,6 +87,10 @@ impl TestCase for Tile {
66 self.window.communicate();87 self.window.communicate();
67 }88 }
68 89
90+ fn are_animations_ongoing(&self) -> bool {
91+ self.tile.are_animations_ongoing()
92+ }
93+
69 fn advance_animations(&mut self, current_time: Duration) {94 fn advance_animations(&mut self, current_time: Duration) {
70 self.tile.advance_animations(current_time, true);95 self.tile.advance_animations(current_time, true);
71 }96 }
niri-visual-tests/src/main.rsmodified+22 -0
@@ -16,6 +16,7 @@ use smithay::utils::{Logical, Size};
16 use smithay_view::SmithayView;16 use smithay_view::SmithayView;
17 use tracing_subscriber::EnvFilter;17 use tracing_subscriber::EnvFilter;
18 18
19+use crate::cases::layout::Layout;
19 use crate::cases::TestCase;20 use crate::cases::TestCase;
20 21
21 mod cases;22 mod cases;
@@ -85,6 +86,27 @@ fn build_ui(app: &adw::Application) {
85 Tile::fixed_size_with_csd_shadow,86 Tile::fixed_size_with_csd_shadow,
86 "Fixed Size Tile - CSD Shadow",87 "Fixed Size Tile - CSD Shadow",
87 );88 );
89+ s.add(Tile::freeform_open, "Freeform Tile - Open");
90+ s.add(Tile::fixed_size_open, "Fixed Size Tile - Open");
91+ s.add(
92+ Tile::fixed_size_with_csd_shadow_open,
93+ "Fixed Size Tile - CSD Shadow - Open",
94+ );
95+
96+ s.add(Layout::open_in_between, "Layout - Open In-Between");
97+ s.add(
98+ Layout::open_multiple_quickly,
99+ "Layout - Open Multiple Quickly",
100+ );
101+ s.add(
102+ Layout::open_multiple_quickly_big,
103+ "Layout - Open Multiple Quickly - Big",
104+ );
105+ s.add(Layout::open_to_the_left, "Layout - Open To The Left");
106+ s.add(
107+ Layout::open_to_the_left_big,
108+ "Layout - Open To The Left - Big",
109+ );
88 110
89 let content_headerbar = adw::HeaderBar::new();111 let content_headerbar = adw::HeaderBar::new();
90 112
niri-visual-tests/src/test_window.rsmodified+3 -1
@@ -5,7 +5,7 @@ use std::rc::Rc;
5 use niri::layout::{LayoutElement, LayoutElementRenderElement};5 use niri::layout::{LayoutElement, LayoutElementRenderElement};
6 use niri::render_helpers::renderer::NiriRenderer;6 use niri::render_helpers::renderer::NiriRenderer;
7 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};7 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
8-use smithay::backend::renderer::element::Kind;8+use smithay::backend::renderer::element::{Id, Kind};
9 use smithay::output::Output;9 use smithay::output::Output;
10 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;10 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
11 use smithay::utils::{Logical, Point, Scale, Size, Transform};11 use smithay::utils::{Logical, Point, Scale, Size, Transform};
@@ -196,6 +196,8 @@ impl LayoutElement for TestWindow {
196 196
197 fn output_leave(&self, _output: &Output) {}197 fn output_leave(&self, _output: &Output) {}
198 198
199+ fn set_offscreen_element_id(&self, _id: Option<Id>) {}
200+
199 fn is_fullscreen(&self) -> bool {201 fn is_fullscreen(&self) -> bool {
200 false202 false
201 }203 }
src/animation.rsmodified+23 -1
@@ -15,6 +15,13 @@ pub struct Animation {
15 duration: Duration,15 duration: Duration,
16 start_time: Duration,16 start_time: Duration,
17 current_time: Duration,17 current_time: Duration,
18+ curve: Curve,
19+}
20+
21+#[derive(Debug, Clone, Copy)]
22+pub enum Curve {
23+ EaseOutCubic,
24+ EaseOutExpo,
18 }25 }
19 26
20 impl Animation {27 impl Animation {
@@ -29,9 +36,15 @@ impl Animation {
29 duration: over.mul_f64(ANIMATION_SLOWDOWN.load(Ordering::Relaxed)),36 duration: over.mul_f64(ANIMATION_SLOWDOWN.load(Ordering::Relaxed)),
30 start_time: now,37 start_time: now,
31 current_time: now,38 current_time: now,
39+ curve: Curve::EaseOutCubic,
32 }40 }
33 }41 }
34 42
43+ pub fn with_curve(mut self, curve: Curve) -> Self {
44+ self.curve = curve;
45+ self
46+ }
47+
35 pub fn set_current_time(&mut self, time: Duration) {48 pub fn set_current_time(&mut self, time: Duration) {
36 self.current_time = time;49 self.current_time = time;
37 }50 }
@@ -44,7 +57,7 @@ impl Animation {
44 let passed = (self.current_time - self.start_time).as_secs_f64();57 let passed = (self.current_time - self.start_time).as_secs_f64();
45 let total = self.duration.as_secs_f64();58 let total = self.duration.as_secs_f64();
46 let x = (passed / total).clamp(0., 1.);59 let x = (passed / total).clamp(0., 1.);
47- EaseOutCubic.y(x) * (self.to - self.from) + self.from60+ self.curve.y(x) * (self.to - self.from) + self.from
48 }61 }
49 62
50 pub fn to(&self) -> f64 {63 pub fn to(&self) -> f64 {
@@ -56,3 +69,12 @@ impl Animation {
56 self.from69 self.from
57 }70 }
58 }71 }
72+
73+impl Curve {
74+ pub fn y(self, x: f64) -> f64 {
75+ match self {
76+ Curve::EaseOutCubic => EaseOutCubic.y(x),
77+ Curve::EaseOutExpo => 1. - 2f64.powf(-10. * x),
78+ }
79+ }
80+}
src/handlers/compositor.rsmodified+1 -0
@@ -120,6 +120,7 @@ impl CompositorHandler for State {
120 };120 };
121 121
122 if let Some(output) = output.cloned() {122 if let Some(output) = output.cloned() {
123+ self.niri.layout.start_open_animation_for_window(&window);
123 self.niri.queue_redraw(output);124 self.niri.queue_redraw(output);
124 }125 }
125 return;126 return;
src/layout/mod.rsmodified+43 -1
@@ -37,7 +37,7 @@ use std::time::Duration;
37 use niri_config::{self, CenterFocusedColumn, Config, SizeChange, Struts};37 use niri_config::{self, CenterFocusedColumn, Config, SizeChange, Struts};
38 use smithay::backend::renderer::element::solid::SolidColorRenderElement;38 use smithay::backend::renderer::element::solid::SolidColorRenderElement;
39 use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;39 use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
40-use smithay::backend::renderer::element::AsRenderElements;40+use smithay::backend::renderer::element::{AsRenderElements, Id};
41 use smithay::desktop::space::SpaceElement;41 use smithay::desktop::space::SpaceElement;
42 use smithay::desktop::Window;42 use smithay::desktop::Window;
43 use smithay::output::Output;43 use smithay::output::Output;
@@ -52,6 +52,7 @@ pub use self::monitor::MonitorRenderElement;
52 use self::monitor::{Monitor, WorkspaceSwitch, WorkspaceSwitchGesture};52 use self::monitor::{Monitor, WorkspaceSwitch, WorkspaceSwitchGesture};
53 use self::workspace::{compute_working_area, Column, ColumnWidth, OutputId, Workspace};53 use self::workspace::{compute_working_area, Column, ColumnWidth, OutputId, Workspace};
54 use crate::animation::Animation;54 use crate::animation::Animation;
55+use crate::niri::WindowOffscreenId;
55 use crate::niri_render_elements;56 use crate::niri_render_elements;
56 use crate::render_helpers::renderer::NiriRenderer;57 use crate::render_helpers::renderer::NiriRenderer;
57 use crate::utils::output_size;58 use crate::utils::output_size;
@@ -105,6 +106,7 @@ pub trait LayoutElement: PartialEq {
105 fn set_preferred_scale_transform(&self, scale: i32, transform: Transform);106 fn set_preferred_scale_transform(&self, scale: i32, transform: Transform);
106 fn output_enter(&self, output: &Output);107 fn output_enter(&self, output: &Output);
107 fn output_leave(&self, output: &Output);108 fn output_leave(&self, output: &Output);
109+ fn set_offscreen_element_id(&self, id: Option<Id>);
108 110
109 /// Whether the element is currently fullscreen.111 /// Whether the element is currently fullscreen.
110 ///112 ///
@@ -292,6 +294,11 @@ impl LayoutElement for Window {
292 SpaceElement::output_leave(self, output)294 SpaceElement::output_leave(self, output)
293 }295 }
294 296
297+ fn set_offscreen_element_id(&self, id: Option<Id>) {
298+ let data = self.user_data().get_or_insert(WindowOffscreenId::default);
299+ data.0.replace(id);
300+ }
301+
295 fn is_fullscreen(&self) -> bool {302 fn is_fullscreen(&self) -> bool {
296 self.toplevel()303 self.toplevel()
297 .current_state()304 .current_state()
@@ -1593,6 +1600,39 @@ impl<W: LayoutElement> Layout<W> {
1593 };1600 };
1594 monitor.move_workspace_up();1601 monitor.move_workspace_up();
1595 }1602 }
1603+
1604+ pub fn start_open_animation_for_window(&mut self, window: &W) {
1605+ match &mut self.monitor_set {
1606+ MonitorSet::Normal { monitors, .. } => {
1607+ for mon in monitors {
1608+ for ws in &mut mon.workspaces {
1609+ for col in &mut ws.columns {
1610+ for tile in &mut col.tiles {
1611+ if tile.window() == window {
1612+ tile.start_open_animation();
1613+ return;
1614+ }
1615+ }
1616+ }
1617+ }
1618+ }
1619+ }
1620+ MonitorSet::NoOutputs { workspaces, .. } => {
1621+ for ws in workspaces {
1622+ if ws.has_window(window) {
1623+ for col in &mut ws.columns {
1624+ for tile in &mut col.tiles {
1625+ if tile.window() == window {
1626+ tile.start_open_animation();
1627+ return;
1628+ }
1629+ }
1630+ }
1631+ }
1632+ }
1633+ }
1634+ }
1635+ }
1596 }1636 }
1597 1637
1598 impl Layout<Window> {1638 impl Layout<Window> {
@@ -1757,6 +1797,8 @@ mod tests {
1757 1797
1758 fn output_leave(&self, _output: &Output) {}1798 fn output_leave(&self, _output: &Output) {}
1759 1799
1800+ fn set_offscreen_element_id(&self, _id: Option<Id>) {}
1801+
1760 fn is_fullscreen(&self) -> bool {1802 fn is_fullscreen(&self) -> bool {
1761 false1803 false
1762 }1804 }
src/layout/tile.rsmodified+90 -4
@@ -3,13 +3,17 @@ use std::rc::Rc;
3 use std::time::Duration;3 use std::time::Duration;
4 4
5 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};5 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
6-use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement};6+use smithay::backend::renderer::element::utils::{
7-use smithay::backend::renderer::element::Kind;7+ Relocate, RelocateRenderElement, RescaleRenderElement,
8+};
9+use smithay::backend::renderer::element::{Element, Kind};
8 use smithay::utils::{Logical, Point, Rectangle, Scale, Size};10 use smithay::utils::{Logical, Point, Rectangle, Scale, Size};
9 11
10 use super::focus_ring::FocusRing;12 use super::focus_ring::FocusRing;
11 use super::{LayoutElement, LayoutElementRenderElement, Options};13 use super::{LayoutElement, LayoutElementRenderElement, Options};
14+use crate::animation::{Animation, Curve};
12 use crate::niri_render_elements;15 use crate::niri_render_elements;
16+use crate::render_helpers::offscreen::OffscreenRenderElement;
13 use crate::render_helpers::renderer::NiriRenderer;17 use crate::render_helpers::renderer::NiriRenderer;
14 18
15 /// Toplevel window with decorations.19 /// Toplevel window with decorations.
@@ -39,6 +43,9 @@ pub struct Tile<W: LayoutElement> {
39 /// The size we were requested to fullscreen into.43 /// The size we were requested to fullscreen into.
40 fullscreen_size: Size<i32, Logical>,44 fullscreen_size: Size<i32, Logical>,
41 45
46+ /// The animation upon opening a window.
47+ open_animation: Option<Animation>,
48+
42 /// Configurable properties of the layout.49 /// Configurable properties of the layout.
43 options: Rc<Options>,50 options: Rc<Options>,
44 }51 }
@@ -47,6 +54,7 @@ niri_render_elements! {
47 TileRenderElement => {54 TileRenderElement => {
48 LayoutElement = LayoutElementRenderElement<R>,55 LayoutElement = LayoutElementRenderElement<R>,
49 SolidColor = RelocateRenderElement<SolidColorRenderElement>,56 SolidColor = RelocateRenderElement<SolidColorRenderElement>,
57+ Offscreen = RescaleRenderElement<OffscreenRenderElement>,
50 }58 }
51 }59 }
52 60
@@ -59,6 +67,7 @@ impl<W: LayoutElement> Tile<W> {
59 is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size.67 is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size.
60 fullscreen_backdrop: SolidColorBuffer::new((0, 0), [0., 0., 0., 1.]),68 fullscreen_backdrop: SolidColorBuffer::new((0, 0), [0., 0., 0., 1.]),
61 fullscreen_size: Default::default(),69 fullscreen_size: Default::default(),
70+ open_animation: None,
62 options,71 options,
63 }72 }
64 }73 }
@@ -76,7 +85,7 @@ impl<W: LayoutElement> Tile<W> {
76 }85 }
77 }86 }
78 87
79- pub fn advance_animations(&mut self, _current_time: Duration, is_active: bool) {88+ pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {
80 let width = self.border.width();89 let width = self.border.width();
81 self.border.update(90 self.border.update(
82 (width, width).into(),91 (width, width).into(),
@@ -88,6 +97,25 @@ impl<W: LayoutElement> Tile<W> {
88 self.focus_ring97 self.focus_ring
89 .update((0, 0).into(), self.tile_size(), self.has_ssd());98 .update((0, 0).into(), self.tile_size(), self.has_ssd());
90 self.focus_ring.set_active(is_active);99 self.focus_ring.set_active(is_active);
100+
101+ match &mut self.open_animation {
102+ Some(anim) => {
103+ anim.set_current_time(current_time);
104+ if anim.is_done() {
105+ self.open_animation = None;
106+ }
107+ }
108+ None => (),
109+ }
110+ }
111+
112+ pub fn are_animations_ongoing(&self) -> bool {
113+ self.open_animation.is_some()
114+ }
115+
116+ pub fn start_open_animation(&mut self) {
117+ self.open_animation =
118+ Some(Animation::new(0., 1., Duration::from_millis(150)).with_curve(Curve::EaseOutExpo));
91 }119 }
92 120
93 pub fn window(&self) -> &W {121 pub fn window(&self) -> &W {
@@ -160,6 +188,22 @@ impl<W: LayoutElement> Tile<W> {
160 self.window.size()188 self.window.size()
161 }189 }
162 190
191+ /// Returns an animated size of the tile for rendering and input.
192+ ///
193+ /// During the window opening animation, windows to the right should gradually slide further to
194+ /// the right. This is what this visual size is used for. Other things like window resizes or
195+ /// transactions or new view position calculation always use the real size, instead of this
196+ /// visual size.
197+ pub fn visual_tile_size(&self) -> Size<i32, Logical> {
198+ let size = self.tile_size();
199+ let v = self
200+ .open_animation
201+ .as_ref()
202+ .map(|anim| anim.value())
203+ .unwrap_or(1.);
204+ Size::from(((f64::from(size.w) * v).round() as i32, size.h))
205+ }
206+
163 pub fn buf_loc(&self) -> Point<i32, Logical> {207 pub fn buf_loc(&self) -> Point<i32, Logical> {
164 let mut loc = Point::from((0, 0));208 let mut loc = Point::from((0, 0));
165 loc += self.window_loc();209 loc += self.window_loc();
@@ -251,7 +295,7 @@ impl<W: LayoutElement> Tile<W> {
251 self.effective_border_width().is_some() || self.window.has_ssd()295 self.effective_border_width().is_some() || self.window.has_ssd()
252 }296 }
253 297
254- pub fn render<R: NiriRenderer>(298+ fn render_inner<R: NiriRenderer>(
255 &self,299 &self,
256 renderer: &mut R,300 renderer: &mut R,
257 location: Point<i32, Logical>,301 location: Point<i32, Logical>,
@@ -300,4 +344,46 @@ impl<W: LayoutElement> Tile<W> {
300 });344 });
301 rv.chain(elem)345 rv.chain(elem)
302 }346 }
347+
348+ pub fn render<R: NiriRenderer>(
349+ &self,
350+ renderer: &mut R,
351+ location: Point<i32, Logical>,
352+ scale: Scale<f64>,
353+ focus_ring: bool,
354+ ) -> impl Iterator<Item = TileRenderElement<R>> {
355+ if let Some(anim) = &self.open_animation {
356+ let renderer = renderer.as_gles_renderer();
357+ let elements = self.render_inner(renderer, location, scale, focus_ring);
358+ let elements = elements.collect::<Vec<TileRenderElement<_>>>();
359+
360+ let elem = OffscreenRenderElement::new(
361+ renderer,
362+ scale.x as i32,
363+ &elements,
364+ anim.value() as f32,
365+ );
366+ self.window()
367+ .set_offscreen_element_id(Some(elem.id().clone()));
368+
369+ let mut center = location;
370+ center.x += self.tile_size().w / 2;
371+ center.y += self.tile_size().h / 2;
372+
373+ Some(TileRenderElement::Offscreen(
374+ RescaleRenderElement::from_element(
375+ elem,
376+ center.to_physical_precise_round(scale),
377+ (anim.value() / 2. + 0.5).min(1.),
378+ ),
379+ ))
380+ .into_iter()
381+ .chain(None.into_iter().flatten())
382+ } else {
383+ self.window().set_offscreen_element_id(None);
384+
385+ let elements = self.render_inner(renderer, location, scale, focus_ring);
386+ None.into_iter().chain(Some(elements).into_iter().flatten())
387+ }
388+ }
303 }389 }
src/layout/workspace.rsmodified+26 -4
@@ -230,7 +230,7 @@ impl<W: LayoutElement> Workspace<W> {
230 }230 }
231 231
232 pub fn are_animations_ongoing(&self) -> bool {232 pub fn are_animations_ongoing(&self) -> bool {
233- self.view_offset_anim.is_some()233+ self.view_offset_anim.is_some() || self.columns.iter().any(Column::are_animations_ongoing)
234 }234 }
235 235
236 pub fn update_config(&mut self, options: Rc<Options>) {236 pub fn update_config(&mut self, options: Rc<Options>) {
@@ -507,6 +507,16 @@ impl<W: LayoutElement> Workspace<W> {
507 x507 x
508 }508 }
509 509
510+ fn visual_column_x(&self, column_idx: usize) -> i32 {
511+ let mut x = 0;
512+
513+ for column in self.columns.iter().take(column_idx) {
514+ x += column.visual_width() + self.options.gaps;
515+ }
516+
517+ x
518+ }
519+
510 pub fn add_window(520 pub fn add_window(
511 &mut self,521 &mut self,
512 window: W,522 window: W,
@@ -978,13 +988,13 @@ impl<W: LayoutElement> Workspace<W> {
978 }988 }
979 989
980 fn tiles_in_render_order(&self) -> impl Iterator<Item = (&'_ Tile<W>, Point<i32, Logical>)> {990 fn tiles_in_render_order(&self) -> impl Iterator<Item = (&'_ Tile<W>, Point<i32, Logical>)> {
981- let view_pos = self.view_pos();991+ let view_pos = self.visual_column_x(self.active_column_idx) + self.view_offset;
982 992
983 // Start with the active window since it's drawn on top.993 // Start with the active window since it's drawn on top.
984 let col = &self.columns[self.active_column_idx];994 let col = &self.columns[self.active_column_idx];
985 let tile = &col.tiles[col.active_tile_idx];995 let tile = &col.tiles[col.active_tile_idx];
986 let tile_pos = Point::from((996 let tile_pos = Point::from((
987- self.column_x(self.active_column_idx) - view_pos,997+ self.visual_column_x(self.active_column_idx) - view_pos,
988 col.tile_y(col.active_tile_idx),998 col.tile_y(col.active_tile_idx),
989 ));999 ));
990 let first = iter::once((tile, tile_pos));1000 let first = iter::once((tile, tile_pos));
@@ -997,7 +1007,7 @@ impl<W: LayoutElement> Workspace<W> {
997 // Keep track of column X position.1007 // Keep track of column X position.
998 .map(move |(col_idx, col)| {1008 .map(move |(col_idx, col)| {
999 let rv = (col_idx, col, x);1009 let rv = (col_idx, col, x);
1000- x += col.width() + self.options.gaps;1010+ x += col.visual_width() + self.options.gaps;
1001 rv1011 rv
1002 })1012 })
1003 .flat_map(move |(col_idx, col, x)| {1013 .flat_map(move |(col_idx, col, x)| {
@@ -1279,6 +1289,10 @@ impl<W: LayoutElement> Column<W> {
1279 }1289 }
1280 }1290 }
1281 1291
1292+ pub fn are_animations_ongoing(&self) -> bool {
1293+ self.tiles.iter().any(Tile::are_animations_ongoing)
1294+ }
1295+
1282 pub fn contains(&self, window: &W) -> bool {1296 pub fn contains(&self, window: &W) -> bool {
1283 self.tiles.iter().map(Tile::window).any(|win| win == window)1297 self.tiles.iter().map(Tile::window).any(|win| win == window)
1284 }1298 }
@@ -1477,6 +1491,14 @@ impl<W: LayoutElement> Column<W> {
1477 .unwrap()1491 .unwrap()
1478 }1492 }
1479 1493
1494+ fn visual_width(&self) -> i32 {
1495+ self.tiles
1496+ .iter()
1497+ .map(|tile| tile.visual_tile_size().w)
1498+ .max()
1499+ .unwrap()
1500+ }
1501+
1480 fn focus_up(&mut self) {1502 fn focus_up(&mut self) {
1481 self.active_tile_idx = self.active_tile_idx.saturating_sub(1);1503 self.active_tile_idx = self.active_tile_idx.saturating_sub(1);
1482 }1504 }