forge
Explore
Log in

Don't you dare go Hollow

tab indicator: Fix gradient area computation

Browse files at this commit

6bd92ab926b53d8da916966798213fcc9b0bf0b2Ivan MolodetskikhParent: 02eccf7
The gradient area should be relative to each tab's geometry. In most cases
these geometries will all match, but not when some tabs have a different size,
for example when they have a fixed size.
src/layout/scrolling.rsmodified+14 -14
@@ -2608,10 +2608,7 @@ impl<W: LayoutElement> ScrollingSpace<W> {
2608 2608
2609 // Draw the tab indicator on top.2609 // Draw the tab indicator on top.
2610 {2610 {
2611- // This is the "static tile position" so to say: it excludes the tile offset (used2611+ let pos = view_off + col_off + col_render_off;
2612- // for e.g. centering smaller tiles in always-center) and the tile render offset
2613- // (used for tile-specific animations).
2614- let pos = view_off + col_off + col_render_off + col.tiles_origin();
2615 let pos = pos.to_physical_precise_round(scale).to_logical(scale);2612 let pos = pos.to_physical_precise_round(scale).to_logical(scale);
2616 rv.extend(col.tab_indicator.render(renderer, pos).map(Into::into));2613 rv.extend(col.tab_indicator.render(renderer, pos).map(Into::into));
2617 }2614 }
@@ -3473,15 +3470,15 @@ impl<W: LayoutElement> Column<W> {
3473 tile.update_render_elements(is_active, tile_view_rect);3470 tile.update_render_elements(is_active, tile_view_rect);
3474 }3471 }
3475 3472
3476- let (tile, tile_off) = self.tiles().nth(self.active_tile_idx).unwrap();
3477- let mut tile_view_rect = view_rect;
3478- tile_view_rect.loc -= tile_off + tile.render_offset();
3479-
3480 let config = self.tab_indicator.config();3473 let config = self.tab_indicator.config();
3481- let tabs = self.tiles.iter().enumerate().map(|(tile_idx, tile)| {3474+ let offsets = self.tile_offsets_iter(self.data.iter().copied());
3482- let is_active = tile_idx == active_idx;3475+ let tabs = zip(&self.tiles, offsets)
3483- TabInfo::from_tile(tile, is_active, &config)3476+ .enumerate()
3484- });3477+ .map(|(tile_idx, (tile, tile_off))| {
3478+ let is_active = tile_idx == active_idx;
3479+ let tile_pos = tile_off + tile.render_offset();
3480+ TabInfo::from_tile(tile, tile_pos, is_active, &config)
3481+ });
3485 3482
3486 // Hide the tab indicator in fullscreen. If you have it configured to overlap the window,3483 // Hide the tab indicator in fullscreen. If you have it configured to overlap the window,
3487 // you don't want that to happen in fullscreen. Also, laying things out correctly when the3484 // you don't want that to happen in fullscreen. Also, laying things out correctly when the
@@ -3489,10 +3486,13 @@ impl<W: LayoutElement> Column<W> {
3489 // many changes to the code for too little benefit (it's mostly invisible anyway).3486 // many changes to the code for too little benefit (it's mostly invisible anyway).
3490 let enabled = self.display_mode == ColumnDisplay::Tabbed && !self.is_fullscreen;3487 let enabled = self.display_mode == ColumnDisplay::Tabbed && !self.is_fullscreen;
3491 3488
3489+ let area_size = self.tiles[active_idx].animated_tile_size();
3490+
3492 self.tab_indicator.update_render_elements(3491 self.tab_indicator.update_render_elements(
3493 enabled,3492 enabled,
3494- tile.animated_tile_size(),3493+ Rectangle::new(self.tiles_origin(), area_size),
3495- tile_view_rect,3494+ view_rect,
3495+ self.tiles.len(),
3496 tabs,3496 tabs,
3497 is_active,3497 is_active,
3498 self.scale,3498 self.scale,
src/layout/tab_indicator.rsmodified+25 -16
@@ -20,7 +20,10 @@ pub struct TabIndicator {
20 20
21 #[derive(Debug)]21 #[derive(Debug)]
22 pub struct TabInfo {22 pub struct TabInfo {
23+ /// Gradient for the tab indicator.
23 pub gradient: Gradient,24 pub gradient: Gradient,
25+ /// Tab geometry in the same coordinate system as the area.
26+ pub geometry: Rectangle<f64, Logical>,
24 }27 }
25 28
26 niri_render_elements! {29 niri_render_elements! {
@@ -48,12 +51,17 @@ impl TabIndicator {
48 }51 }
49 }52 }
50 53
54+ #[allow(clippy::too_many_arguments)]
51 pub fn update_render_elements(55 pub fn update_render_elements(
52 &mut self,56 &mut self,
53 enabled: bool,57 enabled: bool,
54- tile_size: Size<f64, Logical>,58+ // Geometry of the tabs area.
55- tile_view_rect: Rectangle<f64, Logical>,59+ area: Rectangle<f64, Logical>,
56- tabs: impl Iterator<Item = TabInfo> + Clone,60+ // View rect relative to the tabs area.
61+ area_view_rect: Rectangle<f64, Logical>,
62+ // Tab count, should match the tabs iterator length.
63+ tab_count: usize,
64+ tabs: impl Iterator<Item = TabInfo>,
57 // TODO: do we indicate inactive-but-selected somehow?65 // TODO: do we indicate inactive-but-selected somehow?
58 _is_active: bool,66 _is_active: bool,
59 scale: f64,67 scale: f64,
@@ -64,16 +72,13 @@ impl TabIndicator {
64 return;72 return;
65 }73 }
66 74
67- let count = tabs.clone().count();75+ let count = tab_count;
68 if self.config.hide_when_single_tab && count == 1 {76 if self.config.hide_when_single_tab && count == 1 {
69 self.shader_locs.clear();77 self.shader_locs.clear();
70 self.shaders.clear();78 self.shaders.clear();
71 return;79 return;
72 }80 }
73 81
74- // Tab indicators are rendered relative to the tile geometry.
75- let tile_geo = Rectangle::new(Point::from((0., 0.)), tile_size);
76-
77 let round = |logical: f64| round_logical_in_physical(scale, logical);82 let round = |logical: f64| round_logical_in_physical(scale, logical);
78 83
79 let width = round(self.config.width.0);84 let width = round(self.config.width.0);
@@ -81,8 +86,8 @@ impl TabIndicator {
81 let gaps_between = round(self.config.gaps_between_tabs.0);86 let gaps_between = round(self.config.gaps_between_tabs.0);
82 87
83 let side = match self.config.position {88 let side = match self.config.position {
84- TabIndicatorPosition::Left | TabIndicatorPosition::Right => tile_size.h,89+ TabIndicatorPosition::Left | TabIndicatorPosition::Right => area.size.h,
85- TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => tile_size.w,90+ TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => area.size.w,
86 };91 };
87 let total_prop = self.config.length.total_proportion.unwrap_or(0.5);92 let total_prop = self.config.length.total_proportion.unwrap_or(0.5);
88 let min_length = round(side * total_prop.clamp(0., 2.));93 let min_length = round(side * total_prop.clamp(0., 2.));
@@ -101,13 +106,14 @@ impl TabIndicator {
101 let mut shader_loc = Point::from((-gap - width, round((side - length) / 2.)));106 let mut shader_loc = Point::from((-gap - width, round((side - length) / 2.)));
102 match self.config.position {107 match self.config.position {
103 TabIndicatorPosition::Left => (),108 TabIndicatorPosition::Left => (),
104- TabIndicatorPosition::Right => shader_loc.x = tile_size.w + gap,109+ TabIndicatorPosition::Right => shader_loc.x = area.size.w + gap,
105 TabIndicatorPosition::Top => mem::swap(&mut shader_loc.x, &mut shader_loc.y),110 TabIndicatorPosition::Top => mem::swap(&mut shader_loc.x, &mut shader_loc.y),
106 TabIndicatorPosition::Bottom => {111 TabIndicatorPosition::Bottom => {
107 shader_loc.x = shader_loc.y;112 shader_loc.x = shader_loc.y;
108- shader_loc.y = tile_size.h + gap;113+ shader_loc.y = area.size.h + gap;
109 }114 }
110 }115 }
116+ shader_loc += area.loc;
111 117
112 for ((shader, loc), tab) in zip(&mut self.shaders, &mut self.shader_locs).zip(tabs) {118 for ((shader, loc), tab) in zip(&mut self.shaders, &mut self.shader_locs).zip(tabs) {
113 *loc = shader_loc;119 *loc = shader_loc;
@@ -137,8 +143,8 @@ impl TabIndicator {
137 };143 };
138 144
139 let mut gradient_area = match tab.gradient.relative_to {145 let mut gradient_area = match tab.gradient.relative_to {
140- GradientRelativeTo::Window => tile_geo,146+ GradientRelativeTo::Window => tab.geometry,
141- GradientRelativeTo::WorkspaceView => tile_view_rect,147+ GradientRelativeTo::WorkspaceView => area_view_rect,
142 };148 };
143 gradient_area.loc -= *loc;149 gradient_area.loc -= *loc;
144 150
@@ -161,7 +167,7 @@ impl TabIndicator {
161 pub fn render(167 pub fn render(
162 &self,168 &self,
163 renderer: &mut impl NiriRenderer,169 renderer: &mut impl NiriRenderer,
164- tile_pos: Point<f64, Logical>,170+ pos: Point<f64, Logical>,
165 ) -> impl Iterator<Item = TabIndicatorRenderElement> + '_ {171 ) -> impl Iterator<Item = TabIndicatorRenderElement> + '_ {
166 let has_border_shader = BorderRenderElement::has_shader(renderer);172 let has_border_shader = BorderRenderElement::has_shader(renderer);
167 if !has_border_shader {173 if !has_border_shader {
@@ -169,7 +175,7 @@ impl TabIndicator {
169 }175 }
170 176
171 let rv = zip(&self.shaders, &self.shader_locs)177 let rv = zip(&self.shaders, &self.shader_locs)
172- .map(move |(shader, loc)| shader.clone().with_location(tile_pos + *loc))178+ .map(move |(shader, loc)| shader.clone().with_location(pos + *loc))
173 .map(TabIndicatorRenderElement::from);179 .map(TabIndicatorRenderElement::from);
174 180
175 Some(rv).into_iter().flatten()181 Some(rv).into_iter().flatten()
@@ -216,6 +222,7 @@ impl TabIndicator {
216 impl TabInfo {222 impl TabInfo {
217 pub fn from_tile<W: LayoutElement>(223 pub fn from_tile<W: LayoutElement>(
218 tile: &Tile<W>,224 tile: &Tile<W>,
225+ position: Point<f64, Logical>,
219 is_active: bool,226 is_active: bool,
220 config: &niri_config::TabIndicator,227 config: &niri_config::TabIndicator,
221 ) -> Self {228 ) -> Self {
@@ -265,6 +272,8 @@ impl TabInfo {
265 .or_else(gradient_from_config)272 .or_else(gradient_from_config)
266 .unwrap_or_else(gradient_from_border);273 .unwrap_or_else(gradient_from_border);
267 274
268- TabInfo { gradient }275+ let geometry = Rectangle::new(position, tile.animated_tile_size());
276+
277+ TabInfo { gradient, geometry }
269 }278 }
270 }279 }