tab indicator: Add position setting
Browse files at this commit64544a572698b2df5520783203f9723a2dfcac12Parent: d7d5a7f3 changed files +62 -6
- niri-config/src/lib.rs +13 -0
- src/layout/tab_indicator.rs +34 -5
- src/layout/tests.rs +15 -1
niri-config/src/lib.rsmodified+13 -0
| @@ -691,6 +691,8 @@ pub struct TabIndicator { | ||
| 691 | 691 | pub width: FloatOrInt<0, 65535>, |
| 692 | 692 | #[knuffel(child, default = Self::default().length)] |
| 693 | 693 | pub length: TabIndicatorLength, |
| 694 | + #[knuffel(child, unwrap(argument), default = Self::default().position)] | |
| 695 | + pub position: TabIndicatorPosition, | |
| 694 | 696 | #[knuffel(child)] |
| 695 | 697 | pub active_color: Option<Color>, |
| 696 | 698 | #[knuffel(child)] |
| @@ -711,6 +713,7 @@ impl Default for TabIndicator { | ||
| 711 | 713 | length: TabIndicatorLength { |
| 712 | 714 | total_proportion: Some(0.5), |
| 713 | 715 | }, |
| 716 | + position: TabIndicatorPosition::Left, | |
| 714 | 717 | active_color: None, |
| 715 | 718 | inactive_color: None, |
| 716 | 719 | active_gradient: None, |
| @@ -725,6 +728,14 @@ pub struct TabIndicatorLength { | ||
| 725 | 728 | pub total_proportion: Option<f64>, |
| 726 | 729 | } |
| 727 | 730 | |
| 731 | +#[derive(knuffel::DecodeScalar, Debug, Clone, Copy, PartialEq)] | |
| 732 | +pub enum TabIndicatorPosition { | |
| 733 | + Left, | |
| 734 | + Right, | |
| 735 | + Top, | |
| 736 | + Bottom, | |
| 737 | +} | |
| 738 | + | |
| 728 | 739 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] |
| 729 | 740 | pub struct InsertHint { |
| 730 | 741 | #[knuffel(child)] |
| @@ -3555,6 +3566,7 @@ mod tests { | ||
| 3555 | 3566 | |
| 3556 | 3567 | tab-indicator { |
| 3557 | 3568 | width 10 |
| 3569 | + position "top" | |
| 3558 | 3570 | } |
| 3559 | 3571 | |
| 3560 | 3572 | preset-column-widths { |
| @@ -3819,6 +3831,7 @@ mod tests { | ||
| 3819 | 3831 | }, |
| 3820 | 3832 | tab_indicator: TabIndicator { |
| 3821 | 3833 | width: FloatOrInt(10.), |
| 3834 | + position: TabIndicatorPosition::Top, | |
| 3822 | 3835 | ..Default::default() |
| 3823 | 3836 | }, |
| 3824 | 3837 | insert_hint: InsertHint { |
src/layout/tab_indicator.rsmodified+34 -5
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | use std::iter::zip; |
| 2 | +use std::mem; | |
| 2 | 3 | |
| 3 | -use niri_config::{CornerRadius, Gradient, GradientRelativeTo}; | |
| 4 | +use niri_config::{CornerRadius, Gradient, GradientRelativeTo, TabIndicatorPosition}; | |
| 4 | 5 | use smithay::utils::{Logical, Point, Rectangle, Size}; |
| 5 | 6 | |
| 6 | 7 | use super::tile::Tile; |
| @@ -78,8 +79,12 @@ impl TabIndicator { | ||
| 78 | 79 | let width = round(self.config.width.0); |
| 79 | 80 | let gap = round(self.config.gap.0); |
| 80 | 81 | |
| 82 | + let side = match self.config.position { | |
| 83 | + TabIndicatorPosition::Left | TabIndicatorPosition::Right => tile_size.h, | |
| 84 | + TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => tile_size.w, | |
| 85 | + }; | |
| 81 | 86 | let total_prop = self.config.length.total_proportion.unwrap_or(0.5); |
| 82 | - let min_length = round(tile_size.h * total_prop.clamp(0., 2.)); | |
| 87 | + let min_length = round(side * total_prop.clamp(0., 2.)); | |
| 83 | 88 | |
| 84 | 89 | self.shaders.resize_with(count, Default::default); |
| 85 | 90 | self.shader_locs.resize_with(count, Default::default); |
| @@ -92,7 +97,16 @@ impl TabIndicator { | ||
| 92 | 97 | let floored_length = count as f64 * px_per_tab; |
| 93 | 98 | let mut ones_left = ((length - floored_length) / pixel).max(0.).round() as usize; |
| 94 | 99 | |
| 95 | - let mut shader_loc = Point::from((-gap - width, round((tile_size.h - length) / 2.))); | |
| 100 | + let mut shader_loc = Point::from((-gap - width, round((side - length) / 2.))); | |
| 101 | + match self.config.position { | |
| 102 | + TabIndicatorPosition::Left => (), | |
| 103 | + TabIndicatorPosition::Right => shader_loc.x = tile_size.w + gap, | |
| 104 | + TabIndicatorPosition::Top => mem::swap(&mut shader_loc.x, &mut shader_loc.y), | |
| 105 | + TabIndicatorPosition::Bottom => { | |
| 106 | + shader_loc.x = shader_loc.y; | |
| 107 | + shader_loc.y = tile_size.h + gap; | |
| 108 | + } | |
| 109 | + } | |
| 96 | 110 | |
| 97 | 111 | for ((shader, loc), tab) in zip(&mut self.shaders, &mut self.shader_locs).zip(tabs) { |
| 98 | 112 | *loc = shader_loc; |
| @@ -102,9 +116,24 @@ impl TabIndicator { | ||
| 102 | 116 | ones_left -= 1; |
| 103 | 117 | px_per_tab += pixel; |
| 104 | 118 | } |
| 105 | - shader_loc.y += px_per_tab; | |
| 106 | 119 | |
| 107 | - let shader_size = Size::from((width, px_per_tab)); | |
| 120 | + match self.config.position { | |
| 121 | + TabIndicatorPosition::Left | TabIndicatorPosition::Right => { | |
| 122 | + shader_loc.y += px_per_tab | |
| 123 | + } | |
| 124 | + TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => { | |
| 125 | + shader_loc.x += px_per_tab | |
| 126 | + } | |
| 127 | + } | |
| 128 | + | |
| 129 | + let shader_size = match self.config.position { | |
| 130 | + TabIndicatorPosition::Left | TabIndicatorPosition::Right => { | |
| 131 | + Size::from((width, px_per_tab)) | |
| 132 | + } | |
| 133 | + TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => { | |
| 134 | + Size::from((px_per_tab, width)) | |
| 135 | + } | |
| 136 | + }; | |
| 108 | 137 | |
| 109 | 138 | let mut gradient_area = match tab.gradient.relative_to { |
| 110 | 139 | GradientRelativeTo::Window => tile_geo, |
src/layout/tests.rsmodified+15 -1
| @@ -1,6 +1,9 @@ | ||
| 1 | 1 | use std::cell::Cell; |
| 2 | 2 | |
| 3 | -use niri_config::{FloatOrInt, OutputName, TabIndicatorLength, WorkspaceName, WorkspaceReference}; | |
| 3 | +use niri_config::{ | |
| 4 | + FloatOrInt, OutputName, TabIndicatorLength, TabIndicatorPosition, WorkspaceName, | |
| 5 | + WorkspaceReference, | |
| 6 | +}; | |
| 4 | 7 | use proptest::prelude::*; |
| 5 | 8 | use proptest_derive::Arbitrary; |
| 6 | 9 | use smithay::output::{Mode, PhysicalProperties, Subpixel}; |
| @@ -3200,6 +3203,15 @@ fn arbitrary_center_focused_column() -> impl Strategy<Value = CenterFocusedColum | ||
| 3200 | 3203 | ] |
| 3201 | 3204 | } |
| 3202 | 3205 | |
| 3206 | +fn arbitrary_tab_indicator_position() -> impl Strategy<Value = TabIndicatorPosition> { | |
| 3207 | + prop_oneof![ | |
| 3208 | + Just(TabIndicatorPosition::Left), | |
| 3209 | + Just(TabIndicatorPosition::Right), | |
| 3210 | + Just(TabIndicatorPosition::Top), | |
| 3211 | + Just(TabIndicatorPosition::Bottom), | |
| 3212 | + ] | |
| 3213 | +} | |
| 3214 | + | |
| 3203 | 3215 | prop_compose! { |
| 3204 | 3216 | fn arbitrary_focus_ring()( |
| 3205 | 3217 | off in any::<bool>(), |
| @@ -3246,6 +3258,7 @@ prop_compose! { | ||
| 3246 | 3258 | width in arbitrary_spacing(), |
| 3247 | 3259 | gap in arbitrary_spacing_neg(), |
| 3248 | 3260 | length in (0f64..2f64), |
| 3261 | + position in arbitrary_tab_indicator_position(), | |
| 3249 | 3262 | ) -> niri_config::TabIndicator { |
| 3250 | 3263 | niri_config::TabIndicator { |
| 3251 | 3264 | off, |
| @@ -3253,6 +3266,7 @@ prop_compose! { | ||
| 3253 | 3266 | width: FloatOrInt(width), |
| 3254 | 3267 | gap: FloatOrInt(gap), |
| 3255 | 3268 | length: TabIndicatorLength { total_proportion: Some(length) }, |
| 3269 | + position, | |
| 3256 | 3270 | ..Default::default() |
| 3257 | 3271 | } |
| 3258 | 3272 | } |