forge
Explore
Log in

Don't you dare go Hollow

Split update_render_elements() from advance_animations()

Browse files at this commit

73cc0079d628e66b1d64168ed1a10b13b23ab5d0Ivan MolodetskikhParent: 69aeba2
advance_animations() is called from places like input, whereas
update_render_elements() is strictly for rendering.
niri-visual-tests/src/cases/gradient_area.rsmodified+9 -9
@@ -20,7 +20,7 @@ pub struct GradientArea {
20 20
21 impl GradientArea {21 impl GradientArea {
22 pub fn new(_size: Size<i32, Logical>) -> Self {22 pub fn new(_size: Size<i32, Logical>) -> Self {
23- let mut border = FocusRing::new(niri_config::FocusRing {23+ let border = FocusRing::new(niri_config::FocusRing {
24 off: false,24 off: false,
25 width: 1,25 width: 1,
26 active_color: Color::new(255, 255, 255, 128),26 active_color: Color::new(255, 255, 255, 128),
@@ -28,7 +28,6 @@ impl GradientArea {
28 active_gradient: None,28 active_gradient: None,
29 inactive_gradient: None,29 inactive_gradient: None,
30 });30 });
31- border.set_active(true);
32 31
33 Self {32 Self {
34 progress: 0.,33 progress: 0.,
@@ -86,15 +85,16 @@ impl TestCase for GradientArea {
86 let mut g_area = Rectangle::from_loc_and_size(g_loc, g_size);85 let mut g_area = Rectangle::from_loc_and_size(g_loc, g_size);
87 g_area.loc -= area.loc;86 g_area.loc -= area.loc;
88 87
89- self.border.update(g_size, true, CornerRadius::default());88+ self.border.update_render_elements(
89+ g_size,
90+ true,
91+ true,
92+ Rectangle::default(),
93+ CornerRadius::default(),
94+ );
90 rv.extend(95 rv.extend(
91 self.border96 self.border
92- .render(97+ .render(renderer, Point::from(g_loc), Scale::from(1.))
93- renderer,
94- Point::from(g_loc),
95- Scale::from(1.),
96- size.to_logical(1),
97- )
98 .map(|elem| Box::new(elem) as _),98 .map(|elem| Box::new(elem) as _),
99 );99 );
100 100
niri-visual-tests/src/cases/layout.rsmodified+1 -0
@@ -222,6 +222,7 @@ impl TestCase for Layout {
222 renderer: &mut GlesRenderer,222 renderer: &mut GlesRenderer,
223 _size: Size<i32, Physical>,223 _size: Size<i32, Physical>,
224 ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> {224 ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> {
225+ self.layout.update_render_elements(&self.output);
225 self.layout226 self.layout
226 .monitor_for_output(&self.output)227 .monitor_for_output(&self.output)
227 .unwrap()228 .unwrap()
niri-visual-tests/src/cases/tile.rsmodified+6 -3
@@ -6,7 +6,7 @@ use niri::render_helpers::RenderTarget;
6 use niri_config::Color;6 use niri_config::Color;
7 use smithay::backend::renderer::element::RenderElement;7 use smithay::backend::renderer::element::RenderElement;
8 use smithay::backend::renderer::gles::GlesRenderer;8 use smithay::backend::renderer::gles::GlesRenderer;
9-use smithay::utils::{Logical, Physical, Point, Scale, Size};9+use smithay::utils::{Logical, Physical, Point, Rectangle, Scale, Size};
10 10
11 use super::TestCase;11 use super::TestCase;
12 use crate::test_window::TestWindow;12 use crate::test_window::TestWindow;
@@ -94,7 +94,7 @@ impl TestCase for Tile {
94 }94 }
95 95
96 fn advance_animations(&mut self, current_time: Duration) {96 fn advance_animations(&mut self, current_time: Duration) {
97- self.tile.advance_animations(current_time, true);97+ self.tile.advance_animations(current_time);
98 }98 }
99 99
100 fn render(100 fn render(
@@ -105,12 +105,15 @@ impl TestCase for Tile {
105 let tile_size = self.tile.tile_size().to_physical(1);105 let tile_size = self.tile.tile_size().to_physical(1);
106 let location = Point::from(((size.w - tile_size.w) / 2, (size.h - tile_size.h) / 2));106 let location = Point::from(((size.w - tile_size.w) / 2, (size.h - tile_size.h) / 2));
107 107
108+ self.tile.update(
109+ true,
110+ Rectangle::from_loc_and_size((-location.x, -location.y), size.to_logical(1)),
111+ );
108 self.tile112 self.tile
109 .render(113 .render(
110 renderer,114 renderer,
111 location,115 location,
112 Scale::from(1.),116 Scale::from(1.),
113- size.to_logical(1),
114 true,117 true,
115 RenderTarget::Output,118 RenderTarget::Output,
116 )119 )
src/layout/focus_ring.rsmodified+88 -101
@@ -1,9 +1,8 @@
1-use std::cell::RefCell;
2 use std::cmp::{max, min};1 use std::cmp::{max, min};
3 use std::iter::zip;2 use std::iter::zip;
4 3
5 use arrayvec::ArrayVec;4 use arrayvec::ArrayVec;
6-use niri_config::{CornerRadius, GradientRelativeTo};5+use niri_config::{CornerRadius, Gradient, GradientRelativeTo};
7 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};6 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
8 use smithay::backend::renderer::element::Kind;7 use smithay::backend::renderer::element::Kind;
9 use smithay::utils::{Logical, Point, Rectangle, Scale, Size};8 use smithay::utils::{Logical, Point, Rectangle, Scale, Size};
@@ -17,11 +16,10 @@ pub struct FocusRing {
17 buffers: [SolidColorBuffer; 8],16 buffers: [SolidColorBuffer; 8],
18 locations: [Point<i32, Logical>; 8],17 locations: [Point<i32, Logical>; 8],
19 sizes: [Size<i32, Logical>; 8],18 sizes: [Size<i32, Logical>; 8],
20- borders: RefCell<[BorderRenderElement; 8]>,19+ borders: [BorderRenderElement; 8],
21 full_size: Size<i32, Logical>,20 full_size: Size<i32, Logical>,
22- is_active: bool,
23 is_border: bool,21 is_border: bool,
24- radius: CornerRadius,22+ use_border_shader: bool,
25 config: niri_config::FocusRing,23 config: niri_config::FocusRing,
26 }24 }
27 25
@@ -40,9 +38,8 @@ impl FocusRing {
40 sizes: Default::default(),38 sizes: Default::default(),
41 borders: Default::default(),39 borders: Default::default(),
42 full_size: Default::default(),40 full_size: Default::default(),
43- is_active: false,
44 is_border: false,41 is_border: false,
45- radius: Default::default(),42+ use_border_shader: false,
46 config,43 config,
47 }44 }
48 }45 }
@@ -52,18 +49,64 @@ impl FocusRing {
52 }49 }
53 50
54 pub fn update_shaders(&mut self) {51 pub fn update_shaders(&mut self) {
55- let mut borders = self.borders.borrow_mut();52+ for elem in &mut self.borders {
56- for elem in &mut *borders {
57 elem.damage_all();53 elem.damage_all();
58 }54 }
59 }55 }
60 56
61- pub fn update(&mut self, win_size: Size<i32, Logical>, is_border: bool, radius: CornerRadius) {57+ pub fn update_render_elements(
58+ &mut self,
59+ win_size: Size<i32, Logical>,
60+ is_active: bool,
61+ is_border: bool,
62+ view_rect: Rectangle<i32, Logical>,
63+ radius: CornerRadius,
64+ ) {
62 let width = i32::from(self.config.width);65 let width = i32::from(self.config.width);
63 self.full_size = win_size + Size::from((width * 2, width * 2));66 self.full_size = win_size + Size::from((width * 2, width * 2));
64 67
68+ let color = if is_active {
69+ self.config.active_color
70+ } else {
71+ self.config.inactive_color
72+ };
73+
74+ for buf in &mut self.buffers {
75+ buf.set_color(color.into());
76+ }
77+
65 let radius = radius.fit_to(self.full_size.w as f32, self.full_size.h as f32);78 let radius = radius.fit_to(self.full_size.w as f32, self.full_size.h as f32);
66 79
80+ let gradient = if is_active {
81+ self.config.active_gradient
82+ } else {
83+ self.config.inactive_gradient
84+ };
85+
86+ self.use_border_shader = radius != CornerRadius::default() || gradient.is_some();
87+
88+ // Set the defaults for solid color + rounded corners.
89+ let gradient = gradient.unwrap_or(Gradient {
90+ from: color,
91+ to: color,
92+ angle: 0,
93+ relative_to: GradientRelativeTo::Window,
94+ });
95+
96+ let full_rect = Rectangle::from_loc_and_size((-width, -width), self.full_size);
97+ let gradient_area = match gradient.relative_to {
98+ GradientRelativeTo::Window => full_rect,
99+ GradientRelativeTo::WorkspaceView => view_rect,
100+ };
101+
102+ let rounded_corner_border_width = if self.is_border {
103+ // HACK: increase the border width used for the inner rounded corners a tiny bit to
104+ // reduce background bleed.
105+ width as f32 + 0.5
106+ } else {
107+ 0.
108+ };
109+
67 if is_border {110 if is_border {
68 let top_left = max(width, radius.top_left.ceil() as i32);111 let top_left = max(width, radius.top_left.ceil() as i32);
69 let top_right = min(112 let top_right = min(
@@ -121,28 +164,40 @@ impl FocusRing {
121 for (buf, size) in zip(&mut self.buffers, self.sizes) {164 for (buf, size) in zip(&mut self.buffers, self.sizes) {
122 buf.resize(size);165 buf.resize(size);
123 }166 }
167+
168+ for (border, (loc, size)) in zip(&mut self.borders, zip(self.locations, self.sizes)) {
169+ border.update(
170+ size,
171+ Rectangle::from_loc_and_size(gradient_area.loc - loc, gradient_area.size),
172+ gradient.from.into(),
173+ gradient.to.into(),
174+ ((gradient.angle as f32) - 90.).to_radians(),
175+ Rectangle::from_loc_and_size(full_rect.loc - loc, full_rect.size),
176+ rounded_corner_border_width,
177+ radius,
178+ );
179+ }
124 } else {180 } else {
125 self.sizes[0] = self.full_size;181 self.sizes[0] = self.full_size;
126 self.buffers[0].resize(self.sizes[0]);182 self.buffers[0].resize(self.sizes[0]);
127 self.locations[0] = Point::from((-width, -width));183 self.locations[0] = Point::from((-width, -width));
128- }
129-
130- self.is_border = is_border;
131- self.radius = radius;
132- }
133 184
134- pub fn set_active(&mut self, is_active: bool) {185+ self.borders[0].update(
135- let color = if is_active {186+ self.sizes[0],
136- self.config.active_color.into()187+ Rectangle::from_loc_and_size(
137- } else {188+ gradient_area.loc - self.locations[0],
138- self.config.inactive_color.into()189+ gradient_area.size,
139- };190+ ),
140-191+ gradient.from.into(),
141- for buf in &mut self.buffers {192+ gradient.to.into(),
142- buf.set_color(color);193+ ((gradient.angle as f32) - 90.).to_radians(),
194+ Rectangle::from_loc_and_size(full_rect.loc - self.locations[0], full_rect.size),
195+ rounded_corner_border_width,
196+ radius,
197+ );
143 }198 }
144 199
145- self.is_active = is_active;200+ self.is_border = is_border;
146 }201 }
147 202
148 pub fn render(203 pub fn render(
@@ -150,7 +205,6 @@ impl FocusRing {
150 renderer: &mut impl NiriRenderer,205 renderer: &mut impl NiriRenderer,
151 location: Point<i32, Logical>,206 location: Point<i32, Logical>,
152 scale: Scale<f64>,207 scale: Scale<f64>,
153- view_size: Size<i32, Logical>,
154 ) -> impl Iterator<Item = FocusRingRenderElement> {208 ) -> impl Iterator<Item = FocusRingRenderElement> {
155 let mut rv = ArrayVec::<_, 8>::new();209 let mut rv = ArrayVec::<_, 8>::new();
156 210
@@ -165,75 +219,12 @@ impl FocusRing {
165 return rv.into_iter();219 return rv.into_iter();
166 }220 }
167 221
168- let gradient = if self.is_active {
169- self.config.active_gradient
170- } else {
171- self.config.inactive_gradient
172- };
173- let color = if self.is_active {
174- self.config.active_color
175- } else {
176- self.config.inactive_color
177- };
178-
179- let offset = Point::from((border_width, border_width));
180- let full_rect = Rectangle::from_loc_and_size(location - offset, self.full_size);
181- let view_rect = Rectangle::from_loc_and_size((0, 0), view_size);
182-
183- let border_width = if self.is_border {
184- // HACK: increase the border width used for the inner rounded corners a tiny bit to
185- // reduce background bleed.
186- border_width as f32 + 0.5 / scale.x as f32
187- } else {
188- 0.
189- };
190 let has_border_shader = BorderRenderElement::has_shader(renderer);222 let has_border_shader = BorderRenderElement::has_shader(renderer);
191- let mut borders = self.borders.borrow_mut();
192-
193- let mut push = |buffer,
194- border: &mut BorderRenderElement,
195- location: Point<i32, Logical>,
196- size: Size<i32, Logical>| {
197- let full_rect = Rectangle::from_loc_and_size(full_rect.loc - location, full_rect.size);
198- let view_rect = Rectangle::from_loc_and_size(view_rect.loc - location, view_rect.size);
199-
200- let elem = if has_border_shader {
201- if let Some(gradient) = gradient {
202- let gradient_area = match gradient.relative_to {
203- GradientRelativeTo::Window => full_rect,
204- GradientRelativeTo::WorkspaceView => view_rect,
205- };
206- border.update(
207- size,
208- gradient_area,
209- gradient.from.into(),
210- gradient.to.into(),
211- ((gradient.angle as f32) - 90.).to_radians(),
212- full_rect,
213- border_width,
214- self.radius,
215- );
216- Some(border.clone().with_location(location).into())
217- } else if self.radius != CornerRadius::default() {
218- border.update(
219- size,
220- full_rect,
221- color.into(),
222- color.into(),
223- 0.,
224- full_rect,
225- border_width,
226- self.radius,
227- );
228- Some(border.clone().with_location(location).into())
229- } else {
230- None
231- }
232- } else {
233- None
234- };
235 223
236- let elem = elem.unwrap_or_else(|| {224+ let mut push = |buffer, border: &BorderRenderElement, location: Point<i32, Logical>| {
225+ let elem = if self.use_border_shader && has_border_shader {
226+ border.clone().with_location(location).into()
227+ } else {
237 SolidColorRenderElement::from_buffer(228 SolidColorRenderElement::from_buffer(
238 buffer,229 buffer,
239 location.to_physical_precise_round(scale),230 location.to_physical_precise_round(scale),
@@ -242,23 +233,19 @@ impl FocusRing {
242 Kind::Unspecified,233 Kind::Unspecified,
243 )234 )
244 .into()235 .into()
245- });236+ };
246 rv.push(elem);237 rv.push(elem);
247 };238 };
248 239
249 if self.is_border {240 if self.is_border {
250- for ((buf, border), (loc, size)) in zip(241+ for ((buf, border), loc) in zip(zip(&self.buffers, &self.borders), self.locations) {
251- zip(&self.buffers, &mut *borders),242+ push(buf, border, location + loc);
252- zip(self.locations, self.sizes),
253- ) {
254- push(buf, border, location + loc, size);
255 }243 }
256 } else {244 } else {
257 push(245 push(
258 &self.buffers[0],246 &self.buffers[0],
259- &mut borders[0],247+ &self.borders[0],
260 location + self.locations[0],248 location + self.locations[0],
261- self.sizes[0],
262 );249 );
263 }250 }
264 251
src/layout/mod.rsmodified+25 -8
@@ -1354,23 +1354,40 @@ impl<W: LayoutElement> Layout<W> {
1354 let _span = tracy_client::span!("Layout::advance_animations");1354 let _span = tracy_client::span!("Layout::advance_animations");
1355 1355
1356 match &mut self.monitor_set {1356 match &mut self.monitor_set {
1357- MonitorSet::Normal {1357+ MonitorSet::Normal { monitors, .. } => {
1358- monitors,1358+ for mon in monitors {
1359- active_monitor_idx,1359+ mon.advance_animations(current_time);
1360- ..
1361- } => {
1362- for (idx, mon) in monitors.iter_mut().enumerate() {
1363- mon.advance_animations(current_time, idx == *active_monitor_idx);
1364 }1360 }
1365 }1361 }
1366 MonitorSet::NoOutputs { workspaces, .. } => {1362 MonitorSet::NoOutputs { workspaces, .. } => {
1367 for ws in workspaces {1363 for ws in workspaces {
1368- ws.advance_animations(current_time, false);1364+ ws.advance_animations(current_time);
1369 }1365 }
1370 }1366 }
1371 }1367 }
1372 }1368 }
1373 1369
1370+ pub fn update_render_elements(&mut self, output: &Output) {
1371+ let _span = tracy_client::span!("Layout::update_render_elements");
1372+
1373+ let MonitorSet::Normal {
1374+ monitors,
1375+ active_monitor_idx,
1376+ ..
1377+ } = &mut self.monitor_set
1378+ else {
1379+ error!("update_render_elements called with no monitors");
1380+ return;
1381+ };
1382+
1383+ for (idx, mon) in monitors.iter_mut().enumerate() {
1384+ if mon.output == *output {
1385+ mon.update_render_elements(idx == *active_monitor_idx);
1386+ return;
1387+ }
1388+ }
1389+ }
1390+
1374 pub fn update_shaders(&mut self) {1391 pub fn update_shaders(&mut self) {
1375 match &mut self.monitor_set {1392 match &mut self.monitor_set {
1376 MonitorSet::Normal { monitors, .. } => {1393 MonitorSet::Normal { monitors, .. } => {
src/layout/monitor.rsmodified+31 -2
@@ -523,7 +523,7 @@ impl<W: LayoutElement> Monitor<W> {
523 Some(column.tiles[column.active_tile_idx].window())523 Some(column.tiles[column.active_tile_idx].window())
524 }524 }
525 525
526- pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {526+ pub fn advance_animations(&mut self, current_time: Duration) {
527 if let Some(WorkspaceSwitch::Animation(anim)) = &mut self.workspace_switch {527 if let Some(WorkspaceSwitch::Animation(anim)) = &mut self.workspace_switch {
528 anim.set_current_time(current_time);528 anim.set_current_time(current_time);
529 if anim.is_done() {529 if anim.is_done() {
@@ -533,7 +533,7 @@ impl<W: LayoutElement> Monitor<W> {
533 }533 }
534 534
535 for ws in &mut self.workspaces {535 for ws in &mut self.workspaces {
536- ws.advance_animations(current_time, is_active);536+ ws.advance_animations(current_time);
537 }537 }
538 }538 }
539 539
@@ -552,6 +552,35 @@ impl<W: LayoutElement> Monitor<W> {
552 .any(|ws| ws.are_transitions_ongoing())552 .any(|ws| ws.are_transitions_ongoing())
553 }553 }
554 554
555+ pub fn update_render_elements(&mut self, is_active: bool) {
556+ match &self.workspace_switch {
557+ Some(switch) => {
558+ let render_idx = switch.current_idx();
559+ let before_idx = render_idx.floor();
560+ let after_idx = render_idx.ceil();
561+
562+ if after_idx < 0. || before_idx as usize >= self.workspaces.len() {
563+ return;
564+ }
565+
566+ let after_idx = after_idx as usize;
567+ if after_idx < self.workspaces.len() {
568+ self.workspaces[after_idx].update_render_elements(is_active);
569+
570+ if before_idx < 0. {
571+ return;
572+ }
573+ }
574+
575+ let before_idx = before_idx as usize;
576+ self.workspaces[before_idx].update_render_elements(is_active);
577+ }
578+ None => {
579+ self.workspaces[self.active_workspace_idx].update_render_elements(is_active);
580+ }
581+ }
582+ }
583+
555 pub fn update_config(&mut self, options: Rc<Options>) {584 pub fn update_config(&mut self, options: Rc<Options>) {
556 for ws in &mut self.workspaces {585 for ws in &mut self.workspaces {
557 ws.update_config(options.clone());586 ws.update_config(options.clone());
src/layout/tile.rsmodified+27 -35
@@ -201,7 +201,7 @@ impl<W: LayoutElement> Tile<W> {
201 self.rounded_corner_damage.set_size(window_size);201 self.rounded_corner_damage.set_size(window_size);
202 }202 }
203 203
204- pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {204+ pub fn advance_animations(&mut self, current_time: Duration) {
205 if let Some(anim) = &mut self.open_animation {205 if let Some(anim) = &mut self.open_animation {
206 anim.set_current_time(current_time);206 anim.set_current_time(current_time);
207 if anim.is_done() {207 if anim.is_done() {
@@ -228,6 +228,17 @@ impl<W: LayoutElement> Tile<W> {
228 self.move_y_animation = None;228 self.move_y_animation = None;
229 }229 }
230 }230 }
231+ }
232+
233+ pub fn are_animations_ongoing(&self) -> bool {
234+ self.open_animation.is_some()
235+ || self.resize_animation.is_some()
236+ || self.move_x_animation.is_some()
237+ || self.move_y_animation.is_some()
238+ }
239+
240+ pub fn update(&mut self, is_active: bool, mut view_rect: Rectangle<i32, Logical>) {
241+ view_rect.loc -= self.render_offset();
231 242
232 let rules = self.window.rules();243 let rules = self.window.rules();
233 244
@@ -244,12 +255,16 @@ impl<W: LayoutElement> Tile<W> {
244 radius.expanded_by(border_width as f32)255 radius.expanded_by(border_width as f32)
245 })256 })
246 };257 };
247- self.border.update(258+ self.border.update_render_elements(
248 self.animated_window_size(),259 self.animated_window_size(),
260+ is_active,
249 !draw_border_with_background,261 !draw_border_with_background,
262+ Rectangle::from_loc_and_size(
263+ view_rect.loc - Point::from((border_width, border_width)),
264+ view_rect.size,
265+ ),
250 radius,266 radius,
251 );267 );
252- self.border.set_active(is_active);
253 268
254 let draw_focus_ring_with_background = if self.effective_border_width().is_some() {269 let draw_focus_ring_with_background = if self.effective_border_width().is_some() {
255 false270 false
@@ -264,19 +279,13 @@ impl<W: LayoutElement> Tile<W> {
264 rules.geometry_corner_radius.unwrap_or_default()279 rules.geometry_corner_radius.unwrap_or_default()
265 }280 }
266 .expanded_by(self.focus_ring.width() as f32);281 .expanded_by(self.focus_ring.width() as f32);
267- self.focus_ring.update(282+ self.focus_ring.update_render_elements(
268 self.animated_tile_size(),283 self.animated_tile_size(),
284+ is_active,
269 !draw_focus_ring_with_background,285 !draw_focus_ring_with_background,
286+ view_rect,
270 radius,287 radius,
271 );288 );
272- self.focus_ring.set_active(is_active);
273- }
274-
275- pub fn are_animations_ongoing(&self) -> bool {
276- self.open_animation.is_some()
277- || self.resize_animation.is_some()
278- || self.move_x_animation.is_some()
279- || self.move_y_animation.is_some()
280 }289 }
281 290
282 pub fn render_offset(&self) -> Point<i32, Logical> {291 pub fn render_offset(&self) -> Point<i32, Logical> {
@@ -568,7 +577,6 @@ impl<W: LayoutElement> Tile<W> {
568 renderer: &mut R,577 renderer: &mut R,
569 location: Point<i32, Logical>,578 location: Point<i32, Logical>,
570 scale: Scale<f64>,579 scale: Scale<f64>,
571- view_size: Size<i32, Logical>,
572 focus_ring: bool,580 focus_ring: bool,
573 target: RenderTarget,581 target: RenderTarget,
574 ) -> impl Iterator<Item = TileRenderElement<R>> {582 ) -> impl Iterator<Item = TileRenderElement<R>> {
@@ -766,19 +774,14 @@ impl<W: LayoutElement> Tile<W> {
766 774
767 let elem = self.effective_border_width().map(|width| {775 let elem = self.effective_border_width().map(|width| {
768 self.border776 self.border
769- .render(777+ .render(renderer, location + Point::from((width, width)), scale)
770- renderer,
771- location + Point::from((width, width)),
772- scale,
773- view_size,
774- )
775 .map(Into::into)778 .map(Into::into)
776 });779 });
777 let rv = rv.chain(elem.into_iter().flatten());780 let rv = rv.chain(elem.into_iter().flatten());
778 781
779 let elem = focus_ring.then(|| {782 let elem = focus_ring.then(|| {
780 self.focus_ring783 self.focus_ring
781- .render(renderer, location, scale, view_size)784+ .render(renderer, location, scale)
782 .map(Into::into)785 .map(Into::into)
783 });786 });
784 rv.chain(elem.into_iter().flatten())787 rv.chain(elem.into_iter().flatten())
@@ -789,7 +792,6 @@ impl<W: LayoutElement> Tile<W> {
789 renderer: &mut R,792 renderer: &mut R,
790 location: Point<i32, Logical>,793 location: Point<i32, Logical>,
791 scale: Scale<f64>,794 scale: Scale<f64>,
792- view_size: Size<i32, Logical>,
793 focus_ring: bool,795 focus_ring: bool,
794 target: RenderTarget,796 target: RenderTarget,
795 ) -> impl Iterator<Item = TileRenderElement<R>> {797 ) -> impl Iterator<Item = TileRenderElement<R>> {
@@ -797,8 +799,7 @@ impl<W: LayoutElement> Tile<W> {
797 799
798 if let Some(anim) = &self.open_animation {800 if let Some(anim) = &self.open_animation {
799 let renderer = renderer.as_gles_renderer();801 let renderer = renderer.as_gles_renderer();
800- let elements =802+ let elements = self.render_inner(renderer, location, scale, focus_ring, target);
801- self.render_inner(renderer, location, scale, view_size, focus_ring, target);
802 let elements = elements.collect::<Vec<TileRenderElement<_>>>();803 let elements = elements.collect::<Vec<TileRenderElement<_>>>();
803 804
804 let elem = OffscreenRenderElement::new(805 let elem = OffscreenRenderElement::new(
@@ -826,31 +827,24 @@ impl<W: LayoutElement> Tile<W> {
826 } else {827 } else {
827 self.window().set_offscreen_element_id(None);828 self.window().set_offscreen_element_id(None);
828 829
829- let elements =830+ let elements = self.render_inner(renderer, location, scale, focus_ring, target);
830- self.render_inner(renderer, location, scale, view_size, focus_ring, target);
831 None.into_iter().chain(Some(elements).into_iter().flatten())831 None.into_iter().chain(Some(elements).into_iter().flatten())
832 }832 }
833 }833 }
834 834
835- pub fn store_unmap_snapshot_if_empty(835+ pub fn store_unmap_snapshot_if_empty(&self, renderer: &mut GlesRenderer, scale: Scale<f64>) {
836- &self,
837- renderer: &mut GlesRenderer,
838- scale: Scale<f64>,
839- view_size: Size<i32, Logical>,
840- ) {
841 let mut snapshot = self.unmap_snapshot.borrow_mut();836 let mut snapshot = self.unmap_snapshot.borrow_mut();
842 if snapshot.is_some() {837 if snapshot.is_some() {
843 return;838 return;
844 }839 }
845 840
846- *snapshot = Some(self.render_snapshot(renderer, scale, view_size));841+ *snapshot = Some(self.render_snapshot(renderer, scale));
847 }842 }
848 843
849 fn render_snapshot(844 fn render_snapshot(
850 &self,845 &self,
851 renderer: &mut GlesRenderer,846 renderer: &mut GlesRenderer,
852 scale: Scale<f64>,847 scale: Scale<f64>,
853- view_size: Size<i32, Logical>,
854 ) -> TileRenderSnapshot {848 ) -> TileRenderSnapshot {
855 let _span = tracy_client::span!("Tile::render_snapshot");849 let _span = tracy_client::span!("Tile::render_snapshot");
856 850
@@ -858,7 +852,6 @@ impl<W: LayoutElement> Tile<W> {
858 renderer,852 renderer,
859 Point::from((0, 0)),853 Point::from((0, 0)),
860 scale,854 scale,
861- view_size,
862 false,855 false,
863 RenderTarget::Output,856 RenderTarget::Output,
864 );857 );
@@ -868,7 +861,6 @@ impl<W: LayoutElement> Tile<W> {
868 renderer,861 renderer,
869 Point::from((0, 0)),862 Point::from((0, 0)),
870 scale,863 scale,
871- view_size,
872 false,864 false,
873 RenderTarget::Screencast,865 RenderTarget::Screencast,
874 );866 );
src/layout/workspace.rsmodified+37 -18
@@ -289,7 +289,7 @@ impl<W: LayoutElement> Workspace<W> {
289 self.id289 self.id
290 }290 }
291 291
292- pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {292+ pub fn advance_animations(&mut self, current_time: Duration) {
293 if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj {293 if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj {
294 anim.set_current_time(current_time);294 anim.set_current_time(current_time);
295 self.view_offset = anim.value().round() as i32;295 self.view_offset = anim.value().round() as i32;
@@ -300,9 +300,8 @@ impl<W: LayoutElement> Workspace<W> {
300 self.view_offset = gesture.current_view_offset.round() as i32;300 self.view_offset = gesture.current_view_offset.round() as i32;
301 }301 }
302 302
303- for (col_idx, col) in self.columns.iter_mut().enumerate() {303+ for col in &mut self.columns {
304- let is_active = is_active && col_idx == self.active_column_idx;304+ col.advance_animations(current_time);
305- col.advance_animations(current_time, is_active);
306 }305 }
307 306
308 self.closing_windows.retain_mut(|closing| {307 self.closing_windows.retain_mut(|closing| {
@@ -325,6 +324,16 @@ impl<W: LayoutElement> Workspace<W> {
325 || !self.closing_windows.is_empty()324 || !self.closing_windows.is_empty()
326 }325 }
327 326
327+ pub fn update_render_elements(&mut self, is_active: bool) {
328+ let mut view_rect = Rectangle::from_loc_and_size((self.view_pos(), 0), self.view_size);
329+
330+ for (col_idx, col) in self.columns.iter_mut().enumerate() {
331+ let is_active = is_active && col_idx == self.active_column_idx;
332+ col.update_render_elements(is_active, view_rect);
333+ view_rect.loc.x -= col.width() + self.options.gaps;
334+ }
335+ }
336+
328 pub fn update_config(&mut self, options: Rc<Options>) {337 pub fn update_config(&mut self, options: Rc<Options>) {
329 for column in &mut self.columns {338 for column in &mut self.columns {
330 column.update_config(options.clone());339 column.update_config(options.clone());
@@ -1198,7 +1207,7 @@ impl<W: LayoutElement> Workspace<W> {
1198 .map(|o| Scale::from(o.current_scale().fractional_scale()))1207 .map(|o| Scale::from(o.current_scale().fractional_scale()))
1199 .unwrap_or(Scale::from(1.));1208 .unwrap_or(Scale::from(1.));
1200 1209
1201- tile.store_unmap_snapshot_if_empty(renderer, output_scale, self.view_size);1210+ tile.store_unmap_snapshot_if_empty(renderer, output_scale);
1202 }1211 }
1203 1212
1204 pub fn clear_unmap_snapshot(&mut self, window: &W::Id) {1213 pub fn clear_unmap_snapshot(&mut self, window: &W::Id) {
@@ -1947,15 +1956,8 @@ impl<W: LayoutElement> Workspace<W> {
1947 first = false;1956 first = false;
1948 1957
1949 rv.extend(1958 rv.extend(
1950- tile.render(1959+ tile.render(renderer, tile_pos, output_scale, focus_ring, target)
1951- renderer,1960+ .map(Into::into),
1952- tile_pos,
1953- output_scale,
1954- self.view_size,
1955- focus_ring,
1956- target,
1957- )
1958- .map(Into::into),
1959 );1961 );
1960 }1962 }
1961 1963
@@ -2298,7 +2300,7 @@ impl<W: LayoutElement> Column<W> {
2298 self.update_tile_sizes(true);2300 self.update_tile_sizes(true);
2299 }2301 }
2300 2302
2301- pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {2303+ pub fn advance_animations(&mut self, current_time: Duration) {
2302 match &mut self.move_animation {2304 match &mut self.move_animation {
2303 Some(anim) => {2305 Some(anim) => {
2304 anim.set_current_time(current_time);2306 anim.set_current_time(current_time);
@@ -2309,9 +2311,8 @@ impl<W: LayoutElement> Column<W> {
2309 None => (),2311 None => (),
2310 }2312 }
2311 2313
2312- for (tile_idx, tile) in self.tiles.iter_mut().enumerate() {2314+ for tile in &mut self.tiles {
2313- let is_active = is_active && tile_idx == self.active_tile_idx;2315+ tile.advance_animations(current_time);
2314- tile.advance_animations(current_time, is_active);
2315 }2316 }
2316 }2317 }
2317 2318
@@ -2319,6 +2320,24 @@ impl<W: LayoutElement> Column<W> {
2319 self.move_animation.is_some() || self.tiles.iter().any(Tile::are_animations_ongoing)2320 self.move_animation.is_some() || self.tiles.iter().any(Tile::are_animations_ongoing)
2320 }2321 }
2321 2322
2323+ pub fn update_render_elements(
2324+ &mut self,
2325+ is_active: bool,
2326+ mut view_rect: Rectangle<i32, Logical>,
2327+ ) {
2328+ view_rect.loc -= self.render_offset();
2329+
2330+ if !self.is_fullscreen {
2331+ view_rect.loc.y -= self.working_area.loc.y + self.options.gaps;
2332+ }
2333+
2334+ for (tile_idx, tile) in self.tiles.iter_mut().enumerate() {
2335+ let is_active = is_active && tile_idx == self.active_tile_idx;
2336+ tile.update(is_active, view_rect);
2337+ view_rect.loc.y -= tile.tile_size().h + self.options.gaps;
2338+ }
2339+ }
2340+
2322 pub fn render_offset(&self) -> Point<i32, Logical> {2341 pub fn render_offset(&self) -> Point<i32, Logical> {
2323 let mut offset = Point::from((0., 0.));2342 let mut offset = Point::from((0., 0.));
2324 2343
src/niri.rsmodified+2 -0
@@ -2525,6 +2525,8 @@ impl Niri {
2525 .cursor_manager2525 .cursor_manager
2526 .is_current_cursor_animated(output.current_scale().integer_scale());2526 .is_current_cursor_animated(output.current_scale().integer_scale());
2527 2527
2528+ self.layout.update_render_elements(output);
2529+
2528 // Render.2530 // Render.
2529 res = backend.render(self, output, target_presentation_time);2531 res = backend.render(self, output, target_presentation_time);
2530 }2532 }