forge
Explore
Log in

Don't you dare go Hollow

Implement window resize animations

Browse files at this commit

71be19b234d58f4ec447e921633506beb81a52c0Ivan MolodetskikhParent: 4fd9300
Cargo.lockmodified+2 -2
@@ -3115,7 +3115,7 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
3115 [[package]]3115 [[package]]
3116 name = "smithay"3116 name = "smithay"
3117 version = "0.3.0"3117 version = "0.3.0"
3118-source = "git+https://github.com/Smithay/smithay.git#e237b077bd922e17849eff91ba05853c7a68f958"3118+source = "git+https://github.com/Smithay/smithay.git#c5e9a697e41f50dc56b918d9ef1e3d2e52c84ac0"
3119 dependencies = [3119 dependencies = [
3120 "appendlist",3120 "appendlist",
3121 "bitflags 2.5.0",3121 "bitflags 2.5.0",
@@ -3187,7 +3187,7 @@ dependencies = [
3187 [[package]]3187 [[package]]
3188 name = "smithay-drm-extras"3188 name = "smithay-drm-extras"
3189 version = "0.1.0"3189 version = "0.1.0"
3190-source = "git+https://github.com/Smithay/smithay.git#e237b077bd922e17849eff91ba05853c7a68f958"3190+source = "git+https://github.com/Smithay/smithay.git#c5e9a697e41f50dc56b918d9ef1e3d2e52c84ac0"
3191 dependencies = [3191 dependencies = [
3192 "drm",3192 "drm",
3193 "edid-rs",3193 "edid-rs",
niri-config/src/lib.rsmodified+14 -0
@@ -489,6 +489,8 @@ pub struct Animations {
489 pub window_open: Animation,489 pub window_open: Animation,
490 #[knuffel(child, default = Animation::default_window_close())]490 #[knuffel(child, default = Animation::default_window_close())]
491 pub window_close: Animation,491 pub window_close: Animation,
492+ #[knuffel(child, default = Animation::default_window_resize())]
493+ pub window_resize: Animation,
492 #[knuffel(child, default = Animation::default_config_notification_open_close())]494 #[knuffel(child, default = Animation::default_config_notification_open_close())]
493 pub config_notification_open_close: Animation,495 pub config_notification_open_close: Animation,
494 }496 }
@@ -503,6 +505,7 @@ impl Default for Animations {
503 window_movement: Animation::default_window_movement(),505 window_movement: Animation::default_window_movement(),
504 window_open: Animation::default_window_open(),506 window_open: Animation::default_window_open(),
505 window_close: Animation::default_window_close(),507 window_close: Animation::default_window_close(),
508+ window_resize: Animation::default_window_resize(),
506 config_notification_open_close: Animation::default_config_notification_open_close(),509 config_notification_open_close: Animation::default_config_notification_open_close(),
507 }510 }
508 }511 }
@@ -592,6 +595,17 @@ impl Animation {
592 }),595 }),
593 }596 }
594 }597 }
598+
599+ pub const fn default_window_resize() -> Self {
600+ Self {
601+ off: false,
602+ kind: AnimationKind::Spring(SpringParams {
603+ damping_ratio: 1.,
604+ stiffness: 800,
605+ epsilon: 0.0001,
606+ }),
607+ }
608+ }
595 }609 }
596 610
597 #[derive(Debug, Clone, Copy, PartialEq)]611 #[derive(Debug, Clone, Copy, PartialEq)]
niri-visual-tests/src/cases/tile.rsmodified+5 -4
@@ -20,7 +20,7 @@ impl Tile {
20 pub fn freeform(size: Size<i32, Logical>) -> Self {20 pub fn freeform(size: Size<i32, Logical>) -> Self {
21 let window = TestWindow::freeform(0);21 let window = TestWindow::freeform(0);
22 let mut rv = Self::with_window(window);22 let mut rv = Self::with_window(window);
23- rv.tile.request_tile_size(size);23+ rv.tile.request_tile_size(size, false);
24 rv.window.communicate();24 rv.window.communicate();
25 rv25 rv
26 }26 }
@@ -28,7 +28,7 @@ impl Tile {
28 pub fn fixed_size(size: Size<i32, Logical>) -> Self {28 pub fn fixed_size(size: Size<i32, Logical>) -> Self {
29 let window = TestWindow::fixed_size(0);29 let window = TestWindow::fixed_size(0);
30 let mut rv = Self::with_window(window);30 let mut rv = Self::with_window(window);
31- rv.tile.request_tile_size(size);31+ rv.tile.request_tile_size(size, false);
32 rv.window.communicate();32 rv.window.communicate();
33 rv33 rv
34 }34 }
@@ -37,7 +37,7 @@ impl Tile {
37 let window = TestWindow::fixed_size(0);37 let window = TestWindow::fixed_size(0);
38 window.set_csd_shadow_width(64);38 window.set_csd_shadow_width(64);
39 let mut rv = Self::with_window(window);39 let mut rv = Self::with_window(window);
40- rv.tile.request_tile_size(size);40+ rv.tile.request_tile_size(size, false);
41 rv.window.communicate();41 rv.window.communicate();
42 rv42 rv
43 }43 }
@@ -84,7 +84,8 @@ impl Tile {
84 84
85 impl TestCase for Tile {85 impl TestCase for Tile {
86 fn resize(&mut self, width: i32, height: i32) {86 fn resize(&mut self, width: i32, height: i32) {
87- self.tile.request_tile_size(Size::from((width, height)));87+ self.tile
88+ .request_tile_size(Size::from((width, height)), false);
88 self.window.communicate();89 self.window.communicate();
89 }90 }
90 91
niri-visual-tests/src/cases/window.rsmodified+7 -7
@@ -13,23 +13,23 @@ pub struct Window {
13 13
14 impl Window {14 impl Window {
15 pub fn freeform(size: Size<i32, Logical>) -> Self {15 pub fn freeform(size: Size<i32, Logical>) -> Self {
16- let window = TestWindow::freeform(0);16+ let mut window = TestWindow::freeform(0);
17- window.request_size(size);17+ window.request_size(size, false);
18 window.communicate();18 window.communicate();
19 Self { window }19 Self { window }
20 }20 }
21 21
22 pub fn fixed_size(size: Size<i32, Logical>) -> Self {22 pub fn fixed_size(size: Size<i32, Logical>) -> Self {
23- let window = TestWindow::fixed_size(0);23+ let mut window = TestWindow::fixed_size(0);
24- window.request_size(size);24+ window.request_size(size, false);
25 window.communicate();25 window.communicate();
26 Self { window }26 Self { window }
27 }27 }
28 28
29 pub fn fixed_size_with_csd_shadow(size: Size<i32, Logical>) -> Self {29 pub fn fixed_size_with_csd_shadow(size: Size<i32, Logical>) -> Self {
30- let window = TestWindow::fixed_size(0);30+ let mut window = TestWindow::fixed_size(0);
31 window.set_csd_shadow_width(64);31 window.set_csd_shadow_width(64);
32- window.request_size(size);32+ window.request_size(size, false);
33 window.communicate();33 window.communicate();
34 Self { window }34 Self { window }
35 }35 }
@@ -37,7 +37,7 @@ impl Window {
37 37
38 impl TestCase for Window {38 impl TestCase for Window {
39 fn resize(&mut self, width: i32, height: i32) {39 fn resize(&mut self, width: i32, height: i32) {
40- self.window.request_size(Size::from((width, height)));40+ self.window.request_size(Size::from((width, height)), false);
41 self.window.communicate();41 self.window.communicate();
42 }42 }
43 43
niri-visual-tests/src/smithay_view.rsmodified+2 -1
@@ -11,7 +11,7 @@ mod imp {
11 use anyhow::{ensure, Context};11 use anyhow::{ensure, Context};
12 use gtk::gdk;12 use gtk::gdk;
13 use gtk::prelude::*;13 use gtk::prelude::*;
14- use niri::render_helpers::shaders;14+ use niri::render_helpers::{resources, shaders};
15 use niri::utils::get_monotonic_time;15 use niri::utils::get_monotonic_time;
16 use smithay::backend::egl::ffi::egl;16 use smithay::backend::egl::ffi::egl;
17 use smithay::backend::egl::EGLContext;17 use smithay::backend::egl::EGLContext;
@@ -194,6 +194,7 @@ mod imp {
194 let mut renderer = GlesRenderer::with_capabilities(egl_context, capabilities)194 let mut renderer = GlesRenderer::with_capabilities(egl_context, capabilities)
195 .context("error creating GlesRenderer")?;195 .context("error creating GlesRenderer")?;
196 196
197+ resources::init(&mut renderer);
197 shaders::init(&mut renderer);198 shaders::init(&mut renderer);
198 199
199 Ok(renderer)200 Ok(renderer)
niri-visual-tests/src/test_window.rsmodified+13 -3
@@ -2,7 +2,9 @@ use std::cell::RefCell;
2 use std::cmp::{max, min};2 use std::cmp::{max, min};
3 use std::rc::Rc;3 use std::rc::Rc;
4 4
5-use niri::layout::{LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot};5+use niri::layout::{
6+ AnimationSnapshot, LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot,
7+};
6 use niri::render_helpers::renderer::NiriRenderer;8 use niri::render_helpers::renderer::NiriRenderer;
7 use niri::render_helpers::{RenderSnapshot, RenderTarget};9 use niri::render_helpers::{RenderSnapshot, RenderTarget};
8 use niri::window::ResolvedWindowRules;10 use niri::window::ResolvedWindowRules;
@@ -177,7 +179,7 @@ impl LayoutElement for TestWindow {
177 RenderSnapshot::default()179 RenderSnapshot::default()
178 }180 }
179 181
180- fn request_size(&self, size: Size<i32, Logical>) {182+ fn request_size(&mut self, size: Size<i32, Logical>, _animate: bool) {
181 self.inner.borrow_mut().requested_size = Some(size);183 self.inner.borrow_mut().requested_size = Some(size);
182 self.inner.borrow_mut().pending_fullscreen = false;184 self.inner.borrow_mut().pending_fullscreen = false;
183 }185 }
@@ -214,7 +216,7 @@ impl LayoutElement for TestWindow {
214 216
215 fn set_bounds(&self, _bounds: Size<i32, Logical>) {}217 fn set_bounds(&self, _bounds: Size<i32, Logical>) {}
216 218
217- fn send_pending_configure(&self) {}219+ fn send_pending_configure(&mut self) {}
218 220
219 fn is_fullscreen(&self) -> bool {221 fn is_fullscreen(&self) -> bool {
220 false222 false
@@ -230,4 +232,12 @@ impl LayoutElement for TestWindow {
230 static EMPTY: ResolvedWindowRules = ResolvedWindowRules::empty();232 static EMPTY: ResolvedWindowRules = ResolvedWindowRules::empty();
231 &EMPTY233 &EMPTY
232 }234 }
235+
236+ fn animation_snapshot(&self) -> Option<&AnimationSnapshot> {
237+ None
238+ }
239+
240+ fn take_animation_snapshot(&mut self) -> Option<AnimationSnapshot> {
241+ None
242+ }
233 }243 }
src/backend/tty.rsmodified+2 -1
@@ -59,7 +59,7 @@ use super::{IpcOutputMap, RenderResult};
59 use crate::frame_clock::FrameClock;59 use crate::frame_clock::FrameClock;
60 use crate::niri::{Niri, RedrawState, State};60 use crate::niri::{Niri, RedrawState, State};
61 use crate::render_helpers::renderer::AsGlesRenderer;61 use crate::render_helpers::renderer::AsGlesRenderer;
62-use crate::render_helpers::{shaders, RenderTarget};62+use crate::render_helpers::{resources, shaders, RenderTarget};
63 use crate::utils::{get_monotonic_time, logical_output};63 use crate::utils::{get_monotonic_time, logical_output};
64 64
65 const SUPPORTED_COLOR_FORMATS: &[Fourcc] = &[Fourcc::Argb8888, Fourcc::Abgr8888];65 const SUPPORTED_COLOR_FORMATS: &[Fourcc] = &[Fourcc::Argb8888, Fourcc::Abgr8888];
@@ -490,6 +490,7 @@ impl Tty {
490 warn!("error binding wl-display in EGL: {err:?}");490 warn!("error binding wl-display in EGL: {err:?}");
491 }491 }
492 492
493+ resources::init(renderer.as_gles_renderer());
493 shaders::init(renderer.as_gles_renderer());494 shaders::init(renderer.as_gles_renderer());
494 495
495 // Create the dmabuf global.496 // Create the dmabuf global.
src/backend/winit.rsmodified+2 -1
@@ -19,7 +19,7 @@ use smithay::reexports::winit::window::WindowBuilder;
19 19
20 use super::{IpcOutputMap, RenderResult};20 use super::{IpcOutputMap, RenderResult};
21 use crate::niri::{Niri, RedrawState, State};21 use crate::niri::{Niri, RedrawState, State};
22-use crate::render_helpers::{shaders, RenderTarget};22+use crate::render_helpers::{resources, shaders, RenderTarget};
23 use crate::utils::{get_monotonic_time, logical_output};23 use crate::utils::{get_monotonic_time, logical_output};
24 24
25 pub struct Winit {25 pub struct Winit {
@@ -130,6 +130,7 @@ impl Winit {
130 warn!("error binding renderer wl_display: {err}");130 warn!("error binding renderer wl_display: {err}");
131 }131 }
132 132
133+ resources::init(renderer);
133 shaders::init(renderer);134 shaders::init(renderer);
134 135
135 niri.add_output(self.output.clone(), None);136 niri.add_output(self.output.clone(), None);
src/handlers/xdg_shell.rsmodified+30 -3
@@ -815,16 +815,34 @@ fn unconstrain_with_padding(
815 815
816 pub fn add_mapped_toplevel_pre_commit_hook(toplevel: &ToplevelSurface) -> HookId {816 pub fn add_mapped_toplevel_pre_commit_hook(toplevel: &ToplevelSurface) -> HookId {
817 add_pre_commit_hook::<State, _>(toplevel.wl_surface(), move |state, _dh, surface| {817 add_pre_commit_hook::<State, _>(toplevel.wl_surface(), move |state, _dh, surface| {
818+ let _span = tracy_client::span!("mapped toplevel pre-commit");
819+
818 let Some((mapped, _)) = state.niri.layout.find_window_and_output_mut(surface) else {820 let Some((mapped, _)) = state.niri.layout.find_window_and_output_mut(surface) else {
819 error!("pre-commit hook for mapped surfaces must be removed upon unmapping");821 error!("pre-commit hook for mapped surfaces must be removed upon unmapping");
820 return;822 return;
821 };823 };
822 824
823- let got_unmapped = with_states(surface, |states| {825+ let (got_unmapped, commit_serial) = with_states(surface, |states| {
824- let attrs = states.cached_state.current::<SurfaceAttributes>();826+ let attrs = states.cached_state.pending::<SurfaceAttributes>();
825- matches!(attrs.buffer, Some(BufferAssignment::Removed))827+ let got_unmapped = matches!(attrs.buffer, Some(BufferAssignment::Removed));
828+
829+ let role = states
830+ .data_map
831+ .get::<XdgToplevelSurfaceData>()
832+ .unwrap()
833+ .lock()
834+ .unwrap();
835+
836+ (got_unmapped, role.configure_serial)
826 });837 });
827 838
839+ let animate = if let Some(serial) = commit_serial {
840+ mapped.should_animate_commit(serial)
841+ } else {
842+ error!("commit on a mapped surface without a configured serial");
843+ false
844+ };
845+
828 if got_unmapped {846 if got_unmapped {
829 state.backend.with_primary_renderer(|renderer| {847 state.backend.with_primary_renderer(|renderer| {
830 mapped.render_and_store_snapshot(renderer);848 mapped.render_and_store_snapshot(renderer);
@@ -832,6 +850,15 @@ pub fn add_mapped_toplevel_pre_commit_hook(toplevel: &ToplevelSurface) -> HookId
832 } else {850 } else {
833 // The toplevel remains mapped; clear any cached render snapshot.851 // The toplevel remains mapped; clear any cached render snapshot.
834 let _ = mapped.take_last_render();852 let _ = mapped.take_last_render();
853+
854+ if animate {
855+ state.backend.with_primary_renderer(|renderer| {
856+ mapped.store_animation_snapshot(renderer);
857+ });
858+
859+ let window = mapped.window.clone();
860+ state.niri.layout.prepare_for_resize_animation(&window);
861+ }
835 }862 }
836 })863 })
837 }864 }
src/layout/mod.rsmodified+52 -4
@@ -60,6 +60,9 @@ pub mod monitor;
60 pub mod tile;60 pub mod tile;
61 pub mod workspace;61 pub mod workspace;
62 62
63+/// Size changes up to this many pixels don't animate.
64+pub const RESIZE_ANIMATION_THRESHOLD: i32 = 10;
65+
63 niri_render_elements! {66 niri_render_elements! {
64 LayoutElementRenderElement<R> => {67 LayoutElementRenderElement<R> => {
65 Wayland = WaylandSurfaceRenderElement<R>,68 Wayland = WaylandSurfaceRenderElement<R>,
@@ -70,6 +73,15 @@ niri_render_elements! {
70 pub type LayoutElementRenderSnapshot =73 pub type LayoutElementRenderSnapshot =
71 RenderSnapshot<BakedBuffer<TextureBuffer<GlesTexture>>, BakedBuffer<SolidColorBuffer>>;74 RenderSnapshot<BakedBuffer<TextureBuffer<GlesTexture>>, BakedBuffer<SolidColorBuffer>>;
72 75
76+/// Snapshot of an element for animation.
77+#[derive(Debug)]
78+pub struct AnimationSnapshot {
79+ /// Snapshot of the render.
80+ pub render: LayoutElementRenderSnapshot,
81+ /// Visual size of the element at the point of the snapshot.
82+ pub size: Size<i32, Logical>,
83+}
84+
73 pub trait LayoutElement {85 pub trait LayoutElement {
74 /// Type that can be used as a unique ID of this element.86 /// Type that can be used as a unique ID of this element.
75 type Id: PartialEq;87 type Id: PartialEq;
@@ -108,7 +120,7 @@ pub trait LayoutElement {
108 120
109 fn take_last_render(&self) -> LayoutElementRenderSnapshot;121 fn take_last_render(&self) -> LayoutElementRenderSnapshot;
110 122
111- fn request_size(&self, size: Size<i32, Logical>);123+ fn request_size(&mut self, size: Size<i32, Logical>, animate: bool);
112 fn request_fullscreen(&self, size: Size<i32, Logical>);124 fn request_fullscreen(&self, size: Size<i32, Logical>);
113 fn min_size(&self) -> Size<i32, Logical>;125 fn min_size(&self) -> Size<i32, Logical>;
114 fn max_size(&self) -> Size<i32, Logical>;126 fn max_size(&self) -> Size<i32, Logical>;
@@ -121,7 +133,7 @@ pub trait LayoutElement {
121 fn set_activated(&mut self, active: bool);133 fn set_activated(&mut self, active: bool);
122 fn set_bounds(&self, bounds: Size<i32, Logical>);134 fn set_bounds(&self, bounds: Size<i32, Logical>);
123 135
124- fn send_pending_configure(&self);136+ fn send_pending_configure(&mut self);
125 137
126 /// Whether the element is currently fullscreen.138 /// Whether the element is currently fullscreen.
127 ///139 ///
@@ -137,6 +149,9 @@ pub trait LayoutElement {
137 149
138 /// Runs periodic clean-up tasks.150 /// Runs periodic clean-up tasks.
139 fn refresh(&self);151 fn refresh(&self);
152+
153+ fn animation_snapshot(&self) -> Option<&AnimationSnapshot>;
154+ fn take_animation_snapshot(&mut self) -> Option<AnimationSnapshot>;
140 }155 }
141 156
142 #[derive(Debug)]157 #[derive(Debug)]
@@ -1787,6 +1802,31 @@ impl<W: LayoutElement> Layout<W> {
1787 }1802 }
1788 }1803 }
1789 1804
1805+ pub fn prepare_for_resize_animation(&mut self, window: &W::Id) {
1806+ let _span = tracy_client::span!("Layout::prepare_for_resize_animation");
1807+
1808+ match &mut self.monitor_set {
1809+ MonitorSet::Normal { monitors, .. } => {
1810+ for mon in monitors {
1811+ for ws in &mut mon.workspaces {
1812+ if ws.has_window(window) {
1813+ ws.prepare_for_resize_animation(window);
1814+ return;
1815+ }
1816+ }
1817+ }
1818+ }
1819+ MonitorSet::NoOutputs { workspaces, .. } => {
1820+ for ws in workspaces {
1821+ if ws.has_window(window) {
1822+ ws.prepare_for_resize_animation(window);
1823+ return;
1824+ }
1825+ }
1826+ }
1827+ }
1828+ }
1829+
1790 pub fn refresh(&mut self) {1830 pub fn refresh(&mut self) {
1791 let _span = tracy_client::span!("Layout::refresh");1831 let _span = tracy_client::span!("Layout::refresh");
1792 1832
@@ -1930,7 +1970,7 @@ mod tests {
1930 RenderSnapshot::default()1970 RenderSnapshot::default()
1931 }1971 }
1932 1972
1933- fn request_size(&self, size: Size<i32, Logical>) {1973+ fn request_size(&mut self, size: Size<i32, Logical>, _animate: bool) {
1934 self.0.requested_size.set(Some(size));1974 self.0.requested_size.set(Some(size));
1935 self.0.pending_fullscreen.set(false);1975 self.0.pending_fullscreen.set(false);
1936 }1976 }
@@ -1967,7 +2007,7 @@ mod tests {
1967 2007
1968 fn set_bounds(&self, _bounds: Size<i32, Logical>) {}2008 fn set_bounds(&self, _bounds: Size<i32, Logical>) {}
1969 2009
1970- fn send_pending_configure(&self) {}2010+ fn send_pending_configure(&mut self) {}
1971 2011
1972 fn is_fullscreen(&self) -> bool {2012 fn is_fullscreen(&self) -> bool {
1973 false2013 false
@@ -1983,6 +2023,14 @@ mod tests {
1983 static EMPTY: ResolvedWindowRules = ResolvedWindowRules::empty();2023 static EMPTY: ResolvedWindowRules = ResolvedWindowRules::empty();
1984 &EMPTY2024 &EMPTY
1985 }2025 }
2026+
2027+ fn animation_snapshot(&self) -> Option<&AnimationSnapshot> {
2028+ None
2029+ }
2030+
2031+ fn take_animation_snapshot(&mut self) -> Option<AnimationSnapshot> {
2032+ None
2033+ }
1986 }2034 }
1987 2035
1988 fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> {2036 fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> {
src/layout/tile.rsmodified+334 -24
@@ -1,21 +1,31 @@
1+use std::cell::OnceCell;
1 use std::cmp::max;2 use std::cmp::max;
2 use std::rc::Rc;3 use std::rc::Rc;
3 use std::time::Duration;4 use std::time::Duration;
4 5
6+use niri_config::BlockOutFrom;
7+use smithay::backend::allocator::Fourcc;
5 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};8 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
6 use smithay::backend::renderer::element::utils::RescaleRenderElement;9 use smithay::backend::renderer::element::utils::RescaleRenderElement;
7 use smithay::backend::renderer::element::{Element, Kind};10 use smithay::backend::renderer::element::{Element, Kind};
8-use smithay::backend::renderer::gles::GlesRenderer;11+use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture};
9-use smithay::utils::{Logical, Point, Rectangle, Scale, Size};12+use smithay::utils::{Logical, Physical, Point, Rectangle, Scale, Size, Transform};
10 13
11 use super::focus_ring::{FocusRing, FocusRingRenderElement};14 use super::focus_ring::{FocusRing, FocusRingRenderElement};
12-use super::{LayoutElement, LayoutElementRenderElement, Options};15+use super::{
16+ AnimationSnapshot, LayoutElement, LayoutElementRenderElement, Options,
17+ RESIZE_ANIMATION_THRESHOLD,
18+};
13 use crate::animation::Animation;19 use crate::animation::Animation;
14 use crate::niri_render_elements;20 use crate::niri_render_elements;
21+use crate::render_helpers::crossfade::CrossfadeRenderElement;
15 use crate::render_helpers::offscreen::OffscreenRenderElement;22 use crate::render_helpers::offscreen::OffscreenRenderElement;
16 use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;23 use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;
17 use crate::render_helpers::renderer::NiriRenderer;24 use crate::render_helpers::renderer::NiriRenderer;
18-use crate::render_helpers::{RenderSnapshot, RenderTarget, ToRenderElement};25+use crate::render_helpers::shaders::Shaders;
26+use crate::render_helpers::{
27+ render_to_encompassing_texture, RenderSnapshot, RenderTarget, ToRenderElement,
28+};
19 29
20 /// Toplevel window with decorations.30 /// Toplevel window with decorations.
21 #[derive(Debug)]31 #[derive(Debug)]
@@ -47,6 +57,12 @@ pub struct Tile<W: LayoutElement> {
47 /// The animation upon opening a window.57 /// The animation upon opening a window.
48 open_animation: Option<Animation>,58 open_animation: Option<Animation>,
49 59
60+ /// The animation of the window resizing.
61+ resize_animation: Option<ResizeAnimation>,
62+
63+ /// The animation of a tile visually moving.
64+ move_animation: Option<MoveAnimation>,
65+
50 /// Configurable properties of the layout.66 /// Configurable properties of the layout.
51 options: Rc<Options>,67 options: Rc<Options>,
52 }68 }
@@ -57,17 +73,41 @@ niri_render_elements! {
57 FocusRing = FocusRingRenderElement,73 FocusRing = FocusRingRenderElement,
58 SolidColor = SolidColorRenderElement,74 SolidColor = SolidColorRenderElement,
59 Offscreen = RescaleRenderElement<OffscreenRenderElement>,75 Offscreen = RescaleRenderElement<OffscreenRenderElement>,
76+ Crossfade = CrossfadeRenderElement,
60 }77 }
61 }78 }
62 79
63 niri_render_elements! {80 niri_render_elements! {
64- TileSnapshotRenderElement => {81+ TileSnapshotContentsRenderElement => {
65 Texture = PrimaryGpuTextureRenderElement,82 Texture = PrimaryGpuTextureRenderElement,
83+ SolidColor = SolidColorRenderElement,
84+ }
85+}
86+
87+niri_render_elements! {
88+ TileSnapshotRenderElement => {
89+ Contents = RescaleRenderElement<TileSnapshotContentsRenderElement>,
66 FocusRing = FocusRingRenderElement,90 FocusRing = FocusRingRenderElement,
67 SolidColor = SolidColorRenderElement,91 SolidColor = SolidColorRenderElement,
68 }92 }
69 }93 }
70 94
95+#[derive(Debug)]
96+struct ResizeAnimation {
97+ anim: Animation,
98+ size_from: Size<i32, Logical>,
99+ snapshot: AnimationSnapshot,
100+ /// Snapshot rendered into a texture (happens lazily).
101+ snapshot_texture: OnceCell<Option<(GlesTexture, Rectangle<i32, Physical>)>>,
102+ snapshot_blocked_out_texture: OnceCell<Option<(GlesTexture, Rectangle<i32, Physical>)>>,
103+}
104+
105+#[derive(Debug)]
106+struct MoveAnimation {
107+ anim: Animation,
108+ from: Point<i32, Logical>,
109+}
110+
71 impl<W: LayoutElement> Tile<W> {111 impl<W: LayoutElement> Tile<W> {
72 pub fn new(window: W, options: Rc<Options>) -> Self {112 pub fn new(window: W, options: Rc<Options>) -> Self {
73 Self {113 Self {
@@ -78,6 +118,8 @@ impl<W: LayoutElement> Tile<W> {
78 fullscreen_backdrop: SolidColorBuffer::new((0, 0), [0., 0., 0., 1.]),118 fullscreen_backdrop: SolidColorBuffer::new((0, 0), [0., 0., 0., 1.]),
79 fullscreen_size: Default::default(),119 fullscreen_size: Default::default(),
80 open_animation: None,120 open_animation: None,
121+ resize_animation: None,
122+ move_animation: None,
81 options,123 options,
82 }124 }
83 }125 }
@@ -93,16 +135,76 @@ impl<W: LayoutElement> Tile<W> {
93 if self.fullscreen_size != Size::from((0, 0)) {135 if self.fullscreen_size != Size::from((0, 0)) {
94 self.is_fullscreen = self.window.is_fullscreen();136 self.is_fullscreen = self.window.is_fullscreen();
95 }137 }
138+
139+ if let Some(animate_from) = self.window.take_animation_snapshot() {
140+ let size_from = if let Some(resize) = self.resize_animation.take() {
141+ // Compute like in animated_window_size(), but using the snapshot geometry (since
142+ // the current one is already overwritten).
143+ let mut size = animate_from.size;
144+
145+ let val = resize.anim.value();
146+ let size_from = resize.size_from;
147+
148+ size.w = (size_from.w as f64 + (size.w - size_from.w) as f64 * val).round() as i32;
149+ size.h = (size_from.h as f64 + (size.h - size_from.h) as f64 * val).round() as i32;
150+
151+ size
152+ } else {
153+ animate_from.size
154+ };
155+
156+ let change = self.window.size().to_point() - size_from.to_point();
157+ let change = max(change.x.abs(), change.y.abs());
158+ if change > RESIZE_ANIMATION_THRESHOLD {
159+ let anim = Animation::new(
160+ 0.,
161+ 1.,
162+ 0.,
163+ self.options.animations.window_resize,
164+ niri_config::Animation::default_window_resize(),
165+ );
166+ self.resize_animation = Some(ResizeAnimation {
167+ anim,
168+ size_from,
169+ snapshot: animate_from,
170+ snapshot_texture: OnceCell::new(),
171+ snapshot_blocked_out_texture: OnceCell::new(),
172+ });
173+ } else {
174+ self.resize_animation = None;
175+ }
176+ }
96 }177 }
97 178
98 pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {179 pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {
180+ if let Some(anim) = &mut self.open_animation {
181+ anim.set_current_time(current_time);
182+ if anim.is_done() {
183+ self.open_animation = None;
184+ }
185+ }
186+
187+ if let Some(resize) = &mut self.resize_animation {
188+ resize.anim.set_current_time(current_time);
189+ if resize.anim.is_done() {
190+ self.resize_animation = None;
191+ }
192+ }
193+
194+ if let Some(move_) = &mut self.move_animation {
195+ move_.anim.set_current_time(current_time);
196+ if move_.anim.is_done() {
197+ self.move_animation = None;
198+ }
199+ }
200+
99 let draw_border_with_background = self201 let draw_border_with_background = self
100 .window202 .window
101 .rules()203 .rules()
102 .draw_border_with_background204 .draw_border_with_background
103 .unwrap_or_else(|| !self.window.has_ssd());205 .unwrap_or_else(|| !self.window.has_ssd());
104 self.border206 self.border
105- .update(self.window.size(), !draw_border_with_background);207+ .update(self.animated_window_size(), !draw_border_with_background);
106 self.border.set_active(is_active);208 self.border.set_active(is_active);
107 209
108 let draw_focus_ring_with_background = if self.effective_border_width().is_some() {210 let draw_focus_ring_with_background = if self.effective_border_width().is_some() {
@@ -111,22 +213,24 @@ impl<W: LayoutElement> Tile<W> {
111 draw_border_with_background213 draw_border_with_background
112 };214 };
113 self.focus_ring215 self.focus_ring
114- .update(self.tile_size(), !draw_focus_ring_with_background);216+ .update(self.animated_tile_size(), !draw_focus_ring_with_background);
115 self.focus_ring.set_active(is_active);217 self.focus_ring.set_active(is_active);
116-
117- match &mut self.open_animation {
118- Some(anim) => {
119- anim.set_current_time(current_time);
120- if anim.is_done() {
121- self.open_animation = None;
122- }
123- }
124- None => (),
125- }
126 }218 }
127 219
128 pub fn are_animations_ongoing(&self) -> bool {220 pub fn are_animations_ongoing(&self) -> bool {
129 self.open_animation.is_some()221 self.open_animation.is_some()
222+ || self.resize_animation.is_some()
223+ || self.move_animation.is_some()
224+ }
225+
226+ pub fn render_offset(&self) -> Point<i32, Logical> {
227+ let mut offset = Point::from((0., 0.));
228+
229+ if let Some(move_) = &self.move_animation {
230+ offset += move_.from.to_f64().upscale(move_.anim.value());
231+ }
232+
233+ offset.to_i32_round()
130 }234 }
131 235
132 pub fn start_open_animation(&mut self) {236 pub fn start_open_animation(&mut self) {
@@ -143,6 +247,24 @@ impl<W: LayoutElement> Tile<W> {
143 &self.open_animation247 &self.open_animation
144 }248 }
145 249
250+ pub fn resize_animation(&self) -> Option<&Animation> {
251+ self.resize_animation.as_ref().map(|resize| &resize.anim)
252+ }
253+
254+ pub fn animate_move_from_with_config(
255+ &mut self,
256+ from: Point<i32, Logical>,
257+ config: niri_config::Animation,
258+ default: niri_config::Animation,
259+ ) {
260+ let current_offset = self.render_offset();
261+
262+ self.move_animation = Some(MoveAnimation {
263+ anim: Animation::new(1., 0., 0., config, default),
264+ from: from + current_offset,
265+ });
266+ }
267+
146 pub fn window(&self) -> &W {268 pub fn window(&self) -> &W {
147 &self.window269 &self.window
148 }270 }
@@ -217,6 +339,39 @@ impl<W: LayoutElement> Tile<W> {
217 self.window.size()339 self.window.size()
218 }340 }
219 341
342+ fn animated_window_size(&self) -> Size<i32, Logical> {
343+ let mut size = self.window.size();
344+
345+ if let Some(resize) = &self.resize_animation {
346+ let val = resize.anim.value();
347+ let size_from = resize.size_from;
348+
349+ size.w = (size_from.w as f64 + (size.w - size_from.w) as f64 * val).round() as i32;
350+ size.h = (size_from.h as f64 + (size.h - size_from.h) as f64 * val).round() as i32;
351+ }
352+
353+ size
354+ }
355+
356+ fn animated_tile_size(&self) -> Size<i32, Logical> {
357+ let mut size = self.animated_window_size();
358+
359+ if self.is_fullscreen {
360+ // Normally we'd just return the fullscreen size here, but this makes things a bit
361+ // nicer if a fullscreen window is bigger than the fullscreen size for some reason.
362+ size.w = max(size.w, self.fullscreen_size.w);
363+ size.h = max(size.h, self.fullscreen_size.h);
364+ return size;
365+ }
366+
367+ if let Some(width) = self.effective_border_width() {
368+ size.w = size.w.saturating_add(width * 2);
369+ size.h = size.h.saturating_add(width * 2);
370+ }
371+
372+ size
373+ }
374+
220 pub fn buf_loc(&self) -> Point<i32, Logical> {375 pub fn buf_loc(&self) -> Point<i32, Logical> {
221 let mut loc = Point::from((0, 0));376 let mut loc = Point::from((0, 0));
222 loc += self.window_loc();377 loc += self.window_loc();
@@ -234,7 +389,7 @@ impl<W: LayoutElement> Tile<W> {
234 activation_region.to_f64().contains(point)389 activation_region.to_f64().contains(point)
235 }390 }
236 391
237- pub fn request_tile_size(&mut self, mut size: Size<i32, Logical>) {392+ pub fn request_tile_size(&mut self, mut size: Size<i32, Logical>, animate: bool) {
238 // Can't go through effective_border_width() because we might be fullscreen.393 // Can't go through effective_border_width() because we might be fullscreen.
239 if !self.border.is_off() {394 if !self.border.is_off() {
240 let width = self.border.width();395 let width = self.border.width();
@@ -242,7 +397,7 @@ impl<W: LayoutElement> Tile<W> {
242 size.h = max(1, size.h - width * 2);397 size.h = max(1, size.h - width * 2);
243 }398 }
244 399
245- self.window.request_size(size);400+ self.window.request_size(size, animate);
246 }401 }
247 402
248 pub fn tile_width_for_window_width(&self, size: i32) -> i32 {403 pub fn tile_width_for_window_width(&self, size: i32) -> i32 {
@@ -330,11 +485,85 @@ impl<W: LayoutElement> Tile<W> {
330 self.window.rules().opacity.unwrap_or(1.).clamp(0., 1.)485 self.window.rules().opacity.unwrap_or(1.).clamp(0., 1.)
331 };486 };
332 487
333- let rv = self488+ let window_loc = self.window_loc();
334- .window489+ let window_size = self.window_size();
335- .render(renderer, location + self.window_loc(), scale, alpha, target)490+ let animated_window_size = self.animated_window_size();
491+ let window_render_loc = location + window_loc;
492+ let area = Rectangle::from_loc_and_size(window_render_loc, animated_window_size);
493+
494+ let gles_renderer = renderer.as_gles_renderer();
495+
496+ // If we're resizing, try to render a crossfade, or a fallback.
497+ let mut crossfade = None;
498+ let mut crossfade_fallback = None;
499+
500+ if let Some(resize) = &self.resize_animation {
501+ if Shaders::get(gles_renderer).crossfade.is_some() {
502+ if let Some(texture_from) = resize.rendered_texture(gles_renderer, scale, target) {
503+ let window_elements =
504+ self.window
505+ .render(gles_renderer, Point::from((0, 0)), scale, 1., target);
506+ let current = render_to_encompassing_texture(
507+ gles_renderer,
508+ scale,
509+ Transform::Normal,
510+ Fourcc::Abgr8888,
511+ &window_elements,
512+ )
513+ .map_err(|err| warn!("error rendering window to texture: {err:?}"))
514+ .ok();
515+
516+ if let Some((texture_current, _sync_point, texture_current_geo)) = current {
517+ let elem = CrossfadeRenderElement::new(
518+ gles_renderer,
519+ area,
520+ scale,
521+ texture_from.clone(),
522+ resize.snapshot.size,
523+ (texture_current, texture_current_geo),
524+ window_size,
525+ resize.anim.clamped_value().clamp(0., 1.) as f32,
526+ alpha,
527+ )
528+ .expect("we checked the crossfade shader above");
529+ self.window
530+ .set_offscreen_element_id(Some(elem.id().clone()));
531+ crossfade = Some(elem.into());
532+ }
533+ }
534+ }
535+
536+ if crossfade.is_none() {
537+ let fallback_buffer = SolidColorBuffer::new(area.size, [1., 0., 0., 1.]);
538+ crossfade_fallback = Some(
539+ SolidColorRenderElement::from_buffer(
540+ &fallback_buffer,
541+ area.loc.to_physical_precise_round(scale),
542+ scale,
543+ alpha,
544+ Kind::Unspecified,
545+ )
546+ .into(),
547+ );
548+ self.window.set_offscreen_element_id(None);
549+ }
550+ }
551+
552+ // If we're not resizing, render the window itself.
553+ let mut window = None;
554+ if crossfade.is_none() && crossfade_fallback.is_none() {
555+ window = Some(
556+ self.window
557+ .render(renderer, window_render_loc, scale, alpha, target)
558+ .into_iter()
559+ .map(Into::into),
560+ );
561+ }
562+
563+ let rv = crossfade
336 .into_iter()564 .into_iter()
337- .map(Into::into);565+ .chain(crossfade_fallback)
566+ .chain(window.into_iter().flatten());
338 567
339 let elem = self.effective_border_width().map(|width| {568 let elem = self.effective_border_width().map(|width| {
340 self.border569 self.border
@@ -422,7 +651,7 @@ impl<W: LayoutElement> Tile<W> {
422 contents: Vec<C>,651 contents: Vec<C>,
423 ) -> Vec<TileSnapshotRenderElement>652 ) -> Vec<TileSnapshotRenderElement>
424 where653 where
425- E: Into<TileSnapshotRenderElement>,654+ E: Into<TileSnapshotContentsRenderElement>,
426 C: ToRenderElement<RenderElement = E>,655 C: ToRenderElement<RenderElement = E>,
427 {656 {
428 let alpha = if self.is_fullscreen {657 let alpha = if self.is_fullscreen {
@@ -431,10 +660,18 @@ impl<W: LayoutElement> Tile<W> {
431 self.window.rules().opacity.unwrap_or(1.).clamp(0., 1.)660 self.window.rules().opacity.unwrap_or(1.).clamp(0., 1.)
432 };661 };
433 662
663+ let window_size = self.window_size();
664+ let animated_window_size = self.animated_window_size();
665+ let animated_scale = animated_window_size.to_f64() / window_size.to_f64();
666+
434 let mut rv = vec![];667 let mut rv = vec![];
435 668
436 for baked in contents {669 for baked in contents {
437 let elem = baked.to_render_element(self.window_loc(), scale, alpha, Kind::Unspecified);670 let elem = baked.to_render_element(self.window_loc(), scale, alpha, Kind::Unspecified);
671+ let elem: TileSnapshotContentsRenderElement = elem.into();
672+
673+ let origin = self.window_loc().to_physical_precise_round(scale);
674+ let elem = RescaleRenderElement::from_element(elem, origin, animated_scale);
438 rv.push(elem.into());675 rv.push(elem.into());
439 }676 }
440 677
@@ -483,3 +720,76 @@ impl<W: LayoutElement> Tile<W> {
483 }720 }
484 }721 }
485 }722 }
723+
724+impl ResizeAnimation {
725+ fn rendered_texture(
726+ &self,
727+ renderer: &mut GlesRenderer,
728+ scale: Scale<f64>,
729+ target: RenderTarget,
730+ ) -> &Option<(GlesTexture, Rectangle<i32, Physical>)> {
731+ let block_out = match self.snapshot.render.block_out_from {
732+ None => false,
733+ Some(BlockOutFrom::Screencast) => target == RenderTarget::Screencast,
734+ Some(BlockOutFrom::ScreenCapture) => target != RenderTarget::Output,
735+ };
736+
737+ if block_out {
738+ self.snapshot_blocked_out_texture.get_or_init(|| {
739+ let _span = tracy_client::span!("ResizeAnimation::rendered_texture");
740+
741+ let elements: Vec<_> = self
742+ .snapshot
743+ .render
744+ .blocked_out_contents
745+ .iter()
746+ .map(|baked| {
747+ baked.to_render_element(Point::from((0, 0)), scale, 1., Kind::Unspecified)
748+ })
749+ .collect();
750+
751+ match render_to_encompassing_texture(
752+ renderer,
753+ scale,
754+ Transform::Normal,
755+ Fourcc::Abgr8888,
756+ &elements,
757+ ) {
758+ Ok((texture, _sync_point, geo)) => Some((texture, geo)),
759+ Err(err) => {
760+ warn!("error rendering snapshot to texture: {err:?}");
761+ None
762+ }
763+ }
764+ })
765+ } else {
766+ self.snapshot_texture.get_or_init(|| {
767+ let _span = tracy_client::span!("ResizeAnimation::rendered_texture");
768+
769+ let elements: Vec<_> = self
770+ .snapshot
771+ .render
772+ .contents
773+ .iter()
774+ .map(|baked| {
775+ baked.to_render_element(Point::from((0, 0)), scale, 1., Kind::Unspecified)
776+ })
777+ .collect();
778+
779+ match render_to_encompassing_texture(
780+ renderer,
781+ scale,
782+ Transform::Normal,
783+ Fourcc::Abgr8888,
784+ &elements,
785+ ) {
786+ Ok((texture, _sync_point, geo)) => Some((texture, geo)),
787+ Err(err) => {
788+ warn!("error rendering snapshot to texture: {err:?}");
789+ None
790+ }
791+ }
792+ })
793+ }
794+ }
795+}
src/layout/workspace.rsmodified+104 -23
@@ -190,6 +190,9 @@ pub struct Column<W: LayoutElement> {
190 /// Animation of the render offset during window swapping.190 /// Animation of the render offset during window swapping.
191 move_animation: Option<Animation>,191 move_animation: Option<Animation>,
192 192
193+ /// Width right before a resize animation on one of the windows of the column.
194+ pub width_before_resize: Option<i32>,
195+
193 /// Latest known view size for this column's workspace.196 /// Latest known view size for this column's workspace.
194 view_size: Size<i32, Logical>,197 view_size: Size<i32, Logical>,
195 198
@@ -815,7 +818,7 @@ impl<W: LayoutElement> Workspace<W> {
815 }818 }
816 819
817 column.active_tile_idx = min(column.active_tile_idx, column.tiles.len() - 1);820 column.active_tile_idx = min(column.active_tile_idx, column.tiles.len() - 1);
818- column.update_tile_sizes();821+ column.update_tile_sizes(false);
819 822
820 window823 window
821 }824 }
@@ -879,16 +882,48 @@ impl<W: LayoutElement> Workspace<W> {
879 }882 }
880 883
881 pub fn update_window(&mut self, window: &W::Id) {884 pub fn update_window(&mut self, window: &W::Id) {
882- let (idx, column) = self885+ let (col_idx, column) = self
883 .columns886 .columns
884 .iter_mut()887 .iter_mut()
885 .enumerate()888 .enumerate()
886 .find(|(_, col)| col.contains(window))889 .find(|(_, col)| col.contains(window))
887 .unwrap();890 .unwrap();
891+ let tile_idx = column
892+ .tiles
893+ .iter()
894+ .position(|tile| tile.window().id() == window)
895+ .unwrap();
896+
897+ let offset = column
898+ .width_before_resize
899+ .take()
900+ .map_or(0, |prev| prev - column.width());
901+
888 column.update_window(window);902 column.update_window(window);
889- column.update_tile_sizes();903+ column.update_tile_sizes(false);
890 904
891- if idx == self.active_column_idx905+ // Move other columns in tandem with resizing.
906+ if column.tiles[tile_idx].resize_animation().is_some() && offset != 0 {
907+ if self.active_column_idx <= col_idx {
908+ for col in &mut self.columns[col_idx + 1..] {
909+ col.animate_move_from_with_config(
910+ offset,
911+ self.options.animations.window_resize,
912+ niri_config::Animation::default_window_resize(),
913+ );
914+ }
915+ } else {
916+ for col in &mut self.columns[..col_idx] {
917+ col.animate_move_from_with_config(
918+ -offset,
919+ self.options.animations.window_resize,
920+ niri_config::Animation::default_window_resize(),
921+ );
922+ }
923+ }
924+ }
925+
926+ if col_idx == self.active_column_idx
892 && !matches!(self.view_offset_adj, Some(ViewOffsetAdjustment::Gesture(_)))927 && !matches!(self.view_offset_adj, Some(ViewOffsetAdjustment::Gesture(_)))
893 {928 {
894 // We might need to move the view to ensure the resized window is still visible.929 // We might need to move the view to ensure the resized window is still visible.
@@ -896,7 +931,7 @@ impl<W: LayoutElement> Workspace<W> {
896 931
897 // FIXME: we will want to skip the animation in some cases here to make continuously932 // FIXME: we will want to skip the animation in some cases here to make continuously
898 // resizing windows not look janky.933 // resizing windows not look janky.
899- self.animate_view_offset_to_column(current_x, idx, None);934+ self.animate_view_offset_to_column(current_x, col_idx, None);
900 }935 }
901 }936 }
902 937
@@ -1005,6 +1040,16 @@ impl<W: LayoutElement> Workspace<W> {
1005 }1040 }
1006 }1041 }
1007 1042
1043+ pub fn prepare_for_resize_animation(&mut self, window: &W::Id) {
1044+ let column = self
1045+ .columns
1046+ .iter_mut()
1047+ .find(|col| col.contains(window))
1048+ .unwrap();
1049+
1050+ column.width_before_resize = Some(column.width());
1051+ }
1052+
1008 #[cfg(test)]1053 #[cfg(test)]
1009 pub fn verify_invariants(&self) {1054 pub fn verify_invariants(&self) {
1010 assert!(self.view_size.w > 0);1055 assert!(self.view_size.w > 0);
@@ -1265,8 +1310,9 @@ impl<W: LayoutElement> Workspace<W> {
1265 // Start with the active window since it's drawn on top.1310 // Start with the active window since it's drawn on top.
1266 let col = &self.columns[self.active_column_idx];1311 let col = &self.columns[self.active_column_idx];
1267 let tile = &col.tiles[col.active_tile_idx];1312 let tile = &col.tiles[col.active_tile_idx];
1268- let tile_pos =1313+ let tile_pos = Point::from((-self.view_offset, col.tile_y(col.active_tile_idx)))
1269- Point::from((-self.view_offset, col.tile_y(col.active_tile_idx))) + col.render_offset();1314+ + col.render_offset()
1315+ + tile.render_offset();
1270 let first = iter::once((tile, tile_pos));1316 let first = iter::once((tile, tile_pos));
1271 1317
1272 // Next, the rest of the tiles in the active column, since it should be drawn on top as a1318 // Next, the rest of the tiles in the active column, since it should be drawn on top as a
@@ -1280,7 +1326,9 @@ impl<W: LayoutElement> Workspace<W> {
1280 return None;1326 return None;
1281 }1327 }
1282 1328
1283- let tile_pos = Point::from((-self.view_offset, y)) + col.render_offset();1329+ let tile_pos = Point::from((-self.view_offset, y))
1330+ + col.render_offset()
1331+ + tile.render_offset();
1284 Some((tile, tile_pos))1332 Some((tile, tile_pos))
1285 });1333 });
1286 1334
@@ -1305,7 +1353,7 @@ impl<W: LayoutElement> Workspace<W> {
1305 })1353 })
1306 .flat_map(move |(col, x)| {1354 .flat_map(move |(col, x)| {
1307 zip(&col.tiles, col.tile_ys()).map(move |(tile, y)| {1355 zip(&col.tiles, col.tile_ys()).map(move |(tile, y)| {
1308- let tile_pos = Point::from((x, y)) + col.render_offset();1356+ let tile_pos = Point::from((x, y)) + col.render_offset() + tile.render_offset();
1309 (tile, tile_pos)1357 (tile, tile_pos)
1310 })1358 })
1311 });1359 });
@@ -1409,7 +1457,7 @@ impl<W: LayoutElement> Workspace<W> {
1409 let window = col.tiles.remove(tile_idx).into_window();1457 let window = col.tiles.remove(tile_idx).into_window();
1410 col.heights.remove(tile_idx);1458 col.heights.remove(tile_idx);
1411 col.active_tile_idx = min(col.active_tile_idx, col.tiles.len() - 1);1459 col.active_tile_idx = min(col.active_tile_idx, col.tiles.len() - 1);
1412- col.update_tile_sizes();1460+ col.update_tile_sizes(false);
1413 let width = col.width;1461 let width = col.width;
1414 let is_full_width = col.is_full_width;1462 let is_full_width = col.is_full_width;
1415 1463
@@ -1744,6 +1792,7 @@ impl<W: LayoutElement> Column<W> {
1744 is_full_width,1792 is_full_width,
1745 is_fullscreen: false,1793 is_fullscreen: false,
1746 move_animation: None,1794 move_animation: None,
1795+ width_before_resize: None,
1747 view_size,1796 view_size,
1748 working_area,1797 working_area,
1749 options,1798 options,
@@ -1768,7 +1817,7 @@ impl<W: LayoutElement> Column<W> {
1768 self.view_size = size;1817 self.view_size = size;
1769 self.working_area = working_area;1818 self.working_area = working_area;
1770 1819
1771- self.update_tile_sizes();1820+ self.update_tile_sizes(false);
1772 }1821 }
1773 1822
1774 fn update_config(&mut self, options: Rc<Options>) {1823 fn update_config(&mut self, options: Rc<Options>) {
@@ -1798,14 +1847,14 @@ impl<W: LayoutElement> Column<W> {
1798 self.options = options;1847 self.options = options;
1799 1848
1800 if update_sizes {1849 if update_sizes {
1801- self.update_tile_sizes();1850+ self.update_tile_sizes(false);
1802 }1851 }
1803 }1852 }
1804 1853
1805 fn set_width(&mut self, width: ColumnWidth) {1854 fn set_width(&mut self, width: ColumnWidth) {
1806 self.width = width;1855 self.width = width;
1807 self.is_full_width = false;1856 self.is_full_width = false;
1808- self.update_tile_sizes();1857+ self.update_tile_sizes(true);
1809 }1858 }
1810 1859
1811 pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {1860 pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {
@@ -1840,14 +1889,27 @@ impl<W: LayoutElement> Column<W> {
1840 }1889 }
1841 1890
1842 pub fn animate_move_from(&mut self, from_x_offset: i32) {1891 pub fn animate_move_from(&mut self, from_x_offset: i32) {
1892+ self.animate_move_from_with_config(
1893+ from_x_offset,
1894+ self.options.animations.window_movement,
1895+ niri_config::Animation::default_window_movement(),
1896+ );
1897+ }
1898+
1899+ pub fn animate_move_from_with_config(
1900+ &mut self,
1901+ from_x_offset: i32,
1902+ config: niri_config::Animation,
1903+ default: niri_config::Animation,
1904+ ) {
1843 let current_offset = self.move_animation.as_ref().map_or(0., Animation::value);1905 let current_offset = self.move_animation.as_ref().map_or(0., Animation::value);
1844 1906
1845 self.move_animation = Some(Animation::new(1907 self.move_animation = Some(Animation::new(
1846 f64::from(from_x_offset) + current_offset,1908 f64::from(from_x_offset) + current_offset,
1847 0.,1909 0.,
1848 0.,1910 0.,
1849- self.options.animations.window_movement,1911+ config,
1850- niri_config::Animation::default_window_movement(),1912+ default,
1851 ));1913 ));
1852 }1914 }
1853 1915
@@ -1875,19 +1937,38 @@ impl<W: LayoutElement> Column<W> {
1875 self.is_fullscreen = false;1937 self.is_fullscreen = false;
1876 self.tiles.push(tile);1938 self.tiles.push(tile);
1877 self.heights.push(WindowHeight::Auto);1939 self.heights.push(WindowHeight::Auto);
1878- self.update_tile_sizes();1940+ self.update_tile_sizes(false);
1879 }1941 }
1880 1942
1881 fn update_window(&mut self, window: &W::Id) {1943 fn update_window(&mut self, window: &W::Id) {
1882- let tile = self1944+ let (tile_idx, tile) = self
1883 .tiles1945 .tiles
1884 .iter_mut()1946 .iter_mut()
1885- .find(|tile| tile.window().id() == window)1947+ .enumerate()
1948+ .find(|(_, tile)| tile.window().id() == window)
1886 .unwrap();1949 .unwrap();
1950+
1951+ let height = tile.window().size().h;
1952+ let offset = tile
1953+ .window()
1954+ .animation_snapshot()
1955+ .map_or(0, |from| from.size.h - height);
1956+
1887 tile.update_window();1957 tile.update_window();
1958+
1959+ // Move windows below in tandem with resizing.
1960+ if tile.resize_animation().is_some() && offset != 0 {
1961+ for tile in &mut self.tiles[tile_idx + 1..] {
1962+ tile.animate_move_from_with_config(
1963+ Point::from((0, offset)),
1964+ self.options.animations.window_resize,
1965+ niri_config::Animation::default_window_resize(),
1966+ );
1967+ }
1968+ }
1888 }1969 }
1889 1970
1890- fn update_tile_sizes(&mut self) {1971+ fn update_tile_sizes(&mut self, animate: bool) {
1891 if self.is_fullscreen {1972 if self.is_fullscreen {
1892 self.tiles[0].request_fullscreen(self.view_size);1973 self.tiles[0].request_fullscreen(self.view_size);
1893 return;1974 return;
@@ -2040,7 +2121,7 @@ impl<W: LayoutElement> Column<W> {
2040 };2121 };
2041 2122
2042 let size = Size::from((width, height));2123 let size = Size::from((width, height));
2043- tile.request_tile_size(size);2124+ tile.request_tile_size(size, animate);
2044 }2125 }
2045 }2126 }
2046 2127
@@ -2127,7 +2208,7 @@ impl<W: LayoutElement> Column<W> {
2127 2208
2128 fn toggle_full_width(&mut self) {2209 fn toggle_full_width(&mut self) {
2129 self.is_full_width = !self.is_full_width;2210 self.is_full_width = !self.is_full_width;
2130- self.update_tile_sizes();2211+ self.update_tile_sizes(true);
2131 }2212 }
2132 2213
2133 fn set_column_width(&mut self, change: SizeChange) {2214 fn set_column_width(&mut self, change: SizeChange) {
@@ -2226,13 +2307,13 @@ impl<W: LayoutElement> Column<W> {
2226 }2307 }
2227 2308
2228 self.heights[self.active_tile_idx] = WindowHeight::Fixed(window_height.clamp(1, MAX_PX));2309 self.heights[self.active_tile_idx] = WindowHeight::Fixed(window_height.clamp(1, MAX_PX));
2229- self.update_tile_sizes();2310+ self.update_tile_sizes(true);
2230 }2311 }
2231 2312
2232 fn set_fullscreen(&mut self, is_fullscreen: bool) {2313 fn set_fullscreen(&mut self, is_fullscreen: bool) {
2233 assert_eq!(self.tiles.len(), 1);2314 assert_eq!(self.tiles.len(), 1);
2234 self.is_fullscreen = is_fullscreen;2315 self.is_fullscreen = is_fullscreen;
2235- self.update_tile_sizes();2316+ self.update_tile_sizes(false);
2236 }2317 }
2237 2318
2238 pub fn window_y(&self, tile_idx: usize) -> i32 {2319 pub fn window_y(&self, tile_idx: usize) -> i32 {
src/render_helpers/crossfade.rsadded+156 -0
@@ -0,0 +1,156 @@
1+use std::collections::HashMap;
2+
3+use smithay::backend::renderer::element::{Element, Id, Kind, RenderElement, UnderlyingStorage};
4+use smithay::backend::renderer::gles::{GlesError, GlesFrame, GlesRenderer, GlesTexture, Uniform};
5+use smithay::backend::renderer::utils::{CommitCounter, DamageSet};
6+use smithay::utils::{Buffer, Logical, Physical, Rectangle, Scale, Size, Transform};
7+
8+use super::primary_gpu_pixel_shader_with_textures::PrimaryGpuPixelShaderWithTexturesRenderElement;
9+use super::renderer::AsGlesFrame;
10+use super::shaders::Shaders;
11+use crate::backend::tty::{TtyFrame, TtyRenderer, TtyRendererError};
12+
13+#[derive(Debug)]
14+pub struct CrossfadeRenderElement(PrimaryGpuPixelShaderWithTexturesRenderElement);
15+
16+impl CrossfadeRenderElement {
17+ #[allow(clippy::too_many_arguments)]
18+ pub fn new(
19+ renderer: &mut GlesRenderer,
20+ area: Rectangle<i32, Logical>,
21+ scale: Scale<f64>,
22+ texture_from: (GlesTexture, Rectangle<i32, Physical>),
23+ size_from: Size<i32, Logical>,
24+ texture_to: (GlesTexture, Rectangle<i32, Physical>),
25+ size_to: Size<i32, Logical>,
26+ amount: f32,
27+ result_alpha: f32,
28+ ) -> Option<Self> {
29+ let (texture_from, texture_from_geo) = texture_from;
30+ let (texture_to, texture_to_geo) = texture_to;
31+
32+ let scale_from = area.size.to_f64() / size_from.to_f64();
33+ let scale_to = area.size.to_f64() / size_to.to_f64();
34+
35+ let tex_from_geo = texture_from_geo.to_f64().upscale(scale_from);
36+ let tex_to_geo = texture_to_geo.to_f64().upscale(scale_to);
37+ let combined_geo = tex_from_geo.merge(tex_to_geo);
38+
39+ let area = Rectangle::from_loc_and_size(
40+ area.loc + combined_geo.loc.to_logical(scale).to_i32_round(),
41+ combined_geo.size.to_logical(scale).to_i32_round(),
42+ );
43+
44+ let tex_from_loc = (tex_from_geo.loc - combined_geo.loc)
45+ .downscale((combined_geo.size.w, combined_geo.size.h));
46+ let tex_to_loc = (tex_to_geo.loc - combined_geo.loc)
47+ .downscale((combined_geo.size.w, combined_geo.size.h));
48+ let tex_from_size = tex_from_geo.size / combined_geo.size;
49+ let tex_to_size = tex_to_geo.size / combined_geo.size;
50+
51+ // FIXME: cropping this element will mess up the coordinates.
52+ Shaders::get(renderer).crossfade.clone().map(|shader| {
53+ Self(PrimaryGpuPixelShaderWithTexturesRenderElement::new(
54+ shader,
55+ HashMap::from([
56+ (String::from("tex_from"), texture_from),
57+ (String::from("tex_to"), texture_to),
58+ ]),
59+ area,
60+ None,
61+ result_alpha,
62+ vec![
63+ Uniform::new(
64+ "tex_from_loc",
65+ (tex_from_loc.x as f32, tex_from_loc.y as f32),
66+ ),
67+ Uniform::new(
68+ "tex_from_size",
69+ (tex_from_size.x as f32, tex_from_size.y as f32),
70+ ),
71+ Uniform::new("tex_to_loc", (tex_to_loc.x as f32, tex_to_loc.y as f32)),
72+ Uniform::new("tex_to_size", (tex_to_size.x as f32, tex_to_size.y as f32)),
73+ Uniform::new("amount", amount),
74+ ],
75+ Kind::Unspecified,
76+ ))
77+ })
78+ }
79+}
80+
81+impl Element for CrossfadeRenderElement {
82+ fn id(&self) -> &Id {
83+ self.0.id()
84+ }
85+
86+ fn current_commit(&self) -> CommitCounter {
87+ self.0.current_commit()
88+ }
89+
90+ fn geometry(&self, scale: Scale<f64>) -> Rectangle<i32, Physical> {
91+ self.0.geometry(scale)
92+ }
93+
94+ fn transform(&self) -> Transform {
95+ self.0.transform()
96+ }
97+
98+ fn src(&self) -> Rectangle<f64, Buffer> {
99+ self.0.src()
100+ }
101+
102+ fn damage_since(
103+ &self,
104+ scale: Scale<f64>,
105+ commit: Option<CommitCounter>,
106+ ) -> DamageSet<i32, Physical> {
107+ self.0.damage_since(scale, commit)
108+ }
109+
110+ fn opaque_regions(&self, scale: Scale<f64>) -> Vec<Rectangle<i32, Physical>> {
111+ self.0.opaque_regions(scale)
112+ }
113+
114+ fn alpha(&self) -> f32 {
115+ self.0.alpha()
116+ }
117+
118+ fn kind(&self) -> Kind {
119+ self.0.kind()
120+ }
121+}
122+
123+impl RenderElement<GlesRenderer> for CrossfadeRenderElement {
124+ fn draw(
125+ &self,
126+ frame: &mut GlesFrame<'_>,
127+ src: Rectangle<f64, Buffer>,
128+ dst: Rectangle<i32, Physical>,
129+ damage: &[Rectangle<i32, Physical>],
130+ ) -> Result<(), GlesError> {
131+ RenderElement::<GlesRenderer>::draw(&self.0, frame, src, dst, damage)?;
132+ Ok(())
133+ }
134+
135+ fn underlying_storage(&self, renderer: &mut GlesRenderer) -> Option<UnderlyingStorage> {
136+ self.0.underlying_storage(renderer)
137+ }
138+}
139+
140+impl<'render> RenderElement<TtyRenderer<'render>> for CrossfadeRenderElement {
141+ fn draw(
142+ &self,
143+ frame: &mut TtyFrame<'_, '_>,
144+ src: Rectangle<f64, Buffer>,
145+ dst: Rectangle<i32, Physical>,
146+ damage: &[Rectangle<i32, Physical>],
147+ ) -> Result<(), TtyRendererError<'render>> {
148+ let gles_frame = frame.as_gles_frame();
149+ RenderElement::<GlesRenderer>::draw(&self.0, gles_frame, src, dst, damage)?;
150+ Ok(())
151+ }
152+
153+ fn underlying_storage(&self, renderer: &mut TtyRenderer<'render>) -> Option<UnderlyingStorage> {
154+ self.0.underlying_storage(renderer)
155+ }
156+}
src/render_helpers/mod.rsmodified+3 -0
@@ -17,12 +17,15 @@ use smithay::wayland::shm;
17 17
18 use self::primary_gpu_texture::PrimaryGpuTextureRenderElement;18 use self::primary_gpu_texture::PrimaryGpuTextureRenderElement;
19 19
20+pub mod crossfade;
20 pub mod gradient;21 pub mod gradient;
21 pub mod offscreen;22 pub mod offscreen;
22 pub mod primary_gpu_pixel_shader;23 pub mod primary_gpu_pixel_shader;
24+pub mod primary_gpu_pixel_shader_with_textures;
23 pub mod primary_gpu_texture;25 pub mod primary_gpu_texture;
24 pub mod render_elements;26 pub mod render_elements;
25 pub mod renderer;27 pub mod renderer;
28+pub mod resources;
26 pub mod shaders;29 pub mod shaders;
27 pub mod surface;30 pub mod surface;
28 31
src/render_helpers/primary_gpu_pixel_shader_with_textures.rsadded+423 -0
@@ -0,0 +1,423 @@
1+use std::collections::HashMap;
2+use std::ffi::{CStr, CString};
3+use std::rc::Rc;
4+
5+use glam::{Mat3, Vec2};
6+use smithay::backend::renderer::element::{Element, Id, Kind, RenderElement, UnderlyingStorage};
7+use smithay::backend::renderer::gles::{
8+ ffi, link_program, Capability, GlesError, GlesFrame, GlesRenderer, GlesTexture, Uniform,
9+ UniformDesc, UniformName,
10+};
11+use smithay::backend::renderer::utils::CommitCounter;
12+use smithay::utils::{Buffer, Logical, Physical, Rectangle, Scale, Transform};
13+
14+use super::renderer::AsGlesFrame;
15+use super::resources::Resources;
16+use crate::backend::tty::{TtyFrame, TtyRenderer, TtyRendererError};
17+
18+/// Wrapper for a pixel shader from the primary GPU for rendering with the primary GPU.
19+///
20+/// The shader accepts textures as input.
21+#[derive(Debug)]
22+pub struct PrimaryGpuPixelShaderWithTexturesRenderElement {
23+ shader: PixelWithTexturesProgram,
24+ textures: HashMap<String, GlesTexture>,
25+ id: Id,
26+ commit_counter: CommitCounter,
27+ area: Rectangle<i32, Logical>,
28+ opaque_regions: Vec<Rectangle<i32, Logical>>,
29+ alpha: f32,
30+ additional_uniforms: Vec<Uniform<'static>>,
31+ kind: Kind,
32+}
33+
34+#[derive(Debug, Clone)]
35+pub struct PixelWithTexturesProgram(Rc<PixelWithTexturesProgramInner>);
36+
37+#[derive(Debug)]
38+struct PixelWithTexturesProgramInner {
39+ program: ffi::types::GLuint,
40+ uniform_tex_matrix: ffi::types::GLint,
41+ uniform_matrix: ffi::types::GLint,
42+ uniform_size: ffi::types::GLint,
43+ uniform_alpha: ffi::types::GLint,
44+ attrib_vert: ffi::types::GLint,
45+ attrib_vert_position: ffi::types::GLint,
46+ additional_uniforms: HashMap<String, UniformDesc>,
47+ texture_uniforms: HashMap<String, ffi::types::GLint>,
48+}
49+
50+unsafe fn compile_program(
51+ gl: &ffi::Gles2,
52+ src: &str,
53+ additional_uniforms: &[UniformName<'_>],
54+ texture_uniforms: &[&str],
55+ // destruction_callback_sender: Sender<CleanupResource>,
56+) -> Result<PixelWithTexturesProgram, GlesError> {
57+ let shader = src;
58+
59+ let program = unsafe { link_program(gl, include_str!("shaders/texture.vert"), shader)? };
60+
61+ let vert = CStr::from_bytes_with_nul(b"vert\0").expect("NULL terminated");
62+ let vert_position = CStr::from_bytes_with_nul(b"vert_position\0").expect("NULL terminated");
63+ let matrix = CStr::from_bytes_with_nul(b"matrix\0").expect("NULL terminated");
64+ let tex_matrix = CStr::from_bytes_with_nul(b"tex_matrix\0").expect("NULL terminated");
65+ let size = CStr::from_bytes_with_nul(b"size\0").expect("NULL terminated");
66+ let alpha = CStr::from_bytes_with_nul(b"alpha\0").expect("NULL terminated");
67+
68+ Ok(PixelWithTexturesProgram(Rc::new(
69+ PixelWithTexturesProgramInner {
70+ program,
71+ uniform_matrix: gl
72+ .GetUniformLocation(program, matrix.as_ptr() as *const ffi::types::GLchar),
73+ uniform_tex_matrix: gl
74+ .GetUniformLocation(program, tex_matrix.as_ptr() as *const ffi::types::GLchar),
75+ uniform_size: gl
76+ .GetUniformLocation(program, size.as_ptr() as *const ffi::types::GLchar),
77+ uniform_alpha: gl
78+ .GetUniformLocation(program, alpha.as_ptr() as *const ffi::types::GLchar),
79+ attrib_vert: gl.GetAttribLocation(program, vert.as_ptr() as *const ffi::types::GLchar),
80+ attrib_vert_position: gl
81+ .GetAttribLocation(program, vert_position.as_ptr() as *const ffi::types::GLchar),
82+ additional_uniforms: additional_uniforms
83+ .iter()
84+ .map(|uniform| {
85+ let name =
86+ CString::new(uniform.name.as_bytes()).expect("Interior null in name");
87+ let location =
88+ gl.GetUniformLocation(program, name.as_ptr() as *const ffi::types::GLchar);
89+ (
90+ uniform.name.clone().into_owned(),
91+ UniformDesc {
92+ location,
93+ type_: uniform.type_,
94+ },
95+ )
96+ })
97+ .collect(),
98+ texture_uniforms: texture_uniforms
99+ .iter()
100+ .map(|name_| {
101+ let name = CString::new(name_.as_bytes()).expect("Interior null in name");
102+ let location =
103+ gl.GetUniformLocation(program, name.as_ptr() as *const ffi::types::GLchar);
104+ (name_.to_string(), location)
105+ })
106+ .collect(),
107+ },
108+ )))
109+}
110+
111+impl PixelWithTexturesProgram {
112+ pub fn compile(
113+ renderer: &mut GlesRenderer,
114+ src: &str,
115+ additional_uniforms: &[UniformName<'_>],
116+ texture_uniforms: &[&str],
117+ ) -> Result<Self, GlesError> {
118+ renderer.with_context(move |gl| unsafe {
119+ compile_program(gl, src, additional_uniforms, texture_uniforms)
120+ })?
121+ }
122+}
123+
124+impl PrimaryGpuPixelShaderWithTexturesRenderElement {
125+ pub fn new(
126+ shader: PixelWithTexturesProgram,
127+ textures: HashMap<String, GlesTexture>,
128+ area: Rectangle<i32, Logical>,
129+ opaque_regions: Option<Vec<Rectangle<i32, Logical>>>,
130+ alpha: f32,
131+ additional_uniforms: Vec<Uniform<'_>>,
132+ kind: Kind,
133+ ) -> Self {
134+ Self {
135+ shader,
136+ textures,
137+ id: Id::new(),
138+ commit_counter: CommitCounter::default(),
139+ area,
140+ opaque_regions: opaque_regions.unwrap_or_default(),
141+ alpha,
142+ additional_uniforms: additional_uniforms
143+ .into_iter()
144+ .map(|u| u.into_owned())
145+ .collect(),
146+ kind,
147+ }
148+ }
149+}
150+
151+impl Element for PrimaryGpuPixelShaderWithTexturesRenderElement {
152+ fn id(&self) -> &Id {
153+ &self.id
154+ }
155+
156+ fn current_commit(&self) -> CommitCounter {
157+ self.commit_counter
158+ }
159+
160+ fn src(&self) -> Rectangle<f64, Buffer> {
161+ self.area
162+ .to_f64()
163+ .to_buffer(1.0, Transform::Normal, &self.area.size.to_f64())
164+ }
165+
166+ fn geometry(&self, scale: Scale<f64>) -> Rectangle<i32, Physical> {
167+ self.area.to_physical_precise_round(scale)
168+ }
169+
170+ fn opaque_regions(&self, scale: Scale<f64>) -> Vec<Rectangle<i32, Physical>> {
171+ self.opaque_regions
172+ .iter()
173+ .map(|region| region.to_physical_precise_round(scale))
174+ .collect()
175+ }
176+
177+ fn alpha(&self) -> f32 {
178+ 1.0
179+ }
180+
181+ fn kind(&self) -> Kind {
182+ self.kind
183+ }
184+}
185+
186+impl RenderElement<GlesRenderer> for PrimaryGpuPixelShaderWithTexturesRenderElement {
187+ fn draw(
188+ &self,
189+ frame: &mut GlesFrame<'_>,
190+ _src: Rectangle<f64, Buffer>,
191+ dest: Rectangle<i32, Physical>,
192+ damage: &[Rectangle<i32, Physical>],
193+ ) -> Result<(), GlesError> {
194+ let frame = frame.as_gles_frame();
195+
196+ let Some(resources) = Resources::get(frame) else {
197+ return Ok(());
198+ };
199+ let mut resources = resources.borrow_mut();
200+
201+ let supports_instancing = frame.capabilities().contains(&Capability::Instancing);
202+
203+ // prepare the vertices
204+ resources.vertices.clear();
205+ if supports_instancing {
206+ resources.vertices.extend(damage.iter().flat_map(|rect| {
207+ let dest_size = dest.size;
208+
209+ let rect_constrained_loc = rect
210+ .loc
211+ .constrain(Rectangle::from_extemities((0, 0), dest_size.to_point()));
212+ let rect_clamped_size = rect.size.clamp(
213+ (0, 0),
214+ (dest_size.to_point() - rect_constrained_loc).to_size(),
215+ );
216+
217+ let rect = Rectangle::from_loc_and_size(rect_constrained_loc, rect_clamped_size);
218+ [
219+ rect.loc.x as f32,
220+ rect.loc.y as f32,
221+ rect.size.w as f32,
222+ rect.size.h as f32,
223+ ]
224+ }));
225+ } else {
226+ resources.vertices.extend(damage.iter().flat_map(|rect| {
227+ let dest_size = dest.size;
228+
229+ let rect_constrained_loc = rect
230+ .loc
231+ .constrain(Rectangle::from_extemities((0, 0), dest_size.to_point()));
232+ let rect_clamped_size = rect.size.clamp(
233+ (0, 0),
234+ (dest_size.to_point() - rect_constrained_loc).to_size(),
235+ );
236+
237+ let rect = Rectangle::from_loc_and_size(rect_constrained_loc, rect_clamped_size);
238+ // Add the 4 f32s per damage rectangle for each of the 6 vertices.
239+ (0..6).flat_map(move |_| {
240+ [
241+ rect.loc.x as f32,
242+ rect.loc.y as f32,
243+ rect.size.w as f32,
244+ rect.size.h as f32,
245+ ]
246+ })
247+ }));
248+ }
249+
250+ if resources.vertices.is_empty() {
251+ return Ok(());
252+ }
253+
254+ // dest position and scale
255+ let mut matrix = Mat3::from_translation(Vec2::new(dest.loc.x as f32, dest.loc.y as f32));
256+ let tex_matrix = Mat3::from_scale(Vec2::new(
257+ (1.0f64 / dest.size.w as f64) as f32,
258+ (1.0f64 / dest.size.h as f64) as f32,
259+ ));
260+
261+ //apply output transformation
262+ matrix = Mat3::from_cols_array(frame.projection()) * matrix;
263+
264+ let program = &self.shader.0;
265+
266+ // render
267+ frame.with_context(move |gl| -> Result<(), GlesError> {
268+ unsafe {
269+ for (i, texture) in self.textures.values().enumerate() {
270+ gl.ActiveTexture(ffi::TEXTURE0 + i as u32);
271+ gl.BindTexture(ffi::TEXTURE_2D, texture.tex_id());
272+ gl.TexParameteri(ffi::TEXTURE_2D, ffi::TEXTURE_MIN_FILTER, ffi::LINEAR as i32);
273+ gl.TexParameteri(ffi::TEXTURE_2D, ffi::TEXTURE_MAG_FILTER, ffi::LINEAR as i32);
274+ gl.TexParameteri(
275+ ffi::TEXTURE_2D,
276+ ffi::TEXTURE_WRAP_S,
277+ ffi::CLAMP_TO_BORDER as i32,
278+ );
279+ gl.TexParameteri(
280+ ffi::TEXTURE_2D,
281+ ffi::TEXTURE_WRAP_T,
282+ ffi::CLAMP_TO_BORDER as i32,
283+ );
284+ }
285+
286+ gl.UseProgram(program.program);
287+
288+ for (i, name) in self.textures.keys().enumerate() {
289+ gl.Uniform1i(program.texture_uniforms[name], i as i32);
290+ }
291+
292+ gl.UniformMatrix3fv(
293+ program.uniform_matrix,
294+ 1,
295+ ffi::FALSE,
296+ matrix.as_ref().as_ptr(),
297+ );
298+ gl.UniformMatrix3fv(
299+ program.uniform_tex_matrix,
300+ 1,
301+ ffi::FALSE,
302+ tex_matrix.as_ref().as_ptr(),
303+ );
304+ gl.Uniform2f(program.uniform_size, dest.size.w as f32, dest.size.h as f32);
305+ gl.Uniform1f(program.uniform_alpha, self.alpha);
306+
307+ for uniform in &self.additional_uniforms {
308+ let desc =
309+ program
310+ .additional_uniforms
311+ .get(&*uniform.name)
312+ .ok_or_else(|| {
313+ GlesError::UnknownUniform(uniform.name.clone().into_owned())
314+ })?;
315+ uniform.value.set(gl, desc)?;
316+ }
317+
318+ gl.EnableVertexAttribArray(program.attrib_vert as u32);
319+ gl.BindBuffer(ffi::ARRAY_BUFFER, resources.vbos[0]);
320+ gl.VertexAttribPointer(
321+ program.attrib_vert as u32,
322+ 2,
323+ ffi::FLOAT,
324+ ffi::FALSE,
325+ 0,
326+ std::ptr::null(),
327+ );
328+
329+ // vert_position
330+ gl.EnableVertexAttribArray(program.attrib_vert_position as u32);
331+ gl.BindBuffer(ffi::ARRAY_BUFFER, resources.vbos[1]);
332+ gl.BufferData(
333+ ffi::ARRAY_BUFFER,
334+ (std::mem::size_of::<ffi::types::GLfloat>() * resources.vertices.len())
335+ as isize,
336+ resources.vertices.as_ptr() as *const _,
337+ ffi::STREAM_DRAW,
338+ );
339+
340+ gl.VertexAttribPointer(
341+ program.attrib_vert_position as u32,
342+ 4,
343+ ffi::FLOAT,
344+ ffi::FALSE,
345+ 0,
346+ std::ptr::null(),
347+ );
348+
349+ let damage_len = damage.len() as i32;
350+ if supports_instancing {
351+ gl.VertexAttribDivisor(program.attrib_vert as u32, 0);
352+ gl.VertexAttribDivisor(program.attrib_vert_position as u32, 1);
353+ gl.DrawArraysInstanced(ffi::TRIANGLE_STRIP, 0, 4, damage_len);
354+ } else {
355+ // When we have more than 10 rectangles, draw them in batches of 10.
356+ for i in 0..(damage_len - 1) / 10 {
357+ gl.DrawArrays(ffi::TRIANGLES, 0, 6);
358+
359+ // Set damage pointer to the next 10 rectangles.
360+ let offset =
361+ (i + 1) as usize * 6 * 4 * std::mem::size_of::<ffi::types::GLfloat>();
362+ gl.VertexAttribPointer(
363+ program.attrib_vert_position as u32,
364+ 4,
365+ ffi::FLOAT,
366+ ffi::FALSE,
367+ 0,
368+ offset as *const _,
369+ );
370+ }
371+
372+ // Draw the up to 10 remaining rectangles.
373+ let count = ((damage_len - 1) % 10 + 1) * 6;
374+ gl.DrawArrays(ffi::TRIANGLES, 0, count);
375+ }
376+
377+ gl.BindBuffer(ffi::ARRAY_BUFFER, 0);
378+ gl.BindTexture(ffi::TEXTURE_2D, 0);
379+ gl.ActiveTexture(ffi::TEXTURE0);
380+ gl.BindTexture(ffi::TEXTURE_2D, 0);
381+ gl.DisableVertexAttribArray(program.attrib_vert as u32);
382+ gl.DisableVertexAttribArray(program.attrib_vert_position as u32);
383+ }
384+
385+ Ok(())
386+ })??;
387+
388+ Ok(())
389+ }
390+
391+ fn underlying_storage(&self, _renderer: &mut GlesRenderer) -> Option<UnderlyingStorage> {
392+ // If scanout for things other than Wayland buffers is implemented, this will need to take
393+ // the target GPU into account.
394+ None
395+ }
396+}
397+
398+impl<'render> RenderElement<TtyRenderer<'render>>
399+ for PrimaryGpuPixelShaderWithTexturesRenderElement
400+{
401+ fn draw(
402+ &self,
403+ frame: &mut TtyFrame<'_, '_>,
404+ src: Rectangle<f64, Buffer>,
405+ dst: Rectangle<i32, Physical>,
406+ damage: &[Rectangle<i32, Physical>],
407+ ) -> Result<(), TtyRendererError<'render>> {
408+ let frame = frame.as_gles_frame();
409+
410+ RenderElement::<GlesRenderer>::draw(self, frame, src, dst, damage)?;
411+
412+ Ok(())
413+ }
414+
415+ fn underlying_storage(
416+ &self,
417+ _renderer: &mut TtyRenderer<'render>,
418+ ) -> Option<UnderlyingStorage> {
419+ // If scanout for things other than Wayland buffers is implemented, this will need to take
420+ // the target GPU into account.
421+ None
422+ }
423+}
src/render_helpers/resources.rsadded+106 -0
@@ -0,0 +1,106 @@
1+use std::cell::RefCell;
2+use std::rc::Rc;
3+
4+use smithay::backend::renderer::gles::{ffi, Capability, GlesError, GlesFrame, GlesRenderer};
5+
6+pub struct Resources {
7+ pub vertices: Vec<f32>,
8+ pub vbos: [ffi::types::GLuint; 2],
9+}
10+
11+static INSTANCED_VERTS: [ffi::types::GLfloat; 8] = [
12+ 1.0, 0.0, // top right
13+ 0.0, 0.0, // top left
14+ 1.0, 1.0, // bottom right
15+ 0.0, 1.0, // bottom left
16+];
17+
18+/// Vertices for rendering individual triangles.
19+const MAX_RECTS_PER_DRAW: usize = 10;
20+const TRIANGLE_VERTS: [ffi::types::GLfloat; 12 * MAX_RECTS_PER_DRAW] = triangle_verts();
21+const fn triangle_verts() -> [ffi::types::GLfloat; 12 * MAX_RECTS_PER_DRAW] {
22+ let mut verts = [0.; 12 * MAX_RECTS_PER_DRAW];
23+ let mut i = 0;
24+ loop {
25+ // Top Left.
26+ verts[i * 12] = 0.0;
27+ verts[i * 12 + 1] = 0.0;
28+
29+ // Bottom left.
30+ verts[i * 12 + 2] = 0.0;
31+ verts[i * 12 + 3] = 1.0;
32+
33+ // Bottom right.
34+ verts[i * 12 + 4] = 1.0;
35+ verts[i * 12 + 5] = 1.0;
36+
37+ // Top left.
38+ verts[i * 12 + 6] = 0.0;
39+ verts[i * 12 + 7] = 0.0;
40+
41+ // Bottom right.
42+ verts[i * 12 + 8] = 1.0;
43+ verts[i * 12 + 9] = 1.0;
44+
45+ // Top right.
46+ verts[i * 12 + 10] = 1.0;
47+ verts[i * 12 + 11] = 0.0;
48+
49+ i += 1;
50+ if i == MAX_RECTS_PER_DRAW {
51+ break;
52+ }
53+ }
54+ verts
55+}
56+
57+impl Resources {
58+ fn create(renderer: &mut GlesRenderer) -> Result<Self, GlesError> {
59+ let _span = tracy_client::span!("Resources::init");
60+
61+ let supports_instancing = renderer.capabilities().contains(&Capability::Instancing);
62+ renderer.with_context(|gl| unsafe {
63+ let vertices: &[ffi::types::GLfloat] = if supports_instancing {
64+ &INSTANCED_VERTS
65+ } else {
66+ &TRIANGLE_VERTS
67+ };
68+
69+ let mut vbos = [0; 2];
70+ gl.GenBuffers(vbos.len() as i32, vbos.as_mut_ptr());
71+ gl.BindBuffer(ffi::ARRAY_BUFFER, vbos[0]);
72+ gl.BufferData(
73+ ffi::ARRAY_BUFFER,
74+ std::mem::size_of_val(vertices) as isize,
75+ vertices.as_ptr() as *const _,
76+ ffi::STATIC_DRAW,
77+ );
78+
79+ gl.BindBuffer(ffi::ARRAY_BUFFER, 0);
80+
81+ Self {
82+ vertices: vec![],
83+ vbos,
84+ }
85+ })
86+ }
87+
88+ pub fn get(frame: &mut GlesFrame) -> Option<Rc<RefCell<Self>>> {
89+ let data = frame.egl_context().user_data();
90+ data.get().cloned()
91+ }
92+}
93+
94+pub fn init(renderer: &mut GlesRenderer) {
95+ match Resources::create(renderer) {
96+ Ok(resources) => {
97+ let data = renderer.egl_context().user_data();
98+ if !data.insert_if_missing(|| Rc::new(RefCell::new(resources))) {
99+ error!("resources were already initialized");
100+ }
101+ }
102+ Err(err) => {
103+ warn!("error creating resources for rendering: {err:?}");
104+ }
105+ }
106+}
src/render_helpers/shaders/crossfade.fragadded+31 -0
@@ -0,0 +1,31 @@
1+#version 100
2+
3+precision mediump float;
4+
5+uniform sampler2D tex_from;
6+uniform vec2 tex_from_loc;
7+uniform vec2 tex_from_size;
8+
9+uniform sampler2D tex_to;
10+uniform vec2 tex_to_loc;
11+uniform vec2 tex_to_size;
12+
13+uniform float alpha;
14+uniform float amount;
15+
16+uniform vec2 size;
17+varying vec2 v_coords;
18+
19+void main() {
20+ vec2 coords_from = (v_coords - tex_from_loc) / tex_from_size;
21+ vec2 coords_to = (v_coords - tex_to_loc) / tex_to_size;
22+
23+ vec4 color_from = texture2D(tex_from, coords_from);
24+ vec4 color_to = texture2D(tex_to, coords_to);
25+
26+ vec4 color = mix(color_from, color_to, amount);
27+ color = color * alpha;
28+
29+ gl_FragColor = color;
30+}
31+
src/render_helpers/shaders/mod.rsmodified+23 -1
@@ -1,9 +1,11 @@
1 use smithay::backend::renderer::gles::{GlesPixelProgram, GlesRenderer, UniformName, UniformType};1 use smithay::backend::renderer::gles::{GlesPixelProgram, GlesRenderer, UniformName, UniformType};
2 2
3+use super::primary_gpu_pixel_shader_with_textures::PixelWithTexturesProgram;
3 use super::renderer::NiriRenderer;4 use super::renderer::NiriRenderer;
4 5
5 pub struct Shaders {6 pub struct Shaders {
6 pub gradient_border: Option<GlesPixelProgram>,7 pub gradient_border: Option<GlesPixelProgram>,
8+ pub crossfade: Option<PixelWithTexturesProgram>,
7 }9 }
8 10
9 impl Shaders {11 impl Shaders {
@@ -26,7 +28,27 @@ impl Shaders {
26 })28 })
27 .ok();29 .ok();
28 30
29- Self { gradient_border }31+ let crossfade = PixelWithTexturesProgram::compile(
32+ renderer,
33+ include_str!("crossfade.frag"),
34+ &[
35+ UniformName::new("tex_from_loc", UniformType::_2f),
36+ UniformName::new("tex_from_size", UniformType::_2f),
37+ UniformName::new("tex_to_loc", UniformType::_2f),
38+ UniformName::new("tex_to_size", UniformType::_2f),
39+ UniformName::new("amount", UniformType::_1f),
40+ ],
41+ &["tex_from", "tex_to"],
42+ )
43+ .map_err(|err| {
44+ warn!("error compiling crossfade shader: {err:?}");
45+ })
46+ .ok();
47+
48+ Self {
49+ gradient_border,
50+ crossfade,
51+ }
30 }52 }
31 53
32 pub fn get(renderer: &mut impl NiriRenderer) -> &Self {54 pub fn get(renderer: &mut impl NiriRenderer) -> &Self {
src/render_helpers/shaders/texture.vertadded+25 -0
@@ -0,0 +1,25 @@
1+#version 100
2+
3+uniform mat3 matrix;
4+uniform mat3 tex_matrix;
5+
6+attribute vec2 vert;
7+attribute vec4 vert_position;
8+
9+varying vec2 v_coords;
10+
11+mat2 scale(vec2 scale_vec){
12+ return mat2(
13+ scale_vec.x, 0.0,
14+ 0.0, scale_vec.y
15+ );
16+}
17+
18+void main() {
19+ vec2 vert_transform_translation = vert_position.xy;
20+ vec2 vert_transform_scale = vert_position.zw;
21+ vec3 position = vec3(vert * scale(vert_transform_scale) + vert_transform_translation, 1.0);
22+ v_coords = (tex_matrix * position).xy;
23+ gl_Position = vec4(matrix * position, 1.0);
24+}
25+
src/window/mapped.rsmodified+77 -14
@@ -11,14 +11,16 @@ use smithay::output::Output;
11 use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1;11 use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1;
12 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;12 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
13 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;13 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
14-use smithay::utils::{Logical, Point, Rectangle, Scale, Size, Transform};14+use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform};
15 use smithay::wayland::compositor::{15 use smithay::wayland::compositor::{
16 remove_pre_commit_hook, send_surface_state, with_states, HookId,16 remove_pre_commit_hook, send_surface_state, with_states, HookId,
17 };17 };
18 use smithay::wayland::shell::xdg::{SurfaceCachedState, ToplevelSurface};18 use smithay::wayland::shell::xdg::{SurfaceCachedState, ToplevelSurface};
19 19
20 use super::{ResolvedWindowRules, WindowRef};20 use super::{ResolvedWindowRules, WindowRef};
21-use crate::layout::{LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot};21+use crate::layout::{
22+ AnimationSnapshot, LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot,
23+};
22 use crate::niri::WindowOffscreenId;24 use crate::niri::WindowOffscreenId;
23 use crate::render_helpers::renderer::NiriRenderer;25 use crate::render_helpers::renderer::NiriRenderer;
24 use crate::render_helpers::surface::render_snapshot_from_surface_tree;26 use crate::render_helpers::surface::render_snapshot_from_surface_tree;
@@ -48,6 +50,15 @@ pub struct Mapped {
48 50
49 /// Snapshot of the last render for use in the close animation.51 /// Snapshot of the last render for use in the close animation.
50 last_render: RefCell<LayoutElementRenderSnapshot>,52 last_render: RefCell<LayoutElementRenderSnapshot>,
53+
54+ /// Whether the next configure should be animated, if the configured state changed.
55+ animate_next_configure: bool,
56+
57+ /// Serials of commits that should be animated.
58+ animate_serials: Vec<Serial>,
59+
60+ /// Snapshot right before an animated commit.
61+ animation_snapshot: Option<AnimationSnapshot>,
51 }62 }
52 63
53 impl Mapped {64 impl Mapped {
@@ -60,6 +71,9 @@ impl Mapped {
60 is_focused: false,71 is_focused: false,
61 block_out_buffer: RefCell::new(SolidColorBuffer::new((0, 0), [0., 0., 0., 1.])),72 block_out_buffer: RefCell::new(SolidColorBuffer::new((0, 0), [0., 0., 0., 1.])),
62 last_render: RefCell::new(RenderSnapshot::default()),73 last_render: RefCell::new(RenderSnapshot::default()),
74+ animate_next_configure: false,
75+ animate_serials: Vec::new(),
76+ animation_snapshot: None,
63 }77 }
64 }78 }
65 79
@@ -101,15 +115,13 @@ impl Mapped {
101 self.need_to_recompute_rules = true;115 self.need_to_recompute_rules = true;
102 }116 }
103 117
104- pub fn render_and_store_snapshot(&self, renderer: &mut GlesRenderer) {118+ fn render_snapshot(&self, renderer: &mut GlesRenderer) -> LayoutElementRenderSnapshot {
105- let mut snapshot = self.last_render.borrow_mut();119+ let _span = tracy_client::span!("Mapped::render_snapshot");
106- if !snapshot.contents.is_empty() {
107- return;
108- }
109 120
110- snapshot.contents.clear();121+ let mut snapshot = RenderSnapshot {
111- snapshot.blocked_out_contents.clear();122+ block_out_from: self.rules.block_out_from,
112- snapshot.block_out_from = self.rules.block_out_from;123+ ..Default::default()
124+ };
113 125
114 let mut buffer = self.block_out_buffer.borrow_mut();126 let mut buffer = self.block_out_buffer.borrow_mut();
115 buffer.resize(self.window.geometry().size);127 buffer.resize(self.window.geometry().size);
@@ -135,6 +147,37 @@ impl Mapped {
135 }147 }
136 148
137 render_snapshot_from_surface_tree(renderer, surface, buf_pos, &mut snapshot.contents);149 render_snapshot_from_surface_tree(renderer, surface, buf_pos, &mut snapshot.contents);
150+
151+ snapshot
152+ }
153+
154+ pub fn render_and_store_snapshot(&self, renderer: &mut GlesRenderer) {
155+ let mut snapshot = self.last_render.borrow_mut();
156+ if !snapshot.contents.is_empty() {
157+ return;
158+ }
159+
160+ *snapshot = self.render_snapshot(renderer);
161+ }
162+
163+ pub fn should_animate_commit(&mut self, commit_serial: Serial) -> bool {
164+ let mut should_animate = false;
165+ self.animate_serials.retain_mut(|serial| {
166+ if commit_serial.is_no_older_than(serial) {
167+ should_animate = true;
168+ false
169+ } else {
170+ true
171+ }
172+ });
173+ should_animate
174+ }
175+
176+ pub fn store_animation_snapshot(&mut self, renderer: &mut GlesRenderer) {
177+ self.animation_snapshot = Some(AnimationSnapshot {
178+ render: self.render_snapshot(renderer),
179+ size: self.size(),
180+ });
138 }181 }
139 }182 }
140 183
@@ -200,11 +243,17 @@ impl LayoutElement for Mapped {
200 self.last_render.take()243 self.last_render.take()
201 }244 }
202 245
203- fn request_size(&self, size: Size<i32, Logical>) {246+ fn request_size(&mut self, size: Size<i32, Logical>, animate: bool) {
204- self.toplevel().with_pending_state(|state| {247+ let changed = self.toplevel().with_pending_state(|state| {
248+ let changed = state.size != Some(size);
205 state.size = Some(size);249 state.size = Some(size);
206 state.states.unset(xdg_toplevel::State::Fullscreen);250 state.states.unset(xdg_toplevel::State::Fullscreen);
251+ changed
207 });252 });
253+
254+ if changed && animate {
255+ self.animate_next_configure = true;
256+ }
208 }257 }
209 258
210 fn request_fullscreen(&self, size: Size<i32, Logical>) {259 fn request_fullscreen(&self, size: Size<i32, Logical>) {
@@ -303,8 +352,14 @@ impl LayoutElement for Mapped {
303 });352 });
304 }353 }
305 354
306- fn send_pending_configure(&self) {355+ fn send_pending_configure(&mut self) {
307- self.toplevel().send_pending_configure();356+ if let Some(serial) = self.toplevel().send_pending_configure() {
357+ if self.animate_next_configure {
358+ self.animate_serials.push(serial);
359+ }
360+ }
361+
362+ self.animate_next_configure = false;
308 }363 }
309 364
310 fn is_fullscreen(&self) -> bool {365 fn is_fullscreen(&self) -> bool {
@@ -326,4 +381,12 @@ impl LayoutElement for Mapped {
326 fn rules(&self) -> &ResolvedWindowRules {381 fn rules(&self) -> &ResolvedWindowRules {
327 &self.rules382 &self.rules
328 }383 }
384+
385+ fn animation_snapshot(&self) -> Option<&AnimationSnapshot> {
386+ self.animation_snapshot.as_ref()
387+ }
388+
389+ fn take_animation_snapshot(&mut self) -> Option<AnimationSnapshot> {
390+ self.animation_snapshot.take()
391+ }
329 }392 }
wiki/Configuration:-Animations.mdmodified+21 -0
@@ -38,6 +38,10 @@ animations {
38 curve "ease-out-quad"38 curve "ease-out-quad"
39 }39 }
40 40
41+ window-resize {
42+ spring damping-ratio=1.0 stiffness=800 epsilon=0.0001
43+ }
44+
41 config-notification-open-close {45 config-notification-open-close {
42 spring damping-ratio=0.6 stiffness=1000 epsilon=0.00146 spring damping-ratio=0.6 stiffness=1000 epsilon=0.001
43 }47 }
@@ -196,6 +200,23 @@ animations {
196 }200 }
197 ```201 ```
198 202
203+#### `window-resize`
204+
205+<sup>Since: 0.1.5</sup>
206+
207+Window resize animation.
208+
209+Only manual window resizes are animated, i.e. when you resize the window with `switch-preset-column-width` or `maximize-column`.
210+Also, very small resizes (up to 10 pixels) are not animated.
211+
212+```
213+animations {
214+ window-resize {
215+ spring damping-ratio=1.0 stiffness=800 epsilon=0.0001
216+ }
217+}
218+```
219+
199 #### `config-notification-open-close`220 #### `config-notification-open-close`
200 221
201 The open/close animation of the config parse error and new default config notifications.222 The open/close animation of the config parse error and new default config notifications.